#include <fstream>
#include <iterator>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <time.h>

#define blockSize 64
#define Ke 8.99e9
#define Qe -1.602e-19
#define epsilon 1e-8
#define mass 9.11e-31
 
//macro for error checking
#define cudaCheckError(){	   												  \
	cudaError_t err = cudaGetLastError();											  \
	if(err != cudaSuccess){              											  \
		std::cout << "Error in " << __FILE__ << " at line " << __LINE__ << " : " <<  cudaGetErrorString(err) << std::endl; \
		exit(EXIT_FAILURE);                 										  \
	}                                     											  \
}

//calculate bodybody coulomb interactions
__device__ float3 bodyBodyCoulomb(float3 bi, float3 bj, float3 ai){
	float3 rij;
	
	//components of rij
	rij.x = bj.x - bi.x;
	rij.y = bj.y - bi.y;
	rij.z = bj.z - bi.z;
	
	//distance squared for solving force equation
	float distSquared = rij.x*rij.x + rij.y*rij.y + rij.z*rij.z + epsilon;
	if(distSquared > 10){
		ai.x = -1;
		ai.y = -1;
		ai.z = -1;
		return ai;
	}
	//inverse cubed with softening factor
	float inverseDist = 1.0f*Qe/sqrtf(distSquared*distSquared*distSquared);

	//finish the equation by multiplying by charge
	float kernel = Ke*Qe*inverseDist;
	
	//get acceleration for each component
	ai.x += rij.x*kernel;
	ai.y += rij.y*kernel;
	ai.z += rij.z*kernel;
	return ai;
}

__device__ float3 tileFunction(float3 position, float3 acceleration, float3* shared){
	#pragma unroll
	for(int i = 0; i < blockDim.x; i++){
		acceleration = bodyBodyCoulomb(position, shared[i], acceleration);
	}
	return acceleration;
}

__global__ void find_forces(float3* X, float3* A, int numberOfBodies){
	float3 position;
	float3 acc = {0.0f, 0.0f, 0.0f};
	int tid = blockIdx.x*blockDim.x + threadIdx.x;
	
	if(tid < numberOfBodies){
		//read into shared memory and calculate tile
		position = X[tid];

		for(int i = 0, tile = 0; i < gridDim.x; i += blockSize, tile++){
			//declare shared memory bank
			__shared__ float3 sharedPosition[blockSize];

			int idx = tile*blockDim.x + threadIdx.x;
			sharedPosition[threadIdx.x] = X[idx];
			__syncthreads();
			acc = tileFunction(position, acc, sharedPosition);
			__syncthreads();
		}	

		//read back to global memory for integration step
		A[tid] = acc;	
	}
}

//main   
int main(const int argc, const char** argv){ 

	cudaSetDevice(10);
	
	//declare dt, numberofSteps from the command line	
	float dt = atof(argv[1]);
	int numberOfSteps = atoi(argv[2]);
	int numberOfBodies = atoi(argv[3]);
	
	//allocate random data array
	float3* x;
	x = (float3*)malloc(numberOfBodies*sizeof(float3));
	
	float3* v;
	v = (float3*)malloc(numberOfBodies*sizeof(float3));
	
	float3* a;
	a = (float3*)malloc(numberOfBodies*sizeof(float3));

	
	srand (time(NULL));
	//fill random starting position and acceleration
	for(int i = 0; i < numberOfBodies; i++){
		x[i].x = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		x[i].y = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		x[i].z = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		
		v[i].x = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		v[i].y = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		v[i].z = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;

		a[i].x = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		a[i].y = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		a[i].z = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;

	}
	
	//allocate cuda memory
	float3 *d_x;
	cudaMalloc((void**)&d_x, numberOfBodies*sizeof(float3));
	
	float3 *d_a;
	cudaMalloc((void**)&d_a, numberOfBodies*sizeof(float3));
	
	//declare gridSize
	int gridSize = (numberOfBodies+blockSize-1)/(blockSize);

	//start loop over time steps
	for(int k = 0; k < numberOfSteps; k++){
		
		//copy position, acceleration to device
		cudaMemcpy(d_x, x, numberOfBodies*sizeof(float3), cudaMemcpyHostToDevice);
		cudaCheckError();
		cudaMemcpy(d_a, a, numberOfBodies*sizeof(float3), cudaMemcpyHostToDevice);
		cudaCheckError();


		//call kernel
		find_forces<<<gridSize, blockSize>>>(d_x, d_a, numberOfBodies);
		
		//copy position, acceleration off device
		cudaMemcpy(x, d_x, numberOfBodies*sizeof(float3), cudaMemcpyDeviceToHost);
		cudaCheckError();
		cudaMemcpy(a, d_a, numberOfBodies*sizeof(float3), cudaMemcpyDeviceToHost);
		cudaCheckError();

		for(int i = 0; i < numberOfBodies; i++){
			if(a[i].x == -1){
				v[i].x += 0;
				v[i].y += 0;
				v[i].z += 0;
			}
			else{
				v[i].x += 0.5*a[i].x*dt*dt/mass;
				v[i].y += 0.5*a[i].y*dt*dt/mass;
				v[i].z += 0.5*a[i].z*dt*dt/mass;

				x[i].x += v[i].x*dt;
				x[i].y += v[i].y*dt;
				x[i].z += v[i].z*dt;
			}
		}
	}
	
	//read out some results just for fun
	for(int i = 0; i < 10; i++){
		std::cout << x[i].x << "  " << a[i].x << std::endl;
	}
	
	free(x);
	free(a);		
	cudaFree(d_x);
	cudaFree(d_a);
}

	.file	"tmpxft_00267ccf_00000000-6_Nbody.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4391:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4391:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB5064:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE5064:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z15bodyBodyCoulomb6float3S_S_
	.type	_Z15bodyBodyCoulomb6float3S_S_, @function
_Z15bodyBodyCoulomb6float3S_S_:
.LFB4386:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$72, %rsp
	.cfi_def_cfa_offset 80
	movl	$1, 60(%rsp)
	movl	60(%rsp), %edi
	movq	%xmm0, 32(%rsp)
	movss	%xmm1, 40(%rsp)
	movq	%xmm2, 16(%rsp)
	movss	%xmm3, 24(%rsp)
	movq	%xmm4, (%rsp)
	movss	%xmm5, 8(%rsp)
	call	exit@PLT
	.cfi_endproc
.LFE4386:
	.size	_Z15bodyBodyCoulomb6float3S_S_, .-_Z15bodyBodyCoulomb6float3S_S_
	.globl	_Z12tileFunction6float3S_PS_
	.type	_Z12tileFunction6float3S_PS_, @function
_Z12tileFunction6float3S_PS_:
.LFB4387:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$56, %rsp
	.cfi_def_cfa_offset 64
	movl	$1, 44(%rsp)
	movl	44(%rsp), %edi
	movq	%xmm0, 16(%rsp)
	movss	%xmm1, 24(%rsp)
	movq	%xmm2, (%rsp)
	movss	%xmm3, 8(%rsp)
	call	exit@PLT
	.cfi_endproc
.LFE4387:
	.size	_Z12tileFunction6float3S_PS_, .-_Z12tileFunction6float3S_PS_
	.globl	_Z41__device_stub__Z11find_forcesP6float3S0_iP6float3S0_i
	.type	_Z41__device_stub__Z11find_forcesP6float3S0_iP6float3S0_i, @function
_Z41__device_stub__Z11find_forcesP6float3S0_iP6float3S0_i:
.LFB4413:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L7
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z11find_forcesP6float3S0_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L7:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4413:
	.size	_Z41__device_stub__Z11find_forcesP6float3S0_iP6float3S0_i, .-_Z41__device_stub__Z11find_forcesP6float3S0_iP6float3S0_i
	.globl	_Z11find_forcesP6float3S0_i
	.type	_Z11find_forcesP6float3S0_i, @function
_Z11find_forcesP6float3S0_i:
.LFB4414:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z11find_forcesP6float3S0_iP6float3S0_i
	.cfi_endproc
.LFE4414:
	.size	_Z11find_forcesP6float3S0_i, .-_Z11find_forcesP6float3S0_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"Error in "
.LC3:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/dgates8/personal-/master/NBody/Nbody.cu"
.LC4:
	.string	" at line "
.LC5:
	.string	" : "
.LC10:
	.string	"  "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4388:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$10, %edi
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	cudaSetDevice@PLT
	movq	8(%rbx), %rdi
	call	atof@PLT
	movq	16(%rbx), %rdi
	cvtsd2ss	%xmm0, %xmm6
	movss	%xmm6, 8(%rsp)
	call	atoi@PLT
	movq	24(%rbx), %rdi
	movl	%eax, %r14d
	call	atoi@PLT
	movl	%eax, %r13d
	cltq
	imulq	$12, %rax, %rax
	movq	%rax, %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, %rbx
	call	malloc@PLT
	movq	(%rsp), %rdi
	movq	%rax, %rbp
	call	malloc@PLT
	xorl	%edi, %edi
	movq	%rax, %r12
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	xorl	%edx, %edx
.L14:
	cmpl	%r13d, %edx
	jge	.L34
	movl	%edx, 12(%rsp)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	addss	%xmm0, %xmm0
	subss	.LC1(%rip), %xmm0
	movss	%xmm0, (%rbx,%r15)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	addss	%xmm0, %xmm0
	subss	.LC1(%rip), %xmm0
	movss	%xmm0, 4(%rbx,%r15)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	addss	%xmm0, %xmm0
	subss	.LC1(%rip), %xmm0
	movss	%xmm0, 8(%rbx,%r15)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	addss	%xmm0, %xmm0
	subss	.LC1(%rip), %xmm0
	movss	%xmm0, 0(%rbp,%r15)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	addss	%xmm0, %xmm0
	subss	.LC1(%rip), %xmm0
	movss	%xmm0, 4(%rbp,%r15)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	addss	%xmm0, %xmm0
	subss	.LC1(%rip), %xmm0
	movss	%xmm0, 8(%rbp,%r15)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	addss	%xmm0, %xmm0
	subss	.LC1(%rip), %xmm0
	movss	%xmm0, (%r12,%r15)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	addss	%xmm0, %xmm0
	subss	.LC1(%rip), %xmm0
	movss	%xmm0, 4(%r12,%r15)
	call	rand@PLT
	movl	12(%rsp), %edx
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	incl	%edx
	addss	%xmm0, %xmm0
	subss	.LC1(%rip), %xmm0
	movss	%xmm0, 8(%r12,%r15)
	addq	$12, %r15
	jmp	.L14
.L34:
	movq	(%rsp), %rsi
	leaq	16(%rsp), %rdi
	xorl	%r15d, %r15d
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	24(%rsp), %rdi
	call	cudaMalloc@PLT
	leal	63(%r13), %eax
	movl	$64, %ecx
	cltd
	idivl	%ecx
	movl	%eax, 12(%rsp)
.L16:
	cmpl	%r14d, %r15d
	jge	.L35
	movq	(%rsp), %rdx
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L17
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	%eax, (%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC4(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$144, %esi
	movq	%rax, %rdi
	jmp	.L33
.L17:
	movq	(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L18
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	%eax, (%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC4(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$146, %esi
	movq	%rax, %rdi
.L33:
	call	_ZNSolsEi@PLT
	leaq	.LC5(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	(%rsp), %edi
	movq	%rax, %rbx
	call	cudaGetErrorString@PLT
	movq	%rbx, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$1, %edi
	call	exit@PLT
.L18:
	movl	12(%rsp), %eax
	movl	$67108865, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$6, %rdx
	movl	$1, %ecx
	movl	%eax, 32(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 36(%rsp)
	movq	32(%rsp), %rdi
	movl	40(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	%r13d, %edx
	call	_Z41__device_stub__Z11find_forcesP6float3S0_iP6float3S0_i
.L19:
	movq	(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L20
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	%eax, (%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC4(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$154, %esi
	movq	%rax, %rdi
	jmp	.L33
.L20:
	movq	(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L29
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	%eax, (%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC4(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$156, %esi
	movq	%rax, %rdi
	jmp	.L33
.L29:
	movss	.LC6(%rip), %xmm6
	xorl	%eax, %eax
	xorl	%edx, %edx
	xorps	%xmm5, %xmm5
	movsd	.LC8(%rip), %xmm3
	movsd	.LC9(%rip), %xmm4
.L21:
	cmpl	%r13d, %edx
	jge	.L36
	movss	(%r12,%rax), %xmm0
	movss	0(%rbp,%rax), %xmm2
	movss	4(%rbp,%rax), %xmm9
	movss	8(%rbp,%rax), %xmm8
	ucomiss	%xmm6, %xmm0
	jp	.L22
	jne	.L22
	addss	%xmm5, %xmm2
	addss	%xmm5, %xmm9
	addss	%xmm5, %xmm8
	movss	%xmm2, 0(%rbp,%rax)
	movss	%xmm9, 4(%rbp,%rax)
	movss	%xmm8, 8(%rbp,%rax)
	jmp	.L24
.L22:
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm3, %xmm0
	cvtss2sd	8(%rsp), %xmm7
	cvtss2sd	%xmm2, %xmm2
	cvtss2sd	8(%r12,%rax), %xmm1
	mulsd	%xmm3, %xmm1
	cvtss2sd	%xmm9, %xmm9
	cvtss2sd	%xmm8, %xmm8
	mulsd	%xmm7, %xmm0
	mulsd	%xmm7, %xmm1
	mulsd	%xmm7, %xmm0
	mulsd	%xmm7, %xmm1
	divsd	%xmm4, %xmm0
	divsd	%xmm4, %xmm1
	addsd	%xmm2, %xmm0
	cvtss2sd	4(%r12,%rax), %xmm2
	mulsd	%xmm3, %xmm2
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 0(%rbp,%rax)
	mulss	8(%rsp), %xmm0
	addss	(%rbx,%rax), %xmm0
	mulsd	%xmm7, %xmm2
	movss	%xmm0, (%rbx,%rax)
	mulsd	%xmm7, %xmm2
	divsd	%xmm4, %xmm2
	addsd	%xmm8, %xmm1
	cvtsd2ss	%xmm1, %xmm1
	movss	%xmm1, 8(%rbp,%rax)
	mulss	8(%rsp), %xmm1
	addss	8(%rbx,%rax), %xmm1
	movss	%xmm1, 8(%rbx,%rax)
	addsd	%xmm9, %xmm2
	cvtsd2ss	%xmm2, %xmm2
	movss	%xmm2, 4(%rbp,%rax)
	mulss	8(%rsp), %xmm2
	addss	4(%rbx,%rax), %xmm2
	movss	%xmm2, 4(%rbx,%rax)
.L24:
	incl	%edx
	addq	$12, %rax
	jmp	.L21
.L36:
	incl	%r15d
	jmp	.L16
.L35:
	xorl	%ebp, %ebp
	leaq	_ZSt4cout(%rip), %r13
.L27:
	movq	%r13, %rdi
	cvtss2sd	(%rbx,%rbp), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	(%r12,%rbp), %xmm0
	addq	$12, %rbp
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	cmpq	$120, %rbp
	jne	.L27
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4388:
	.size	main, .-main
	.section	.rodata.str1.1
.LC11:
	.string	"_Z11find_forcesP6float3S0_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4416:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC11(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z11find_forcesP6float3S0_i(%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
.LFE4416:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.align 4
.LC1:
	.long	1065353216
	.align 4
.LC6:
	.long	-1082130432
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC8:
	.long	0
	.long	1071644672
	.align 8
.LC9:
	.long	-1270622874
	.long	967997998
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <fstream>
#include <iterator>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <time.h>

#define blockSize 64
#define Ke 8.99e9
#define Qe -1.602e-19
#define epsilon 1e-8
#define mass 9.11e-31
 
//macro for error checking
#define cudaCheckError(){	   												  \
	hipError_t err = hipGetLastError();											  \
	if(err != hipSuccess){              											  \
		std::cout << "Error in " << __FILE__ << " at line " << __LINE__ << " : " <<  hipGetErrorString(err) << std::endl; \
		exit(EXIT_FAILURE);                 										  \
	}                                     											  \
}

//calculate bodybody coulomb interactions
__device__ float3 bodyBodyCoulomb(float3 bi, float3 bj, float3 ai){
	float3 rij;
	
	//components of rij
	rij.x = bj.x - bi.x;
	rij.y = bj.y - bi.y;
	rij.z = bj.z - bi.z;
	
	//distance squared for solving force equation
	float distSquared = rij.x*rij.x + rij.y*rij.y + rij.z*rij.z + epsilon;
	if(distSquared > 10){
		ai.x = -1;
		ai.y = -1;
		ai.z = -1;
		return ai;
	}
	//inverse cubed with softening factor
	float inverseDist = 1.0f*Qe/sqrtf(distSquared*distSquared*distSquared);

	//finish the equation by multiplying by charge
	float kernel = Ke*Qe*inverseDist;
	
	//get acceleration for each component
	ai.x += rij.x*kernel;
	ai.y += rij.y*kernel;
	ai.z += rij.z*kernel;
	return ai;
}

__device__ float3 tileFunction(float3 position, float3 acceleration, float3* shared){
	#pragma unroll
	for(int i = 0; i < blockDim.x; i++){
		acceleration = bodyBodyCoulomb(position, shared[i], acceleration);
	}
	return acceleration;
}

__global__ void find_forces(float3* X, float3* A, int numberOfBodies){
	float3 position;
	float3 acc = {0.0f, 0.0f, 0.0f};
	int tid = blockIdx.x*blockDim.x + threadIdx.x;
	
	if(tid < numberOfBodies){
		//read into shared memory and calculate tile
		position = X[tid];

		for(int i = 0, tile = 0; i < gridDim.x; i += blockSize, tile++){
			//declare shared memory bank
			__shared__ float3 sharedPosition[blockSize];

			int idx = tile*blockDim.x + threadIdx.x;
			sharedPosition[threadIdx.x] = X[idx];
			__syncthreads();
			acc = tileFunction(position, acc, sharedPosition);
			__syncthreads();
		}	

		//read back to global memory for integration step
		A[tid] = acc;	
	}
}

//main   
int main(const int argc, const char** argv){ 

	hipSetDevice(10);
	
	//declare dt, numberofSteps from the command line	
	float dt = atof(argv[1]);
	int numberOfSteps = atoi(argv[2]);
	int numberOfBodies = atoi(argv[3]);
	
	//allocate random data array
	float3* x;
	x = (float3*)malloc(numberOfBodies*sizeof(float3));
	
	float3* v;
	v = (float3*)malloc(numberOfBodies*sizeof(float3));
	
	float3* a;
	a = (float3*)malloc(numberOfBodies*sizeof(float3));

	
	srand (time(NULL));
	//fill random starting position and acceleration
	for(int i = 0; i < numberOfBodies; i++){
		x[i].x = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		x[i].y = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		x[i].z = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		
		v[i].x = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		v[i].y = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		v[i].z = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;

		a[i].x = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		a[i].y = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;
		a[i].z = 2.0f * (rand() / (float)RAND_MAX) - 1.0f;

	}
	
	//allocate cuda memory
	float3 *d_x;
	hipMalloc((void**)&d_x, numberOfBodies*sizeof(float3));
	
	float3 *d_a;
	hipMalloc((void**)&d_a, numberOfBodies*sizeof(float3));
	
	//declare gridSize
	int gridSize = (numberOfBodies+blockSize-1)/(blockSize);

	//start loop over time steps
	for(int k = 0; k < numberOfSteps; k++){
		
		//copy position, acceleration to device
		hipMemcpy(d_x, x, numberOfBodies*sizeof(float3), hipMemcpyHostToDevice);
		cudaCheckError();
		hipMemcpy(d_a, a, numberOfBodies*sizeof(float3), hipMemcpyHostToDevice);
		cudaCheckError();


		//call kernel
		find_forces<<<gridSize, blockSize>>>(d_x, d_a, numberOfBodies);
		
		//copy position, acceleration off device
		hipMemcpy(x, d_x, numberOfBodies*sizeof(float3), hipMemcpyDeviceToHost);
		cudaCheckError();
		hipMemcpy(a, d_a, numberOfBodies*sizeof(float3), hipMemcpyDeviceToHost);
		cudaCheckError();

		for(int i = 0; i < numberOfBodies; i++){
			if(a[i].x == -1){
				v[i].x += 0;
				v[i].y += 0;
				v[i].z += 0;
			}
			else{
				v[i].x += 0.5*a[i].x*dt*dt/mass;
				v[i].y += 0.5*a[i].y*dt*dt/mass;
				v[i].z += 0.5*a[i].z*dt*dt/mass;

				x[i].x += v[i].x*dt;
				x[i].y += v[i].y*dt;
				x[i].z += v[i].z*dt;
			}
		}
	}
	
	//read out some results just for fun
	for(int i = 0; i < 10; i++){
		std::cout << x[i].x << "  " << a[i].x << std::endl;
	}
	
	free(x);
	free(a);		
	hipFree(d_x);
	hipFree(d_a);
}

	.text
	.file	"Nbody.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i # -- Begin function _Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i
	.type	_Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i,@function
_Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i: # @_Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	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	$_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i, .Lfunc_end0-_Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i
	.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	0xbf800000                      # float -1
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_2:
	.quad	0x3fe0000000000000              # double 0.5
.LCPI1_3:
	.quad	0x39b27a2eb443d566              # double 9.1100000000000003E-31
	.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
	movq	%rsi, %rbx
	movl	$10, %edi
	callq	hipSetDevice
	movq	8(%rbx), %rdi
	callq	atof
	movsd	%xmm0, 40(%rsp)                 # 8-byte Spill
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, 12(%rsp)                  # 4-byte Spill
	movq	24(%rbx), %rdi
	callq	atoi
	movl	%eax, %r12d
	cltq
	shlq	$2, %rax
	leaq	(%rax,%rax,2), %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r13
	movq	%r14, 48(%rsp)                  # 8-byte Spill
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r14
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movl	%r12d, %r15d
	movq	%r12, 32(%rsp)                  # 8-byte Spill
	testl	%r12d, %r12d
	jle	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	leaq	(,%r15,4), %rax
	leaq	(%rax,%rax,2), %r12
	xorl	%ebp, %ebp
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	addss	%xmm0, %xmm0
	movss	.LCPI1_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	addss	%xmm1, %xmm0
	movss	%xmm0, (%rbx,%rbp)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	addss	%xmm0, %xmm0
	addss	.LCPI1_1(%rip), %xmm0
	movss	%xmm0, 4(%rbx,%rbp)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	addss	%xmm0, %xmm0
	addss	.LCPI1_1(%rip), %xmm0
	movss	%xmm0, 8(%rbx,%rbp)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	addss	%xmm0, %xmm0
	addss	.LCPI1_1(%rip), %xmm0
	movss	%xmm0, (%r13,%rbp)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	addss	%xmm0, %xmm0
	addss	.LCPI1_1(%rip), %xmm0
	movss	%xmm0, 4(%r13,%rbp)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	addss	%xmm0, %xmm0
	addss	.LCPI1_1(%rip), %xmm0
	movss	%xmm0, 8(%r13,%rbp)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	addss	%xmm0, %xmm0
	addss	.LCPI1_1(%rip), %xmm0
	movss	%xmm0, (%r14,%rbp)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	addss	%xmm0, %xmm0
	addss	.LCPI1_1(%rip), %xmm0
	movss	%xmm0, 4(%r14,%rbp)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	addss	%xmm0, %xmm0
	addss	.LCPI1_1(%rip), %xmm0
	movss	%xmm0, 8(%r14,%rbp)
	addq	$12, %rbp
	cmpq	%rbp, %r12
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	leaq	24(%rsp), %rdi
	movq	48(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	cmpl	$0, 12(%rsp)                    # 4-byte Folded Reload
	jle	.LBB1_4
# %bb.7:                                # %.lr.ph137
	cvtsd2ss	40(%rsp), %xmm4                 # 8-byte Folded Reload
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	movq	32(%rsp), %rcx                  # 8-byte Reload
	leal	63(%rcx), %eax
	addl	$126, %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	sarl	$6, %ecx
	btsq	$32, %rcx
	movq	%rcx, 72(%rsp)                  # 8-byte Spill
	cvtss2sd	%xmm4, %xmm5
	shlq	$2, %r15
	leaq	(%r15,%r15,2), %r15
	xorl	%r12d, %r12d
	addq	$64, %rdx
	movq	%rdx, 80(%rsp)                  # 8-byte Spill
	movss	%xmm4, 60(%rsp)                 # 4-byte Spill
	movsd	%xmm5, 64(%rsp)                 # 8-byte Spill
.LBB1_8:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_20 Depth 2
	movq	24(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.11:                               #   in Loop: Header=BB1_8 Depth=1
	movq	%rbp, %rdx
	movq	16(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_12
# %bb.13:                               #   in Loop: Header=BB1_8 Depth=1
	movq	%r12, 40(%rsp)                  # 8-byte Spill
	movq	72(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movq	80(%rsp), %rdx                  # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_15
# %bb.14:                               #   in Loop: Header=BB1_8 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	32(%rsp), %rdx                  # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	callq	_Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i
.LBB1_15:                               #   in Loop: Header=BB1_8 Depth=1
	movq	24(%rsp), %rsi
	movq	%rbx, %rdi
	movq	48(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_16
# %bb.17:                               #   in Loop: Header=BB1_8 Depth=1
	movq	16(%rsp), %rsi
	movq	%r14, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_22
# %bb.18:                               # %.preheader121
                                        #   in Loop: Header=BB1_8 Depth=1
	cmpl	$0, 32(%rsp)                    # 4-byte Folded Reload
	movq	48(%rsp), %rbp                  # 8-byte Reload
	movss	60(%rsp), %xmm4                 # 4-byte Reload
                                        # xmm4 = mem[0],zero,zero,zero
	movsd	64(%rsp), %xmm5                 # 8-byte Reload
                                        # xmm5 = mem[0],zero
	movq	40(%rsp), %r12                  # 8-byte Reload
	movss	.LCPI1_1(%rip), %xmm6           # xmm6 = mem[0],zero,zero,zero
	movsd	.LCPI1_2(%rip), %xmm7           # xmm7 = mem[0],zero
	movsd	.LCPI1_3(%rip), %xmm8           # xmm8 = mem[0],zero
	jle	.LBB1_25
# %bb.19:                               # %.lr.ph133.preheader
                                        #   in Loop: Header=BB1_8 Depth=1
	xorl	%eax, %eax
.LBB1_20:                               # %.lr.ph133
                                        #   Parent Loop BB1_8 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r14,%rax), %xmm0              # xmm0 = mem[0],zero,zero,zero
	ucomiss	%xmm6, %xmm0
	jne	.LBB1_23
	jp	.LBB1_23
# %bb.21:                               #   in Loop: Header=BB1_20 Depth=2
	xorps	%xmm1, %xmm1
	movss	(%r13,%rax), %xmm0              # xmm0 = mem[0],zero,zero,zero
	addss	%xmm1, %xmm0
	movss	%xmm0, (%r13,%rax)
	movss	4(%r13,%rax), %xmm0             # xmm0 = mem[0],zero,zero,zero
	addss	%xmm1, %xmm0
	movss	%xmm0, 4(%r13,%rax)
	movq	%r13, %rcx
	jmp	.LBB1_24
.LBB1_23:                               #   in Loop: Header=BB1_20 Depth=2
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm7, %xmm0
	mulsd	%xmm5, %xmm0
	mulsd	%xmm5, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	(%r13,%rax), %xmm1
	divsd	%xmm8, %xmm0
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, (%r13,%rax)
	xorps	%xmm1, %xmm1
	cvtss2sd	4(%r14,%rax), %xmm1
	mulsd	%xmm7, %xmm1
	mulsd	%xmm5, %xmm1
	mulsd	%xmm5, %xmm1
	xorps	%xmm2, %xmm2
	cvtss2sd	4(%r13,%rax), %xmm2
	divsd	%xmm8, %xmm1
	addsd	%xmm1, %xmm2
	cvtsd2ss	%xmm2, %xmm2
	movss	%xmm2, 4(%r13,%rax)
	xorps	%xmm1, %xmm1
	cvtss2sd	8(%r14,%rax), %xmm1
	mulsd	%xmm7, %xmm1
	mulsd	%xmm5, %xmm1
	mulsd	%xmm5, %xmm1
	xorps	%xmm3, %xmm3
	cvtss2sd	8(%r13,%rax), %xmm3
	divsd	%xmm8, %xmm1
	addsd	%xmm1, %xmm3
	xorps	%xmm1, %xmm1
	cvtsd2ss	%xmm3, %xmm1
	mulss	%xmm4, %xmm0
	addss	(%rbx,%rax), %xmm0
	movss	%xmm0, (%rbx,%rax)
	mulss	%xmm4, %xmm2
	addss	4(%rbx,%rax), %xmm2
	movss	%xmm1, 8(%r13,%rax)
	movss	%xmm2, 4(%rbx,%rax)
	mulss	%xmm4, %xmm1
	movq	%rbx, %rcx
.LBB1_24:                               #   in Loop: Header=BB1_20 Depth=2
	addss	8(%rcx,%rax), %xmm1
	movss	%xmm1, 8(%rcx,%rax)
	addq	$12, %rax
	cmpq	%rax, %r15
	jne	.LBB1_20
.LBB1_25:                               # %._crit_edge134
                                        #   in Loop: Header=BB1_8 Depth=1
	incl	%r12d
	cmpl	12(%rsp), %r12d                 # 4-byte Folded Reload
	jne	.LBB1_8
.LBB1_4:                                # %.preheader.preheader
	xorl	%r12d, %r12d
.LBB1_5:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r12), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.4, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r12), %xmm0
	movq	%r15, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	addq	$12, %r12
	cmpq	$120, %r12
	jne	.LBB1_5
# %bb.6:
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %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
.LBB1_22:
	.cfi_def_cfa_offset 144
	movl	%eax, %ebp
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$158, %esi
	jmp	.LBB1_10
.LBB1_16:
	movl	%eax, %ebp
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$156, %esi
	jmp	.LBB1_10
.LBB1_12:
	movl	%eax, %ebp
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$148, %esi
	jmp	.LBB1_10
.LBB1_9:
	movl	%eax, %ebp
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$146, %esi
.LBB1_10:
	callq	_ZNSolsEi
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rbx
	movl	%ebp, %edi
	callq	hipGetErrorString
	movq	%rbx, %rdi
	movq	%rax, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.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	$_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i, %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	_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i,@object # @_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i
	.section	.rodata,"a",@progbits
	.globl	_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i
	.p2align	3, 0x0
_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i:
	.quad	_Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i
	.size	_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Error in "
	.size	.L.str, 10

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/dgates8/personal-/master/NBody/Nbody.hip"
	.size	.L.str.1, 103

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	" at line "
	.size	.L.str.2, 10

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

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i"
	.size	.L__unnamed_1, 45

	.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 _Z26__device_stub__find_forcesP15HIP_vector_typeIfLj3EES1_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z11find_forcesP15HIP_vector_typeIfLj3EES1_i
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i ; -- Begin function _Z11find_forcesP15HIP_vector_typeIfLj3EES1_i
	.globl	_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i
	.p2align	8
	.type	_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i,@function
_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i: ; @_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b32 s5, s[0:1], 0x10
	s_add_u32 s2, s0, 24
	s_addc_u32 s3, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s12, s4, 0xffff
	s_mov_b32 s4, exec_lo
	v_mad_u64_u32 v[7:8], null, s15, s12, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s5, v7
	s_cbranch_execz .LBB0_13
; %bb.1:
	s_load_b32 s14, s[2:3], 0x0
	s_load_b128 s[4:7], s[0:1], 0x0
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v5, 0
	v_mov_b32_e32 v6, 0
	s_mov_b32 s1, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_eq_u32 s14, 0
	s_cbranch_scc1 .LBB0_12
; %bb.2:                                ; %.lr.ph
	v_mad_i64_i32 v[1:2], null, v7, 12, s[4:5]
	s_cmp_lg_u32 s12, 0
	v_mul_u32_u24_e32 v8, 12, v0
	v_dual_mov_b32 v9, 0 :: v_dual_mov_b32 v10, 0
	v_mov_b32_e32 v11, 0
	s_cselect_b32 s13, -1, 0
	global_load_b96 v[1:3], v[1:2], off
	s_add_i32 s14, s14, -1
	s_mov_b32 s2, 0xe2308c3a
	s_mov_b32 s8, 0x549647fb
	s_mov_b32 s10, 0xcb45df97
	s_mov_b32 s3, 0x3e45798e
	s_mov_b32 s9, 0xbc07a42f
	s_mov_b32 s11, 0xbe18be0e
	s_lshr_b32 s14, s14, 6
.LBB0_3:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_5 Depth 2
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[4:5], null, s1, s12, v[0:1]
	s_and_not1_b32 vcc_lo, exec_lo, s13
	s_delay_alu instid0(VALU_DEP_1)
	v_mad_i64_i32 v[5:6], null, v4, 12, s[4:5]
	global_load_b96 v[4:6], v[5:6], off
	s_waitcnt vmcnt(0)
	ds_store_2addr_b32 v8, v4, v5 offset1:1
	ds_store_b32 v8, v6 offset:8
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_vccnz .LBB0_9
; %bb.4:                                ; %.lr.ph.i.preheader
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_mov_b32 s15, 0
	s_mov_b32 s16, s12
.LBB0_5:                                ; %.lr.ph.i
                                        ;   Parent Loop BB0_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_mov_b32_e32 v6, s15
	s_mov_b32 s17, exec_lo
	ds_load_2addr_b32 v[4:5], v6 offset1:1
	ds_load_b32 v6, v6 offset:8
	s_waitcnt lgkmcnt(0)
	v_dual_sub_f32 v12, v5, v2 :: v_dual_sub_f32 v13, v6, v3
	v_sub_f32_e32 v14, v4, v1
	v_mov_b32_e32 v6, -1.0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v4, v12, v12
	v_fmac_f32_e32 v4, v14, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v4, v13, v13
	v_cvt_f64_f32_e32 v[4:5], v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[4:5], v[4:5], s[2:3]
	v_cvt_f32_f64_e32 v15, v[4:5]
	v_dual_mov_b32 v4, -1.0 :: v_dual_mov_b32 v5, -1.0
	s_delay_alu instid0(VALU_DEP_2)
	v_cmpx_nlt_f32_e32 0x41200000, v15
	s_cbranch_execz .LBB0_7
; %bb.6:                                ;   in Loop: Header=BB0_5 Depth=2
	v_mul_f32_e32 v4, v15, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v4, v4, v15
	v_mul_f32_e32 v5, 0x4f800000, v4
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v4, v4, v5, vcc_lo
	v_sqrt_f32_e32 v5, v4
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v6, -1, v5
	v_add_nc_u32_e32 v15, 1, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v16, -v6, v5, v4
	v_fma_f32 v17, -v15, v5, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s0, 0, v16
	v_cndmask_b32_e64 v5, v5, v6, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e64 s0, 0, v17
	v_cndmask_b32_e64 v5, v5, v15, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v6, 0x37800000, v5
	v_cndmask_b32_e32 v5, v5, v6, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v4, 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v4, v5, v4, vcc_lo
	v_cvt_f64_f32_e32 v[4:5], v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f64 v[15:16], null, v[4:5], v[4:5], s[8:9]
	v_div_scale_f64 v[21:22], vcc_lo, s[8:9], v[4:5], s[8:9]
	v_rcp_f64_e32 v[17:18], v[15:16]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[19:20], -v[15:16], v[17:18], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[17:18], v[17:18], v[19:20], v[17:18]
	v_fma_f64 v[19:20], -v[15:16], v[17:18], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[17:18], v[17:18], v[19:20], v[17:18]
	v_mul_f64 v[19:20], v[21:22], v[17:18]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[15:16], -v[15:16], v[19:20], v[21:22]
	v_div_fmas_f64 v[15:16], v[15:16], v[17:18], v[19:20]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f64 v[4:5], v[15:16], v[4:5], s[8:9]
	v_cvt_f32_f64_e32 v4, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f64_f32_e32 v[4:5], v4
	v_mul_f64 v[4:5], v[4:5], s[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f32_f64_e32 v4, v[4:5]
	v_fmac_f32_e32 v11, v13, v4
	v_fmac_f32_e32 v9, v14, v4
	v_fmac_f32_e32 v10, v12, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v6, v11
	v_dual_mov_b32 v4, v9 :: v_dual_mov_b32 v5, v10
.LBB0_7:                                ; %_Z15bodyBodyCoulomb15HIP_vector_typeIfLj3EES0_S0_.exit.i
                                        ;   in Loop: Header=BB0_5 Depth=2
	s_or_b32 exec_lo, exec_lo, s17
	s_add_i32 s16, s16, -1
	s_add_i32 s15, s15, 12
	s_cmp_lg_u32 s16, 0
	s_cbranch_scc0 .LBB0_10
; %bb.8:                                ;   in Loop: Header=BB0_5 Depth=2
	v_dual_mov_b32 v11, v6 :: v_dual_mov_b32 v10, v5
	v_mov_b32_e32 v9, v4
	s_branch .LBB0_5
.LBB0_9:                                ;   in Loop: Header=BB0_3 Depth=1
	v_dual_mov_b32 v6, v11 :: v_dual_mov_b32 v5, v10
	v_mov_b32_e32 v4, v9
.LBB0_10:                               ; %_Z12tileFunction15HIP_vector_typeIfLj3EES0_PS0_.exit
                                        ;   in Loop: Header=BB0_3 Depth=1
	s_add_i32 s0, s1, 1
	s_cmp_eq_u32 s1, s14
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_12
; %bb.11:                               ;   in Loop: Header=BB0_3 Depth=1
	v_dual_mov_b32 v9, v4 :: v_dual_mov_b32 v10, v5
	v_mov_b32_e32 v11, v6
	s_mov_b32 s1, s0
	s_branch .LBB0_3
.LBB0_12:                               ; %Flow50
	v_mad_i64_i32 v[0:1], null, v7, 12, s[6:7]
	global_store_b96 v[0:1], v[4:6], off
.LBB0_13:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11find_forcesP15HIP_vector_typeIfLj3EES1_i
		.amdhsa_group_segment_fixed_size 768
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 23
		.amdhsa_next_free_sgpr 18
		.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	_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i, .Lfunc_end0-_Z11find_forcesP15HIP_vector_typeIfLj3EES1_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 836
; NumSgprs: 20
; NumVgprs: 23
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 768 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 23
; 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
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 768
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11find_forcesP15HIP_vector_typeIfLj3EES1_i
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z11find_forcesP15HIP_vector_typeIfLj3EES1_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     23
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
