/***************************************************************************
 *cr
 *cr            (C) Copyright 2007 The Board of Trustees of the
 *cr                        University of Illinois
 *cr                         All Rights Reserved
 *cr
 ***************************************************************************/
/*
 * CUDA accelerated coulombic potential grid test code
 *   John E. Stone and Chris Rodrigues
 *   http://www.ks.uiuc.edu/~johns/
 */

#include <stdio.h>
#include <stdlib.h>

#define CUERR { cudaError_t err; \
  if ((err = cudaGetLastError()) != cudaSuccess) { \
  printf("CUDA error: %s, line %d\n", cudaGetErrorString(err), __LINE__); \
  return -1; }}

// max constant buffer size is 64KB, minus whatever
// the CUDA runtime and compiler are using that we don't know about
// At 16 bytes for atom, for this program 4070 atoms is about the max
// we can store in the constant buffer.
#define MAXATOMS 4000
__constant__ float4 atominfo[MAXATOMS];

#define UNROLLX       8
#define UNROLLY       1
#define BLOCKSIZEX   16
#define BLOCKSIZEY   16
#define BLOCKSIZE    BLOCKSIZEX * BLOCKSIZEY

// This kernel calculates coulombic potential at each grid point and
// stores the results in the output array.
//
// This kernel was written by Chris Rodrigues of Wen-mei's group
//
__global__ void cenergy(int numatoms, float gridspacing, float * energygrid) {
  unsigned int xindex  = __umul24(blockIdx.x, blockDim.x) * UNROLLX
                         + threadIdx.x;
  unsigned int yindex  = __umul24(blockIdx.y, blockDim.y) + threadIdx.y;
  unsigned int outaddr = (__umul24(gridDim.x, blockDim.x) * UNROLLX) * yindex
                         + xindex;

  float coory = gridspacing * yindex;
  float coorx = gridspacing * xindex;

  float energyvalx1=0.0f;
  float energyvalx2=0.0f;
  float energyvalx3=0.0f;
  float energyvalx4=0.0f;
#if UNROLLX == 8
  float energyvalx5=0.0f;
  float energyvalx6=0.0f;
  float energyvalx7=0.0f;
  float energyvalx8=0.0f;
#endif

  float gridspacing_u = gridspacing * BLOCKSIZEX;

  //
  // XXX 59/8 FLOPS per atom
  //
  int atomid;
  for (atomid=0; atomid<numatoms; atomid++) {
    float dy = coory - atominfo[atomid].y;
    float dyz2 = (dy * dy) + atominfo[atomid].z;
    float atomq=atominfo[atomid].w;

    float dx1 = coorx - atominfo[atomid].x;
    float dx2 = dx1 + gridspacing_u;
    float dx3 = dx2 + gridspacing_u;
    float dx4 = dx3 + gridspacing_u;
#if UNROLLX == 8
    float dx5 = dx4 + gridspacing_u;
    float dx6 = dx5 + gridspacing_u;
    float dx7 = dx6 + gridspacing_u;
    float dx8 = dx7 + gridspacing_u;
#endif
    

    energyvalx1 += atomq * rsqrtf(dx1*dx1 + dyz2);
    energyvalx2 += atomq * rsqrtf(dx2*dx2 + dyz2);
    energyvalx3 += atomq * rsqrtf(dx3*dx3 + dyz2);
    energyvalx4 += atomq * rsqrtf(dx4*dx4 + dyz2);
#if UNROLLX == 8
    energyvalx5 += atomq * rsqrtf(dx5*dx5 + dyz2);
    energyvalx6 += atomq * rsqrtf(dx6*dx6 + dyz2);
    energyvalx7 += atomq * rsqrtf(dx7*dx7 + dyz2);
    energyvalx8 += atomq * rsqrtf(dx8*dx8 + dyz2);
#endif
  }

  energygrid[outaddr             ] += energyvalx1;
  energygrid[outaddr+1*BLOCKSIZEX] += energyvalx2;
  energygrid[outaddr+2*BLOCKSIZEX] += energyvalx3;
  energygrid[outaddr+3*BLOCKSIZEX] += energyvalx4;
#if UNROLLX == 8
  energygrid[outaddr+4*BLOCKSIZEX] += energyvalx5;
  energygrid[outaddr+5*BLOCKSIZEX] += energyvalx6;
  energygrid[outaddr+6*BLOCKSIZEX] += energyvalx7;
  energygrid[outaddr+7*BLOCKSIZEX] += energyvalx8;
#endif
}



int copyatomstoconstbuf(float *atoms, int count, float zplane) {
  CUERR // check and clear any existing errors

  if (count > MAXATOMS) {
    printf("Atom count exceeds constant buffer storage capacity\n");
    return -1;
  }

  float atompre[4*MAXATOMS];
  int i;
  for (i=0; i<count*4; i+=4) {
    atompre[i    ] = atoms[i    ];
    atompre[i + 1] = atoms[i + 1];
    float dz = zplane - atoms[i + 2];
    atompre[i + 2]  = dz*dz;
    atompre[i + 3] = atoms[i + 3];
  }

  cudaMemcpyToSymbol(atominfo, atompre, count * 4 * sizeof(float), 0);
  CUERR // check and clear any existing errors

  return 0;
}


int initatoms(float **atombuf, int count, dim3 volsize, float gridspacing) {
  dim3 size;
  int i;
  float *atoms;

  atoms = (float *) malloc(count * 4 * sizeof(float));
  *atombuf = atoms;

  // compute grid dimensions in angstroms
  size.x = (unsigned int) gridspacing * volsize.x;
  size.y = (unsigned int) gridspacing * volsize.y;
  size.z = (unsigned int) gridspacing * volsize.z;

  for (i=0; i<count; i++) {
    int addr = i * 4;
    atoms[addr    ] = (rand() / (float) RAND_MAX) * size.x; 
    atoms[addr + 1] = (rand() / (float) RAND_MAX) * size.y; 
    atoms[addr + 2] = (rand() / (float) RAND_MAX) * size.z; 
    atoms[addr + 3] = ((rand() / (float) RAND_MAX) * 2.0) - 1.0;  // charge
  }  

  return 0;
}

	.file	"tmpxft_002230ab_00000000-6_cuenergy.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CUDA error: %s, line %d\n"
.LC1:
	.string	"Atom count exceeds constant buffer storage capacity\n"
	.text
	.globl	_Z19copyatomstoconstbufPfif
	.type	_Z19copyatomstoconstbufPfif, @function
_Z19copyatomstoconstbufPfif:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	-61440(%rsp), %r11
	.cfi_def_cfa 11, 61464
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2600, %rsp
	.cfi_def_cfa_offset 64064
	movss	%xmm0, 12(%rsp)
	movq	%rdi, %rbp
	movl	%esi, %ebx
	movq	%fs:40, %rax
	movq	%rax, 64024(%rsp)
	xorl	%eax, %eax
	call	cudaGetLastError@PLT
	movss	12(%rsp), %xmm0
	testl	%eax, %eax
	je	.L3
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$111, %ecx
	movq	%rax, %rdx
	jmp	.L13
.L3:
	cmpl	$4000, %ebx
	jg	.L5
	leaq	24(%rsp), %rdx
	sall	$2, %ebx
	xorl	%eax, %eax
	movq	%rdx, %rsi
	jmp	.L6
.L5:
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L4:
	orl	$-1, %eax
	jmp	.L2
.L6:
	cmpl	%eax, %ebx
	jle	.L15
	movss	0(%rbp,%rax,4), %xmm1
	addq	$16, %rdx
	movss	%xmm1, -16(%rdx)
	movss	4(%rbp,%rax,4), %xmm1
	movss	%xmm1, -12(%rdx)
	movaps	%xmm0, %xmm1
	subss	8(%rbp,%rax,4), %xmm1
	mulss	%xmm1, %xmm1
	movss	%xmm1, -8(%rdx)
	movss	12(%rbp,%rax,4), %xmm1
	addq	$4, %rax
	movss	%xmm1, -4(%rdx)
	jmp	.L6
.L15:
	movslq	%ebx, %rbx
	leaq	_ZL8atominfo(%rip), %rdi
	movl	$1, %r8d
	xorl	%ecx, %ecx
	leaq	0(,%rbx,4), %rdx
	call	cudaMemcpyToSymbol@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	xorl	%eax, %eax
	testl	%edi, %edi
	je	.L2
	call	cudaGetErrorString@PLT
	movl	$129, %ecx
	movq	%rax, %rdx
.L13:
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L4
.L2:
	movq	64024(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$64040, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z19copyatomstoconstbufPfif, .-_Z19copyatomstoconstbufPfif
	.globl	_Z9initatomsPPfi4dim3f
	.type	_Z9initatomsPPfi4dim3f, @function
_Z9initatomsPPfi4dim3f:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	leal	0(,%rsi,4), %edi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%edi, %rdi
	salq	$2, %rdi
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movss	%xmm0, 12(%rsp)
	movq	%rdx, 16(%rsp)
	movl	%ecx, 24(%rsp)
	call	malloc@PLT
	movss	12(%rsp), %xmm0
	movl	16(%rsp), %r13d
	movq	%rax, 0(%rbp)
	movl	20(%rsp), %r14d
	movq	%rax, %rbx
	cvttss2siq	%xmm0, %rbp
	imull	%ebp, %r13d
	imull	%ebp, %r14d
	imull	24(%rsp), %ebp
.L17:
	cmpl	%r12d, %r15d
	jge	.L26
	call	rand@PLT
	incl	%r15d
	addq	$16, %rbx
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	movl	%r13d, %eax
	cvtsi2ssq	%rax, %xmm1
	mulss	%xmm1, %xmm0
	movss	%xmm0, -16(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	movl	%r14d, %eax
	cvtsi2ssq	%rax, %xmm1
	mulss	%xmm1, %xmm0
	movss	%xmm0, -12(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	movl	%ebp, %eax
	cvtsi2ssq	%rax, %xmm1
	mulss	%xmm1, %xmm0
	movss	%xmm0, -8(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	addsd	%xmm0, %xmm0
	subsd	.LC3(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, -4(%rbx)
	jmp	.L17
.L26:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9initatomsPPfi4dim3f, .-_Z9initatomsPPfi4dim3f
	.globl	_Z28__device_stub__Z7cenergyifPfifPf
	.type	_Z28__device_stub__Z7cenergyifPfifPf, @function
_Z28__device_stub__Z7cenergyifPfifPf:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movl	%edi, 12(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	32(%rsp), %rdi
	leaq	44(%rsp), %rsi
	movss	%xmm0, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z7cenergyifPf(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L27:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
	call	__stack_chk_fail@PLT
.L29:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z28__device_stub__Z7cenergyifPfifPf, .-_Z28__device_stub__Z7cenergyifPfifPf
	.globl	_Z7cenergyifPf
	.type	_Z7cenergyifPf, @function
_Z7cenergyifPf:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z7cenergyifPfifPf
	.cfi_endproc
.LFE2054:
	.size	_Z7cenergyifPf, .-_Z7cenergyifPf
	.section	.rodata.str1.1
.LC4:
	.string	"_Z7cenergyifPf"
.LC5:
	.string	"atominfo"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC4(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7cenergyifPf(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC5(%rip), %rdx
	movl	$64000, %r9d
	leaq	_ZL8atominfo(%rip), %rsi
	pushq	$1
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2056:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZL8atominfo
	.comm	_ZL8atominfo,64000,32
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC2:
	.long	805306368
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	0
	.long	1072693248
	.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:

/***************************************************************************
 *cr
 *cr            (C) Copyright 2007 The Board of Trustees of the
 *cr                        University of Illinois
 *cr                         All Rights Reserved
 *cr
 ***************************************************************************/
/*
 * CUDA accelerated coulombic potential grid test code
 *   John E. Stone and Chris Rodrigues
 *   http://www.ks.uiuc.edu/~johns/
 */


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>

#define CUERR { hipError_t err; \
  if ((err = hipGetLastError()) != hipSuccess) { \
  printf("CUDA error: %s, line %d\n", hipGetErrorString(err), __LINE__); \
  return -1; }}

// max constant buffer size is 64KB, minus whatever
// the CUDA runtime and compiler are using that we don't know about
// At 16 bytes for atom, for this program 4070 atoms is about the max
// we can store in the constant buffer.
#define MAXATOMS 4000
__constant__ float4 atominfo[MAXATOMS];

#define UNROLLX       8
#define UNROLLY       1
#define BLOCKSIZEX   16
#define BLOCKSIZEY   16
#define BLOCKSIZE    BLOCKSIZEX * BLOCKSIZEY

// This kernel calculates coulombic potential at each grid point and
// stores the results in the output array.
//
// This kernel was written by Chris Rodrigues of Wen-mei's group
//
__global__ void cenergy(int numatoms, float gridspacing, float * energygrid) {
  unsigned int xindex  = __umul24(blockIdx.x, blockDim.x) * UNROLLX
                         + threadIdx.x;
  unsigned int yindex  = __umul24(blockIdx.y, blockDim.y) + threadIdx.y;
  unsigned int outaddr = (__umul24(gridDim.x, blockDim.x) * UNROLLX) * yindex
                         + xindex;

  float coory = gridspacing * yindex;
  float coorx = gridspacing * xindex;

  float energyvalx1=0.0f;
  float energyvalx2=0.0f;
  float energyvalx3=0.0f;
  float energyvalx4=0.0f;
#if UNROLLX == 8
  float energyvalx5=0.0f;
  float energyvalx6=0.0f;
  float energyvalx7=0.0f;
  float energyvalx8=0.0f;
#endif

  float gridspacing_u = gridspacing * BLOCKSIZEX;

  //
  // XXX 59/8 FLOPS per atom
  //
  int atomid;
  for (atomid=0; atomid<numatoms; atomid++) {
    float dy = coory - atominfo[atomid].y;
    float dyz2 = (dy * dy) + atominfo[atomid].z;
    float atomq=atominfo[atomid].w;

    float dx1 = coorx - atominfo[atomid].x;
    float dx2 = dx1 + gridspacing_u;
    float dx3 = dx2 + gridspacing_u;
    float dx4 = dx3 + gridspacing_u;
#if UNROLLX == 8
    float dx5 = dx4 + gridspacing_u;
    float dx6 = dx5 + gridspacing_u;
    float dx7 = dx6 + gridspacing_u;
    float dx8 = dx7 + gridspacing_u;
#endif
    

    energyvalx1 += atomq * rsqrtf(dx1*dx1 + dyz2);
    energyvalx2 += atomq * rsqrtf(dx2*dx2 + dyz2);
    energyvalx3 += atomq * rsqrtf(dx3*dx3 + dyz2);
    energyvalx4 += atomq * rsqrtf(dx4*dx4 + dyz2);
#if UNROLLX == 8
    energyvalx5 += atomq * rsqrtf(dx5*dx5 + dyz2);
    energyvalx6 += atomq * rsqrtf(dx6*dx6 + dyz2);
    energyvalx7 += atomq * rsqrtf(dx7*dx7 + dyz2);
    energyvalx8 += atomq * rsqrtf(dx8*dx8 + dyz2);
#endif
  }

  energygrid[outaddr             ] += energyvalx1;
  energygrid[outaddr+1*BLOCKSIZEX] += energyvalx2;
  energygrid[outaddr+2*BLOCKSIZEX] += energyvalx3;
  energygrid[outaddr+3*BLOCKSIZEX] += energyvalx4;
#if UNROLLX == 8
  energygrid[outaddr+4*BLOCKSIZEX] += energyvalx5;
  energygrid[outaddr+5*BLOCKSIZEX] += energyvalx6;
  energygrid[outaddr+6*BLOCKSIZEX] += energyvalx7;
  energygrid[outaddr+7*BLOCKSIZEX] += energyvalx8;
#endif
}



int copyatomstoconstbuf(float *atoms, int count, float zplane) {
  CUERR // check and clear any existing errors

  if (count > MAXATOMS) {
    printf("Atom count exceeds constant buffer storage capacity\n");
    return -1;
  }

  float atompre[4*MAXATOMS];
  int i;
  for (i=0; i<count*4; i+=4) {
    atompre[i    ] = atoms[i    ];
    atompre[i + 1] = atoms[i + 1];
    float dz = zplane - atoms[i + 2];
    atompre[i + 2]  = dz*dz;
    atompre[i + 3] = atoms[i + 3];
  }

  hipMemcpyToSymbol(HIP_SYMBOL(atominfo), atompre, count * 4 * sizeof(float), 0);
  CUERR // check and clear any existing errors

  return 0;
}


int initatoms(float **atombuf, int count, dim3 volsize, float gridspacing) {
  dim3 size;
  int i;
  float *atoms;

  atoms = (float *) malloc(count * 4 * sizeof(float));
  *atombuf = atoms;

  // compute grid dimensions in angstroms
  size.x = (unsigned int) gridspacing * volsize.x;
  size.y = (unsigned int) gridspacing * volsize.y;
  size.z = (unsigned int) gridspacing * volsize.z;

  for (i=0; i<count; i++) {
    int addr = i * 4;
    atoms[addr    ] = (rand() / (float) RAND_MAX) * size.x; 
    atoms[addr + 1] = (rand() / (float) RAND_MAX) * size.y; 
    atoms[addr + 2] = (rand() / (float) RAND_MAX) * size.z; 
    atoms[addr + 3] = ((rand() / (float) RAND_MAX) * 2.0) - 1.0;  // charge
  }  

  return 0;
}

	.text
	.file	"cuenergy.hip"
	.globl	_Z22__device_stub__cenergyifPf  # -- Begin function _Z22__device_stub__cenergyifPf
	.type	_Z22__device_stub__cenergyifPf,@function
_Z22__device_stub__cenergyifPf:         # @_Z22__device_stub__cenergyifPf
	.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	$96, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	4(%rsp), %rax
	movl	%edi, (%rax)
	movq	%rsp, %rcx
	movss	%xmm0, (%rcx)
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rdx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rdx, 16(%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	$_Z7cenergyifPf, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$112, %rsp
	.cfi_adjust_cfa_offset -112
	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	_Z22__device_stub__cenergyifPf, .Lfunc_end0-_Z22__device_stub__cenergyifPf
	.cfi_endproc
                                        # -- End function
	.globl	_Z19copyatomstoconstbufPfif     # -- Begin function _Z19copyatomstoconstbufPfif
	.type	_Z19copyatomstoconstbufPfif,@function
_Z19copyatomstoconstbufPfif:            # @_Z19copyatomstoconstbufPfif
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$64016, %rsp                    # imm = 0xFA10
	.cfi_def_cfa_offset 64048
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
	movl	%esi, %r14d
	movq	%rdi, %rbx
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB1_2
# %bb.1:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$113, %edx
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_4
.LBB1_2:
	movss	12(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	cmpl	$4001, %r14d                    # imm = 0xFA1
	jl	.LBB1_5
# %bb.3:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB1_4:
	movl	$-1, %ebx
.LBB1_12:
	movl	%ebx, %eax
	addq	$64016, %rsp                    # imm = 0xFA10
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_5:
	.cfi_def_cfa_offset 64048
	leal	(,%r14,4), %eax
	testl	%r14d, %r14d
	jle	.LBB1_8
# %bb.6:                                # %.lr.ph.preheader
	movl	%eax, %edx
	xorl	%eax, %eax
.LBB1_7:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rbx,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 16(%rsp,%rax,4)
	movss	4(%rbx,%rax,4), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 20(%rsp,%rax,4)
	movaps	%xmm1, %xmm0
	subss	8(%rbx,%rax,4), %xmm0
	mulss	%xmm0, %xmm0
	movss	%xmm0, 24(%rsp,%rax,4)
	movss	12(%rbx,%rax,4), %xmm0          # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 28(%rsp,%rax,4)
	addq	$4, %rax
	cmpq	%rdx, %rax
	jb	.LBB1_7
	jmp	.LBB1_9
.LBB1_8:                                # %.._crit_edge_crit_edge
	movslq	%eax, %rdx
.LBB1_9:                                # %._crit_edge
	shlq	$2, %rdx
	xorl	%ebx, %ebx
	leaq	16(%rsp), %rsi
	movl	$atominfo, %edi
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	callq	hipGetLastError
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.LBB1_11
# %bb.10:
	movl	%ebp, %edi
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movq	%rax, %rsi
	movl	$131, %edx
	xorl	%eax, %eax
	callq	printf
.LBB1_11:
	negl	%ebp
	sbbl	%ebx, %ebx
	jmp	.LBB1_12
.Lfunc_end1:
	.size	_Z19copyatomstoconstbufPfif, .Lfunc_end1-_Z19copyatomstoconstbufPfif
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z9initatomsPPfi4dim3f
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI2_1:
	.quad	0xbff0000000000000              # double -1
	.text
	.globl	_Z9initatomsPPfi4dim3f
	.type	_Z9initatomsPPfi4dim3f,@function
_Z9initatomsPPfi4dim3f:                 # @_Z9initatomsPPfi4dim3f
	.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	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	movl	%ecx, %r14d
	movq	%rdx, %r12
	movl	%esi, %r15d
	movq	%rdi, %r13
	leal	(,%r15,4), %eax
	movslq	%eax, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, (%r13)
	testl	%r15d, %r15d
	jle	.LBB2_3
# %bb.1:                                # %.lr.ph
	movq	%rax, %rbx
	cvttss2si	4(%rsp), %rax           # 4-byte Folded Reload
	imull	%eax, %r14d
	movq	%r12, %rcx
	shrq	$32, %rcx
	imull	%eax, %r12d
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r12, %xmm0
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	imull	%eax, %ecx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rcx, %xmm0
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r14, %xmm0
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	movl	%r15d, %r14d
	shlq	$2, %r14
	xorl	%r15d, %r15d
.LBB2_2:                                # =>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
	mulss	4(%rsp), %xmm0                  # 4-byte Folded Reload
	movl	%r15d, %eax
	movss	%xmm0, (%rbx,%rax,4)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	mulss	12(%rsp), %xmm0                 # 4-byte Folded Reload
	leal	1(%r15), %eax
	movss	%xmm0, (%rbx,%rax,4)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	mulss	8(%rsp), %xmm0                  # 4-byte Folded Reload
	leal	2(%r15), %eax
	movss	%xmm0, (%rbx,%rax,4)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	addsd	%xmm0, %xmm0
	addsd	.LCPI2_1(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	leal	3(%r15), %eax
	movss	%xmm0, (%rbx,%rax,4)
	addq	$4, %r15
	cmpq	%r15, %r14
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	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_end2:
	.size	_Z9initatomsPPfi4dim3f, .Lfunc_end2-_Z9initatomsPPfi4dim3f
	.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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7cenergyifPf, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$1, (%rsp)
	movl	$atominfo, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$64000, %r9d                    # imm = 0xFA00
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.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	atominfo,@object                # @atominfo
	.local	atominfo
	.comm	atominfo,64000,16
	.type	_Z7cenergyifPf,@object          # @_Z7cenergyifPf
	.section	.rodata,"a",@progbits
	.globl	_Z7cenergyifPf
	.p2align	3, 0x0
_Z7cenergyifPf:
	.quad	_Z22__device_stub__cenergyifPf
	.size	_Z7cenergyifPf, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CUDA error: %s, line %d\n"
	.size	.L.str, 25

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7cenergyifPf"
	.size	.L__unnamed_1, 15

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"atominfo"
	.size	.L__unnamed_2, 9

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Atom count exceeds constant buffer storage capacity"
	.size	.Lstr, 52

	.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 _Z22__device_stub__cenergyifPf
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym atominfo
	.addrsig_sym _Z7cenergyifPf
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7cenergyifPf          ; -- Begin function _Z7cenergyifPf
	.globl	_Z7cenergyifPf
	.p2align	8
	.type	_Z7cenergyifPf,@function
_Z7cenergyifPf:                         ; @_Z7cenergyifPf
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x1c
	s_load_b64 s[8:9], s[0:1], 0x0
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_lshl_b32 s3, s14, 3
	s_and_b32 s4, s15, 0xffffff
	s_and_b32 s3, s3, 0x7fffff8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s12, s2, 0xffff
	s_lshr_b32 s5, s2, 16
	v_mad_u64_u32 v[0:1], null, s3, s12, v[2:3]
	v_mad_u64_u32 v[1:2], null, s4, s5, v[3:4]
	s_cmp_lt_i32 s8, 1
	s_cbranch_scc1 .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_f32_u32_e32 v2, v1
	v_cvt_f32_u32_e32 v3, v0
	v_mul_f32_e64 v10, 0x41800000, s9
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v5, 0
	s_delay_alu instid0(VALU_DEP_3)
	v_dual_mul_f32 v11, s9, v2 :: v_dual_mul_f32 v12, s9, v3
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v3, 0
	v_dual_mov_b32 v6, 0 :: v_dual_mov_b32 v7, 0
	v_dual_mov_b32 v8, 0 :: v_dual_mov_b32 v9, 0
	s_getpc_b64 s[10:11]
	s_add_u32 s10, s10, atominfo@rel32@lo+16
	s_addc_u32 s11, s11, atominfo@rel32@hi+24
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_add_u32 s2, s10, -12
	s_addc_u32 s3, s11, -1
	s_add_i32 s8, s8, -1
	s_load_b128 s[4:7], s[2:3], 0x0
	s_add_u32 s10, s10, 16
	s_addc_u32 s11, s11, 0
	s_cmp_lg_u32 s8, 0
	s_waitcnt lgkmcnt(0)
	v_dual_subrev_f32 v13, s4, v12 :: v_dual_subrev_f32 v14, s5, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_f32_e32 v15, v10, v13
	v_fma_f32 v14, v14, v14, s6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v13, v13, v13, v14
	v_mul_f32_e32 v18, 0x4b800000, v13
	v_cmp_gt_f32_e64 s2, 0x800000, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v13, v13, v18, s2
	v_rsq_f32_e32 v13, v13
	s_waitcnt_depctr 0xfff
	v_dual_add_f32 v16, v10, v15 :: v_dual_mul_f32 v23, 0x45800000, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_add_f32_e32 v17, v10, v16
	v_fma_f32 v16, v16, v16, v14
	v_cndmask_b32_e64 v13, v13, v23, s2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v18, 0x4b800000, v16
	v_fma_f32 v15, v15, v15, v14
	v_cmp_gt_f32_e64 s3, 0x800000, v16
	v_mul_f32_e32 v19, 0x4b800000, v15
	v_cmp_gt_f32_e32 vcc_lo, 0x800000, v15
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v16, v16, v18, s3
	v_cndmask_b32_e32 v15, v15, v19, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rsq_f32_e32 v16, v16
	v_rsq_f32_e32 v15, v15
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v24, 0x45800000, v15
	v_add_f32_e32 v20, v10, v17
	v_fma_f32 v17, v17, v17, v14
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v15, v15, v24, vcc_lo
	v_dual_add_f32 v19, v10, v20 :: v_dual_mul_f32 v18, 0x4b800000, v17
	v_fma_f32 v20, v20, v20, v14
	v_cmp_gt_f32_e64 s4, 0x800000, v17
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_dual_fmac_f32 v2, s7, v13 :: v_dual_fmac_f32 v3, s7, v15
	v_add_f32_e32 v21, v10, v19
	v_fma_f32 v19, v19, v19, v14
	s_delay_alu instid0(VALU_DEP_4)
	v_cndmask_b32_e64 v17, v17, v18, s4
	v_mul_f32_e32 v18, 0x4b800000, v20
	v_cmp_gt_f32_e64 s5, 0x800000, v20
	v_add_f32_e32 v22, v10, v21
	v_cmp_gt_f32_e64 s6, 0x800000, v19
	v_rsq_f32_e32 v17, v17
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v18, v20, v18, s5
	v_fma_f32 v20, v21, v21, v14
	v_dual_mul_f32 v21, 0x4b800000, v19 :: v_dual_fmac_f32 v14, v22, v22
	v_rsq_f32_e32 v18, v18
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_f32_e32 vcc_lo, 0x800000, v20
	v_cndmask_b32_e64 v19, v19, v21, s6
	v_mul_f32_e32 v21, 0x45800000, v16
	v_dual_mul_f32 v22, 0x4b800000, v20 :: v_dual_mul_f32 v23, 0x4b800000, v14
	v_cmp_gt_f32_e64 s2, 0x800000, v14
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_rsq_f32_e32 v19, v19
	v_cndmask_b32_e64 v16, v16, v21, s3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_dual_cndmask_b32 v20, v20, v22 :: v_dual_mul_f32 v13, 0x45800000, v17
	v_cndmask_b32_e64 v14, v14, v23, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_dual_mul_f32 v15, 0x45800000, v18 :: v_dual_fmac_f32 v4, s7, v16
	v_rsq_f32_e32 v20, v20
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v13, v17, v13, s4
	v_rsq_f32_e32 v14, v14
	s_delay_alu instid0(TRANS32_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mul_f32_e32 v16, 0x45800000, v19
	v_cndmask_b32_e64 v15, v18, v15, s5
	v_fmac_f32_e32 v5, s7, v13
	s_delay_alu instid0(VALU_DEP_3)
	v_cndmask_b32_e64 v16, v19, v16, s6
	s_delay_alu instid0(TRANS32_DEP_2) | instid1(VALU_DEP_3)
	v_dual_fmac_f32 v6, s7, v15 :: v_dual_mul_f32 v21, 0x45800000, v20
	s_waitcnt_depctr 0xfff
	v_dual_mul_f32 v22, 0x45800000, v14 :: v_dual_cndmask_b32 v17, v20, v21
	v_fmac_f32_e32 v7, s7, v16
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v14, v14, v22, s2
	v_dual_fmac_f32 v8, s7, v17 :: v_dual_fmac_f32 v9, s7, v14
	s_cbranch_scc1 .LBB0_2
	s_branch .LBB0_4
.LBB0_3:
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v3, 0
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v5, 0
	v_dual_mov_b32 v6, 0 :: v_dual_mov_b32 v7, 0
	v_dual_mov_b32 v8, 0 :: v_dual_mov_b32 v9, 0
.LBB0_4:                                ; %Flow177
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x10
	s_load_b64 s[0:1], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_lshl_b32 s2, s2, 3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, 0x7fffff8
	s_mul_i32 s2, s2, s12
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[10:11], null, s2, v1, v[0:1]
	v_dual_mov_b32 v11, 0 :: v_dual_add_nc_u32 v0, 16, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_dual_mov_b32 v1, v11 :: v_dual_add_nc_u32 v12, 32, v10
	v_lshlrev_b64 v[16:17], 2, v[10:11]
	v_dual_mov_b32 v13, v11 :: v_dual_add_nc_u32 v14, 48, v10
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_dual_mov_b32 v15, v11 :: v_dual_add_nc_u32 v18, 64, v10
	s_delay_alu instid0(VALU_DEP_3)
	v_lshlrev_b64 v[12:13], 2, v[12:13]
	v_add_co_u32 v16, vcc_lo, s0, v16
	v_dual_mov_b32 v19, v11 :: v_dual_add_nc_u32 v20, 0x50, v10
	v_add_co_ci_u32_e32 v17, vcc_lo, s1, v17, vcc_lo
	v_lshlrev_b64 v[14:15], 2, v[14:15]
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_dual_mov_b32 v21, v11 :: v_dual_add_nc_u32 v22, 0x60, v10
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	v_add_co_u32 v12, vcc_lo, s0, v12
	v_lshlrev_b64 v[18:19], 2, v[18:19]
	v_dual_mov_b32 v23, v11 :: v_dual_add_nc_u32 v10, 0x70, v10
	v_add_co_ci_u32_e32 v13, vcc_lo, s1, v13, vcc_lo
	v_add_co_u32 v14, vcc_lo, s0, v14
	v_lshlrev_b64 v[20:21], 2, v[20:21]
	v_add_co_ci_u32_e32 v15, vcc_lo, s1, v15, vcc_lo
	v_add_co_u32 v18, vcc_lo, s0, v18
	v_lshlrev_b64 v[22:23], 2, v[22:23]
	v_add_co_ci_u32_e32 v19, vcc_lo, s1, v19, vcc_lo
	v_add_co_u32 v20, vcc_lo, s0, v20
	v_lshlrev_b64 v[10:11], 2, v[10:11]
	v_add_co_ci_u32_e32 v21, vcc_lo, s1, v21, vcc_lo
	v_add_co_u32 v22, vcc_lo, s0, v22
	v_add_co_ci_u32_e32 v23, vcc_lo, s1, v23, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_u32 v10, vcc_lo, s0, v10
	v_add_co_ci_u32_e32 v11, vcc_lo, s1, v11, vcc_lo
	s_clause 0x7
	global_load_b32 v24, v[16:17], off
	global_load_b32 v25, v[0:1], off
	global_load_b32 v26, v[12:13], off
	global_load_b32 v27, v[14:15], off
	global_load_b32 v28, v[18:19], off
	global_load_b32 v29, v[20:21], off
	global_load_b32 v30, v[22:23], off
	global_load_b32 v31, v[10:11], off
	s_waitcnt vmcnt(6)
	v_dual_add_f32 v2, v2, v24 :: v_dual_add_f32 v3, v3, v25
	s_waitcnt vmcnt(4)
	v_dual_add_f32 v4, v4, v26 :: v_dual_add_f32 v5, v5, v27
	s_waitcnt vmcnt(2)
	v_dual_add_f32 v6, v6, v28 :: v_dual_add_f32 v7, v7, v29
	s_waitcnt vmcnt(0)
	v_dual_add_f32 v8, v8, v30 :: v_dual_add_f32 v9, v9, v31
	s_clause 0x7
	global_store_b32 v[16:17], v2, off
	global_store_b32 v[0:1], v3, off
	global_store_b32 v[12:13], v4, off
	global_store_b32 v[14:15], v5, off
	global_store_b32 v[18:19], v6, off
	global_store_b32 v[20:21], v7, off
	global_store_b32 v[22:23], v8, off
	global_store_b32 v[10:11], v9, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7cenergyifPf
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 32
		.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	_Z7cenergyifPf, .Lfunc_end0-_Z7cenergyifPf
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1336
; NumSgprs: 18
; NumVgprs: 32
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 3
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 32
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.protected	atominfo                ; @atominfo
	.type	atominfo,@object
	.section	.bss,"aw",@nobits
	.globl	atominfo
	.p2align	4, 0x0
atominfo:
	.zero	64000
	.size	atominfo, 64000

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.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 atominfo
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7cenergyifPf
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7cenergyifPf.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     32
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
