#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

#define LY 9460730472580800 // Light-year
#define G 6.67408e-11

#define BLOCK_Z 1
#define BLOCK_Y 1
#define BLOCK_X 1024 
#define GRID_Z 1
#define GRID_Y 1
#define GRID_X 1024
#define TotalPoint BLOCK_X * BLOCK_Y * BLOCK_Z * GRID_X * GRID_Y * GRID_Z
#define BlackHoles 100
#define rool 40

#define dt 10 * 365 * 24 * 3600.0f
#define half_dt dt/2
#define BodiesPerSave TotalPoint*(TotalPoint/ 1000000000.0)*rool

#define Rx_u 300 * LY
#define Ry_u 300 * LY
#define Rz_u 300 * LY
#define Rx_l -300 * LY
#define Ry_l -300 * LY
#define Rz_l -300 * LY

#define Rvx_u 1e6
#define Rvy_u 1e6
#define Rvz_u 1e6
#define Rvx_l -1e6
#define Rvy_l -1e6
#define Rvz_l -1e6

#define Rm_u 1e30
#define Rm_l 1e10

#define fix 1e3

#define flopf (19*TotalPoint + 15)*1e-9
#define flopS flopf*rool*TotalPoint

void GenerateRandomPoints(float4 *Point, float4 *Point_v) {
  srand(time(NULL));
  //Generate random location for points.
  for (int Tv=0; Tv < TotalPoint; Tv++) {
    Point[Tv].x = rand()/(float)RAND_MAX * (Rx_u - Rx_l) + Rx_l;
    Point[Tv].y = rand()/(float)RAND_MAX * (Ry_u - Ry_l) + Ry_l;
    Point[Tv].z = rand()/(float)RAND_MAX * (Rz_u - Rz_l) + Rz_l;
    
    //Point_Gmdt = Point.w
    Point[Tv].w = rand()/(float)RAND_MAX * (Rm_u + Rm_l) * G * dt;
    
    Point_v[Tv].x = rand()/(float)RAND_MAX * (Rvx_u - Rvx_l) + Rvx_l;
    Point_v[Tv].y = rand()/(float)RAND_MAX * (Rvy_u - Rvy_l) + Rvy_l;
    Point_v[Tv].z = rand()/(float)RAND_MAX * (Rvz_u - Rvz_l) + Rvz_l;
  }
  
  for (int Tv=0; Tv < BlackHoles; Tv++) {
    Point[Tv].w = 1e10 * Rm_u * G * dt;
  }
}

void Save(float4 *Point) {
  FILE *save;
  if ((save=fopen("data.data", "a+")) == NULL) {
    printf("Can't save data.\n");
  }
  
  //Data = [[x1, x2, ...], [y1, y2, ...], [z1, z2, ...]]
  fprintf(save, "[");
  //Print P_xs;
  fprintf(save, "[");
  for (int i=0; i < TotalPoint; i++) {
    fprintf(save, "%.2f", Point[i].x);
    if (i != TotalPoint-1)
      fprintf(save, ", ");
  }
  fprintf(save, "]");
  
  //Print P_ys;
  fprintf(save, ", [");
  for (int i=0; i < TotalPoint; i++) {
    fprintf(save, "%.2f", Point[i].y);
    if (i != TotalPoint-1)
      fprintf(save, ", ");
  }
  fprintf(save, "]");
  
  //Print P_zs;
  fprintf(save, ", [");
  for (int i=0; i < TotalPoint; i++) {
    fprintf(save, "%.2f", Point[i].z);
    if (i != TotalPoint-1)
      fprintf(save, ", ");
  }
  fprintf(save, "]");
  fprintf(save, "]\n"); // The end.
  
  fclose(save);
}

__global__ void CaculateTheNextTick(float4 *Point, float4 *Point_v, float4 *T) {
         
  int i =  blockIdx.x * blockDim.x + threadIdx.x; // Get thread's index

  //if (i < TotalPoint) {
    float da_i = 0.0f;
    float rd = 0.0f; 

    float x_i = Point[i].x;
    float y_i = Point[i].y;
    float z_i = Point[i].z;
    
    float dx = 0.0f;
    float dy = 0.0f;
    float dz = 0.0f;
    
    float da_ix = 0.0f;
    float da_iy = 0.0f;
    float da_iz = 0.0f;
    
    __shared__ float4 Temp[BLOCK_X];
#pragma unroll 
    for (int tile=0; tile < gridDim.x; tile++) { 
      Temp[threadIdx.x] = Point[tile * blockDim.x + threadIdx.x]; 
      __syncthreads(); 
      
      for (int j=0; j<BLOCK_X; j++) {
        dx = Temp[j].x - x_i;//1 flo
        dy = Temp[j].y - y_i;//1 flo
        dz = Temp[j].z - z_i;//1 flo
      
        rd = rsqrtf((dx * dx) + (dy * dy) + (dz * dz) + fix);//7 flo
        da_i = Temp[j].w * rd * rd * rd;//3 flo
        da_ix += dx * da_i;//2 flo
        da_iy += dy * da_i;//2 flo
        da_iz += dz * da_i;//2 flo
      }//total 19 * TotalPoint flo 
      __syncthreads(); 
    }
    
    T[i].x = x_i + Point_v[i].x * dt + half_dt * da_ix;//4 flo
    T[i].y = y_i + Point_v[i].y * dt + half_dt * da_iy;//4 flo
    T[i].z = z_i + Point_v[i].z * dt + half_dt * da_iz;//4 flo
    
    Point_v[i].x = Point_v[i].x + da_ix;//1 flo
    Point_v[i].y = Point_v[i].y + da_iy;//1 flo
    Point_v[i].z = Point_v[i].z + da_iz;//1 flo
  //}//total 15 + 19*TotalPoint flo
}

int main() {
  //Define what we need on CPU.
  float4 *Point;
  
  float4 *Point_v;
  
  Point = (float4 *)malloc(TotalPoint * sizeof(float4));
  Point_v = (float4 *)malloc(TotalPoint * sizeof(float4));
  
  //Define what we need on GPU.
  float4 *GPU_Point;
  
  float4 *GPU_Point_v;

  float4 *GPU_T;
  
  cudaMalloc((void**)&GPU_Point, TotalPoint * sizeof(float4));
  cudaMalloc((void**)&GPU_Point_v, TotalPoint * sizeof(float4));
  cudaMalloc((void**)&GPU_T, TotalPoint * sizeof(float4));
  
  int count = 0;
  float starttime, endtime;
  
  dim3 grid(GRID_X, GRID_Y, GRID_Z); 
  dim3 block(BLOCK_X, BLOCK_Y, BLOCK_Z);

  FILE *save;
  if ((save=fopen("data.data", "w")) == NULL) {
    printf("Can't save data.\n");
  }
  fclose(save);
  //Generate random point.
  GenerateRandomPoints(Point, Point_v);
  cudaMemcpy(GPU_Point, Point, TotalPoint * sizeof(float4), cudaMemcpyHostToDevice);
  cudaMemcpy(GPU_Point_v, Point_v, TotalPoint * sizeof(float4), cudaMemcpyHostToDevice);
  free(Point_v);

  printf("Start calc. N=%d, dt=%f, frame per save=%d\n", TotalPoint, dt, rool);
  while (1==1) {
    count++;
    
    printf("[Save %d]: Computing... ", count);
    //Caculate the location of next tick.
    starttime = clock();
    
    for (int k=0; k < rool; k++) {
      if (k%2) {
        CaculateTheNextTick<<<grid, block>>>(GPU_T, GPU_Point_v, GPU_Point);
      } else {
        CaculateTheNextTick<<<grid, block>>>(GPU_Point, GPU_Point_v, GPU_T);
      }
      //cudaDeviceSynchronize();
      cudaThreadSynchronize();
      //Update the locations of particles.
      //cudaMemcpy(GPU_Point_x, GPU_T_x, size, cudaMemcpyDeviceToDevice);
      //cudaMemcpy(GPU_Point_y, GPU_T_y, size, cudaMemcpyDeviceToDevice);
      //cudaMemcpy(GPU_Point_z, GPU_T_z, size, cudaMemcpyDeviceToDevice);
    } 
    
    endtime = clock();
    cudaMemcpy(Point, GPU_T, TotalPoint * sizeof(float4), cudaMemcpyDeviceToHost);
    printf("Done. %.2lf fps, %.3lf Sps, %.2lf GBps, %.2lf GFLOPS",
            rool / (endtime-starttime)*CLOCKS_PER_SEC,
            1 / (endtime-starttime)*CLOCKS_PER_SEC,
            BodiesPerSave / (endtime-starttime)*CLOCKS_PER_SEC,
            flopS / (endtime-starttime)*CLOCKS_PER_SEC);
    printf(" Saving... ");
    Save(Point);
    printf("Done. \n");
  }
  //fclose(save);
  //General end of C programs.
  return 0;
}

	.file	"tmpxft_00388306_00000000-6_Nbody.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z20GenerateRandomPointsP6float4S0_
	.type	_Z20GenerateRandomPointsP6float4S0_, @function
_Z20GenerateRandomPointsP6float4S0_:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	xorl	%edi, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
.L3:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC1(%rip), %xmm0
	subss	.LC2(%rip), %xmm0
	movss	%xmm0, 0(%rbp,%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC1(%rip), %xmm0
	subss	.LC2(%rip), %xmm0
	movss	%xmm0, 4(%rbp,%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC1(%rip), %xmm0
	subss	.LC2(%rip), %xmm0
	movss	%xmm0, 8(%rbp,%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC3(%rip), %xmm0
	mulsd	.LC4(%rip), %xmm0
	mulsd	.LC5(%rip), %xmm0
	mulsd	.LC6(%rip), %xmm0
	mulsd	.LC7(%rip), %xmm0
	mulsd	.LC8(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 12(%rbp,%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC9(%rip), %xmm0
	subsd	.LC10(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r12,%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC9(%rip), %xmm0
	subsd	.LC10(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 4(%r12,%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC9(%rip), %xmm0
	subsd	.LC10(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 8(%r12,%rbx)
	addq	$16, %rbx
	cmpq	$16777216, %rbx
	jne	.L3
	movss	.LC11(%rip), %xmm0
	xorl	%eax, %eax
.L4:
	movss	%xmm0, 12(%rbp,%rax)
	addq	$16, %rax
	cmpq	$1600, %rax
	jne	.L4
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z20GenerateRandomPointsP6float4S0_, .-_Z20GenerateRandomPointsP6float4S0_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC12:
	.string	"a+"
.LC13:
	.string	"data.data"
.LC14:
	.string	"Can't save data.\n"
.LC15:
	.string	"["
.LC16:
	.string	"%.2f"
.LC17:
	.string	"]"
.LC18:
	.string	", ["
.LC19:
	.string	", "
.LC20:
	.string	"]\n"
	.text
	.globl	_Z4SaveP6float4
	.type	_Z4SaveP6float4, @function
_Z4SaveP6float4:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC12(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	leaq	.LC13(%rip), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%rdx
	.cfi_def_cfa_offset 64
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L10
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L10:
	leaq	.LC15(%rip), %r12
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movq	%r12, %rdx
	leaq	16777216(%rbp), %r13
	call	__fprintf_chk@PLT
	movq	%r12, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movq	%rbp, %r12
	call	__fprintf_chk@PLT
.L13:
	cvtss2sd	(%r12), %xmm0
	leaq	.LC16(%rip), %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	addq	$16, %r12
	call	__fprintf_chk@PLT
	cmpq	%r13, %r12
	jne	.L11
	leaq	.LC17(%rip), %r13
	movq	%rbx, %rdi
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	movq	%r13, %rdx
	movl	$2, %esi
	leaq	.LC18(%rip), %r14
	call	__fprintf_chk@PLT
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	.LC19(%rip), %r15
	call	__fprintf_chk@PLT
	jmp	.L12
.L11:
	leaq	.LC19(%rip), %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L13
.L14:
	movq	%r15, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L12:
	cvtss2sd	4(%rbp,%r12), %xmm0
	leaq	.LC16(%rip), %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	addq	$16, %r12
	call	__fprintf_chk@PLT
	cmpq	$16777216, %r12
	jne	.L14
	movq	%r13, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	leaq	.LC19(%rip), %r14
	call	__fprintf_chk@PLT
	jmp	.L15
.L16:
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L15:
	cvtss2sd	8(%rbp,%r12), %xmm0
	leaq	.LC16(%rip), %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	addq	$16, %r12
	call	__fprintf_chk@PLT
	cmpq	$16777216, %r12
	jne	.L16
	movq	%r13, %rdx
	movq	%rbx, %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC20(%rip), %rdx
	call	__fprintf_chk@PLT
	popq	%rax
	.cfi_def_cfa_offset 56
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z4SaveP6float4, .-_Z4SaveP6float4
	.globl	_Z51__device_stub__Z19CaculateTheNextTickP6float4S0_S0_P6float4S0_S0_
	.type	_Z51__device_stub__Z19CaculateTheNextTickP6float4S0_S0_P6float4S0_S0_, @function
_Z51__device_stub__Z19CaculateTheNextTickP6float4S0_S0_P6float4S0_S0_:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z19CaculateTheNextTickP6float4S0_S0_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L18:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z51__device_stub__Z19CaculateTheNextTickP6float4S0_S0_P6float4S0_S0_, .-_Z51__device_stub__Z19CaculateTheNextTickP6float4S0_S0_P6float4S0_S0_
	.globl	_Z19CaculateTheNextTickP6float4S0_S0_
	.type	_Z19CaculateTheNextTickP6float4S0_S0_, @function
_Z19CaculateTheNextTickP6float4S0_S0_:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z51__device_stub__Z19CaculateTheNextTickP6float4S0_S0_P6float4S0_S0_
	.cfi_endproc
.LFE2055:
	.size	_Z19CaculateTheNextTickP6float4S0_S0_, .-_Z19CaculateTheNextTickP6float4S0_S0_
	.section	.rodata.str1.1
.LC21:
	.string	"w"
.LC23:
	.string	"Start calc. N=%d, dt=%f, frame per save=%d\n"
.LC24:
	.string	"[Save %d]: Computing... "
.LC30:
	.string	"Done. %.2lf fps, %.3lf Sps, %.2lf GBps, %.2lf GFLOPS"
.LC31:
	.string	" Saving... "
.LC32:
	.string	"Done. \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$16777216, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$88, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$16777216, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	leaq	24(%rsp), %rdi
	movl	$16777216, %esi
	movq	%rax, %rbp
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$16777216, %esi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movl	$16777216, %esi
	call	cudaMalloc@PLT
	movl	$4194305, %eax
	leaq	.LC21(%rip), %rsi
	leaq	.LC13(%rip), %rdi
	salq	$10, %rax
	movl	$1, 56(%rsp)
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	fopen@PLT
	movq	%rax, %r12
	testq	%rax, %rax
	jne	.L24
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L24:
	movq	%r12, %rdi
	leaq	.LC24(%rip), %r12
	call	fclose@PLT
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	_Z20GenerateRandomPointsP6float4S0_
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$16777216, %edx
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	movl	$16777216, %edx
	call	cudaMemcpy@PLT
	movq	%rbp, %rdi
	xorl	%ebp, %ebp
	call	free@PLT
	movsd	.LC22(%rip), %xmm0
	movb	$1, %al
	movl	$40, %ecx
	movl	$1048576, %edx
	leaq	.LC23(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
.L30:
	incl	%ebp
	movq	%r12, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movl	%ebp, %edx
	xorl	%r13d, %r13d
	call	__printf_chk@PLT
	call	clock@PLT
	cvtsi2ssq	%rax, %xmm7
	movss	%xmm7, 8(%rsp)
.L29:
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	60(%rsp), %rdx
	movl	68(%rsp), %ecx
	testl	$1, %r13d
	movq	48(%rsp), %rdi
	movl	56(%rsp), %esi
	je	.L25
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	24(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	40(%rsp), %rdi
	jmp	.L34
.L25:
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
.L34:
	call	_Z51__device_stub__Z19CaculateTheNextTickP6float4S0_S0_P6float4S0_S0_
.L27:
	call	cudaThreadSynchronize@PLT
	incl	%r13d
	cmpl	$40, %r13d
	jne	.L29
	call	clock@PLT
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	cvtsi2ssq	%rax, %xmm4
	movl	$16777216, %edx
	movss	%xmm4, 12(%rsp)
	call	cudaMemcpy@PLT
	movss	12(%rsp), %xmm4
	movb	$4, %al
	subss	8(%rsp), %xmm4
	movsd	.LC25(%rip), %xmm3
	movsd	.LC26(%rip), %xmm2
	leaq	.LC30(%rip), %rsi
	movl	$2, %edi
	movss	.LC27(%rip), %xmm1
	movsd	.LC10(%rip), %xmm5
	cvtss2sd	%xmm4, %xmm0
	divsd	%xmm0, %xmm3
	movss	.LC28(%rip), %xmm6
	divsd	%xmm0, %xmm2
	movss	.LC29(%rip), %xmm0
	mulsd	%xmm5, %xmm3
	divss	%xmm4, %xmm1
	mulsd	%xmm5, %xmm2
	divss	%xmm4, %xmm0
	mulss	%xmm6, %xmm1
	cvtss2sd	%xmm1, %xmm1
	mulss	%xmm6, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC31(%rip), %rsi
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	_Z4SaveP6float4
	leaq	.LC32(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L30
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC33:
	.string	"_Z19CaculateTheNextTickP6float4S0_S0_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC33(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z19CaculateTheNextTickP6float4S0_S0_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2057:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.align 4
.LC1:
	.long	1587383685
	.align 4
.LC2:
	.long	1578995077
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	966823146
	.long	1177108057
	.align 8
.LC4:
	.long	1580726787
	.long	1037195383
	.align 8
.LC5:
	.long	0
	.long	1076101120
	.align 8
.LC6:
	.long	0
	.long	1081528320
	.align 8
.LC7:
	.long	0
	.long	1077411840
	.align 8
.LC8:
	.long	0
	.long	1085022208
	.align 8
.LC9:
	.long	0
	.long	1094616192
	.align 8
.LC10:
	.long	0
	.long	1093567616
	.section	.rodata.cst4
	.align 4
.LC11:
	.long	2132694983
	.section	.rodata.cst8
	.align 8
.LC22:
	.long	0
	.long	1102236675
	.align 8
.LC25:
	.long	-289864250
	.long	1093238874
	.align 8
.LC26:
	.long	-500134854
	.long	1088780686
	.section	.rodata.cst4
	.align 4
.LC27:
	.long	1065353216
	.align 4
.LC28:
	.long	1232348160
	.align 4
.LC29:
	.long	1109393408
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

#define LY 9460730472580800 // Light-year
#define G 6.67408e-11

#define BLOCK_Z 1
#define BLOCK_Y 1
#define BLOCK_X 1024 
#define GRID_Z 1
#define GRID_Y 1
#define GRID_X 1024
#define TotalPoint BLOCK_X * BLOCK_Y * BLOCK_Z * GRID_X * GRID_Y * GRID_Z
#define BlackHoles 100
#define rool 40

#define dt 10 * 365 * 24 * 3600.0f
#define half_dt dt/2
#define BodiesPerSave TotalPoint*(TotalPoint/ 1000000000.0)*rool

#define Rx_u 300 * LY
#define Ry_u 300 * LY
#define Rz_u 300 * LY
#define Rx_l -300 * LY
#define Ry_l -300 * LY
#define Rz_l -300 * LY

#define Rvx_u 1e6
#define Rvy_u 1e6
#define Rvz_u 1e6
#define Rvx_l -1e6
#define Rvy_l -1e6
#define Rvz_l -1e6

#define Rm_u 1e30
#define Rm_l 1e10

#define fix 1e3

#define flopf (19*TotalPoint + 15)*1e-9
#define flopS flopf*rool*TotalPoint

void GenerateRandomPoints(float4 *Point, float4 *Point_v) {
  srand(time(NULL));
  //Generate random location for points.
  for (int Tv=0; Tv < TotalPoint; Tv++) {
    Point[Tv].x = rand()/(float)RAND_MAX * (Rx_u - Rx_l) + Rx_l;
    Point[Tv].y = rand()/(float)RAND_MAX * (Ry_u - Ry_l) + Ry_l;
    Point[Tv].z = rand()/(float)RAND_MAX * (Rz_u - Rz_l) + Rz_l;
    
    //Point_Gmdt = Point.w
    Point[Tv].w = rand()/(float)RAND_MAX * (Rm_u + Rm_l) * G * dt;
    
    Point_v[Tv].x = rand()/(float)RAND_MAX * (Rvx_u - Rvx_l) + Rvx_l;
    Point_v[Tv].y = rand()/(float)RAND_MAX * (Rvy_u - Rvy_l) + Rvy_l;
    Point_v[Tv].z = rand()/(float)RAND_MAX * (Rvz_u - Rvz_l) + Rvz_l;
  }
  
  for (int Tv=0; Tv < BlackHoles; Tv++) {
    Point[Tv].w = 1e10 * Rm_u * G * dt;
  }
}

void Save(float4 *Point) {
  FILE *save;
  if ((save=fopen("data.data", "a+")) == NULL) {
    printf("Can't save data.\n");
  }
  
  //Data = [[x1, x2, ...], [y1, y2, ...], [z1, z2, ...]]
  fprintf(save, "[");
  //Print P_xs;
  fprintf(save, "[");
  for (int i=0; i < TotalPoint; i++) {
    fprintf(save, "%.2f", Point[i].x);
    if (i != TotalPoint-1)
      fprintf(save, ", ");
  }
  fprintf(save, "]");
  
  //Print P_ys;
  fprintf(save, ", [");
  for (int i=0; i < TotalPoint; i++) {
    fprintf(save, "%.2f", Point[i].y);
    if (i != TotalPoint-1)
      fprintf(save, ", ");
  }
  fprintf(save, "]");
  
  //Print P_zs;
  fprintf(save, ", [");
  for (int i=0; i < TotalPoint; i++) {
    fprintf(save, "%.2f", Point[i].z);
    if (i != TotalPoint-1)
      fprintf(save, ", ");
  }
  fprintf(save, "]");
  fprintf(save, "]\n"); // The end.
  
  fclose(save);
}

__global__ void CaculateTheNextTick(float4 *Point, float4 *Point_v, float4 *T) {
         
  int i =  blockIdx.x * blockDim.x + threadIdx.x; // Get thread's index

  //if (i < TotalPoint) {
    float da_i = 0.0f;
    float rd = 0.0f; 

    float x_i = Point[i].x;
    float y_i = Point[i].y;
    float z_i = Point[i].z;
    
    float dx = 0.0f;
    float dy = 0.0f;
    float dz = 0.0f;
    
    float da_ix = 0.0f;
    float da_iy = 0.0f;
    float da_iz = 0.0f;
    
    __shared__ float4 Temp[BLOCK_X];
#pragma unroll 
    for (int tile=0; tile < gridDim.x; tile++) { 
      Temp[threadIdx.x] = Point[tile * blockDim.x + threadIdx.x]; 
      __syncthreads(); 
      
      for (int j=0; j<BLOCK_X; j++) {
        dx = Temp[j].x - x_i;//1 flo
        dy = Temp[j].y - y_i;//1 flo
        dz = Temp[j].z - z_i;//1 flo
      
        rd = rsqrtf((dx * dx) + (dy * dy) + (dz * dz) + fix);//7 flo
        da_i = Temp[j].w * rd * rd * rd;//3 flo
        da_ix += dx * da_i;//2 flo
        da_iy += dy * da_i;//2 flo
        da_iz += dz * da_i;//2 flo
      }//total 19 * TotalPoint flo 
      __syncthreads(); 
    }
    
    T[i].x = x_i + Point_v[i].x * dt + half_dt * da_ix;//4 flo
    T[i].y = y_i + Point_v[i].y * dt + half_dt * da_iy;//4 flo
    T[i].z = z_i + Point_v[i].z * dt + half_dt * da_iz;//4 flo
    
    Point_v[i].x = Point_v[i].x + da_ix;//1 flo
    Point_v[i].y = Point_v[i].y + da_iy;//1 flo
    Point_v[i].z = Point_v[i].z + da_iz;//1 flo
  //}//total 15 + 19*TotalPoint flo
}

int main() {
  //Define what we need on CPU.
  float4 *Point;
  
  float4 *Point_v;
  
  Point = (float4 *)malloc(TotalPoint * sizeof(float4));
  Point_v = (float4 *)malloc(TotalPoint * sizeof(float4));
  
  //Define what we need on GPU.
  float4 *GPU_Point;
  
  float4 *GPU_Point_v;

  float4 *GPU_T;
  
  hipMalloc((void**)&GPU_Point, TotalPoint * sizeof(float4));
  hipMalloc((void**)&GPU_Point_v, TotalPoint * sizeof(float4));
  hipMalloc((void**)&GPU_T, TotalPoint * sizeof(float4));
  
  int count = 0;
  float starttime, endtime;
  
  dim3 grid(GRID_X, GRID_Y, GRID_Z); 
  dim3 block(BLOCK_X, BLOCK_Y, BLOCK_Z);

  FILE *save;
  if ((save=fopen("data.data", "w")) == NULL) {
    printf("Can't save data.\n");
  }
  fclose(save);
  //Generate random point.
  GenerateRandomPoints(Point, Point_v);
  hipMemcpy(GPU_Point, Point, TotalPoint * sizeof(float4), hipMemcpyHostToDevice);
  hipMemcpy(GPU_Point_v, Point_v, TotalPoint * sizeof(float4), hipMemcpyHostToDevice);
  free(Point_v);

  printf("Start calc. N=%d, dt=%f, frame per save=%d\n", TotalPoint, dt, rool);
  while (1==1) {
    count++;
    
    printf("[Save %d]: Computing... ", count);
    //Caculate the location of next tick.
    starttime = clock();
    
    for (int k=0; k < rool; k++) {
      if (k%2) {
        CaculateTheNextTick<<<grid, block>>>(GPU_T, GPU_Point_v, GPU_Point);
      } else {
        CaculateTheNextTick<<<grid, block>>>(GPU_Point, GPU_Point_v, GPU_T);
      }
      //cudaDeviceSynchronize();
      hipDeviceSynchronize();
      //Update the locations of particles.
      //cudaMemcpy(GPU_Point_x, GPU_T_x, size, cudaMemcpyDeviceToDevice);
      //cudaMemcpy(GPU_Point_y, GPU_T_y, size, cudaMemcpyDeviceToDevice);
      //cudaMemcpy(GPU_Point_z, GPU_T_z, size, cudaMemcpyDeviceToDevice);
    } 
    
    endtime = clock();
    hipMemcpy(Point, GPU_T, TotalPoint * sizeof(float4), hipMemcpyDeviceToHost);
    printf("Done. %.2lf fps, %.3lf Sps, %.2lf GBps, %.2lf GFLOPS",
            rool / (endtime-starttime)*CLOCKS_PER_SEC,
            1 / (endtime-starttime)*CLOCKS_PER_SEC,
            BodiesPerSave / (endtime-starttime)*CLOCKS_PER_SEC,
            flopS / (endtime-starttime)*CLOCKS_PER_SEC);
    printf(" Saving... ");
    Save(Point);
    printf("Done. \n");
  }
  //fclose(save);
  //General end of C programs.
  return 0;
}

	.text
	.file	"Nbody.hip"
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z20GenerateRandomPointsP15HIP_vector_typeIfLj4EES1_
.LCPI0_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI0_1:
	.long	0x5e9d8d85                      # float 5.67643824E+18
.LCPI0_2:
	.long	0xde1d8d85                      # float -2.83821912E+18
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI0_3:
	.quad	0x46293e5939a08cea              # double 1.0E+30
.LCPI0_4:
	.quad	0x3dd258775e37fa03              # double 6.6740800000000003E-11
.LCPI0_5:
	.quad	0x4024000000000000              # double 10
.LCPI0_6:
	.quad	0x4076d00000000000              # double 365
.LCPI0_7:
	.quad	0x4038000000000000              # double 24
.LCPI0_8:
	.quad	0x40ac200000000000              # double 3600
.LCPI0_9:
	.quad	0x413e848000000000              # double 2.0E+6
.LCPI0_10:
	.quad	0xc12e848000000000              # double -1.0E+6
	.text
	.globl	_Z20GenerateRandomPointsP15HIP_vector_typeIfLj4EES1_
	.type	_Z20GenerateRandomPointsP15HIP_vector_typeIfLj4EES1_,@function
_Z20GenerateRandomPointsP15HIP_vector_typeIfLj4EES1_: # @_Z20GenerateRandomPointsP15HIP_vector_typeIfLj4EES1_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %r14
	movq	%rdi, %rbx
	xorl	%r15d, %r15d
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	.LCPI0_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	.LCPI0_2(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	addss	%xmm1, %xmm0
	movss	%xmm0, (%rbx,%r15)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	mulss	.LCPI0_1(%rip), %xmm0
	addss	.LCPI0_2(%rip), %xmm0
	movss	%xmm0, 4(%rbx,%r15)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	mulss	.LCPI0_1(%rip), %xmm0
	addss	.LCPI0_2(%rip), %xmm0
	movss	%xmm0, 8(%rbx,%r15)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI0_3(%rip), %xmm0
	mulsd	.LCPI0_4(%rip), %xmm0
	mulsd	.LCPI0_5(%rip), %xmm0
	mulsd	.LCPI0_6(%rip), %xmm0
	mulsd	.LCPI0_7(%rip), %xmm0
	mulsd	.LCPI0_8(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 12(%rbx,%r15)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movsd	.LCPI0_9(%rip), %xmm1           # xmm1 = mem[0],zero
	mulsd	%xmm1, %xmm0
	movsd	.LCPI0_10(%rip), %xmm1          # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r14,%r15)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI0_9(%rip), %xmm0
	addsd	.LCPI0_10(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 4(%r14,%r15)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI0_9(%rip), %xmm0
	addsd	.LCPI0_10(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 8(%r14,%r15)
	addq	$16, %r15
	cmpq	$16777216, %r15                 # imm = 0x1000000
	jne	.LBB0_1
# %bb.2:                                # %.preheader
	movl	$12, %eax
.LBB0_3:                                # =>This Inner Loop Header: Depth=1
	movl	$2132694983, (%rbx,%rax)        # imm = 0x7F1E57C7
	addq	$16, %rax
	cmpq	$1612, %rax                     # imm = 0x64C
	jne	.LBB0_3
# %bb.4:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z20GenerateRandomPointsP15HIP_vector_typeIfLj4EES1_, .Lfunc_end0-_Z20GenerateRandomPointsP15HIP_vector_typeIfLj4EES1_
	.cfi_endproc
                                        # -- End function
	.globl	_Z4SaveP15HIP_vector_typeIfLj4EE # -- Begin function _Z4SaveP15HIP_vector_typeIfLj4EE
	.type	_Z4SaveP15HIP_vector_typeIfLj4EE,@function
_Z4SaveP15HIP_vector_typeIfLj4EE:       # @_Z4SaveP15HIP_vector_typeIfLj4EE
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %r14
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.LBB1_2
# %bb.1:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
.LBB1_2:
	movl	$91, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movl	$91, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	cvtss2sd	(%r14), %xmm0
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movl	$16, %r15d
.LBB1_3:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.5, %edi
	movl	$2, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15), %xmm0
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	addq	$16, %r15
	cmpq	$16777216, %r15                 # imm = 0x1000000
	jne	.LBB1_3
# %bb.4:
	movl	$93, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movl	$.L.str.7, %edi
	movl	$3, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	xorps	%xmm0, %xmm0
	cvtss2sd	4(%r14), %xmm0
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	xorl	%r15d, %r15d
.LBB1_5:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.5, %edi
	movl	$2, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	xorps	%xmm0, %xmm0
	cvtss2sd	20(%r14,%r15), %xmm0
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	addq	$16, %r15
	cmpq	$16777200, %r15                 # imm = 0xFFFFF0
	jne	.LBB1_5
# %bb.6:
	movl	$93, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movl	$.L.str.7, %edi
	movl	$3, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	xorps	%xmm0, %xmm0
	cvtss2sd	8(%r14), %xmm0
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	xorl	%r15d, %r15d
.LBB1_7:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.5, %edi
	movl	$2, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	xorps	%xmm0, %xmm0
	cvtss2sd	24(%r14,%r15), %xmm0
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	addq	$16, %r15
	cmpq	$16777200, %r15                 # imm = 0xFFFFF0
	jne	.LBB1_7
# %bb.8:
	movl	$93, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movl	$.L.str.8, %edi
	movl	$2, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.Lfunc_end1:
	.size	_Z4SaveP15HIP_vector_typeIfLj4EE, .Lfunc_end1-_Z4SaveP15HIP_vector_typeIfLj4EE
	.cfi_endproc
                                        # -- End function
	.globl	_Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_ # -- Begin function _Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.type	_Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_,@function
_Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_: # @_Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_, .Lfunc_end2-_Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI3_0:
	.quad	0x41b2cc0300000000              # double 3.1536E+8
.LCPI3_4:
	.quad	0x40e5798ee2308c3a              # double 43980.465111040001
.LCPI3_5:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI3_6:
	.quad	0x4129805aeeb905c6              # double 835629.46625536005
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI3_1:
	.long	0x42200000                      # float 40
.LCPI3_2:
	.long	0x49742400                      # float 1.0E+6
.LCPI3_3:
	.long	0x3f800000                      # float 1
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$16777216, %edi                 # imm = 0x1000000
	callq	malloc
	movq	%rax, %rbx
	movl	$16777216, %edi                 # imm = 0x1000000
	callq	malloc
	movq	%rax, %r15
	leaq	24(%rsp), %rdi
	movl	$16777216, %esi                 # imm = 0x1000000
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movl	$16777216, %esi                 # imm = 0x1000000
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$16777216, %esi                 # imm = 0x1000000
	callq	hipMalloc
	movl	$.L.str, %edi
	movl	$.L.str.9, %esi
	callq	fopen
	movq	%rax, %r12
	testq	%rax, %rax
	jne	.LBB3_2
# %bb.1:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
.LBB3_2:
	movabsq	$4294968320, %r14               # imm = 0x100000400
	movq	%r12, %rdi
	callq	fclose
	movq	%rbx, %rdi
	movq	%r15, %rsi
	callq	_Z20GenerateRandomPointsP15HIP_vector_typeIfLj4EES1_
	movq	24(%rsp), %rdi
	movl	$16777216, %edx                 # imm = 0x1000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	movl	$16777216, %edx                 # imm = 0x1000000
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r15, %rdi
	callq	free
	movsd	.LCPI3_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$.L.str.10, %edi
	movl	$1048576, %esi                  # imm = 0x100000
	movl	$40, %edx
	movb	$1, %al
	callq	printf
	xorl	%ebp, %ebp
.LBB3_3:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
	incl	%ebp
	movl	$.L.str.11, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	callq	clock
	movq	%rax, %r15
	xorl	%r12d, %r12d
.LBB3_4:                                #   Parent Loop BB3_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testb	$1, %r12b
	jne	.LBB3_5
# %bb.7:                                #   in Loop: Header=BB3_4 Depth=2
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.8:                                #   in Loop: Header=BB3_4 Depth=2
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	jmp	.LBB3_9
.LBB3_5:                                #   in Loop: Header=BB3_4 Depth=2
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.6:                                #   in Loop: Header=BB3_4 Depth=2
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	24(%rsp), %rdx
.LBB3_9:                                #   in Loop: Header=BB3_4 Depth=2
	callq	_Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
.LBB3_10:                               #   in Loop: Header=BB3_4 Depth=2
	callq	hipDeviceSynchronize
	incl	%r12d
	cmpl	$40, %r12d
	jne	.LBB3_4
# %bb.11:                               #   in Loop: Header=BB3_3 Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15, %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	callq	clock
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	subss	4(%rsp), %xmm0                  # 4-byte Folded Reload
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	movq	8(%rsp), %rsi
	movl	$16777216, %edx                 # imm = 0x1000000
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movss	.LCPI3_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	4(%rsp), %xmm3                  # 4-byte Reload
                                        # xmm3 = mem[0],zero,zero,zero
	divss	%xmm3, %xmm0
	movss	.LCPI3_2(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	mulss	%xmm2, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movss	.LCPI3_3(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	divss	%xmm3, %xmm1
	mulss	%xmm2, %xmm1
	cvtss2sd	%xmm1, %xmm1
	xorps	%xmm4, %xmm4
	cvtss2sd	%xmm3, %xmm4
	movsd	.LCPI3_4(%rip), %xmm2           # xmm2 = mem[0],zero
	divsd	%xmm4, %xmm2
	movsd	.LCPI3_5(%rip), %xmm5           # xmm5 = mem[0],zero
	mulsd	%xmm5, %xmm2
	movsd	.LCPI3_6(%rip), %xmm3           # xmm3 = mem[0],zero
	divsd	%xmm4, %xmm3
	mulsd	%xmm5, %xmm3
	movl	$.L.str.12, %edi
	movb	$4, %al
	callq	printf
	movl	$.L.str.13, %edi
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %rdi
	callq	_Z4SaveP15HIP_vector_typeIfLj4EE
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	jmp	.LBB3_3
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"data.data"
	.size	.L.str, 10

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"a+"
	.size	.L.str.1, 3

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%.2f"
	.size	.L.str.4, 5

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	", "
	.size	.L.str.5, 3

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	", ["
	.size	.L.str.7, 4

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"]\n"
	.size	.L.str.8, 3

	.type	_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_,@object # @_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.section	.rodata,"a",@progbits
	.globl	_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.p2align	3, 0x0
_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_:
	.quad	_Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.size	_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_, 8

	.type	.L.str.9,@object                # @.str.9
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.9:
	.asciz	"w"
	.size	.L.str.9, 2

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Start calc. N=%d, dt=%f, frame per save=%d\n"
	.size	.L.str.10, 44

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"[Save %d]: Computing... "
	.size	.L.str.11, 25

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Done. %.2lf fps, %.3lf Sps, %.2lf GBps, %.2lf GFLOPS"
	.size	.L.str.12, 53

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	" Saving... "
	.size	.L.str.13, 12

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_"
	.size	.L__unnamed_1, 55

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr.1,@object                 # @str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr.1:
	.asciz	"Can't save data."
	.size	.Lstr.1, 17

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Done. "
	.size	.Lstr.2, 7

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z34__device_stub__CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_ ; -- Begin function _Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.globl	_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
	.p2align	8
	.type	_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_,@function
_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_: ; @_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s8, s2, 0xffff
	s_load_b64 s[2:3], s[0:1], 0x10
	v_mad_u64_u32 v[1:2], null, s15, s8, v[0:1]
	s_load_b32 s0, s[0:1], 0x18
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[4:5], 4, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v5, vcc_lo
	s_waitcnt lgkmcnt(0)
	s_cmp_eq_u32 s0, 0
	global_load_b96 v[1:3], v[1:2], off
	s_cbranch_scc1 .LBB0_5
; %bb.1:                                ; %.lr.ph
	v_dual_mov_b32 v6, 0 :: v_dual_lshlrev_b32 v9, 4, v0
	v_dual_mov_b32 v10, 0 :: v_dual_mov_b32 v7, 0
	v_mov_b32_e32 v8, 0
	s_mov_b32 s1, 0
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[11:12], null, s1, s8, v[0:1]
	v_mov_b32_e32 v12, v10
	s_mov_b32 s9, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[11:12], 4, v[11:12]
	v_add_co_u32 v11, vcc_lo, s4, v11
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v12, vcc_lo, s5, v12, vcc_lo
	global_load_b128 v[11:14], v[11:12], off
	s_waitcnt vmcnt(0)
	ds_store_b128 v9, v[11:14]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_3:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_mov_b32_e32 v11, s9
	s_add_i32 s9, s9, 16
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	s_cmpk_eq_i32 s9, 0x4000
	ds_load_b128 v[11:14], v11
	s_waitcnt lgkmcnt(0)
	v_dual_sub_f32 v12, v12, v2 :: v_dual_sub_f32 v11, v11, v1
	v_sub_f32_e32 v13, v13, v3
	v_mul_f32_e32 v15, v12, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v15, v11, v11
	v_fmac_f32_e32 v15, v13, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v15, 0x447a0000, v15
	v_mul_f32_e32 v16, 0x4b800000, v15
	v_cmp_gt_f32_e32 vcc_lo, 0x800000, v15
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v15, v15, v16, vcc_lo
	v_rsq_f32_e32 v15, v15
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v16, 0x45800000, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v15, v15, v16, vcc_lo
	v_mul_f32_e32 v14, v14, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v14, v15, v14
	v_mul_f32_e32 v14, v15, v14
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v7, v12, v14
	v_fmac_f32_e32 v8, v11, v14
	v_fmac_f32_e32 v6, v13, v14
	s_cbranch_scc0 .LBB0_3
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s1, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s1, s0
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_2
	s_branch .LBB0_6
.LBB0_5:
	v_dual_mov_b32 v6, 0 :: v_dual_mov_b32 v7, 0
	v_mov_b32_e32 v8, 0
.LBB0_6:                                ; %Flow114
	v_add_co_u32 v9, vcc_lo, s6, v4
	v_add_co_ci_u32_e32 v10, vcc_lo, s7, v5, vcc_lo
	global_load_b32 v0, v[9:10], off
	s_waitcnt vmcnt(0)
	v_mul_f32_e32 v0, 0x41200000, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v0, 0x43b68000, v0
	v_mul_f32_e32 v0, 0x41c00000, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_fmamk_f32 v11, v0, 0x45610000, v1
	v_add_co_u32 v0, vcc_lo, s2, v4
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v5, vcc_lo
	v_fmac_f32_e32 v11, 0x4d166018, v8
	global_store_b32 v[0:1], v11, off
	global_load_b32 v4, v[9:10], off offset:4
	s_waitcnt vmcnt(0)
	v_mul_f32_e32 v4, 0x41200000, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v4, 0x43b68000, v4
	v_mul_f32_e32 v4, 0x41c00000, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmamk_f32 v2, v4, 0x45610000, v2
	v_fmac_f32_e32 v2, 0x4d166018, v7
	global_store_b32 v[0:1], v2, off offset:4
	global_load_b32 v2, v[9:10], off offset:8
	s_waitcnt vmcnt(0)
	v_mul_f32_e32 v2, 0x41200000, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v2, 0x43b68000, v2
	v_mul_f32_e32 v2, 0x41c00000, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v3, 0x45610000, v2
	v_fmac_f32_e32 v3, 0x4d166018, v6
	global_store_b32 v[0:1], v3, off offset:8
	global_load_b96 v[0:2], v[9:10], off
	s_waitcnt vmcnt(0)
	v_dual_add_f32 v0, v8, v0 :: v_dual_add_f32 v1, v7, v1
	v_add_f32_e32 v2, v6, v2
	global_store_b96 v[9:10], v[0:2], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
		.amdhsa_group_segment_fixed_size 16384
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 17
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_, .Lfunc_end0-_Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 684
; NumSgprs: 18
; NumVgprs: 17
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 16384 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 17
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 16384
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19CaculateTheNextTickP15HIP_vector_typeIfLj4EES1_S1_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     17
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
