#include <stdio.h>
#include <stdlib.h>
//#include <sys/time.h>
#define NUM_PARTICLES 10000 // Third argument
#define NUM_ITERATIONS 100 // Second argument
#define BLOCK_SIZE 16 // First argument

typedef struct
{
   float3 position;
   float3 velocity;
} Particle;


__global__ void timeStep(Particle *particles, int time) {
    const int i = blockIdx.x * blockDim.x + threadIdx.x;
    if (i < NUM_PARTICLES) {
        particles[i].velocity.x = (time % 3 == 0) ? time % 5 / 1.7 : -time % 5 / 2.8;
        particles[i].velocity.y = (time % 7 == 0) ? time % 4 / 4.5: -time % 3 / 2.3;
        particles[i].velocity.z = (time % 2 == 0) ? time % 3 * 1.6 : -time % 7 / 1.2;
        particles[i].position.x += particles[i].velocity.x;
        particles[i].position.y += particles[i].velocity.y;
        particles[i].position.z += particles[i].velocity.z;
    }
}

void timeStepCPU(Particle *particles, int time) {
    for (int i = 0; i < NUM_PARTICLES; ++i) {
        particles[i].velocity.x = (time % 3 == 0) ? time % 5 / 1.7 : -time % 5 / 2.8;
        particles[i].velocity.y = (time % 7 == 0) ? time % 4 / 4.5: -time % 3 / 2.3;
        particles[i].velocity.z = (time % 2 == 0) ? time % 3 * 1.6 : -time % 7 / 1.2;
        particles[i].position.x += particles[i].velocity.x;
        particles[i].position.y += particles[i].velocity.y;
        particles[i].position.z += particles[i].velocity.z;
    }
}

int main(int argc, char *argv[]){
    int numParticles, numIterations, blockSize;
    if (argc == 1) {
        numParticles = NUM_PARTICLES;
        numIterations = NUM_ITERATIONS;
        blockSize = BLOCK_SIZE;
    } else if (argc == 2) {
        numParticles = NUM_PARTICLES;
        numIterations = NUM_ITERATIONS;
        blockSize = atoi(argv[1]);
    } else if (argc == 3) {
        numParticles = NUM_PARTICLES;
        numIterations = atoi(argv[2]);
        blockSize = atoi(argv[1]);
    } else {
        numParticles = atoi(argv[3]);
        numIterations = atoi(argv[2]);
        blockSize = atoi(argv[1]);
    }
    //struct timeval start, end;

    Particle *particles = (Particle*)malloc(numParticles * sizeof(Particle));
    Particle *particles_GPU = (Particle*)malloc(numParticles * sizeof(Particle));
    Particle *d_particles;
    for (int i = 0; i < numParticles; ++i) {
        particles[i].velocity.x = 1;
        particles[i].velocity.y = 1;
        particles[i].velocity.z = 1;
        particles[i].position.x = 0;
        particles[i].position.y = 0;
        particles[i].position.z = 0;
    }
    cudaMalloc(&d_particles, numParticles * sizeof(Particle));
    cudaMemcpy(d_particles, particles, numParticles * sizeof(Particle), cudaMemcpyHostToDevice);

    //gettimeofday(&start, NULL);
    for (int t = 0; t < numIterations; ++t){
        timeStepCPU(particles, t);
    }
    //gettimeofday(&end, NULL);
    //printf("Computing %d iterations on the CPU... Done in %ld microseconds!\n", numIterations, ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));
    
    //gettimeofday(&start, NULL);
    for (int t = 0; t < numIterations; ++t){
        timeStep<<<blockSize, numParticles / blockSize + 1>>>(d_particles, t);
    }
    //gettimeofday(&end, NULL);
    //printf("Computing %d iterations on the GPU... Done in %ld microseconds!\n", numIterations, ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));
    cudaMemcpy(particles_GPU, d_particles, numParticles * sizeof(Particle), cudaMemcpyDeviceToHost);

    int sameArray = 1;
    for (int i = 0; i < numParticles; ++i) {
        if ((particles[i].position.x != particles_GPU[i].position.x) || (particles[i].position.y != particles_GPU[i].position.y)|| (particles[i].position.z != particles_GPU[i].position.z)) {
            printf("Comparing the output for each implementation… Wrong at %d!\n", i);
            printf("GPU.x: %f, CPU.x: %f\n", particles[i].position.x, particles_GPU[i].position.x);
            sameArray = 0;
            break;
        }
    }
    if (sameArray == 1) {
        printf("Comparing the output for each implementation… Correct!\n");
    }


    free(particles);
    free(particles_GPU);
    cudaFree(d_particles);
}
	.file	"tmpxft_002ffb44_00000000-6_exercise_3_joel.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	_Z11timeStepCPUP8Particlei
	.type	_Z11timeStepCPUP8Particlei, @function
_Z11timeStepCPUP8Particlei:
.LFB2027:
	.cfi_startproc
	endbr64
	movl	%esi, %eax
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$5, %r10d
	movq	%rdi, %rcx
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	cltd
	movl	%esi, %ebp
	movl	$7, %r12d
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	$3, %ebx
	negl	%ebp
	movsd	.LC1(%rip), %xmm2
	idivl	%ebx
	movsd	.LC0(%rip), %xmm3
	movsd	.LC3(%rip), %xmm4
	movsd	.LC2(%rip), %xmm5
	movsd	.LC5(%rip), %xmm6
	movsd	.LC4(%rip), %xmm7
	movl	%ebp, %eax
	movl	%edx, %edi
	cltd
	idivl	%r10d
	movl	%esi, %eax
	movl	%edx, %r8d
	cltd
	idivl	%r10d
	movl	%esi, %eax
	movl	%edx, %r9d
	cltd
	idivl	%r12d
	movl	%ebp, %eax
	movl	%edx, %r10d
	cltd
	idivl	%ebx
	movl	%esi, %eax
	movl	$4, %ebx
	andl	$1, %esi
	movl	%edx, %r11d
	cltd
	idivl	%ebx
	movl	%ebp, %eax
	movl	%edx, %ebx
	cltd
	idivl	%r12d
	leaq	240000(%rcx), %rax
.L9:
	testl	%edi, %edi
	jne	.L3
	cvtsi2sdl	%r9d, %xmm8
	divsd	%xmm3, %xmm8
	jmp	.L4
.L3:
	cvtsi2sdl	%r8d, %xmm8
	divsd	%xmm2, %xmm8
.L4:
	cvtsd2ss	%xmm8, %xmm8
	movss	%xmm8, 12(%rcx)
	testl	%r10d, %r10d
	jne	.L5
	cvtsi2sdl	%ebx, %xmm1
	divsd	%xmm5, %xmm1
	jmp	.L6
.L5:
	cvtsi2sdl	%r11d, %xmm1
	divsd	%xmm4, %xmm1
.L6:
	cvtsd2ss	%xmm1, %xmm1
	movss	%xmm1, 16(%rcx)
	testl	%esi, %esi
	jne	.L7
	cvtsi2sdl	%edi, %xmm0
	mulsd	%xmm7, %xmm0
	jmp	.L8
.L7:
	cvtsi2sdl	%edx, %xmm0
	divsd	%xmm6, %xmm0
.L8:
	addss	(%rcx), %xmm8
	addss	4(%rcx), %xmm1
	cvtsd2ss	%xmm0, %xmm0
	addq	$24, %rcx
	movss	%xmm0, -4(%rcx)
	addss	-16(%rcx), %xmm0
	movss	%xmm8, -24(%rcx)
	movss	%xmm1, -20(%rcx)
	movss	%xmm0, -16(%rcx)
	cmpq	%rcx, %rax
	jne	.L9
	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	_Z11timeStepCPUP8Particlei, .-_Z11timeStepCPUP8Particlei
	.globl	_Z36__device_stub__Z8timeStepP8ParticleiP8Particlei
	.type	_Z36__device_stub__Z8timeStepP8ParticleiP8Particlei, @function
_Z36__device_stub__Z8timeStepP8ParticleiP8Particlei:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z8timeStepP8Particlei(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	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 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L13:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z36__device_stub__Z8timeStepP8ParticleiP8Particlei, .-_Z36__device_stub__Z8timeStepP8ParticleiP8Particlei
	.globl	_Z8timeStepP8Particlei
	.type	_Z8timeStepP8Particlei, @function
_Z8timeStepP8Particlei:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z8timeStepP8ParticleiP8Particlei
	.cfi_endproc
.LFE2054:
	.size	_Z8timeStepP8Particlei, .-_Z8timeStepP8Particlei
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC8:
	.string	"Comparing the output for each implementation\342\200\246 Wrong at %d!\n"
.LC9:
	.string	"GPU.x: %f, CPU.x: %f\n"
.LC10:
	.string	"Comparing the output for each implementation\342\200\246 Correct!\n"
	.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
	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
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	cmpl	$1, %edi
	je	.L36
	movl	%edi, %r14d
	movq	8(%rsi), %rdi
	movq	%rsi, %r13
	call	atoi@PLT
	movl	%eax, %r12d
	cmpl	$2, %r14d
	je	.L37
	movq	16(%r13), %rdi
	movl	$10000, %ebx
	call	atoi@PLT
	movl	%eax, %ebp
	cmpl	$3, %r14d
	je	.L19
	movq	24(%r13), %rdi
	call	atoi@PLT
	movl	%eax, %ebx
	jmp	.L19
.L36:
	movl	$16, %r12d
.L37:
	movl	$100, %ebp
	movl	$10000, %ebx
.L19:
	movslq	%ebx, %rax
	imulq	$24, %rax, %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	16(%rsp), %r13
	movss	.LC6(%rip), %xmm0
	xorl	%edx, %edx
	movq	%rax, 24(%rsp)
	movq	%r13, %rax
.L20:
	cmpl	%edx, %ebx
	jle	.L42
	movl	$0x00000000, (%rax)
	incl	%edx
	addq	$24, %rax
	movss	%xmm0, -12(%rax)
	movss	%xmm0, -8(%rax)
	movss	%xmm0, -4(%rax)
	movl	$0x00000000, -20(%rax)
	movl	$0x00000000, -16(%rax)
	jmp	.L20
.L42:
	movq	8(%rsp), %rsi
	leaq	40(%rsp), %rdi
	xorl	%r14d, %r14d
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	40(%rsp), %rdi
	call	cudaMemcpy@PLT
.L22:
	cmpl	%r14d, %ebp
	jle	.L43
	movq	16(%rsp), %rdi
	movl	%r14d, %esi
	incl	%r14d
	call	_Z11timeStepCPUP8Particlei
	jmp	.L22
.L43:
	movabsq	$4294967297, %r15
	xorl	%r14d, %r14d
.L24:
	cmpl	%r14d, %ebp
	jle	.L44
	movl	%ebx, %eax
	movq	%r15, 64(%rsp)
	movl	68(%rsp), %ecx
	xorl	%r9d, %r9d
	cltd
	movq	%r15, 52(%rsp)
	movl	56(%rsp), %esi
	xorl	%r8d, %r8d
	idivl	%r12d
	movl	%r12d, 48(%rsp)
	movq	48(%rsp), %rdi
	incl	%eax
	movl	%eax, 60(%rsp)
	movq	60(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	40(%rsp), %rdi
	movl	%r14d, %esi
	call	_Z36__device_stub__Z8timeStepP8ParticleiP8Particlei
.L25:
	incl	%r14d
	jmp	.L24
.L44:
	movq	8(%rsp), %rdx
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	24(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rax
	xorl	%edx, %edx
.L27:
	cmpl	%edx, %ebx
	jle	.L45
	movss	0(%r13), %xmm0
	ucomiss	(%rax), %xmm0
	movq	%r13, %r12
	movq	%rax, %rbp
	jp	.L28
	jne	.L28
	movss	4(%r13), %xmm0
	ucomiss	4(%rax), %xmm0
	jp	.L28
	jne	.L28
	movss	8(%r12), %xmm0
	addq	$24, %r13
	addq	$24, %rax
	ucomiss	8(%rbp), %xmm0
	jp	.L28
	je	.L31
.L28:
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movb	$2, %al
	cvtss2sd	(%r12), %xmm0
	cvtss2sd	0(%rbp), %xmm1
	call	__printf_chk@PLT
	jmp	.L33
.L31:
	incl	%edx
	jmp	.L27
.L45:
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L33:
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$88, %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
.LC11:
	.string	"_Z8timeStepP8Particlei"
	.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	.LC11(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z8timeStepP8Particlei(%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.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	858993459
	.long	1073427251
	.align 8
.LC1:
	.long	1717986918
	.long	1074161254
	.align 8
.LC2:
	.long	0
	.long	1074921472
	.align 8
.LC3:
	.long	1717986918
	.long	1073899110
	.align 8
.LC4:
	.long	-1717986918
	.long	1073322393
	.align 8
.LC5:
	.long	858993459
	.long	1072902963
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC6:
	.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 <stdlib.h>
//#include <sys/time.h>
#define NUM_PARTICLES 10000 // Third argument
#define NUM_ITERATIONS 100 // Second argument
#define BLOCK_SIZE 16 // First argument

typedef struct
{
   float3 position;
   float3 velocity;
} Particle;


__global__ void timeStep(Particle *particles, int time) {
    const int i = blockIdx.x * blockDim.x + threadIdx.x;
    if (i < NUM_PARTICLES) {
        particles[i].velocity.x = (time % 3 == 0) ? time % 5 / 1.7 : -time % 5 / 2.8;
        particles[i].velocity.y = (time % 7 == 0) ? time % 4 / 4.5: -time % 3 / 2.3;
        particles[i].velocity.z = (time % 2 == 0) ? time % 3 * 1.6 : -time % 7 / 1.2;
        particles[i].position.x += particles[i].velocity.x;
        particles[i].position.y += particles[i].velocity.y;
        particles[i].position.z += particles[i].velocity.z;
    }
}

void timeStepCPU(Particle *particles, int time) {
    for (int i = 0; i < NUM_PARTICLES; ++i) {
        particles[i].velocity.x = (time % 3 == 0) ? time % 5 / 1.7 : -time % 5 / 2.8;
        particles[i].velocity.y = (time % 7 == 0) ? time % 4 / 4.5: -time % 3 / 2.3;
        particles[i].velocity.z = (time % 2 == 0) ? time % 3 * 1.6 : -time % 7 / 1.2;
        particles[i].position.x += particles[i].velocity.x;
        particles[i].position.y += particles[i].velocity.y;
        particles[i].position.z += particles[i].velocity.z;
    }
}

int main(int argc, char *argv[]){
    int numParticles, numIterations, blockSize;
    if (argc == 1) {
        numParticles = NUM_PARTICLES;
        numIterations = NUM_ITERATIONS;
        blockSize = BLOCK_SIZE;
    } else if (argc == 2) {
        numParticles = NUM_PARTICLES;
        numIterations = NUM_ITERATIONS;
        blockSize = atoi(argv[1]);
    } else if (argc == 3) {
        numParticles = NUM_PARTICLES;
        numIterations = atoi(argv[2]);
        blockSize = atoi(argv[1]);
    } else {
        numParticles = atoi(argv[3]);
        numIterations = atoi(argv[2]);
        blockSize = atoi(argv[1]);
    }
    //struct timeval start, end;

    Particle *particles = (Particle*)malloc(numParticles * sizeof(Particle));
    Particle *particles_GPU = (Particle*)malloc(numParticles * sizeof(Particle));
    Particle *d_particles;
    for (int i = 0; i < numParticles; ++i) {
        particles[i].velocity.x = 1;
        particles[i].velocity.y = 1;
        particles[i].velocity.z = 1;
        particles[i].position.x = 0;
        particles[i].position.y = 0;
        particles[i].position.z = 0;
    }
    hipMalloc(&d_particles, numParticles * sizeof(Particle));
    hipMemcpy(d_particles, particles, numParticles * sizeof(Particle), hipMemcpyHostToDevice);

    //gettimeofday(&start, NULL);
    for (int t = 0; t < numIterations; ++t){
        timeStepCPU(particles, t);
    }
    //gettimeofday(&end, NULL);
    //printf("Computing %d iterations on the CPU... Done in %ld microseconds!\n", numIterations, ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));
    
    //gettimeofday(&start, NULL);
    for (int t = 0; t < numIterations; ++t){
        timeStep<<<blockSize, numParticles / blockSize + 1>>>(d_particles, t);
    }
    //gettimeofday(&end, NULL);
    //printf("Computing %d iterations on the GPU... Done in %ld microseconds!\n", numIterations, ((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));
    hipMemcpy(particles_GPU, d_particles, numParticles * sizeof(Particle), hipMemcpyDeviceToHost);

    int sameArray = 1;
    for (int i = 0; i < numParticles; ++i) {
        if ((particles[i].position.x != particles_GPU[i].position.x) || (particles[i].position.y != particles_GPU[i].position.y)|| (particles[i].position.z != particles_GPU[i].position.z)) {
            printf("Comparing the output for each implementation… Wrong at %d!\n", i);
            printf("GPU.x: %f, CPU.x: %f\n", particles[i].position.x, particles_GPU[i].position.x);
            sameArray = 0;
            break;
        }
    }
    if (sameArray == 1) {
        printf("Comparing the output for each implementation… Correct!\n");
    }


    free(particles);
    free(particles_GPU);
    hipFree(d_particles);
}
	.text
	.file	"exercise_3_joel.hip"
	.globl	_Z23__device_stub__timeStepP8Particlei # -- Begin function _Z23__device_stub__timeStepP8Particlei
	.type	_Z23__device_stub__timeStepP8Particlei,@function
_Z23__device_stub__timeStepP8Particlei: # @_Z23__device_stub__timeStepP8Particlei
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%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	$_Z8timeStepP8Particlei, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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_end0:
	.size	_Z23__device_stub__timeStepP8Particlei, .Lfunc_end0-_Z23__device_stub__timeStepP8Particlei
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z11timeStepCPUP8Particlei
.LCPI1_0:
	.quad	0x4006666666666666              # double 2.7999999999999998
.LCPI1_1:
	.quad	0x3ffb333333333333              # double 1.7
.LCPI1_2:
	.quad	0x4002666666666666              # double 2.2999999999999998
.LCPI1_3:
	.quad	0x4012000000000000              # double 4.5
.LCPI1_4:
	.quad	0x3ff3333333333333              # double 1.2
.LCPI1_5:
	.quad	0x3ff999999999999a              # double 1.6000000000000001
	.text
	.globl	_Z11timeStepCPUP8Particlei
	.type	_Z11timeStepCPUP8Particlei,@function
_Z11timeStepCPUP8Particlei:             # @_Z11timeStepCPUP8Particlei
	.cfi_startproc
# %bb.0:
	movslq	%esi, %rdx
	imulq	$1431655766, %rdx, %rax         # imm = 0x55555556
	movq	%rax, %rcx
	shrq	$63, %rcx
	shrq	$32, %rax
	addl	%ecx, %eax
	leal	(%rax,%rax,2), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	imulq	$-1840700269, %rdx, %rcx        # imm = 0x92492493
	shrq	$32, %rcx
	addl	%esi, %ecx
	movl	%ecx, %r8d
	shrl	$31, %r8d
	sarl	$2, %ecx
	addl	%r8d, %ecx
	leal	(,%rcx,8), %r8d
	subl	%r8d, %ecx
	addl	%esi, %ecx
	imulq	$1717986919, %rdx, %r8          # imm = 0x66666667
	movq	%r8, %r9
	shrq	$63, %r9
	sarq	$33, %r8
	addl	%r9d, %r8d
	leal	(%r8,%r8,4), %r8d
	movl	%edx, %r9d
	subl	%r8d, %r9d
	leal	3(%rdx), %r8d
	testl	%edx, %edx
	cmovnsl	%esi, %r8d
	testl	%eax, %eax
	je	.LBB1_1
# %bb.2:
	negl	%r9d
	cvtsi2sd	%r9d, %xmm0
	divsd	.LCPI1_0(%rip), %xmm0
	jmp	.LBB1_3
.LBB1_1:
	cvtsi2sd	%r9d, %xmm0
	divsd	.LCPI1_1(%rip), %xmm0
.LBB1_3:
	testl	%ecx, %ecx
	je	.LBB1_4
# %bb.5:
	movl	%eax, %edx
	negl	%edx
	cvtsi2sd	%edx, %xmm1
	divsd	.LCPI1_2(%rip), %xmm1
	jmp	.LBB1_6
.LBB1_4:
	andl	$-4, %r8d
	movl	%esi, %edx
	subl	%r8d, %edx
	cvtsi2sd	%edx, %xmm1
	divsd	.LCPI1_3(%rip), %xmm1
.LBB1_6:
	testb	$1, %sil
	je	.LBB1_7
# %bb.8:
	negl	%ecx
	cvtsi2sd	%ecx, %xmm2
	divsd	.LCPI1_4(%rip), %xmm2
	jmp	.LBB1_9
.LBB1_7:
	cvtsi2sd	%eax, %xmm2
	mulsd	.LCPI1_5(%rip), %xmm2
.LBB1_9:
	cvtsd2ss	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm1
	cvtsd2ss	%xmm2, %xmm2
	xorl	%eax, %eax
.LBB1_10:                               # =>This Inner Loop Header: Depth=1
	movss	%xmm0, 12(%rdi,%rax)
	movss	%xmm1, 16(%rdi,%rax)
	movss	%xmm2, 20(%rdi,%rax)
	movss	(%rdi,%rax), %xmm3              # xmm3 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm3
	movss	%xmm3, (%rdi,%rax)
	movss	4(%rdi,%rax), %xmm3             # xmm3 = mem[0],zero,zero,zero
	addss	%xmm1, %xmm3
	movss	%xmm3, 4(%rdi,%rax)
	movss	8(%rdi,%rax), %xmm3             # xmm3 = mem[0],zero,zero,zero
	addss	%xmm2, %xmm3
	movss	%xmm3, 8(%rdi,%rax)
	addq	$24, %rax
	cmpq	$240000, %rax                   # imm = 0x3A980
	jne	.LBB1_10
# %bb.11:
	retq
.Lfunc_end1:
	.size	_Z11timeStepCPUP8Particlei, .Lfunc_end1-_Z11timeStepCPUP8Particlei
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x00000000                      # float 0
	.long	0x00000000                      # float 0
	.long	0x00000000                      # float 0
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$10000, %ebp                    # imm = 0x2710
	movl	$100, %r15d
	cmpl	$1, %edi
	je	.LBB2_1
# %bb.2:
	movq	%rsi, %rbx
	cmpl	$2, %edi
	je	.LBB2_6
# %bb.3:
	cmpl	$3, %edi
	je	.LBB2_5
# %bb.4:
	movq	24(%rbx), %rdi
	callq	atoi
	movl	%eax, %ebp
.LBB2_5:                                # %.sink.split.sink.split
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %r15d
.LBB2_6:                                # %.sink.split
	movq	8(%rbx), %rdi
	callq	atoi
	movl	%eax, 8(%rsp)                   # 4-byte Spill
	jmp	.LBB2_7
.LBB2_1:
	movl	$16, 8(%rsp)                    # 4-byte Folded Spill
.LBB2_7:
	movslq	%ebp, %r12
	leaq	(,%r12,8), %rax
	leaq	(%rax,%rax,2), %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r14
	movl	%ebp, 12(%rsp)                  # 4-byte Spill
	movl	%ebp, %esi
	testl	%r12d, %r12d
	jle	.LBB2_10
# %bb.8:                                # %.lr.ph.preheader
	leaq	(,%rsi,8), %rax
	leaq	(%rax,%rax,2), %rax
	xorl	%ecx, %ecx
	movabsq	$4575657222473777152, %rdx      # imm = 0x3F8000003F800000
	movaps	.LCPI2_0(%rip), %xmm0           # xmm0 = [0.0E+0,0.0E+0,0.0E+0,1.0E+0]
.LBB2_9:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%rdx, 16(%rbx,%rcx)
	movups	%xmm0, (%rbx,%rcx)
	addq	$24, %rcx
	cmpq	%rcx, %rax
	jne	.LBB2_9
.LBB2_10:                               # %._crit_edge
	movq	%rsi, 24(%rsp)                  # 8-byte Spill
	leaq	16(%rsp), %r12
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r12), %rdi
	movq	%rbx, %rsi
	movq	%r13, 32(%rsp)                  # 8-byte Spill
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%r15d, %r15d
	jle	.LBB2_18
# %bb.11:                               # %.lr.ph85.preheader
	xorl	%ebp, %ebp
.LBB2_12:                               # %.lr.ph85
                                        # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	_Z11timeStepCPUP8Particlei
	incl	%ebp
	cmpl	%ebp, %r15d
	jne	.LBB2_12
# %bb.13:                               # %.preheader
	testl	%r15d, %r15d
	jle	.LBB2_18
# %bb.14:                               # %.lr.ph87
	movl	12(%rsp), %eax                  # 4-byte Reload
	cltd
	movl	8(%rsp), %ecx                   # 4-byte Reload
	idivl	%ecx
	movl	%eax, %r13d
	incl	%r13d
	movl	%ecx, %ebp
	btsq	$32, %rbp
	btsq	$32, %r13
	xorl	%r12d, %r12d
.LBB2_15:                               # =>This Inner Loop Header: Depth=1
	movq	%rbp, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_17
# %bb.16:                               #   in Loop: Header=BB2_15 Depth=1
	movq	16(%rsp), %rdi
	movl	%r12d, %esi
	callq	_Z23__device_stub__timeStepP8Particlei
.LBB2_17:                               #   in Loop: Header=BB2_15 Depth=1
	incl	%r12d
	cmpl	%r12d, %r15d
	jne	.LBB2_15
.LBB2_18:                               # %._crit_edge88
	movq	16(%rsp), %rsi
	movq	%r14, %rdi
	movq	32(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	cmpl	$0, 12(%rsp)                    # 4-byte Folded Reload
	jle	.LBB2_25
# %bb.19:                               # %.lr.ph92.preheader
	movq	24(%rsp), %rax                  # 8-byte Reload
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %rax
	xorl	%r15d, %r15d
	xorl	%esi, %esi
.LBB2_20:                               # %.lr.ph92
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rbx,%r15), %xmm0              # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%r14,%r15), %xmm0
	jne	.LBB2_23
	jp	.LBB2_23
# %bb.21:                               #   in Loop: Header=BB2_20 Depth=1
	movss	4(%rbx,%r15), %xmm0             # xmm0 = mem[0],zero,zero,zero
	ucomiss	4(%r14,%r15), %xmm0
	jne	.LBB2_23
	jp	.LBB2_23
# %bb.22:                               #   in Loop: Header=BB2_20 Depth=1
	movss	8(%rbx,%r15), %xmm0             # xmm0 = mem[0],zero,zero,zero
	ucomiss	8(%r14,%r15), %xmm0
	jne	.LBB2_23
	jp	.LBB2_23
# %bb.24:                               #   in Loop: Header=BB2_20 Depth=1
	incl	%esi
	addq	$24, %r15
	cmpq	%r15, %rax
	jne	.LBB2_20
.LBB2_25:                               # %.critedge
	movl	$.Lstr, %edi
	callq	puts@PLT
	jmp	.LBB2_26
.LBB2_23:
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r15), %xmm0
	cvtss2sd	(%r14,%r15), %xmm1
	movl	$.L.str.1, %edi
	movb	$2, %al
	callq	printf
.LBB2_26:
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$40, %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	$_Z8timeStepP8Particlei, %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	_Z8timeStepP8Particlei,@object  # @_Z8timeStepP8Particlei
	.section	.rodata,"a",@progbits
	.globl	_Z8timeStepP8Particlei
	.p2align	3, 0x0
_Z8timeStepP8Particlei:
	.quad	_Z23__device_stub__timeStepP8Particlei
	.size	_Z8timeStepP8Particlei, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Comparing the output for each implementation\342\200\246 Wrong at %d!\n"
	.size	.L.str, 62

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"GPU.x: %f, CPU.x: %f\n"
	.size	.L.str.1, 22

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z8timeStepP8Particlei"
	.size	.L__unnamed_1, 23

	.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,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Comparing the output for each implementation\342\200\246 Correct!"
	.size	.Lstr, 57

	.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__timeStepP8Particlei
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z8timeStepP8Particlei
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8timeStepP8Particlei  ; -- Begin function _Z8timeStepP8Particlei
	.globl	_Z8timeStepP8Particlei
	.p2align	8
	.type	_Z8timeStepP8Particlei,@function
_Z8timeStepP8Particlei:                 ; @_Z8timeStepP8Particlei
; %bb.0:
	s_load_b32 s2, s[0:1], 0x1c
	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_e32 0x2710, v1
	s_cbranch_execz .LBB0_12
; %bb.1:
	s_clause 0x1
	s_load_b32 s5, s[0:1], 0x8
	s_load_b64 s[0:1], s[0:1], 0x0
	s_mov_b32 s8, 0
	s_waitcnt lgkmcnt(0)
	s_mul_hi_i32 s2, s5, 0x66666667
	s_mul_hi_i32 s3, s5, 0x55555556
	s_lshr_b32 s4, s2, 31
	s_ashr_i32 s2, s2, 1
	s_lshr_b32 s6, s3, 31
	s_add_i32 s2, s2, s4
	s_add_i32 s3, s3, s6
	s_mul_i32 s2, s2, 5
	s_mul_i32 s3, s3, 3
	s_sub_i32 s2, s5, s2
	s_sub_i32 s4, s5, s3
	s_sub_i32 s3, 0, s2
	s_cmp_eq_u32 s4, 0
	s_mov_b32 s6, 0x33333333
	s_cselect_b32 s2, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cvt_f64_i32_e32 v[2:3], s2
	s_mov_b32 s2, 0x3ffb3333
	s_cselect_b32 s3, s2, 0x40066666
	s_cselect_b32 s2, s6, 0x66666666
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_div_scale_f64 v[4:5], null, s[2:3], s[2:3], v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[6:7], v[4:5]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	v_div_scale_f64 v[8:9], vcc_lo, v[2:3], s[2:3], v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[8:9], v[6:7]
	v_fma_f64 v[4:5], -v[4:5], v[10:11], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[4:5], v[4:5], v[6:7], v[10:11]
	v_div_fixup_f64 v[2:3], v[4:5], s[2:3], v[2:3]
	v_mad_i64_i32 v[4:5], null, v1, 24, s[0:1]
	s_mul_hi_i32 s2, s5, 0x92492493
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s2, s2, s5
	s_lshr_b32 s3, s2, 31
	s_ashr_i32 s2, s2, 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s2, s2, s3
	s_mul_i32 s2, s2, 7
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	s_sub_i32 s6, s5, s2
	s_mov_b32 s2, 0x66666666
	s_cmp_lg_u32 s6, 0
	v_cvt_f32_f64_e32 v0, v[2:3]
	v_add_co_u32 v2, vcc_lo, v4, 12
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v5, vcc_lo
	global_store_b32 v[4:5], v0, off offset:12
	s_cbranch_scc0 .LBB0_3
; %bb.2:
	s_sub_i32 s7, 0, s4
	s_mov_b32 s3, 0x40026666
	s_branch .LBB0_4
.LBB0_3:
	s_mov_b32 s8, -1
                                        ; implicit-def: $sgpr2_sgpr3
                                        ; implicit-def: $sgpr7
.LBB0_4:                                ; %Flow35
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s8
	s_cbranch_vccnz .LBB0_6
; %bb.5:
	s_ashr_i32 s2, s5, 31
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshr_b32 s2, s2, 30
	s_add_i32 s7, s5, s2
	s_mov_b32 s2, 0
	s_and_b32 s7, s7, -4
	s_mov_b32 s3, 0x40120000
	s_sub_i32 s7, s5, s7
.LBB0_6:
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f64_i32_e32 v[4:5], s7
	s_bitcmp1_b32 s5, 0
	v_div_scale_f64 v[6:7], null, s[2:3], s[2:3], v[4:5]
	v_div_scale_f64 v[12:13], vcc_lo, v[4:5], s[2:3], v[4:5]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[8:9], v[6:7]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[10:11], -v[6:7], v[8:9], 1.0
	v_fma_f64 v[8:9], v[8:9], v[10:11], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[10:11], -v[6:7], v[8:9], 1.0
	v_fma_f64 v[8:9], v[8:9], v[10:11], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[12:13], v[8:9]
	v_fma_f64 v[6:7], -v[6:7], v[10:11], v[12:13]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[6:7], v[6:7], v[8:9], v[10:11]
	v_div_fixup_f64 v[4:5], v[6:7], s[2:3], v[4:5]
	s_cselect_b32 s2, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_and_b32 vcc_lo, exec_lo, s2
	v_cvt_f32_f64_e32 v6, v[4:5]
	global_store_b32 v[2:3], v6, off offset:4
	s_cbranch_vccz .LBB0_8
; %bb.7:
	s_sub_i32 s2, 0, s6
	s_delay_alu instid0(SALU_CYCLE_1)
	v_cvt_f64_i32_e32 v[4:5], s2
	s_mov_b32 s2, 0x33333333
	s_mov_b32 s3, 0x3ff33333
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_div_scale_f64 v[7:8], null, s[2:3], s[2:3], v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[9:10], v[7:8]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[11:12], -v[7:8], v[9:10], 1.0
	v_fma_f64 v[9:10], v[9:10], v[11:12], v[9:10]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[11:12], -v[7:8], v[9:10], 1.0
	v_fma_f64 v[9:10], v[9:10], v[11:12], v[9:10]
	v_div_scale_f64 v[11:12], vcc_lo, v[4:5], s[2:3], v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[13:14], v[11:12], v[9:10]
	v_fma_f64 v[7:8], -v[7:8], v[13:14], v[11:12]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[7:8], v[7:8], v[9:10], v[13:14]
	v_div_fixup_f64 v[4:5], v[7:8], s[2:3], v[4:5]
	s_mov_b32 s2, 0
	s_branch .LBB0_9
.LBB0_8:
	s_mov_b32 s2, -1
                                        ; implicit-def: $vgpr4_vgpr5
.LBB0_9:                                ; %Flow
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB0_11
; %bb.10:
	v_cvt_f64_i32_e32 v[4:5], s4
	s_mov_b32 s2, 0x9999999a
	s_mov_b32 s3, 0x3ff99999
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mul_f64 v[4:5], v[4:5], s[2:3]
.LBB0_11:
	v_mad_i64_i32 v[10:11], null, v1, 24, s[0:1]
	s_delay_alu instid0(VALU_DEP_2)
	v_cvt_f32_f64_e32 v1, v[4:5]
	global_load_b96 v[7:9], v[10:11], off
	s_waitcnt vmcnt(0)
	v_dual_add_f32 v4, v7, v0 :: v_dual_add_f32 v5, v8, v6
	v_add_f32_e32 v6, v9, v1
	s_clause 0x1
	global_store_b32 v[2:3], v1, off offset:8
	global_store_b96 v[10:11], v[4:6], off
.LBB0_12:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8timeStepP8Particlei
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 15
		.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	_Z8timeStepP8Particlei, .Lfunc_end0-_Z8timeStepP8Particlei
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 856
; NumSgprs: 18
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 15
; 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:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8timeStepP8Particlei
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z8timeStepP8Particlei.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
