#include <iostream>
#include <cuda_runtime.h>
#include <vector>

// Constants
#define N 1024
#define BLOCK_SIZE 256
#define WARP_SIZE 32

// Structure to represent a particle
struct Particle {
    float x, y, z; // Position
    float vx, vy, vz; // Velocity
    float mass; // Mass
    float ax, ay, az; // Acceleration
};

// Kernel to compute forces using Fast Multipole Method
__global__ void fastMultipoleKernel(Particle* particles, int numParticles) {
    extern __shared__ Particle sharedParticles[];

    int tid = threadIdx.x;
    int bid = blockIdx.x;
    int index = bid * blockDim.x + tid;

    // Load particles into shared memory
    if (index < numParticles) {
        sharedParticles[tid] = particles[index];
    }
    __syncthreads();

    // Initialize acceleration
    if (index < numParticles) {
        particles[index].ax = 0.0f;
        particles[index].ay = 0.0f;
        particles[index].az = 0.0f;
    }
    __syncthreads();

    // Perform warp-level reduction to compute forces
    for (int i = 0; i < blockDim.x; i++) {
        if (index < numParticles && i != tid) {
            float dx = sharedParticles[i].x - sharedParticles[tid].x;
            float dy = sharedParticles[i].y - sharedParticles[tid].y;
            float dz = sharedParticles[i].z - sharedParticles[tid].z;
            float distSqr = dx * dx + dy * dy + dz * dz + 1e-10f; // Avoid division by zero
            float dist = sqrtf(distSqr);
            float invDistCube = 1.0f / (distSqr * dist);

            // Compute force contribution
            float fx = dx * invDistCube * sharedParticles[i].mass;
            float fy = dy * invDistCube * sharedParticles[i].mass;
            float fz = dz * invDistCube * sharedParticles[i].mass;

            // Accumulate forces
            atomicAdd(&particles[index].ax, fx);
            atomicAdd(&particles[index].ay, fy);
            atomicAdd(&particles[index].az, fz);
        }
        __syncthreads();
    }
}

// Check for CUDA errors
void checkCudaError(cudaError_t err, const char* msg) {
    if (err != cudaSuccess) {
        std::cerr << "CUDA error: " << msg << " (" << cudaGetErrorString(err) << ")" << std::endl;
        exit(EXIT_FAILURE);
    }
}

int main() {
    // Allocate host memory
    std::vector<Particle> h_particles(N);

    // Initialize particles (random positions and masses for simplicity)
    for (int i = 0; i < N; ++i) {
        h_particles[i].x = static_cast<float>(rand()) / RAND_MAX;
        h_particles[i].y = static_cast<float>(rand()) / RAND_MAX;
        h_particles[i].z = static_cast<float>(rand()) / RAND_MAX;
        h_particles[i].mass = 1.0f;
    }

    // Allocate device memory
    Particle* d_particles;
    checkCudaError(cudaMalloc(&d_particles, N * sizeof(Particle)), "cudaMalloc");

    // Copy data from host to device
    checkCudaError(cudaMemcpy(d_particles, h_particles.data(), N * sizeof(Particle), cudaMemcpyHostToDevice), "cudaMemcpy");

    // Launch kernel
    int numBlocks = (N + BLOCK_SIZE - 1) / BLOCK_SIZE;
    fastMultipoleKernel<<<numBlocks, BLOCK_SIZE, BLOCK_SIZE * sizeof(Particle)>>>(d_particles, N);
    checkCudaError(cudaGetLastError(), "Kernel launch failed");

    // Copy results back to host
    checkCudaError(cudaMemcpy(h_particles.data(), d_particles, N * sizeof(Particle), cudaMemcpyDeviceToHost), "cudaMemcpy");

    // Free device memory
    checkCudaError(cudaFree(d_particles), "cudaFree");

    // Output first particle's acceleration for demonstration
    std::cout << "Particle 0 acceleration: (" << h_particles[0].ax << ", " << h_particles[0].ay << ", " << h_particles[0].az << ")" << std::endl;

    return 0;
}
	.file	"tmpxft_000faa8e_00000000-6_cuda_code_072716.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4002:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4002:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CUDA error: "
.LC1:
	.string	" ("
.LC2:
	.string	")"
	.text
	.globl	_Z14checkCudaError9cudaErrorPKc
	.type	_Z14checkCudaError9cudaErrorPKc, @function
_Z14checkCudaError9cudaErrorPKc:
.LFB3998:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	leaq	_ZSt4cerr(%rip), %rdi
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbp, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %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
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE3998:
	.size	_Z14checkCudaError9cudaErrorPKc, .-_Z14checkCudaError9cudaErrorPKc
	.globl	_Z48__device_stub__Z19fastMultipoleKernelP8ParticleiP8Particlei
	.type	_Z48__device_stub__Z19fastMultipoleKernelP8ParticleiP8Particlei, @function
_Z48__device_stub__Z19fastMultipoleKernelP8ParticleiP8Particlei:
.LFB4024:
	.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	.L8
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z19fastMultipoleKernelP8Particlei(%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
.L8:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4024:
	.size	_Z48__device_stub__Z19fastMultipoleKernelP8ParticleiP8Particlei, .-_Z48__device_stub__Z19fastMultipoleKernelP8ParticleiP8Particlei
	.globl	_Z19fastMultipoleKernelP8Particlei
	.type	_Z19fastMultipoleKernelP8Particlei, @function
_Z19fastMultipoleKernelP8Particlei:
.LFB4025:
	.cfi_startproc
	endbr64
	jmp	_Z48__device_stub__Z19fastMultipoleKernelP8ParticleiP8Particlei
	.cfi_endproc
.LFE4025:
	.size	_Z19fastMultipoleKernelP8Particlei, .-_Z19fastMultipoleKernelP8Particlei
	.section	.rodata.str1.1
.LC3:
	.string	"_Z19fastMultipoleKernelP8Particlei"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4027:
	.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	.LC3(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z19fastMultipoleKernelP8Particlei(%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
.LFE4027:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZNSt6vectorI8ParticleSaIS0_EED2Ev,"axG",@progbits,_ZNSt6vectorI8ParticleSaIS0_EED5Ev,comdat
	.align 2
	.weak	_ZNSt6vectorI8ParticleSaIS0_EED2Ev
	.type	_ZNSt6vectorI8ParticleSaIS0_EED2Ev, @function
_ZNSt6vectorI8ParticleSaIS0_EED2Ev:
.LFB4340:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	testq	%rax, %rax
	je	.L15
	movq	16(%rdi), %rsi
	movq	%rax, %rdi
	subq	%rax, %rsi
	jmp	_ZdlPvm@PLT
.L15:
	ret
	.cfi_endproc
.LFE4340:
	.size	_ZNSt6vectorI8ParticleSaIS0_EED2Ev, .-_ZNSt6vectorI8ParticleSaIS0_EED2Ev
	.weak	_ZNSt6vectorI8ParticleSaIS0_EED1Ev
	.set	_ZNSt6vectorI8ParticleSaIS0_EED1Ev,_ZNSt6vectorI8ParticleSaIS0_EED2Ev
	.section	.rodata.str1.1
.LC6:
	.string	"cudaMalloc"
.LC7:
	.string	"cudaMemcpy"
.LC8:
	.string	"Kernel launch failed"
.LC9:
	.string	"cudaFree"
.LC10:
	.string	"Particle 0 acceleration: ("
.LC11:
	.string	", "
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3999:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3999
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$40960, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$64, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
.LEHB0:
	call	_Znwm@PLT
.LEHE0:
	movl	$10, %ecx
	leaq	40960(%rax), %r12
	movq	%rax, %rbx
	movq	%rax, 32(%rsp)
	xorl	%eax, %eax
	movq	%r12, 48(%rsp)
	movq	%rbx, %rdi
	rep stosl
	xorl	%eax, %eax
.L18:
	addq	$40, %rax
	cmpq	$40960, %rax
	je	.L32
	leaq	(%rbx,%rax), %rdi
	movl	$10, %ecx
	movq	%rbx, %rsi
	rep movsl
	jmp	.L18
.L32:
	movq	%r12, 40(%rsp)
	movq	%rbx, %rbp
.L20:
	call	rand@PLT
	addq	$40, %rbp
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC4(%rip), %xmm0
	movss	%xmm0, -40(%rbp)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC4(%rip), %xmm0
	movss	%xmm0, -36(%rbp)
	call	rand@PLT
	movl	$0x3f800000, -16(%rbp)
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC4(%rip), %xmm0
	movss	%xmm0, -32(%rbp)
	cmpq	%rbp, %r12
	jne	.L20
	movq	%rsp, %rdi
	movl	$40960, %esi
	leaq	32(%rsp), %rbp
.LEHB1:
	call	cudaMalloc@PLT
	movl	%eax, %edi
	leaq	.LC6(%rip), %rsi
	call	_Z14checkCudaError9cudaErrorPKc
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movl	$40960, %edx
	movq	%rbx, %rsi
	call	cudaMemcpy@PLT
	leaq	.LC7(%rip), %r12
	movl	%eax, %edi
	movq	%r12, %rsi
	call	_Z14checkCudaError9cudaErrorPKc
	movl	$16777217, %edx
	movl	$1073741825, %edi
	xorl	%r9d, %r9d
	movl	$10240, %r8d
	salq	$8, %rdx
	movl	$1, %ecx
	salq	$2, %rdi
	movl	$1, %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	je	.L21
.L23:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	leaq	.LC8(%rip), %rsi
	call	_Z14checkCudaError9cudaErrorPKc
	jmp	.L33
.L21:
	movq	(%rsp), %rdi
	movl	$1024, %esi
	call	_Z48__device_stub__Z19fastMultipoleKernelP8ParticleiP8Particlei
	jmp	.L23
.L33:
	movq	(%rsp), %rsi
	movl	$2, %ecx
	movl	$40960, %edx
	movq	%rbx, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	movq	%r12, %rsi
	call	_Z14checkCudaError9cudaErrorPKc
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	leaq	.LC9(%rip), %rsi
	call	_Z14checkCudaError9cudaErrorPKc
	leaq	.LC10(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	cvtss2sd	28(%rbx), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC11(%rip), %r12
	movq	%rax, %rdi
	movq	%r12, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	cvtss2sd	32(%rbx), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	movq	%r12, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	cvtss2sd	36(%rbx), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	leaq	.LC2(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.LEHE1:
	movq	%rbp, %rdi
	call	_ZNSt6vectorI8ParticleSaIS0_EED1Ev
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	jmp	.L30
.L27:
	endbr64
	movq	%rax, %rbx
.L24:
	movq	%rbp, %rdi
	call	_ZNSt6vectorI8ParticleSaIS0_EED1Ev
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L30
	movq	%rbx, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L30:
	call	__stack_chk_fail@PLT
.L26:
	addq	$64, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3999:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3999:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3999-.LLSDACSB3999
.LLSDACSB3999:
	.uleb128 .LEHB0-.LFB3999
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3999
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L27-.LFB3999
	.uleb128 0
	.uleb128 .LEHB2-.LFB3999
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE3999:
	.section	.text.startup
	.size	main, .-main
	.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
.LC4:
	.long	805306368
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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 <vector>

// Constants
#define N 1024
#define BLOCK_SIZE 256
#define WARP_SIZE 32

// Structure to represent a particle
struct Particle {
    float x, y, z; // Position
    float vx, vy, vz; // Velocity
    float mass; // Mass
    float ax, ay, az; // Acceleration
};

// Kernel to compute forces using Fast Multipole Method
__global__ void fastMultipoleKernel(Particle* particles, int numParticles) {
    extern __shared__ Particle sharedParticles[];

    int tid = threadIdx.x;
    int bid = blockIdx.x;
    int index = bid * blockDim.x + tid;

    // Load particles into shared memory
    if (index < numParticles) {
        sharedParticles[tid] = particles[index];
    }
    __syncthreads();

    // Initialize acceleration
    if (index < numParticles) {
        particles[index].ax = 0.0f;
        particles[index].ay = 0.0f;
        particles[index].az = 0.0f;
    }
    __syncthreads();

    // Perform warp-level reduction to compute forces
    for (int i = 0; i < blockDim.x; i++) {
        if (index < numParticles && i != tid) {
            float dx = sharedParticles[i].x - sharedParticles[tid].x;
            float dy = sharedParticles[i].y - sharedParticles[tid].y;
            float dz = sharedParticles[i].z - sharedParticles[tid].z;
            float distSqr = dx * dx + dy * dy + dz * dz + 1e-10f; // Avoid division by zero
            float dist = sqrtf(distSqr);
            float invDistCube = 1.0f / (distSqr * dist);

            // Compute force contribution
            float fx = dx * invDistCube * sharedParticles[i].mass;
            float fy = dy * invDistCube * sharedParticles[i].mass;
            float fz = dz * invDistCube * sharedParticles[i].mass;

            // Accumulate forces
            atomicAdd(&particles[index].ax, fx);
            atomicAdd(&particles[index].ay, fy);
            atomicAdd(&particles[index].az, fz);
        }
        __syncthreads();
    }
}

// Check for CUDA errors
void checkCudaError(hipError_t err, const char* msg) {
    if (err != hipSuccess) {
        std::cerr << "CUDA error: " << msg << " (" << hipGetErrorString(err) << ")" << std::endl;
        exit(EXIT_FAILURE);
    }
}

int main() {
    // Allocate host memory
    std::vector<Particle> h_particles(N);

    // Initialize particles (random positions and masses for simplicity)
    for (int i = 0; i < N; ++i) {
        h_particles[i].x = static_cast<float>(rand()) / RAND_MAX;
        h_particles[i].y = static_cast<float>(rand()) / RAND_MAX;
        h_particles[i].z = static_cast<float>(rand()) / RAND_MAX;
        h_particles[i].mass = 1.0f;
    }

    // Allocate device memory
    Particle* d_particles;
    checkCudaError(hipMalloc(&d_particles, N * sizeof(Particle)), "hipMalloc");

    // Copy data from host to device
    checkCudaError(hipMemcpy(d_particles, h_particles.data(), N * sizeof(Particle), hipMemcpyHostToDevice), "hipMemcpy");

    // Launch kernel
    int numBlocks = (N + BLOCK_SIZE - 1) / BLOCK_SIZE;
    fastMultipoleKernel<<<numBlocks, BLOCK_SIZE, BLOCK_SIZE * sizeof(Particle)>>>(d_particles, N);
    checkCudaError(hipGetLastError(), "Kernel launch failed");

    // Copy results back to host
    checkCudaError(hipMemcpy(h_particles.data(), d_particles, N * sizeof(Particle), hipMemcpyDeviceToHost), "hipMemcpy");

    // Free device memory
    checkCudaError(hipFree(d_particles), "hipFree");

    // Output first particle's acceleration for demonstration
    std::cout << "Particle 0 acceleration: (" << h_particles[0].ax << ", " << h_particles[0].ay << ", " << h_particles[0].az << ")" << std::endl;

    return 0;
}
	.text
	.file	"cuda_code_072716.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z34__device_stub__fastMultipoleKernelP8Particlei # -- Begin function _Z34__device_stub__fastMultipoleKernelP8Particlei
	.type	_Z34__device_stub__fastMultipoleKernelP8Particlei,@function
_Z34__device_stub__fastMultipoleKernelP8Particlei: # @_Z34__device_stub__fastMultipoleKernelP8Particlei
	.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	$_Z19fastMultipoleKernelP8Particlei, %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	_Z34__device_stub__fastMultipoleKernelP8Particlei, .Lfunc_end0-_Z34__device_stub__fastMultipoleKernelP8Particlei
	.cfi_endproc
                                        # -- End function
	.globl	_Z14checkCudaError10hipError_tPKc # -- Begin function _Z14checkCudaError10hipError_tPKc
	.type	_Z14checkCudaError10hipError_tPKc,@function
_Z14checkCudaError10hipError_tPKc:      # @_Z14checkCudaError10hipError_tPKc
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB1_2
# %bb.1:
	retq
.LBB1_2:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rsi, %r14
	movl	%edi, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movq	%r14, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %r14
	movl	%ebx, %edi
	callq	hipGetErrorString
	movq	%r14, %rdi
	movq	%rax, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z14checkCudaError10hipError_tPKc, .Lfunc_end1-_Z14checkCudaError10hipError_tPKc
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:                                # %.noexc
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	$40960, %edi                    # imm = 0xA000
	callq	_Znwm
	movq	%rax, %rbx
	xorps	%xmm0, %xmm0
	movups	%xmm0, (%rax)
	movups	%xmm0, 16(%rax)
	movq	$0, 32(%rax)
	movl	$40, %eax
.LBB2_1:                                # %.lr.ph.i.i.i.i.i.i.i.i.i
                                        # =>This Inner Loop Header: Depth=1
	movq	32(%rbx), %rcx
	movq	%rcx, 32(%rbx,%rax)
	movups	(%rbx), %xmm0
	movups	16(%rbx), %xmm1
	movups	%xmm1, 16(%rbx,%rax)
	movups	%xmm0, (%rbx,%rax)
	addq	$40, %rax
	cmpq	$40960, %rax                    # imm = 0xA000
	jne	.LBB2_1
# %bb.2:                                # %_ZNSt6vectorI8ParticleSaIS0_EEC2EmRKS1_.exit.preheader
	xorl	%r14d, %r14d
.LBB2_3:                                # %_ZNSt6vectorI8ParticleSaIS0_EEC2EmRKS1_.exit
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%rbx,%r14)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, 4(%rbx,%r14)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, 8(%rbx,%r14)
	movl	$1065353216, 24(%rbx,%r14)      # imm = 0x3F800000
	addq	$40, %r14
	cmpq	$40960, %r14                    # imm = 0xA000
	jne	.LBB2_3
# %bb.4:
.Ltmp0:
	movq	%rsp, %rdi
	movl	$40960, %esi                    # imm = 0xA000
	callq	hipMalloc
.Ltmp1:
# %bb.5:                                # %_ZL9hipMallocI8ParticleE10hipError_tPPT_m.exit
.Ltmp2:
	movl	$.L.str.3, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
.Ltmp3:
# %bb.6:
	movq	(%rsp), %rdi
.Ltmp4:
	movl	$40960, %edx                    # imm = 0xA000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp5:
# %bb.7:
.Ltmp6:
	movl	$.L.str.4, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
.Ltmp7:
# %bb.8:
.Ltmp9:
	movabsq	$4294967300, %rdi               # imm = 0x100000004
	movabsq	$4294967552, %rdx               # imm = 0x100000100
	movl	$10240, %r8d                    # imm = 0x2800
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp10:
# %bb.9:
	testl	%eax, %eax
	jne	.LBB2_11
# %bb.10:
	movq	(%rsp), %rdi
.Ltmp11:
	movl	$1024, %esi                     # imm = 0x400
	callq	_Z34__device_stub__fastMultipoleKernelP8Particlei
.Ltmp12:
.LBB2_11:
.Ltmp13:
	callq	hipGetLastError
.Ltmp14:
# %bb.12:
.Ltmp15:
	movl	$.L.str.5, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
.Ltmp16:
# %bb.13:
	movq	(%rsp), %rsi
.Ltmp17:
	movl	$40960, %edx                    # imm = 0xA000
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
.Ltmp18:
# %bb.14:
.Ltmp19:
	movl	$.L.str.4, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
.Ltmp20:
# %bb.15:
	movq	(%rsp), %rdi
.Ltmp21:
	callq	hipFree
.Ltmp22:
# %bb.16:
.Ltmp23:
	movl	$.L.str.6, %esi
	movl	%eax, %edi
	callq	_Z14checkCudaError10hipError_tPKc
.Ltmp24:
# %bb.17:
.Ltmp25:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$26, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp26:
# %bb.18:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
	cvtss2sd	28(%rbx), %xmm0
.Ltmp27:
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp28:
# %bb.19:                               # %_ZNSolsEf.exit
.Ltmp29:
	movq	%rax, %r14
	movl	$.L.str.8, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp30:
# %bb.20:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit20
	xorps	%xmm0, %xmm0
	cvtss2sd	32(%rbx), %xmm0
.Ltmp31:
	movq	%r14, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp32:
# %bb.21:                               # %_ZNSolsEf.exit22
.Ltmp33:
	movq	%rax, %r14
	movl	$.L.str.8, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp34:
# %bb.22:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit24
	xorps	%xmm0, %xmm0
	cvtss2sd	36(%rbx), %xmm0
.Ltmp35:
	movq	%r14, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp36:
# %bb.23:                               # %_ZNSolsEf.exit26
.Ltmp37:
	movq	%rax, %r14
	movl	$.L.str.2, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp38:
# %bb.24:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit28
	movq	(%r14), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
.Ltmp39:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp40:
# %bb.25:                               # %.noexc33
.Ltmp41:
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
.Ltmp42:
# %bb.26:                               # %.noexc34
.Ltmp43:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp44:
# %bb.27:                               # %_ZNSt6vectorI8ParticleSaIS0_EED2Ev.exit
	movq	%rbx, %rdi
	callq	_ZdlPv
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB2_28:
	.cfi_def_cfa_offset 32
.Ltmp8:
	jmp	.LBB2_29
.LBB2_30:
.Ltmp45:
.LBB2_29:                               # %_ZNSt6vectorI8ParticleSaIS0_EED2Ev.exit31
	movq	%rax, %r14
	movq	%rbx, %rdi
	callq	_ZdlPv
	movq	%r14, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table2:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp7-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp7
	.uleb128 .Ltmp8-.Lfunc_begin0           #     jumps to .Ltmp8
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp9-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp44-.Ltmp9                 #   Call between .Ltmp9 and .Ltmp44
	.uleb128 .Ltmp45-.Lfunc_begin0          #     jumps to .Ltmp45
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp44-.Lfunc_begin0          # >> Call Site 4 <<
	.uleb128 .Lfunc_end2-.Ltmp44            #   Call between .Ltmp44 and .Lfunc_end2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.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	$_Z19fastMultipoleKernelP8Particlei, %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	_Z19fastMultipoleKernelP8Particlei,@object # @_Z19fastMultipoleKernelP8Particlei
	.section	.rodata,"a",@progbits
	.globl	_Z19fastMultipoleKernelP8Particlei
	.p2align	3, 0x0
_Z19fastMultipoleKernelP8Particlei:
	.quad	_Z34__device_stub__fastMultipoleKernelP8Particlei
	.size	_Z19fastMultipoleKernelP8Particlei, 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	" ("
	.size	.L.str.1, 3

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	")"
	.size	.L.str.2, 2

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"hipMemcpy"
	.size	.L.str.4, 10

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Kernel launch failed"
	.size	.L.str.5, 21

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"hipFree"
	.size	.L.str.6, 8

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Particle 0 acceleration: ("
	.size	.L.str.7, 27

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z19fastMultipoleKernelP8Particlei"
	.size	.L__unnamed_1, 35

	.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 _Z34__device_stub__fastMultipoleKernelP8Particlei
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z19fastMultipoleKernelP8Particlei
	.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	_Z19fastMultipoleKernelP8Particlei ; -- Begin function _Z19fastMultipoleKernelP8Particlei
	.globl	_Z19fastMultipoleKernelP8Particlei
	.p2align	8
	.type	_Z19fastMultipoleKernelP8Particlei,@function
_Z19fastMultipoleKernelP8Particlei:     ; @_Z19fastMultipoleKernelP8Particlei
; %bb.0:
	s_clause 0x2
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b32 s5, s[0:1], 0x8
	s_load_b64 s[2:3], s[0:1], 0x0
	v_mad_u32_u24 v11, v0, 40, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s1, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s1, v[0:1]
	v_cmp_le_i32_e32 vcc_lo, s5, v1
	v_cmp_gt_i32_e64 s0, s5, v1
	s_delay_alu instid0(VALU_DEP_1)
	s_and_saveexec_b32 s4, s0
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_mad_i64_i32 v[12:13], null, v1, 40, s[2:3]
	s_clause 0x2
	global_load_b128 v[2:5], v[12:13], off offset:24
	global_load_b128 v[6:9], v[12:13], off offset:16
	global_load_b128 v[12:15], v[12:13], off
	s_waitcnt vmcnt(2)
	ds_store_2addr_b32 v11, v2, v3 offset0:6 offset1:7
	ds_store_2addr_b32 v11, v4, v5 offset0:8 offset1:9
	s_waitcnt vmcnt(1)
	ds_store_2addr_b32 v11, v8, v9 offset0:6 offset1:7
	ds_store_2addr_b32 v11, v6, v7 offset0:4 offset1:5
	s_waitcnt vmcnt(0)
	ds_store_2addr_b32 v11, v14, v15 offset0:2 offset1:3
	ds_store_2addr_b32 v11, v12, v13 offset1:1
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s4
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s4, s0
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_mov_b32_e32 v2, 0
	v_mad_i64_i32 v[5:6], null, v1, 40, s[2:3]
	s_delay_alu instid0(VALU_DEP_2)
	v_mov_b32_e32 v3, v2
	v_mov_b32_e32 v4, v2
	global_store_b96 v[5:6], v[2:4], off offset:28
.LBB0_4:
	s_or_b32 exec_lo, exec_lo, s4
	s_cmp_eq_u32 s1, 0
	s_mov_b32 s4, 0
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_14
; %bb.5:                                ; %.lr.ph
	v_mad_i64_i32 v[5:6], null, v1, 40, s[2:3]
	v_add_nc_u32_e32 v12, 8, v11
	s_xor_b32 s2, vcc_lo, -1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v1, s0, v5, 28
	v_add_co_ci_u32_e64 v2, s0, 0, v6, s0
	v_add_co_u32 v3, s0, v5, 32
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v4, s0, 0, v6, s0
	v_add_co_u32 v5, s0, v5, 36
	v_add_co_ci_u32_e64 v6, s0, 0, v6, s0
.LBB0_6:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_8 Depth 2
                                        ;     Child Loop BB0_10 Depth 2
                                        ;     Child Loop BB0_12 Depth 2
	v_cmp_ne_u32_e32 vcc_lo, s4, v0
	s_and_b32 s0, s2, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s0
	s_cbranch_execz .LBB0_13
; %bb.7:                                ;   in Loop: Header=BB0_6 Depth=1
	global_load_b32 v10, v[1:2], off
	s_mul_i32 s0, s4, 40
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s0, s0, 0
	v_mov_b32_e32 v7, s0
	ds_load_2addr_b32 v[14:15], v7 offset1:1
	ds_load_2addr_b32 v[16:17], v11 offset1:1
	ds_load_b32 v9, v12
	ds_load_2addr_b32 v[7:8], v7 offset0:2 offset1:6
	s_waitcnt lgkmcnt(2)
	v_sub_f32_e32 v13, v15, v17
	s_waitcnt lgkmcnt(0)
	v_sub_f32_e32 v7, v7, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_sub_f32 v15, v14, v16 :: v_dual_mul_f32 v14, v13, v13
	v_fmac_f32_e32 v14, v15, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v14, v7, v7
	v_add_f32_e32 v9, 0x2edbe6ff, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v14, 0x4f800000, v9
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v9
	v_cndmask_b32_e32 v14, v9, v14, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_sqrt_f32_e32 v16, v14
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v17, -1, v16
	v_add_nc_u32_e32 v18, 1, v16
	v_fma_f32 v19, -v17, v16, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v20, -v18, v16, v14
	v_cmp_ge_f32_e64 s0, 0, v19
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v16, v16, v17, s0
	v_cmp_lt_f32_e64 s0, 0, v20
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v16, v16, v18, s0
	s_mov_b32 s0, 0
	v_mul_f32_e32 v17, 0x37800000, v16
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v16, v16, v17, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v14, 0x260
	v_cndmask_b32_e32 v14, v16, v14, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v9, v9, v14
	v_div_scale_f32 v14, null, v9, v9, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v16, v14
	s_waitcnt_depctr 0xfff
	v_fma_f32 v17, -v14, v16, 1.0
	v_fmac_f32_e32 v16, v17, v16
	v_div_scale_f32 v17, vcc_lo, 1.0, v9, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v18, v17, v16
	v_fma_f32 v19, -v14, v18, v17
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v18, v19, v16
	v_fma_f32 v14, -v14, v18, v17
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f32 v14, v14, v16, v18
	v_div_fixup_f32 v14, v14, v9, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v9, v15, v14
	v_mul_f32_e32 v15, v8, v9
.LBB0_8:                                ; %atomicrmw.start
                                        ;   Parent Loop BB0_6 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v9, v10, v15
	global_atomic_cmpswap_b32 v9, v[1:2], v[9:10], off glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, v9, v10
	v_mov_b32_e32 v10, v9
	s_or_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s0
	s_cbranch_execnz .LBB0_8
; %bb.9:                                ; %atomicrmw.end
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	global_load_b32 v10, v[3:4], off
	v_mul_f32_e32 v9, v13, v14
	s_mov_b32 s0, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f32_e32 v13, v8, v9
.LBB0_10:                               ; %atomicrmw.start60
                                        ;   Parent Loop BB0_6 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v9, v10, v13
	global_atomic_cmpswap_b32 v9, v[3:4], v[9:10], off glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, v9, v10
	v_mov_b32_e32 v10, v9
	s_or_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s0
	s_cbranch_execnz .LBB0_10
; %bb.11:                               ; %atomicrmw.end59
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	global_load_b32 v9, v[5:6], off
	v_mul_f32_e32 v7, v7, v14
	s_mov_b32 s0, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f32_e32 v7, v8, v7
.LBB0_12:                               ; %atomicrmw.start66
                                        ;   Parent Loop BB0_6 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v8, v9, v7
	global_atomic_cmpswap_b32 v8, v[5:6], v[8:9], off glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, v8, v9
	v_mov_b32_e32 v9, v8
	s_or_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s0
	s_cbranch_execnz .LBB0_12
.LBB0_13:                               ; %Flow74
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_add_i32 s4, s4, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s4, s1
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_6
.LBB0_14:                               ; %._crit_edge
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19fastMultipoleKernelP8Particlei
		.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 21
		.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	_Z19fastMultipoleKernelP8Particlei, .Lfunc_end0-_Z19fastMultipoleKernelP8Particlei
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 956
; NumSgprs: 18
; NumVgprs: 21
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 21
; 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
      - .offset:         136
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .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:           _Z19fastMultipoleKernelP8Particlei
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19fastMultipoleKernelP8Particlei.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     21
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
