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

double wmcw_energy(int n,double2* r,int* sig, double l){

int  i, j, k;
double x, y, inverselx, inversely, h, wmcw_energy;
double pi = 4.0*atan(1.0);

inverselx = 2.0*pi/l;
inversely = 2.0*pi/l;

wmcw_energy = 0.0;
for (i = 0;i<=n-2;i++){
  for (j=i+1;j<=n-1;j++){
    if (i != j){ 
      x = fabs(r[i].x-r[j].x) * inverselx;
      y = fabs(r[i].y-r[j].y) * inversely;
      h = 0.0;
      for (k = -10;k<=10;k++){
        h = h + log((cosh(x-2.0*pi*(double)k)-cos(y))/cosh(2.0*pi*(double)k));
      }
      h = h - x*x/(2.0*pi);
      wmcw_energy = wmcw_energy - h* ((double)sig[i]) *( (double)sig[j]);
    }
  }
}
//Difference between Weiss & McWilliams and (?)Montgomery & Joyce
wmcw_energy = wmcw_energy/(double)n-0.177021697969890;

return wmcw_energy;
 }

	.file	"tmpxft_0028c15d_00000000-6_wmcw_energy.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11wmcw_energyiP7double2Pid
	.type	_Z11wmcw_energyiP7double2Pid, @function
_Z11wmcw_energyiP7double2Pid:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorps	%xmm3, %xmm3
	movq	%rdx, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movsd	.LC1(%rip), %xmm5
	divsd	%xmm0, %xmm5
.L3:
	leal	-1(%rbp), %eax
	movl	%r12d, %edx
	cmpl	%r12d, %eax
	jle	.L12
	leaq	1(%r12), %rax
	movq	%rax, %rbx
.L4:
	cmpl	%ebx, %ebp
	jle	.L13
	cmpl	%edx, %ebx
	je	.L5
	movq	%rbx, %rcx
	movsd	8(%r14), %xmm0
	movsd	(%r14), %xmm1
	xorps	%xmm2, %xmm2
	salq	$4, %rcx
	subsd	8(%r13,%rcx), %xmm0
	subsd	0(%r13,%rcx), %xmm1
	movl	$-10, %ecx
	andps	.LC2(%rip), %xmm1
	mulsd	%xmm5, %xmm0
	mulsd	%xmm5, %xmm1
	movsd	%xmm0, 16(%rsp)
.L6:
	cvtsi2sdl	%ecx, %xmm0
	mulsd	.LC1(%rip), %xmm0
	movq	%rax, 72(%rsp)
	movl	%edx, 68(%rsp)
	movl	%ecx, 64(%rsp)
	movsd	%xmm2, 56(%rsp)
	movsd	%xmm5, 48(%rsp)
	movsd	%xmm0, (%rsp)
	movaps	%xmm1, %xmm0
	subsd	(%rsp), %xmm0
	movsd	%xmm3, 40(%rsp)
	movsd	%xmm1, 32(%rsp)
	call	cosh@PLT
	movsd	%xmm0, 24(%rsp)
	movsd	16(%rsp), %xmm0
	call	cos@PLT
	movsd	%xmm0, 8(%rsp)
	movsd	(%rsp), %xmm0
	call	cosh@PLT
	movsd	24(%rsp), %xmm4
	subsd	8(%rsp), %xmm4
	movaps	%xmm0, %xmm6
	movaps	%xmm4, %xmm0
	divsd	%xmm6, %xmm0
	call	log@PLT
	movl	64(%rsp), %ecx
	movl	68(%rsp), %edx
	movsd	56(%rsp), %xmm2
	movsd	32(%rsp), %xmm1
	incl	%ecx
	movsd	40(%rsp), %xmm3
	movsd	48(%rsp), %xmm5
	cmpl	$11, %ecx
	addsd	%xmm0, %xmm2
	movq	72(%rsp), %rax
	jne	.L6
	cvtsi2sdl	(%r15,%r12,4), %xmm0
	mulsd	%xmm1, %xmm1
	divsd	.LC1(%rip), %xmm1
	subsd	%xmm1, %xmm2
	mulsd	%xmm0, %xmm2
	cvtsi2sdl	(%r15,%rbx,4), %xmm0
	mulsd	%xmm0, %xmm2
	subsd	%xmm2, %xmm3
.L5:
	incq	%rbx
	jmp	.L4
.L13:
	addq	$16, %r14
	movq	%rax, %r12
	jmp	.L3
.L12:
	cvtsi2sdl	%ebp, %xmm1
	divsd	%xmm1, %xmm3
	movaps	%xmm3, %xmm0
	subsd	.LC3(%rip), %xmm0
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	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
.LFE2027:
	.size	_Z11wmcw_energyiP7double2Pid, .-_Z11wmcw_energyiP7double2Pid
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2053:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2053:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	1413754136
	.long	1075388923
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	-1
	.long	2147483647
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC3:
	.long	-1581562423
	.long	1069983909
	.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 <math.h>
#include <stdio.h>
#include <stdlib.h>

double wmcw_energy(int n,double2* r,int* sig, double l){

int  i, j, k;
double x, y, inverselx, inversely, h, wmcw_energy;
double pi = 4.0*atan(1.0);

inverselx = 2.0*pi/l;
inversely = 2.0*pi/l;

wmcw_energy = 0.0;
for (i = 0;i<=n-2;i++){
  for (j=i+1;j<=n-1;j++){
    if (i != j){ 
      x = fabs(r[i].x-r[j].x) * inverselx;
      y = fabs(r[i].y-r[j].y) * inversely;
      h = 0.0;
      for (k = -10;k<=10;k++){
        h = h + log((cosh(x-2.0*pi*(double)k)-cos(y))/cosh(2.0*pi*(double)k));
      }
      h = h - x*x/(2.0*pi);
      wmcw_energy = wmcw_energy - h* ((double)sig[i]) *( (double)sig[j]);
    }
  }
}
//Difference between Weiss & McWilliams and (?)Montgomery & Joyce
wmcw_energy = wmcw_energy/(double)n-0.177021697969890;

return wmcw_energy;
 }

	.text
	.file	"wmcw_energy.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z11wmcw_energyiP15HIP_vector_typeIdLj2EEPid
.LCPI0_0:
	.quad	0x401921fb54442d18              # double 6.2831853071795862
.LCPI0_2:
	.quad	0xc024000000000000              # double -10
.LCPI0_3:
	.quad	0x3ff0000000000000              # double 1
.LCPI0_4:
	.quad	0xc01921fb54442d18              # double -6.2831853071795862
.LCPI0_5:
	.quad	0xbfc6a8a5a1bb45c9              # double -0.17702169796989001
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI0_1:
	.quad	0x7fffffffffffffff              # double NaN
	.quad	0x7fffffffffffffff              # double NaN
	.text
	.globl	_Z11wmcw_energyiP15HIP_vector_typeIdLj2EEPid
	.type	_Z11wmcw_energyiP15HIP_vector_typeIdLj2EEPid,@function
_Z11wmcw_energyiP15HIP_vector_typeIdLj2EEPid: # @_Z11wmcw_energyiP15HIP_vector_typeIdLj2EEPid
	.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	$136, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
                                        # kill: def $edi killed $edi def $rdi
	xorpd	%xmm1, %xmm1
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	cmpl	$2, %edi
	jl	.LBB0_7
# %bb.1:                                # %.lr.ph58.preheader
	movq	%rdx, %r14
	movq	%rsi, %r15
	movsd	.LCPI0_0(%rip), %xmm2           # xmm2 = mem[0],zero
	movapd	%xmm2, %xmm1
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 56(%rsp)                 # 8-byte Spill
	movq	16(%rsp), %rax                  # 8-byte Reload
	leal	-1(%rax), %ecx
	movq	%rcx, 24(%rsp)                  # 8-byte Spill
	movl	%eax, %eax
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	xorpd	%xmm1, %xmm1
	movl	$1, %ebp
	xorl	%r12d, %r12d
.LBB0_3:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
                                        #       Child Loop BB0_5 Depth 3
	leaq	1(%r12), %rax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movq	%r12, %rbx
	shlq	$4, %rbx
	addq	%r15, %rbx
	movq	%rbp, 40(%rsp)                  # 8-byte Spill
.LBB0_4:                                #   Parent Loop BB0_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_5 Depth 3
	movsd	%xmm1, 64(%rsp)                 # 8-byte Spill
	movq	%rbp, %rax
	shlq	$4, %rax
	movsd	(%rbx), %xmm3                   # xmm3 = mem[0],zero
	movsd	8(%rbx), %xmm4                  # xmm4 = mem[0],zero
	subsd	(%r15,%rax), %xmm3
	movapd	.LCPI0_1(%rip), %xmm1           # xmm1 = [NaN,NaN]
	andpd	%xmm1, %xmm3
	movsd	56(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	mulsd	%xmm0, %xmm3
	movapd	%xmm3, 96(%rsp)                 # 16-byte Spill
	subsd	8(%r15,%rax), %xmm4
	andpd	%xmm1, %xmm4
	mulsd	%xmm0, %xmm4
	movapd	%xmm4, 112(%rsp)                # 16-byte Spill
	xorpd	%xmm3, %xmm3
	movl	$21, %r13d
	movsd	.LCPI0_2(%rip), %xmm0           # xmm0 = mem[0],zero
.LBB0_5:                                #   Parent Loop BB0_3 Depth=1
                                        #     Parent Loop BB0_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	%xmm0, 80(%rsp)                 # 8-byte Spill
	movsd	%xmm3, 88(%rsp)                 # 8-byte Spill
	movapd	%xmm0, %xmm1
	mulsd	%xmm2, %xmm1
	movsd	%xmm1, 72(%rsp)                 # 8-byte Spill
	movapd	96(%rsp), %xmm0                 # 16-byte Reload
	subsd	%xmm1, %xmm0
	callq	cosh
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movapd	112(%rsp), %xmm0                # 16-byte Reload
	callq	cos
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	movsd	%xmm1, 8(%rsp)                  # 8-byte Spill
	movsd	72(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	cosh
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
	divsd	%xmm0, %xmm1
	movapd	%xmm1, %xmm0
	callq	log
	movsd	88(%rsp), %xmm3                 # 8-byte Reload
                                        # xmm3 = mem[0],zero
	movsd	.LCPI0_3(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI0_0(%rip), %xmm2           # xmm2 = mem[0],zero
	addsd	%xmm0, %xmm3
	movsd	80(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	addsd	%xmm1, %xmm0
	decl	%r13d
	jne	.LBB0_5
# %bb.6:                                #   in Loop: Header=BB0_4 Depth=2
	movapd	96(%rsp), %xmm1                 # 16-byte Reload
	mulsd	%xmm1, %xmm1
	divsd	.LCPI0_4(%rip), %xmm1
	xorps	%xmm0, %xmm0
	cvtsi2sdl	(%r14,%r12,4), %xmm0
	addsd	%xmm1, %xmm3
	mulsd	%xmm3, %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sdl	(%r14,%rbp,4), %xmm1
	mulsd	%xmm0, %xmm1
	movsd	64(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	subsd	%xmm1, %xmm0
	movapd	%xmm0, %xmm1
	incq	%rbp
	cmpq	48(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB0_4
# %bb.2:                                # %.loopexit
                                        #   in Loop: Header=BB0_3 Depth=1
	movq	40(%rsp), %rbp                  # 8-byte Reload
	incq	%rbp
	movq	32(%rsp), %r12                  # 8-byte Reload
	cmpq	24(%rsp), %r12                  # 8-byte Folded Reload
	jne	.LBB0_3
.LBB0_7:                                # %._crit_edge
	xorps	%xmm0, %xmm0
	cvtsi2sdl	16(%rsp), %xmm0         # 4-byte Folded Reload
	divsd	%xmm0, %xmm1
	addsd	.LCPI0_5(%rip), %xmm1
	movapd	%xmm1, %xmm0
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z11wmcw_energyiP15HIP_vector_typeIdLj2EEPid, .Lfunc_end0-_Z11wmcw_energyiP15HIP_vector_typeIdLj2EEPid
	.cfi_endproc
                                        # -- End function
	.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 __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
