#include <stdio.h>
#include <sys/time.h>

using namespace std;

struct particle {
    float position[3];
    float velocity[3];
};

struct seed {
    int x;
    int y;
    int z;
};

__host__ __device__ float gen_random(int seed, int particle_id, int iteration,int num_particles)
{
  float rand_num = (seed * particle_id + iteration) % num_particles; 
  return rand_num;
}

__global__ void timestep(struct particle* particles, seed seed, int iteration, int num_particles) {
   
   const int i = blockIdx.x * blockDim.x + threadIdx.x;
   
   if (i < num_particles) {

     // Velocity update:
     particles[i].velocity[0] = gen_random(seed.x, i, iteration, num_particles);
     particles[i].velocity[1] = gen_random(seed.y, i, iteration, num_particles);
     particles[i].velocity[2] = gen_random(seed.z, i, iteration, num_particles);

      // Position update:
      particles[i].position[0] = particles[i].position[0] + particles[i].velocity[0];
      particles[i].position[1] = particles[i].position[1] + particles[i].velocity[1];
      particles[i].position[2] = particles[i].position[2] + particles[i].velocity[2];
   }
}

int main(int argc, char *argv[])
{

  int i = 0, j = 0, num_particles = 10000, num_iterations = 100, tpb = 256, num_blocks = 0;
  struct timeval t0, t1;
  seed seed = {5,6,7};

  for(i = 1; i < argc; ++i) {
    if (strcmp(argv[i], "-num_particles") == 0)
    { 
      num_particles = atoi(argv[++i]);
    }
    else if (strcmp(argv[i], "-tpb") == 0)
    {
      tpb = atoi(argv[++i]);
    }
    else if (strcmp(argv[i], "--num_iterations") == 0)
    {
      num_iterations = atoi(argv[++i]);
    }
  }

  num_blocks = (num_particles/tpb + 1); 

  struct particle *particlesCPU = (struct particle*)malloc(num_particles * sizeof(struct particle));
  struct particle *particlesGPU = (struct particle*)malloc(num_particles * sizeof(struct particle));
  struct particle *resultGPUSimulation = (struct particle*)malloc(num_particles * sizeof(struct particle));

  printf("\n\nComputing simulation on the CPU..."); 

  gettimeofday(&t0, 0);

  for(i = 0; i < num_iterations; i++)
  {
     for(j = 0; j < num_particles; j++)
     {
        // Velocity update:
        particlesCPU[j].velocity[0] = gen_random(seed.x, j, i, num_particles);
        particlesCPU[j].velocity[1] = gen_random(seed.y, j, i, num_particles);
        particlesCPU[j].velocity[2] = gen_random(seed.z, j, i, num_particles);

        // Position update:
        particlesCPU[j].position[0] = particlesCPU[j].position[0] + particlesCPU[j].velocity[0];
        particlesCPU[j].position[1] = particlesCPU[j].position[1] + particlesCPU[j].velocity[1];
        particlesCPU[j].position[2] = particlesCPU[j].position[2] + particlesCPU[j].velocity[2];
     }
  }

  gettimeofday(&t1, 0);
  long elapsed_cpu = (t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec;

  printf("Done!");
  printf("\n\nTotal time taken for %d particles and %d iterations on the CPU alone = %ld microseconds", num_particles, num_iterations, elapsed_cpu); 
  cudaMalloc(&particlesGPU, num_particles * sizeof(struct particle));

  printf("\n\nComputing simulation on the GPU...");
  gettimeofday(&t0, 0); 
 
  for (int i = 0; i < num_iterations; i++) {
    timestep<<<num_blocks, tpb>>>(particlesGPU, seed, i, num_particles);
    cudaDeviceSynchronize();
  }

   cudaMemcpy(resultGPUSimulation, particlesGPU, num_particles * sizeof(struct particle), cudaMemcpyDeviceToHost);

  gettimeofday(&t1, 0);
  long elapsed_gpu = (t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec;

  printf("Done!");
  printf("\n\nTotal time taken for %d particles, %d iterations, %d tpb and %d blocks using the GPU = %ld microseconds", num_particles, num_iterations, tpb, num_blocks, elapsed_gpu);
 
  // comparing the results of the two versions

  printf("\n\nComparing the output for each implementation...");

  int flag_comparison = 0;
  
  for (i = 0; i < num_particles; i++)
  {
    if( (abs(particlesCPU[i].velocity[0] - resultGPUSimulation[i].velocity[0]) > 1) || (abs(particlesCPU[i].velocity[1] - resultGPUSimulation[i].velocity[1]) > 1) || (abs(particlesCPU[i].velocity[2] - resultGPUSimulation[i].velocity[2]) > 1) || (abs(particlesCPU[i].position[0] - resultGPUSimulation[i].position[0]) > 1)|| (abs(particlesCPU[i].position[1] - resultGPUSimulation[i].position[1]) > 1) || (abs(particlesCPU[i].position[2] - resultGPUSimulation[i].position[2]) > 1) ) 
    {
      flag_comparison = 1;
      break;
    }
  }

  if(flag_comparison == 0)
  {
     printf("Correct!");
  }
  else
  {
    printf("Incorrect!");
  }


  // clean up
  free(particlesCPU);
  cudaFree(particlesGPU);

  return 0;
}

	.file	"tmpxft_002e0aec_00000000-6_exercise_3.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z10gen_randomiiii
	.type	_Z10gen_randomiiii, @function
_Z10gen_randomiiii:
.LFB2027:
	.cfi_startproc
	endbr64
	imull	%esi, %edi
	leal	(%rdi,%rdx), %eax
	cltd
	idivl	%ecx
	cvtsi2ssl	%edx, %xmm0
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z10gen_randomiiii, .-_Z10gen_randomiiii
	.globl	_Z42__device_stub__Z8timestepP8particle4seediiP8particleR4seedii
	.type	_Z42__device_stub__Z8timestepP8particle4seediiP8particleR4seedii, @function
_Z42__device_stub__Z8timestepP8particle4seediiP8particleR4seedii:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 8(%rsp)
	leaq	40(%rsp), %rdi
	movl	%edx, 4(%rsp)
	leaq	24(%rsp), %rdx
	movl	%ecx, (%rsp)
	leaq	32(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movq	%rsi, 96(%rsp)
	leaq	52(%rsp), %rsi
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 104(%rsp)
	movq	%rsp, %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movl	$1, 48(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L3
	pushq	32(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z8timestepP8particle4seedii(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 160
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L3:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z42__device_stub__Z8timestepP8particle4seediiP8particleR4seedii, .-_Z42__device_stub__Z8timestepP8particle4seediiP8particleR4seedii
	.globl	_Z8timestepP8particle4seedii
	.type	_Z8timestepP8particle4seedii, @function
_Z8timestepP8particle4seedii:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	%edx, %eax
	movl	%ecx, %edx
	movl	%r8d, %ecx
	movq	%rsi, (%rsp)
	movq	%rsp, %rsi
	movl	%eax, 8(%rsp)
	call	_Z42__device_stub__Z8timestepP8particle4seediiP8particleR4seedii
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z8timestepP8particle4seedii, .-_Z8timestepP8particle4seedii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"-num_particles"
.LC1:
	.string	"-tpb"
.LC2:
	.string	"--num_iterations"
.LC3:
	.string	"\n\nComputing simulation on the CPU..."
.LC4:
	.string	"Done!"
.LC5:
	.string	"\n\nTotal time taken for %d particles and %d iterations on the CPU alone = %ld microseconds"
.LC6:
	.string	"\n\nComputing simulation on the GPU..."
.LC7:
	.string	"\n\nTotal time taken for %d particles, %d iterations, %d tpb and %d blocks using the GPU = %ld microseconds"
.LC8:
	.string	"\n\nComparing the output for each implementation..."
.LC11:
	.string	"Correct!"
.LC12:
	.string	"Incorrect!"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	$10000, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	$1, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	movl	$256, 12(%rsp)
	movl	$100, 8(%rsp)
.L11:
	cmpl	%r12d, %ebp
	jge	.L34
	movslq	%ebp, %rax
	leaq	.LC0(%rip), %rsi
	leal	1(%rbp), %r15d
	leaq	0(,%rax,8), %r13
	movq	(%rbx,%rax,8), %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L12
	movq	8(%rbx,%r13), %rdi
	call	atoi@PLT
	movl	%eax, %r14d
	jmp	.L13
.L12:
	movq	(%rsp), %rdi
	leaq	.LC1(%rip), %rsi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L14
	movq	8(%rbx,%r13), %rdi
	call	atoi@PLT
	movl	%eax, 12(%rsp)
	jmp	.L13
.L14:
	movq	(%rsp), %rdi
	leaq	.LC2(%rip), %rsi
	call	strcmp@PLT
	testl	%eax, %eax
	jne	.L29
	movq	8(%rbx,%r13), %rdi
	call	atoi@PLT
	movl	%eax, 8(%rsp)
	jmp	.L13
.L29:
	movl	%ebp, %r15d
.L13:
	leal	1(%r15), %ebp
	jmp	.L11
.L34:
	movl	%r14d, %eax
	leaq	88(%rsp), %rbp
	cltd
	idivl	12(%rsp)
	leal	1(%rax), %ebx
	movslq	%r14d, %rax
	imulq	$24, %rax, %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %r15
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	xorl	%edi, %edi
.L16:
	movl	8(%rsp), %eax
	cmpl	%eax, %edi
	jge	.L18
	movq	%r13, %rcx
	xorl	%esi, %esi
.L19:
	cmpl	%r14d, %esi
	jge	.L35
	leal	(%rsi,%rsi,4), %eax
	addq	$24, %rcx
	addl	%edi, %eax
	cltd
	idivl	%r14d
	imull	$6, %esi, %eax
	addl	%edi, %eax
	cvtsi2ssl	%edx, %xmm2
	cltd
	idivl	%r14d
	movss	%xmm2, -12(%rcx)
	imull	$7, %esi, %eax
	addss	-24(%rcx), %xmm2
	incl	%esi
	addl	%edi, %eax
	movss	%xmm2, -24(%rcx)
	cvtsi2ssl	%edx, %xmm1
	cltd
	idivl	%r14d
	movss	%xmm1, -8(%rcx)
	addss	-20(%rcx), %xmm1
	movss	%xmm1, -20(%rcx)
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, -4(%rcx)
	addss	-16(%rcx), %xmm0
	movss	%xmm0, -16(%rcx)
	jmp	.L19
.L35:
	incl	%edi
	jmp	.L16
.L18:
	leaq	104(%rsp), %rax
	xorl	%esi, %esi
	movabsq	$4294967297, %r12
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	gettimeofday@PLT
	movq	104(%rsp), %r8
	subq	88(%rsp), %r8
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	imulq	$1000000, %r8, %r8
	addq	112(%rsp), %r8
	subq	96(%rsp), %r8
	movq	%r8, 24(%rsp)
	call	__printf_chk@PLT
	movq	24(%rsp), %r8
	movl	8(%rsp), %ecx
	xorl	%eax, %eax
	movl	%r14d, %edx
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	(%rsp), %rsi
	leaq	40(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	xorl	%esi, %esi
	xorl	%ebp, %ebp
	call	gettimeofday@PLT
.L20:
	cmpl	%ebp, 8(%rsp)
	jle	.L36
	movl	12(%rsp), %eax
	movq	%r12, 68(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r12, 56(%rsp)
	movl	72(%rsp), %ecx
	movl	%eax, 64(%rsp)
	movl	60(%rsp), %esi
	movl	%ebx, 52(%rsp)
	movq	64(%rsp), %rdx
	movq	52(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	movq	40(%rsp), %rdi
	leaq	76(%rsp), %rsi
	movl	%r14d, %ecx
	movl	%ebp, %edx
	movabsq	$25769803781, %rax
	movl	$7, 84(%rsp)
	movq	%rax, 76(%rsp)
	call	_Z42__device_stub__Z8timestepP8particle4seediiP8particleR4seedii
.L21:
	call	cudaDeviceSynchronize@PLT
	incl	%ebp
	jmp	.L20
.L36:
	movq	(%rsp), %rdx
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	%r15, %rdi
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	104(%rsp), %rbp
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	subq	88(%rsp), %rbp
	movl	$2, %edi
	imulq	$1000000, %rbp, %rbp
	addq	112(%rsp), %rbp
	subq	96(%rsp), %rbp
	call	__printf_chk@PLT
	movl	%ebx, %r9d
	movl	%r14d, %edx
	movl	$2, %edi
	pushq	%rax
	.cfi_def_cfa_offset 200
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 208
	movl	28(%rsp), %r8d
	movl	24(%rsp), %ecx
	call	__printf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 200
	leaq	.LC8(%rip), %rsi
	popq	%rcx
	.cfi_def_cfa_offset 192
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r13, %rax
	movq	%r15, %rdx
	xorl	%ecx, %ecx
	movss	.LC10(%rip), %xmm1
	movss	.LC9(%rip), %xmm0
.L23:
	cmpl	%r14d, %ecx
	jge	.L37
	movss	12(%rax), %xmm2
	subss	12(%rdx), %xmm2
	movq	%rax, %rdi
	movq	%rdx, %rsi
	andps	%xmm0, %xmm2
	comiss	%xmm1, %xmm2
	ja	.L24
	movss	16(%rax), %xmm2
	subss	16(%rdx), %xmm2
	andps	%xmm0, %xmm2
	comiss	%xmm1, %xmm2
	ja	.L24
	movss	20(%rax), %xmm2
	subss	20(%rdx), %xmm2
	andps	%xmm0, %xmm2
	comiss	%xmm1, %xmm2
	ja	.L24
	movss	(%rax), %xmm2
	subss	(%rdx), %xmm2
	andps	%xmm0, %xmm2
	comiss	%xmm1, %xmm2
	ja	.L24
	movss	4(%rax), %xmm2
	subss	4(%rdx), %xmm2
	andps	%xmm0, %xmm2
	comiss	%xmm1, %xmm2
	ja	.L24
	movss	8(%rdi), %xmm2
	subss	8(%rsi), %xmm2
	addq	$24, %rax
	addq	$24, %rdx
	andps	%xmm0, %xmm2
	comiss	%xmm1, %xmm2
	ja	.L24
	incl	%ecx
	jmp	.L23
.L37:
	leaq	.LC11(%rip), %rsi
	jmp	.L33
.L24:
	leaq	.LC12(%rip), %rsi
.L33:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z8timestepP8particle4seedii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.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	.LC13(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z8timestepP8particle4seedii(%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
.LFE2056:
	.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.cst16,"aM",@progbits,16
	.align 16
.LC9:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC10:
	.long	1065353216
	.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 <sys/time.h>

using namespace std;

struct particle {
    float position[3];
    float velocity[3];
};

struct seed {
    int x;
    int y;
    int z;
};

__host__ __device__ float gen_random(int seed, int particle_id, int iteration,int num_particles)
{
  float rand_num = (seed * particle_id + iteration) % num_particles; 
  return rand_num;
}

__global__ void timestep(struct particle* particles, seed seed, int iteration, int num_particles) {
   
   const int i = blockIdx.x * blockDim.x + threadIdx.x;
   
   if (i < num_particles) {

     // Velocity update:
     particles[i].velocity[0] = gen_random(seed.x, i, iteration, num_particles);
     particles[i].velocity[1] = gen_random(seed.y, i, iteration, num_particles);
     particles[i].velocity[2] = gen_random(seed.z, i, iteration, num_particles);

      // Position update:
      particles[i].position[0] = particles[i].position[0] + particles[i].velocity[0];
      particles[i].position[1] = particles[i].position[1] + particles[i].velocity[1];
      particles[i].position[2] = particles[i].position[2] + particles[i].velocity[2];
   }
}

int main(int argc, char *argv[])
{

  int i = 0, j = 0, num_particles = 10000, num_iterations = 100, tpb = 256, num_blocks = 0;
  struct timeval t0, t1;
  seed seed = {5,6,7};

  for(i = 1; i < argc; ++i) {
    if (strcmp(argv[i], "-num_particles") == 0)
    { 
      num_particles = atoi(argv[++i]);
    }
    else if (strcmp(argv[i], "-tpb") == 0)
    {
      tpb = atoi(argv[++i]);
    }
    else if (strcmp(argv[i], "--num_iterations") == 0)
    {
      num_iterations = atoi(argv[++i]);
    }
  }

  num_blocks = (num_particles/tpb + 1); 

  struct particle *particlesCPU = (struct particle*)malloc(num_particles * sizeof(struct particle));
  struct particle *particlesGPU = (struct particle*)malloc(num_particles * sizeof(struct particle));
  struct particle *resultGPUSimulation = (struct particle*)malloc(num_particles * sizeof(struct particle));

  printf("\n\nComputing simulation on the CPU..."); 

  gettimeofday(&t0, 0);

  for(i = 0; i < num_iterations; i++)
  {
     for(j = 0; j < num_particles; j++)
     {
        // Velocity update:
        particlesCPU[j].velocity[0] = gen_random(seed.x, j, i, num_particles);
        particlesCPU[j].velocity[1] = gen_random(seed.y, j, i, num_particles);
        particlesCPU[j].velocity[2] = gen_random(seed.z, j, i, num_particles);

        // Position update:
        particlesCPU[j].position[0] = particlesCPU[j].position[0] + particlesCPU[j].velocity[0];
        particlesCPU[j].position[1] = particlesCPU[j].position[1] + particlesCPU[j].velocity[1];
        particlesCPU[j].position[2] = particlesCPU[j].position[2] + particlesCPU[j].velocity[2];
     }
  }

  gettimeofday(&t1, 0);
  long elapsed_cpu = (t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec;

  printf("Done!");
  printf("\n\nTotal time taken for %d particles and %d iterations on the CPU alone = %ld microseconds", num_particles, num_iterations, elapsed_cpu); 
  hipMalloc(&particlesGPU, num_particles * sizeof(struct particle));

  printf("\n\nComputing simulation on the GPU...");
  gettimeofday(&t0, 0); 
 
  for (int i = 0; i < num_iterations; i++) {
    timestep<<<num_blocks, tpb>>>(particlesGPU, seed, i, num_particles);
    hipDeviceSynchronize();
  }

   hipMemcpy(resultGPUSimulation, particlesGPU, num_particles * sizeof(struct particle), hipMemcpyDeviceToHost);

  gettimeofday(&t1, 0);
  long elapsed_gpu = (t1.tv_sec-t0.tv_sec)*1000000 + t1.tv_usec-t0.tv_usec;

  printf("Done!");
  printf("\n\nTotal time taken for %d particles, %d iterations, %d tpb and %d blocks using the GPU = %ld microseconds", num_particles, num_iterations, tpb, num_blocks, elapsed_gpu);
 
  // comparing the results of the two versions

  printf("\n\nComparing the output for each implementation...");

  int flag_comparison = 0;
  
  for (i = 0; i < num_particles; i++)
  {
    if( (abs(particlesCPU[i].velocity[0] - resultGPUSimulation[i].velocity[0]) > 1) || (abs(particlesCPU[i].velocity[1] - resultGPUSimulation[i].velocity[1]) > 1) || (abs(particlesCPU[i].velocity[2] - resultGPUSimulation[i].velocity[2]) > 1) || (abs(particlesCPU[i].position[0] - resultGPUSimulation[i].position[0]) > 1)|| (abs(particlesCPU[i].position[1] - resultGPUSimulation[i].position[1]) > 1) || (abs(particlesCPU[i].position[2] - resultGPUSimulation[i].position[2]) > 1) ) 
    {
      flag_comparison = 1;
      break;
    }
  }

  if(flag_comparison == 0)
  {
     printf("Correct!");
  }
  else
  {
    printf("Incorrect!");
  }


  // clean up
  free(particlesCPU);
  hipFree(particlesGPU);

  return 0;
}

	.text
	.file	"exercise_3.hip"
	.globl	_Z10gen_randomiiii              # -- Begin function _Z10gen_randomiiii
	.type	_Z10gen_randomiiii,@function
_Z10gen_randomiiii:                     # @_Z10gen_randomiiii
	.cfi_startproc
# %bb.0:
                                        # kill: def $edx killed $edx def $rdx
                                        # kill: def $edi killed $edi def $rdi
	imull	%esi, %edi
	leal	(%rdi,%rdx), %eax
	cltd
	idivl	%ecx
	cvtsi2ss	%edx, %xmm0
	retq
.Lfunc_end0:
	.size	_Z10gen_randomiiii, .Lfunc_end0-_Z10gen_randomiiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z23__device_stub__timestepP8particle4seedii # -- Begin function _Z23__device_stub__timestepP8particle4seedii
	.type	_Z23__device_stub__timestepP8particle4seedii,@function
_Z23__device_stub__timestepP8particle4seedii: # @_Z23__device_stub__timestepP8particle4seedii
	.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	64(%rsp), %rax
	movq	%rsi, (%rax)
	movl	%edx, 8(%rax)
	leaq	24(%rsp), %rdx
	movq	%rdi, (%rdx)
	leaq	4(%rsp), %rsi
	movl	%ecx, (%rsi)
	movq	%rsp, %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rdx, (%rbx)
	movq	%rax, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rcx, 24(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z8timestepP8particle4seedii, %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_end1:
	.size	_Z23__device_stub__timestepP8particle4seedii, .Lfunc_end1-_Z23__device_stub__timestepP8particle4seedii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI2_1:
	.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	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$2, %edi
	jl	.LBB2_1
# %bb.2:                                # %.lr.ph.preheader
	movq	%rsi, %r15
	movl	%edi, %r12d
	movl	$256, 8(%rsp)                   # 4-byte Folded Spill
                                        # imm = 0x100
	movl	$100, 4(%rsp)                   # 4-byte Folded Spill
	movl	$10000, %ebx                    # imm = 0x2710
	movl	$1, %ebp
.LBB2_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movslq	%ebp, %r14
	movq	(%r15,%r14,8), %r13
	movl	$.L.str, %esi
	movq	%r13, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB2_4
# %bb.5:                                #   in Loop: Header=BB2_3 Depth=1
	movl	$.L.str.1, %esi
	movq	%r13, %rdi
	callq	strcmp
	testl	%eax, %eax
	je	.LBB2_6
# %bb.7:                                #   in Loop: Header=BB2_3 Depth=1
	movl	$.L.str.2, %esi
	movq	%r13, %rdi
	callq	strcmp
	testl	%eax, %eax
	jne	.LBB2_9
# %bb.8:                                #   in Loop: Header=BB2_3 Depth=1
	leal	1(%r14), %ebp
	movq	8(%r15,%r14,8), %rdi
	callq	atoi
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	jmp	.LBB2_9
.LBB2_4:                                #   in Loop: Header=BB2_3 Depth=1
	leal	1(%r14), %ebp
	movq	8(%r15,%r14,8), %rdi
	callq	atoi
	movl	%eax, %ebx
	jmp	.LBB2_9
.LBB2_6:                                #   in Loop: Header=BB2_3 Depth=1
	leal	1(%r14), %ebp
	movq	8(%r15,%r14,8), %rdi
	callq	atoi
	movl	%eax, 8(%rsp)                   # 4-byte Spill
.LBB2_9:                                #   in Loop: Header=BB2_3 Depth=1
	incl	%ebp
	cmpl	%r12d, %ebp
	jl	.LBB2_3
	jmp	.LBB2_10
.LBB2_1:
	movl	$10000, %ebx                    # imm = 0x2710
	movl	$100, 4(%rsp)                   # 4-byte Folded Spill
	movl	$256, 8(%rsp)                   # 4-byte Folded Spill
                                        # imm = 0x100
.LBB2_10:                               # %._crit_edge
	movl	%ebx, %eax
	cltd
	idivl	8(%rsp)                         # 4-byte Folded Reload
	movl	%eax, %ebp
	movslq	%ebx, %rax
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, 16(%rsp)
	movq	%r14, 24(%rsp)                  # 8-byte Spill
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r14
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	%ebx, %r12d
	cmpl	$0, 4(%rsp)                     # 4-byte Folded Reload
	jle	.LBB2_16
# %bb.11:                               # %.preheader.lr.ph
	movl	4(%rsp), %r8d                   # 4-byte Reload
	leaq	(,%r12,8), %rax
	leaq	(%rax,%rax,2), %r9
	xorl	%r10d, %r10d
.LBB2_12:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_14 Depth 2
	testl	%ebx, %ebx
	jle	.LBB2_15
# %bb.13:                               # %.lr.ph135.preheader
                                        #   in Loop: Header=BB2_12 Depth=1
	movl	%r10d, %ecx
	movl	%r10d, %esi
	movl	%r10d, %edi
	xorl	%r11d, %r11d
.LBB2_14:                               # %.lr.ph135
                                        #   Parent Loop BB2_12 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%edi, %eax
	xorl	%edx, %edx
	divl	%ebx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%edx, %xmm0
	movss	%xmm0, 12(%r15,%r11)
	movl	%esi, %eax
	xorl	%edx, %edx
	divl	%ebx
	xorps	%xmm1, %xmm1
	cvtsi2ss	%edx, %xmm1
	movss	%xmm1, 16(%r15,%r11)
	movl	%ecx, %eax
	xorl	%edx, %edx
	divl	%ebx
	xorps	%xmm2, %xmm2
	cvtsi2ss	%edx, %xmm2
	movss	%xmm2, 20(%r15,%r11)
	addss	(%r15,%r11), %xmm0
	movss	%xmm0, (%r15,%r11)
	addss	4(%r15,%r11), %xmm1
	movss	%xmm1, 4(%r15,%r11)
	addss	8(%r15,%r11), %xmm2
	movss	%xmm2, 8(%r15,%r11)
	addq	$24, %r11
	addl	$5, %edi
	addl	$6, %esi
	addl	$7, %ecx
	cmpq	%r11, %r9
	jne	.LBB2_14
.LBB2_15:                               # %._crit_edge136
                                        #   in Loop: Header=BB2_12 Depth=1
	incq	%r10
	cmpq	%r8, %r10
	jne	.LBB2_12
.LBB2_16:                               # %._crit_edge138
	movq	%r12, 48(%rsp)                  # 8-byte Spill
	incl	%ebp
	movl	%ebp, 12(%rsp)                  # 4-byte Spill
	xorl	%ebp, %ebp
	leaq	56(%rsp), %r13
	movq	%r13, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r13), %rax
	leaq	32(%rsp), %rcx
	subq	(%rcx), %rax
	imulq	$1000000, %rax, %r12            # imm = 0xF4240
	addq	8(%r13), %r12
	subq	8(%rcx), %r12
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.5, %edi
	movl	%ebx, %esi
	movq	%r14, %r13
	movl	4(%rsp), %r14d                  # 4-byte Reload
	movl	%r14d, %edx
	movq	%r12, %rcx
	xorl	%eax, %eax
	callq	printf
	leaq	16(%rsp), %rdi
	movq	24(%rsp), %rsi                  # 8-byte Reload
	callq	hipMalloc
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	leaq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	testl	%r14d, %r14d
	movq	%r13, %r14
	jle	.LBB2_21
# %bb.17:                               # %.lr.ph141
	movl	12(%rsp), %r13d                 # 4-byte Reload
	btsq	$32, %r13
	movl	8(%rsp), %r12d                  # 4-byte Reload
	btsq	$32, %r12
.LBB2_18:                               # =>This Inner Loop Header: Depth=1
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_20
# %bb.19:                               #   in Loop: Header=BB2_18 Depth=1
	movq	16(%rsp), %rdi
	movabsq	$25769803781, %rsi              # imm = 0x600000005
	movl	$7, %edx
	movl	%ebp, %ecx
	movl	%ebx, %r8d
	callq	_Z23__device_stub__timestepP8particle4seedii
.LBB2_20:                               #   in Loop: Header=BB2_18 Depth=1
	callq	hipDeviceSynchronize
	incl	%ebp
	cmpl	%ebp, 4(%rsp)                   # 4-byte Folded Reload
	jne	.LBB2_18
.LBB2_21:                               # %._crit_edge142
	movq	16(%rsp), %rsi
	movq	%r14, %rdi
	movq	24(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	56(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r12), %rax
	subq	32(%rsp), %rax
	imulq	$1000000, %rax, %r13            # imm = 0xF4240
	addq	8(%r12), %r13
	subq	40(%rsp), %r13
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.7, %edi
	movl	%ebx, %esi
	movl	4(%rsp), %edx                   # 4-byte Reload
	movl	8(%rsp), %ecx                   # 4-byte Reload
	movl	12(%rsp), %r8d                  # 4-byte Reload
	movq	%r13, %r9
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	testl	%ebx, %ebx
	jle	.LBB2_22
# %bb.24:                               # %.lr.ph146.preheader
	movq	48(%rsp), %rax                  # 8-byte Reload
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %rax
	xorl	%ecx, %ecx
	movaps	.LCPI2_0(%rip), %xmm0           # xmm0 = [NaN,NaN,NaN,NaN]
	movss	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movl	$.L.str.10, %edi
.LBB2_25:                               # %.lr.ph146
                                        # =>This Inner Loop Header: Depth=1
	movss	12(%r15,%rcx), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	12(%r14,%rcx), %xmm2
	andps	%xmm0, %xmm2
	ucomiss	%xmm1, %xmm2
	ja	.LBB2_31
# %bb.26:                               #   in Loop: Header=BB2_25 Depth=1
	movss	16(%r15,%rcx), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	16(%r14,%rcx), %xmm2
	andps	%xmm0, %xmm2
	ucomiss	%xmm1, %xmm2
	ja	.LBB2_31
# %bb.27:                               #   in Loop: Header=BB2_25 Depth=1
	movss	20(%r15,%rcx), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	20(%r14,%rcx), %xmm2
	andps	%xmm0, %xmm2
	ucomiss	%xmm1, %xmm2
	ja	.LBB2_31
# %bb.28:                               #   in Loop: Header=BB2_25 Depth=1
	movss	(%r15,%rcx), %xmm2              # xmm2 = mem[0],zero,zero,zero
	subss	(%r14,%rcx), %xmm2
	andps	%xmm0, %xmm2
	ucomiss	%xmm1, %xmm2
	ja	.LBB2_31
# %bb.29:                               #   in Loop: Header=BB2_25 Depth=1
	movss	4(%r15,%rcx), %xmm2             # xmm2 = mem[0],zero,zero,zero
	subss	4(%r14,%rcx), %xmm2
	andps	%xmm0, %xmm2
	ucomiss	%xmm1, %xmm2
	ja	.LBB2_31
# %bb.30:                               #   in Loop: Header=BB2_25 Depth=1
	movss	8(%r15,%rcx), %xmm2             # xmm2 = mem[0],zero,zero,zero
	subss	8(%r14,%rcx), %xmm2
	andps	%xmm0, %xmm2
	ucomiss	%xmm1, %xmm2
	ja	.LBB2_31
# %bb.23:                               #   in Loop: Header=BB2_25 Depth=1
	addq	$24, %rcx
	cmpq	%rcx, %rax
	jne	.LBB2_25
.LBB2_22:
	movl	$.L.str.9, %edi
.LBB2_31:                               # %.critedge
	xorl	%eax, %eax
	callq	printf
	movq	%r15, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8timestepP8particle4seedii, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z8timestepP8particle4seedii,@object # @_Z8timestepP8particle4seedii
	.section	.rodata,"a",@progbits
	.globl	_Z8timestepP8particle4seedii
	.p2align	3, 0x0
_Z8timestepP8particle4seedii:
	.quad	_Z23__device_stub__timestepP8particle4seedii
	.size	_Z8timestepP8particle4seedii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"-num_particles"
	.size	.L.str, 15

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"-tpb"
	.size	.L.str.1, 5

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"--num_iterations"
	.size	.L.str.2, 17

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\n\nComputing simulation on the CPU..."
	.size	.L.str.3, 37

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Done!"
	.size	.L.str.4, 6

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\n\nTotal time taken for %d particles and %d iterations on the CPU alone = %ld microseconds"
	.size	.L.str.5, 90

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"\n\nComputing simulation on the GPU..."
	.size	.L.str.6, 37

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"\n\nTotal time taken for %d particles, %d iterations, %d tpb and %d blocks using the GPU = %ld microseconds"
	.size	.L.str.7, 106

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"\n\nComparing the output for each implementation..."
	.size	.L.str.8, 50

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Correct!"
	.size	.L.str.9, 9

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Incorrect!"
	.size	.L.str.10, 11

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z8timestepP8particle4seedii"
	.size	.L__unnamed_1, 29

	.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

	.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 _Z23__device_stub__timestepP8particle4seedii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z8timestepP8particle4seedii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8timestepP8particle4seedii ; -- Begin function _Z8timestepP8particle4seedii
	.globl	_Z8timestepP8particle4seedii
	.p2align	8
	.type	_Z8timestepP8particle4seedii,@function
_Z8timestepP8particle4seedii:           ; @_Z8timestepP8particle4seedii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b64 s[4:5], s[0:1], 0x14
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s5, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_clause 0x1
	s_load_b64 s[6:7], s[0:1], 0x0
	s_load_b128 s[0:3], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_ashr_i32 s3, s5, 31
	v_mad_i64_i32 v[7:8], null, v1, 24, s[6:7]
	s_add_i32 s6, s5, s3
	v_mad_u64_u32 v[9:10], null, s1, v1, s[4:5]
	s_xor_b32 s3, s6, s3
	v_mad_u64_u32 v[10:11], null, s2, v1, s[4:5]
	global_load_b96 v[4:6], v[7:8], off
	v_cvt_f32_u32_e32 v0, s3
	s_sub_i32 s6, 0, s3
	v_ashrrev_i32_e32 v11, 31, v9
	v_mad_u64_u32 v[2:3], null, s0, v1, s[4:5]
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_rcp_iflag_f32_e32 v0, v0
	v_ashrrev_i32_e32 v12, 31, v10
	v_add_nc_u32_e32 v9, v9, v11
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_ashrrev_i32_e32 v1, 31, v2
	v_add_nc_u32_e32 v10, v10, v12
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v0, v0
	v_mul_lo_u32 v3, s6, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v3, v0, v3
	v_add_nc_u32_e32 v0, v0, v3
	v_xor_b32_e32 v3, v9, v11
	v_xor_b32_e32 v9, v10, v12
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v13, v3, v0
	v_mul_lo_u32 v13, v13, s3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v3, v3, v13
	v_add_nc_u32_e32 v2, v2, v1
	v_xor_b32_e32 v2, v2, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v10, v2, v0
	v_mul_hi_u32 v0, v9, v0
	v_mul_lo_u32 v10, v10, s3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v0, v0, s3
	v_sub_nc_u32_e32 v2, v2, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v0, v9, v0
	v_subrev_nc_u32_e32 v10, s3, v3
	v_subrev_nc_u32_e32 v9, s3, v2
	v_cmp_le_u32_e32 vcc_lo, s3, v2
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_subrev_nc_u32_e32 v13, s3, v0
	v_cndmask_b32_e32 v2, v2, v9, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s3, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v9, s3, v2
	v_cndmask_b32_e32 v3, v3, v10, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s3, v0
	v_subrev_nc_u32_e32 v10, s3, v3
	v_cndmask_b32_e32 v0, v0, v13, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s3, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v13, s3, v0
	v_cndmask_b32_e32 v2, v2, v9, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s3, v3
	v_xor_b32_e32 v2, v2, v1
	v_cndmask_b32_e32 v3, v3, v10, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s3, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v1, v2, v1
	v_xor_b32_e32 v3, v3, v11
	v_cndmask_b32_e32 v0, v0, v13, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v2, v3, v11
	v_xor_b32_e32 v0, v0, v12
	v_cvt_f32_i32_e32 v3, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_f32_i32_e32 v9, v2
	v_sub_nc_u32_e32 v0, v0, v12
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cvt_f32_i32_e32 v10, v0
	s_waitcnt vmcnt(0)
	v_dual_add_f32 v0, v4, v3 :: v_dual_add_f32 v1, v5, v9
	s_delay_alu instid0(VALU_DEP_2)
	v_add_f32_e32 v2, v6, v10
	s_clause 0x1
	global_store_b64 v[7:8], v[9:10], off offset:16
	global_store_b128 v[7:8], v[0:3], off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8timestepP8particle4seedii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 14
		.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	_Z8timestepP8particle4seedii, .Lfunc_end0-_Z8timestepP8particle4seedii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 504
; NumSgprs: 18
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 14
; 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
      - .offset:         8
        .size:           12
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8timestepP8particle4seedii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z8timestepP8particle4seedii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     14
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
