#include <iostream>
#include <cuda_runtime.h>
#include <cuda_fp16.h>
#include <vector_types.h>

#define NUM_PARTICLES 16384
#define BLOCK_SIZE 256

__device__ float4 computeForce(float4 pos, float4* positions, float4* velocities, int numParticles) {
    float4 force = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
    for (int j = 0; j < numParticles; ++j) {
        float4 diff = make_float4(pos.x - positions[j].x, pos.y - positions[j].y, pos.z - positions[j].z, 0.0f);
        float distSqr = diff.x * diff.x + diff.y * diff.y + diff.z * diff.z + 1.0f; // Add 1 to prevent division by zero
        float dist = rsqrtf(distSqr);
        float distCubed = dist * dist * dist;
        force.x += diff.x * distCubed;
        force.y += diff.y * distCubed;
        force.z += diff.z * distCubed;
    }
    return force;
}

__global__ void rungeKuttaStep(float4* positions, float4* velocities, float4* k1, float4* k2, float4* k3, float4* k4, float dt, int numParticles) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < numParticles) {
        float4 pos = positions[idx];
        float4 vel = velocities[idx];

        // Compute k1
        float4 f1 = computeForce(pos, positions, velocities, numParticles);
        k1[idx] = f1;
        float4 pos2 = make_float4(pos.x + 0.5f * dt * vel.x, pos.y + 0.5f * dt * vel.y, pos.z + 0.5f * dt * vel.z, 0.0f);
        float4 vel2 = make_float4(vel.x + 0.5f * dt * f1.x, vel.y + 0.5f * dt * f1.y, vel.z + 0.5f * dt * f1.z, 0.0f);

        // Compute k2
        float4 f2 = computeForce(pos2, positions, velocities, numParticles);
        k2[idx] = f2;
        float4 pos3 = make_float4(pos.x + 0.5f * dt * vel2.x, pos.y + 0.5f * dt * vel2.y, pos.z + 0.5f * dt * vel2.z, 0.0f);
        float4 vel3 = make_float4(vel.x + 0.5f * dt * f2.x, vel.y + 0.5f * dt * f2.y, vel.z + 0.5f * dt * f2.z, 0.0f);

        // Compute k3
        float4 f3 = computeForce(pos3, positions, velocities, numParticles);
        k3[idx] = f3;
        float4 pos4 = make_float4(pos.x + dt * vel3.x, pos.y + dt * vel3.y, pos.z + dt * vel3.z, 0.0f);
        float4 vel4 = make_float4(vel.x + dt * f3.x, vel.y + dt * f3.y, vel.z + dt * f3.z, 0.0f);

        // Compute k4
        float4 f4 = computeForce(pos4, positions, velocities, numParticles);
        k4[idx] = f4;

        // Update position and velocity
        positions[idx] = make_float4(pos.x + dt / 6.0f * (vel.x + 2.0f * vel2.x + 2.0f * vel3.x + vel4.x),
                                    pos.y + dt / 6.0f * (vel.y + 2.0f * vel2.y + 2.0f * vel3.y + vel4.y),
                                    pos.z + dt / 6.0f * (vel.z + 2.0f * vel2.z + 2.0f * vel3.z + vel4.z),
                                    0.0f);
        velocities[idx] = make_float4(vel.x + dt / 6.0f * (f1.x + 2.0f * f2.x + 2.0f * f3.x + f4.x),
                                     vel.y + dt / 6.0f * (f1.y + 2.0f * f2.y + 2.0f * f3.y + f4.y),
                                     vel.z + dt / 6.0f * (f1.z + 2.0f * f2.z + 2.0f * f3.z + f4.z),
                                     0.0f);
    }
}

int main() {
    float4* d_positions, *d_velocities, *d_k1, *d_k2, *d_k3, *d_k4;
    float4* h_positions = new float4[NUM_PARTICLES];
    float4* h_velocities = new float4[NUM_PARTICLES];

    // Initialize positions and velocities
    for (int i = 0; i < NUM_PARTICLES; ++i) {
        h_positions[i] = make_float4(static_cast<float>(rand()) / RAND_MAX, static_cast<float>(rand()) / RAND_MAX, static_cast<float>(rand()) / RAND_MAX, 0.0f);
        h_velocities[i] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
    }

    // Allocate device memory
    cudaMalloc(&d_positions, NUM_PARTICLES * sizeof(float4));
    cudaMalloc(&d_velocities, NUM_PARTICLES * sizeof(float4));
    cudaMalloc(&d_k1, NUM_PARTICLES * sizeof(float4));
    cudaMalloc(&d_k2, NUM_PARTICLES * sizeof(float4));
    cudaMalloc(&d_k3, NUM_PARTICLES * sizeof(float4));
    cudaMalloc(&d_k4, NUM_PARTICLES * sizeof(float4));

    // Copy data to device
    cudaMemcpy(d_positions, h_positions, NUM_PARTICLES * sizeof(float4), cudaMemcpyHostToDevice);
    cudaMemcpy(d_velocities, h_velocities, NUM_PARTICLES * sizeof(float4), cudaMemcpyHostToDevice);

    // Simulation parameters
    float dt = 0.01f;
    int numSteps = 100;

    // Launch kernel for each time step
    for (int step = 0; step < numSteps; ++step) {
        rungeKuttaStep<<<(NUM_PARTICLES + BLOCK_SIZE - 1) / BLOCK_SIZE, BLOCK_SIZE>>>(d_positions, d_velocities, d_k1, d_k2, d_k3, d_k4, dt, NUM_PARTICLES);
        cudaDeviceSynchronize();

        // Check for errors
        cudaError_t err = cudaGetLastError();
        if (err != cudaSuccess) {
            std::cerr << "CUDA error: " << cudaGetErrorString(err) << std::endl;
            return -1;
        }
    }

    // Copy results back to host
    cudaMemcpy(h_positions, d_positions, NUM_PARTICLES * sizeof(float4), cudaMemcpyDeviceToHost);
    cudaMemcpy(h_velocities, d_velocities, NUM_PARTICLES * sizeof(float4), cudaMemcpyDeviceToHost);

    // Free device memory
    cudaFree(d_positions);
    cudaFree(d_velocities);
    cudaFree(d_k1);
    cudaFree(d_k2);
    cudaFree(d_k3);
    cudaFree(d_k4);

    // Free host memory
    delete[] h_positions;
    delete[] h_velocities;

    std::cout << "Simulation completed successfully." << std::endl;
    return 0;
}
	.file	"tmpxft_00023734_00000000-6_cuda_code_043826.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4013:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4013:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12computeForce6float4PS_S0_i
	.type	_Z12computeForce6float4PS_S0_i, @function
_Z12computeForce6float4PS_S0_i:
.LFB4009:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE4009:
	.size	_Z12computeForce6float4PS_S0_i, .-_Z12computeForce6float4PS_S0_i
	.globl	_Z57__device_stub__Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fiP6float4S0_S0_S0_S0_S0_fi
	.type	_Z57__device_stub__Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fiP6float4S0_S0_S0_S0_S0_fi, @function
_Z57__device_stub__Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fiP6float4S0_S0_S0_S0_S0_fi:
.LFB4035:
	.cfi_startproc
	endbr64
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	%rdi, 56(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movq	%rcx, 32(%rsp)
	leaq	80(%rsp), %rcx
	movq	%r8, 24(%rsp)
	movq	%r9, 16(%rsp)
	movss	%xmm0, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 96(%rsp)
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	224(%rsp), %rax
	movq	%rax, 192(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 88(%rsp)
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L4
	pushq	80(%rsp)
	.cfi_def_cfa_offset 232
	leaq	_Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fi(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 240
	movq	116(%rsp), %rcx
	movl	124(%rsp), %r8d
	movq	104(%rsp), %rsi
	movl	112(%rsp), %edx
	leaq	152(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 232
	popq	%rdx
	.cfi_def_cfa_offset 224
.L4:
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$216, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4035:
	.size	_Z57__device_stub__Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fiP6float4S0_S0_S0_S0_S0_fi, .-_Z57__device_stub__Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fiP6float4S0_S0_S0_S0_S0_fi
	.globl	_Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fi
	.type	_Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fi, @function
_Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fi:
.LFB4036:
	.cfi_startproc
	endbr64
	jmp	_Z57__device_stub__Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fiP6float4S0_S0_S0_S0_S0_fi
	.cfi_endproc
.LFE4036:
	.size	_Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fi, .-_Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	"CUDA error: "
.LC4:
	.string	"Simulation completed successfully."
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4010:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$262144, %edi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	xorl	%ebx, %ebx
	subq	$96, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	_Znam@PLT
	movl	$262144, %edi
	movq	%rax, %r12
	call	_Znam@PLT
	movq	%rax, %rbp
.L11:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	movd	%xmm0, %r13d
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	movss	%xmm0, 12(%rsp)
	call	rand@PLT
	movss	12(%rsp), %xmm0
	movl	%r13d, 8(%r12,%rbx)
	cvtsi2ssl	%eax, %xmm1
	mulss	.LC0(%rip), %xmm1
	movl	$0x00000000, 12(%r12,%rbx)
	movl	$0x00000000, 0(%rbp,%rbx)
	movl	$0x00000000, 4(%rbp,%rbx)
	movl	$0x00000000, 8(%rbp,%rbx)
	movl	$0x00000000, 12(%rbp,%rbx)
	movss	%xmm1, (%r12,%rbx)
	movss	%xmm0, 4(%r12,%rbx)
	addq	$16, %rbx
	cmpq	$262144, %rbx
	jne	.L11
	leaq	16(%rsp), %rdi
	movl	$262144, %esi
	movl	$100, %r13d
	movabsq	$4294967552, %r14
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	leaq	48(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movl	$262144, %esi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$262144, %edx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$262144, %edx
	call	cudaMemcpy@PLT
.L15:
	movl	$67108865, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r14, %rdx
	salq	$6, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	pushq	%rax
	.cfi_def_cfa_offset 152
	movss	.LC2(%rip), %xmm0
	pushq	$16384
	.cfi_def_cfa_offset 160
	movq	72(%rsp), %r9
	movq	64(%rsp), %r8
	movq	56(%rsp), %rcx
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z57__device_stub__Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fiP6float4S0_S0_S0_S0_S0_fi
	popq	%rdx
	.cfi_def_cfa_offset 152
	popq	%rcx
	.cfi_def_cfa_offset 144
.L12:
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L13
	leaq	.LC3(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %edi
	movq	%rax, %rbp
	call	cudaGetErrorString@PLT
	movq	%rbp, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	orl	$-1, %eax
	jmp	.L10
.L13:
	decl	%r13d
	jne	.L15
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movl	$262144, %edx
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	movl	$262144, %edx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r12, %rdi
	call	_ZdaPv@PLT
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	xorl	%eax, %eax
.L10:
	movq	88(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$96, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4010:
	.size	main, .-main
	.section	.rodata.str1.1
.LC5:
	.string	"_Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4038:
	.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	.LC5(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14rungeKuttaStepP6float4S0_S0_S0_S0_S0_fi(%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
.LFE4038:
	.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
.LC2:
	.long	1008981770
	.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 <iostream>
#include <hip/hip_runtime.h>
#include <hip/hip_fp16.h>
#include <hip/hip_vector_types.h>

#define NUM_PARTICLES 16384
#define BLOCK_SIZE 256

__device__ float4 computeForce(float4 pos, float4* positions, float4* velocities, int numParticles) {
    float4 force = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
    for (int j = 0; j < numParticles; ++j) {
        float4 diff = make_float4(pos.x - positions[j].x, pos.y - positions[j].y, pos.z - positions[j].z, 0.0f);
        float distSqr = diff.x * diff.x + diff.y * diff.y + diff.z * diff.z + 1.0f; // Add 1 to prevent division by zero
        float dist = rsqrtf(distSqr);
        float distCubed = dist * dist * dist;
        force.x += diff.x * distCubed;
        force.y += diff.y * distCubed;
        force.z += diff.z * distCubed;
    }
    return force;
}

__global__ void rungeKuttaStep(float4* positions, float4* velocities, float4* k1, float4* k2, float4* k3, float4* k4, float dt, int numParticles) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < numParticles) {
        float4 pos = positions[idx];
        float4 vel = velocities[idx];

        // Compute k1
        float4 f1 = computeForce(pos, positions, velocities, numParticles);
        k1[idx] = f1;
        float4 pos2 = make_float4(pos.x + 0.5f * dt * vel.x, pos.y + 0.5f * dt * vel.y, pos.z + 0.5f * dt * vel.z, 0.0f);
        float4 vel2 = make_float4(vel.x + 0.5f * dt * f1.x, vel.y + 0.5f * dt * f1.y, vel.z + 0.5f * dt * f1.z, 0.0f);

        // Compute k2
        float4 f2 = computeForce(pos2, positions, velocities, numParticles);
        k2[idx] = f2;
        float4 pos3 = make_float4(pos.x + 0.5f * dt * vel2.x, pos.y + 0.5f * dt * vel2.y, pos.z + 0.5f * dt * vel2.z, 0.0f);
        float4 vel3 = make_float4(vel.x + 0.5f * dt * f2.x, vel.y + 0.5f * dt * f2.y, vel.z + 0.5f * dt * f2.z, 0.0f);

        // Compute k3
        float4 f3 = computeForce(pos3, positions, velocities, numParticles);
        k3[idx] = f3;
        float4 pos4 = make_float4(pos.x + dt * vel3.x, pos.y + dt * vel3.y, pos.z + dt * vel3.z, 0.0f);
        float4 vel4 = make_float4(vel.x + dt * f3.x, vel.y + dt * f3.y, vel.z + dt * f3.z, 0.0f);

        // Compute k4
        float4 f4 = computeForce(pos4, positions, velocities, numParticles);
        k4[idx] = f4;

        // Update position and velocity
        positions[idx] = make_float4(pos.x + dt / 6.0f * (vel.x + 2.0f * vel2.x + 2.0f * vel3.x + vel4.x),
                                    pos.y + dt / 6.0f * (vel.y + 2.0f * vel2.y + 2.0f * vel3.y + vel4.y),
                                    pos.z + dt / 6.0f * (vel.z + 2.0f * vel2.z + 2.0f * vel3.z + vel4.z),
                                    0.0f);
        velocities[idx] = make_float4(vel.x + dt / 6.0f * (f1.x + 2.0f * f2.x + 2.0f * f3.x + f4.x),
                                     vel.y + dt / 6.0f * (f1.y + 2.0f * f2.y + 2.0f * f3.y + f4.y),
                                     vel.z + dt / 6.0f * (f1.z + 2.0f * f2.z + 2.0f * f3.z + f4.z),
                                     0.0f);
    }
}

int main() {
    float4* d_positions, *d_velocities, *d_k1, *d_k2, *d_k3, *d_k4;
    float4* h_positions = new float4[NUM_PARTICLES];
    float4* h_velocities = new float4[NUM_PARTICLES];

    // Initialize positions and velocities
    for (int i = 0; i < NUM_PARTICLES; ++i) {
        h_positions[i] = make_float4(static_cast<float>(rand()) / RAND_MAX, static_cast<float>(rand()) / RAND_MAX, static_cast<float>(rand()) / RAND_MAX, 0.0f);
        h_velocities[i] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
    }

    // Allocate device memory
    hipMalloc(&d_positions, NUM_PARTICLES * sizeof(float4));
    hipMalloc(&d_velocities, NUM_PARTICLES * sizeof(float4));
    hipMalloc(&d_k1, NUM_PARTICLES * sizeof(float4));
    hipMalloc(&d_k2, NUM_PARTICLES * sizeof(float4));
    hipMalloc(&d_k3, NUM_PARTICLES * sizeof(float4));
    hipMalloc(&d_k4, NUM_PARTICLES * sizeof(float4));

    // Copy data to device
    hipMemcpy(d_positions, h_positions, NUM_PARTICLES * sizeof(float4), hipMemcpyHostToDevice);
    hipMemcpy(d_velocities, h_velocities, NUM_PARTICLES * sizeof(float4), hipMemcpyHostToDevice);

    // Simulation parameters
    float dt = 0.01f;
    int numSteps = 100;

    // Launch kernel for each time step
    for (int step = 0; step < numSteps; ++step) {
        rungeKuttaStep<<<(NUM_PARTICLES + BLOCK_SIZE - 1) / BLOCK_SIZE, BLOCK_SIZE>>>(d_positions, d_velocities, d_k1, d_k2, d_k3, d_k4, dt, NUM_PARTICLES);
        hipDeviceSynchronize();

        // Check for errors
        hipError_t err = hipGetLastError();
        if (err != hipSuccess) {
            std::cerr << "CUDA error: " << hipGetErrorString(err) << std::endl;
            return -1;
        }
    }

    // Copy results back to host
    hipMemcpy(h_positions, d_positions, NUM_PARTICLES * sizeof(float4), hipMemcpyDeviceToHost);
    hipMemcpy(h_velocities, d_velocities, NUM_PARTICLES * sizeof(float4), hipMemcpyDeviceToHost);

    // Free device memory
    hipFree(d_positions);
    hipFree(d_velocities);
    hipFree(d_k1);
    hipFree(d_k2);
    hipFree(d_k3);
    hipFree(d_k4);

    // Free host memory
    delete[] h_positions;
    delete[] h_velocities;

    std::cout << "Simulation completed successfully." << std::endl;
    return 0;
}
	.text
	.file	"cuda_code_043826.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi # -- Begin function _Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.type	_Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi,@function
_Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi: # @_Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.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	$176, %rsp
	.cfi_def_cfa_offset 224
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	72(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	64(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	56(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	48(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	32(%rsp), %r8
	movq	%r9, (%r8)
	leaq	12(%rsp), %r9
	movss	%xmm0, (%r9)
	leaq	112(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	movq	%r9, 48(%rbx)
	leaq	224(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	96(%rsp), %r14
	leaq	80(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$192, %rsp
	.cfi_adjust_cfa_offset -192
	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	_Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi, .Lfunc_end0-_Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI1_1:
	.long	0x3c23d70a                      # float 0.00999999977
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI1_2:
	.zero	16
	.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	$88, %rsp
	.cfi_def_cfa_offset 144
	.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	$262144, %edi                   # imm = 0x40000
	callq	_Znam
	movq	%rax, %rbx
	movl	$262144, %edi                   # imm = 0x40000
	callq	_Znam
	movq	%rax, %r14
	xorl	%r15d, %r15d
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm1, %xmm1
	cvtsi2ss	%eax, %xmm1
	movss	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm0, %xmm1
	movaps	%xmm1, 64(%rsp)                 # 16-byte Spill
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	movaps	64(%rsp), %xmm1                 # 16-byte Reload
	unpcklps	%xmm0, %xmm1                    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
	movaps	%xmm1, 64(%rsp)                 # 16-byte Spill
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	movq	%xmm0, %xmm0                    # xmm0 = xmm0[0],zero
	movaps	64(%rsp), %xmm1                 # 16-byte Reload
	shufps	$132, %xmm0, %xmm1              # xmm1 = xmm1[0,1],xmm0[0,2]
	movaps	%xmm1, (%rbx,%r15)
	xorps	%xmm0, %xmm0
	movaps	%xmm0, (%r14,%r15)
	addq	$16, %r15
	cmpq	$262144, %r15                   # imm = 0x40000
	jne	.LBB1_1
# %bb.2:
	movabsq	$4294967360, %r15               # imm = 0x100000040
	leaq	24(%rsp), %r13
	movl	$262144, %esi                   # imm = 0x40000
	movq	%r13, %rdi
	callq	hipMalloc
	leaq	16(%rsp), %r12
	movl	$262144, %esi                   # imm = 0x40000
	movq	%r12, %rdi
	callq	hipMalloc
	leaq	56(%rsp), %rdi
	movl	$262144, %esi                   # imm = 0x40000
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movl	$262144, %esi                   # imm = 0x40000
	callq	hipMalloc
	leaq	40(%rsp), %rdi
	movl	$262144, %esi                   # imm = 0x40000
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movl	$262144, %esi                   # imm = 0x40000
	callq	hipMalloc
	movq	(%r13), %rdi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r12), %rdi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$100, %r13d
	leaq	192(%r15), %r12
.LBB1_3:                                # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_5
# %bb.4:                                #   in Loop: Header=BB1_3 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rcx
	movq	40(%rsp), %r8
	movq	32(%rsp), %r9
	movl	$16384, (%rsp)                  # imm = 0x4000
	movss	.LCPI1_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	callq	_Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
.LBB1_5:                                #   in Loop: Header=BB1_3 Depth=1
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_8
# %bb.6:                                #   in Loop: Header=BB1_3 Depth=1
	decl	%r13d
	jne	.LBB1_3
# %bb.7:
	movq	24(%rsp), %rsi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rsi
	movl	$262144, %edx                   # imm = 0x40000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	_ZdaPv
	movq	%r14, %rdi
	callq	_ZdaPv
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$34, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%ebp, %ebp
	jmp	.LBB1_12
.LBB1_8:
	movl	%eax, %ebp
	movl	$_ZSt4cerr, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%ebp, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB1_10
# %bb.9:
	movq	%rax, %r14
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r14, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB1_11
.LBB1_10:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB1_11:
	movl	$-1, %ebp
.LBB1_12:
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	%ebp, %eax
	addq	$88, %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_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi,@object # @_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.section	.rodata,"a",@progbits
	.globl	_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.p2align	3, 0x0
_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi:
	.quad	_Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.size	_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CUDA error: "
	.size	.L.str, 13

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Simulation completed successfully."
	.size	.L.str.1, 35

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi"
	.size	.L__unnamed_1, 61

	.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 _Z29__device_stub__rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.addrsig_sym _ZSt4cerr
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi ; -- Begin function _Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.globl	_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
	.p2align	8
	.type	_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi,@function
_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi: ; @_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x44
	s_load_b64 s[2:3], s[0:1], 0x30
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_mov_b32 s4, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_17
; %bb.1:
	s_load_b256 s[4:11], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_load_b128 s[12:15], s[0:1], 0x20
	v_dual_mov_b32 v10, 0 :: v_dual_mov_b32 v9, 0
	v_mov_b32_e32 v8, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[28:29], 4, v[1:2]
	s_cmp_gt_i32 s3, 0
	s_cselect_b32 s0, -1, 0
	s_cmp_lt_i32 s3, 1
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v24, vcc_lo, s4, v28
	v_add_co_ci_u32_e32 v25, vcc_lo, s5, v29, vcc_lo
	v_add_co_u32 v26, vcc_lo, s6, v28
	v_add_co_ci_u32_e32 v27, vcc_lo, s7, v29, vcc_lo
	global_load_b128 v[0:3], v[24:25], off
	global_load_b96 v[4:6], v[26:27], off
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph.i.preheader
	v_mov_b32_e32 v8, 0
	s_add_u32 s1, s4, 4
	s_addc_u32 s6, s5, 0
	s_mov_b32 s7, s3
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v9, v8
	v_mov_b32_e32 v10, v8
.LBB0_3:                                ; %.lr.ph.i
                                        ; =>This Inner Loop Header: Depth=1
	s_add_u32 s16, s1, -4
	s_addc_u32 s17, s6, -1
	s_add_i32 s7, s7, -1
	s_load_b128 s[16:19], s[16:17], 0x0
	s_add_u32 s1, s1, 16
	s_addc_u32 s6, s6, 0
	s_cmp_lg_u32 s7, 0
	s_waitcnt vmcnt(1) lgkmcnt(0)
	v_dual_subrev_f32 v3, s17, v1 :: v_dual_subrev_f32 v12, s18, v2
	v_subrev_f32_e32 v7, s16, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v11, v3, v3
	v_fmac_f32_e32 v11, v7, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v11, v12, v12
	v_add_f32_e32 v11, 1.0, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v13, 0x4b800000, v11
	v_cmp_gt_f32_e32 vcc_lo, 0x800000, v11
	v_cndmask_b32_e32 v11, v11, v13, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rsq_f32_e32 v11, v11
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v13, 0x45800000, v11
	v_cndmask_b32_e32 v11, v11, v13, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v13, v11, v11
	v_mul_f32_e32 v11, v11, v13
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v10, v12, v11
	v_fmac_f32_e32 v8, v7, v11
	v_fmac_f32_e32 v9, v3, v11
	s_cbranch_scc1 .LBB0_3
.LBB0_4:                                ; %_Z12computeForce15HIP_vector_typeIfLj4EEPS0_S1_i.exit
	v_add_co_u32 v12, vcc_lo, s8, v28
	v_cndmask_b32_e64 v19, 0, 1, s0
	v_add_co_ci_u32_e32 v13, vcc_lo, s9, v29, vcc_lo
	v_mov_b32_e32 v11, 0
	v_mul_f32_e64 v20, s2, 0.5
	s_and_not1_b32 vcc_lo, exec_lo, s0
	global_store_b128 v[12:13], v[8:11], off
	s_cbranch_vccnz .LBB0_7
; %bb.5:                                ; %.lr.ph.i159
	v_mov_b32_e32 v12, 0
	s_waitcnt vmcnt(0)
	v_fma_f32 v3, v20, v4, v0
	v_fma_f32 v7, v20, v5, v1
	v_fma_f32 v15, v20, v6, v2
	s_add_u32 s0, s4, 4
	v_mov_b32_e32 v13, v12
	v_mov_b32_e32 v14, v12
	s_addc_u32 s1, s5, 0
	s_mov_b32 s6, s3
.LBB0_6:                                ; =>This Inner Loop Header: Depth=1
	global_load_b96 v[16:18], v11, s[0:1] offset:-4
	s_add_i32 s6, s6, -1
	s_add_u32 s0, s0, 16
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s6, 0
	s_waitcnt vmcnt(0)
	v_sub_f32_e32 v17, v7, v17
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_sub_f32 v16, v3, v16 :: v_dual_mul_f32 v21, v17, v17
	v_dual_sub_f32 v18, v15, v18 :: v_dual_fmac_f32 v21, v16, v16
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v21, v18, v18
	v_add_f32_e32 v21, 1.0, v21
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v22, 0x4b800000, v21
	v_cmp_gt_f32_e32 vcc_lo, 0x800000, v21
	v_cndmask_b32_e32 v21, v21, v22, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rsq_f32_e32 v21, v21
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v22, 0x45800000, v21
	v_cndmask_b32_e32 v21, v21, v22, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v22, v21, v21
	v_mul_f32_e32 v21, v21, v22
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v12, v16, v21
	v_fmac_f32_e32 v13, v17, v21
	v_fmac_f32_e32 v14, v18, v21
	s_cbranch_scc1 .LBB0_6
	s_branch .LBB0_8
.LBB0_7:
	v_dual_mov_b32 v14, 0 :: v_dual_mov_b32 v13, 0
	v_mov_b32_e32 v12, 0
.LBB0_8:                                ; %_Z12computeForce15HIP_vector_typeIfLj4EEPS0_S1_i.exit173
	v_cmp_ne_u32_e32 vcc_lo, 1, v19
	v_add_co_u32 v16, s0, s10, v28
	s_waitcnt vmcnt(0)
	v_fma_f32 v7, v20, v8, v4
	v_fma_f32 v3, v20, v9, v5
	v_add_co_ci_u32_e64 v17, s0, s11, v29, s0
	v_mov_b32_e32 v15, 0
	v_fma_f32 v11, v20, v10, v6
	global_store_b128 v[16:17], v[12:15], off
	s_cbranch_vccnz .LBB0_11
; %bb.9:                                ; %.lr.ph.i178
	v_mov_b32_e32 v16, 0
	v_fma_f32 v21, v20, v7, v0
	v_fma_f32 v22, v20, v3, v1
	v_fma_f32 v23, v20, v11, v2
	s_add_u32 s0, s4, 4
	v_mov_b32_e32 v17, v16
	v_mov_b32_e32 v18, v16
	s_addc_u32 s1, s5, 0
	s_mov_b32 s6, s3
.LBB0_10:                               ; =>This Inner Loop Header: Depth=1
	global_load_b96 v[30:32], v15, s[0:1] offset:-4
	s_add_i32 s6, s6, -1
	s_add_u32 s0, s0, 16
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s6, 0
	s_waitcnt vmcnt(0)
	v_dual_sub_f32 v31, v22, v31 :: v_dual_sub_f32 v30, v21, v30
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v33, v31, v31
	v_dual_sub_f32 v32, v23, v32 :: v_dual_fmac_f32 v33, v30, v30
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v33, v32, v32
	v_add_f32_e32 v33, 1.0, v33
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v34, 0x4b800000, v33
	v_cmp_gt_f32_e32 vcc_lo, 0x800000, v33
	v_cndmask_b32_e32 v33, v33, v34, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rsq_f32_e32 v33, v33
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v34, 0x45800000, v33
	v_cndmask_b32_e32 v33, v33, v34, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v34, v33, v33
	v_mul_f32_e32 v33, v33, v34
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v16, v30, v33
	v_fmac_f32_e32 v17, v31, v33
	v_fmac_f32_e32 v18, v32, v33
	s_cbranch_scc1 .LBB0_10
	s_branch .LBB0_12
.LBB0_11:
	v_dual_mov_b32 v18, 0 :: v_dual_mov_b32 v17, 0
	v_mov_b32_e32 v16, 0
.LBB0_12:                               ; %_Z12computeForce15HIP_vector_typeIfLj4EEPS0_S1_i.exit192
	v_cmp_ne_u32_e32 vcc_lo, 1, v19
	v_add_co_u32 v21, s0, s12, v28
	v_fma_f32 v15, v20, v12, v4
	v_fma_f32 v30, v20, v13, v5
	v_add_co_ci_u32_e64 v22, s0, s13, v29, s0
	v_mov_b32_e32 v19, 0
	v_fma_f32 v31, v20, v14, v6
	global_store_b128 v[21:22], v[16:19], off
	s_cbranch_vccnz .LBB0_15
; %bb.13:                               ; %.lr.ph.i197
	v_fma_f32 v23, s2, v15, v0
	v_fma_f32 v32, s2, v30, v1
	v_fma_f32 v33, s2, v31, v2
	v_dual_mov_b32 v20, 0 :: v_dual_mov_b32 v21, 0
	v_mov_b32_e32 v22, 0
	s_add_u32 s0, s4, 4
	s_addc_u32 s1, s5, 0
.LBB0_14:                               ; =>This Inner Loop Header: Depth=1
	global_load_b96 v[34:36], v19, s[0:1] offset:-4
	s_add_i32 s3, s3, -1
	s_add_u32 s0, s0, 16
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s3, 0
	s_waitcnt vmcnt(0)
	v_dual_sub_f32 v35, v32, v35 :: v_dual_sub_f32 v34, v23, v34
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_sub_f32 v36, v33, v36 :: v_dual_mul_f32 v37, v35, v35
	v_fmac_f32_e32 v37, v34, v34
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v37, v36, v36
	v_add_f32_e32 v37, 1.0, v37
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v38, 0x4b800000, v37
	v_cmp_gt_f32_e32 vcc_lo, 0x800000, v37
	v_cndmask_b32_e32 v37, v37, v38, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rsq_f32_e32 v37, v37
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v38, 0x45800000, v37
	v_cndmask_b32_e32 v37, v37, v38, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v38, v37, v37
	v_mul_f32_e32 v37, v37, v38
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v20, v34, v37
	v_fmac_f32_e32 v21, v35, v37
	v_fmac_f32_e32 v22, v36, v37
	s_cbranch_scc1 .LBB0_14
	s_branch .LBB0_16
.LBB0_15:
	v_dual_mov_b32 v22, 0 :: v_dual_mov_b32 v21, 0
	v_mov_b32_e32 v20, 0
.LBB0_16:                               ; %_Z12computeForce15HIP_vector_typeIfLj4EEPS0_S1_i.exit211
	s_mov_b32 s0, 0x40c00000
	v_div_scale_f32 v33, vcc_lo, s2, 0x40c00000, s2
	v_div_scale_f32 v19, null, s0, s0, s2
	v_fma_f32 v39, 2.0, v3, v5
	v_fma_f32 v38, 2.0, v7, v4
	v_fma_f32 v11, 2.0, v11, v6
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_4) | instid1(VALU_DEP_4)
	v_rcp_f32_e32 v32, v19
	v_dual_fmac_f32 v8, 2.0, v12 :: v_dual_fmac_f32 v9, 2.0, v13
	v_fma_f32 v34, s2, v16, v4
	v_fma_f32 v35, s2, v17, v5
	v_fma_f32 v36, s2, v18, v6
	v_dual_fmac_f32 v39, 2.0, v30 :: v_dual_fmac_f32 v8, 2.0, v16
	v_fmac_f32_e32 v9, 2.0, v17
	v_add_co_u32 v28, s0, s14, v28
	s_delay_alu instid0(TRANS32_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_fma_f32 v23, -v19, v32, 1.0
	v_add_co_ci_u32_e64 v29, s0, s15, v29, s0
	v_fmac_f32_e32 v10, 2.0, v14
	v_add_f32_e32 v14, v39, v35
	v_dual_fmac_f32 v32, v23, v32 :: v_dual_mov_b32 v23, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_dual_fmac_f32 v11, 2.0, v31 :: v_dual_fmac_f32 v10, 2.0, v18
	v_add_f32_e32 v9, v9, v21
	v_dual_mul_f32 v37, v33, v32 :: v_dual_fmac_f32 v38, 2.0, v15
	v_add_f32_e32 v8, v8, v20
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_f32_e32 v10, v10, v22
	v_fma_f32 v3, -v19, v37, v33
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v37, v3, v32
	v_mov_b32_e32 v3, v23
	v_fma_f32 v7, -v19, v37, v33
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_fmas_f32 v12, v7, v32, v37
	v_mov_b32_e32 v7, v23
	v_div_fixup_f32 v12, v12, 0x40c00000, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_add_f32 v11, v11, v36 :: v_dual_fmac_f32 v6, v12, v10
	v_dual_add_f32 v13, v38, v34 :: v_dual_fmac_f32 v2, v12, v11
	v_fma_f32 v1, v12, v14, v1
	v_fma_f32 v4, v12, v8, v4
	v_fma_f32 v5, v12, v9, v5
	s_delay_alu instid0(VALU_DEP_4)
	v_fma_f32 v0, v12, v13, v0
	global_store_b128 v[28:29], v[20:23], off
	global_store_b128 v[24:25], v[0:3], off
	global_store_b128 v[26:27], v[4:7], off
.LBB0_17:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 312
		.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 40
		.amdhsa_next_free_sgpr 20
		.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	_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi, .Lfunc_end0-_Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1472
; NumSgprs: 22
; NumVgprs: 40
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 4
; NumSGPRsForWavesPerEU: 22
; NumVGPRsForWavesPerEU: 40
; 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
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .offset:         48
        .size:           4
        .value_kind:     by_value
      - .offset:         52
        .size:           4
        .value_kind:     by_value
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         60
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         64
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         68
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         70
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         72
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         74
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         76
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         78
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         112
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         120
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 312
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z14rungeKuttaStepP15HIP_vector_typeIfLj4EES1_S1_S1_S1_S1_fi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     40
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
