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

void distance(float *dist,int dim,int *m,int *n) {
	int i,j,k,h=0;
	float x[3],dm[3];
	float voxel_side = 2.0f;
		

	h = 0;
	dm[0] = (float)m[0];
	dm[1] = (float)m[1];
	dm[2] = (float)m[2];
			
	for (i=0;i<m[0];i++) {
		x[0] = (float)i;
		if (dm[0]/2. < x[0] && x[0] < dm[0])
			x[0] -= dm[0];
		else if (dm[0]/2 < -x[0] && -x[0] < dm[0])
			x[0] += dm[0];
		x[0] /= (float)n[0];
				
		for (j=0;j<m[1];j++) {
			x[1] = (float)j;
			if (dm[1]/2. < x[1] && x[1] < dm[1])
				x[1] -= m[1];
			else if (dm[1]/2. < -x[1] && -x[1] < dm[1])
				x[1] += dm[1];
			x[1] /= (float)n[1];
					
			for (k=0;k<m[2];k++) {
				x[2] = (float)k;
				if (dm[2]/2. < x[2] && x[2] < dm[2])
					x[2] -= dm[2];
				else if (dm[2]/2. < -x[2] && -x[2] < dm[2])
					x[2] += dm[2];
				x[2] /= (float)n[2];
				dist[h] = sqrt( pow(voxel_side*n[0]*x[0],2)+pow(voxel_side*n[1]*x[1],2)+pow(voxel_side*n[2]*x[2],2)   );
                h++;
			}
		}
	}
}
	.file	"tmpxft_0026d32c_00000000-6_distance.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2011:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2011:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z8distancePfiPiS0_
	.type	_Z8distancePfiPiS0_, @function
_Z8distancePfiPiS0_:
.LFB2008:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdx, %rbx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	cvtsi2ssl	(%rdx), %xmm2
	cvtsi2ssl	4(%rdx), %xmm4
	movss	.LC1(%rip), %xmm5
	cvtsi2ssl	8(%rdx), %xmm3
.L3:
	cmpl	%r13d, (%rbx)
	jle	.L41
	cvtss2sd	%xmm2, %xmm1
	mulsd	.LC0(%rip), %xmm1
	cvtsi2ssl	%r13d, %xmm0
	cvtss2sd	%xmm0, %xmm6
	comisd	%xmm1, %xmm6
	jbe	.L4
	comiss	%xmm0, %xmm2
	jbe	.L4
	subss	%xmm2, %xmm0
	jmp	.L7
.L4:
	movss	.LC2(%rip), %xmm6
	movaps	%xmm0, %xmm1
	xorps	%xmm5, %xmm1
	mulss	%xmm2, %xmm6
	comiss	%xmm6, %xmm1
	jbe	.L7
	comiss	%xmm1, %xmm2
	jbe	.L7
	addss	%xmm2, %xmm0
.L7:
	cvtsi2ssl	(%r12), %xmm1
	xorl	%r14d, %r14d
	divss	%xmm1, %xmm0
	movss	%xmm0, 8(%rsp)
.L10:
	movl	4(%rbx), %eax
	cmpl	%r14d, %eax
	jle	.L42
	cvtss2sd	%xmm4, %xmm1
	mulsd	.LC0(%rip), %xmm1
	cvtsi2ssl	%r14d, %xmm0
	cvtss2sd	%xmm0, %xmm6
	comisd	%xmm1, %xmm6
	jbe	.L11
	comiss	%xmm0, %xmm4
	jbe	.L11
	cvtsi2ssl	%eax, %xmm1
	subss	%xmm1, %xmm0
	jmp	.L14
.L11:
	movaps	%xmm0, %xmm6
	xorps	.LC1(%rip), %xmm6
	cvtss2sd	%xmm6, %xmm7
	comisd	%xmm1, %xmm7
	jbe	.L14
	comiss	%xmm6, %xmm4
	jbe	.L14
	addss	%xmm4, %xmm0
.L14:
	cvtsi2ssl	4(%r12), %xmm1
	movslq	%ebp, %rbp
	xorl	%eax, %eax
	divss	%xmm1, %xmm0
	movss	%xmm0, 12(%rsp)
.L17:
	cmpl	%eax, 8(%rbx)
	jle	.L43
	cvtss2sd	%xmm3, %xmm0
	mulsd	.LC0(%rip), %xmm0
	cvtsi2ssl	%eax, %xmm1
	cvtss2sd	%xmm1, %xmm6
	comisd	%xmm0, %xmm6
	jbe	.L18
	comiss	%xmm1, %xmm3
	jbe	.L18
	subss	%xmm3, %xmm1
	jmp	.L21
.L18:
	movaps	%xmm1, %xmm6
	xorps	.LC1(%rip), %xmm6
	cvtss2sd	%xmm6, %xmm7
	comisd	%xmm0, %xmm7
	jbe	.L21
	comiss	%xmm6, %xmm3
	jbe	.L21
	addss	%xmm3, %xmm1
.L21:
	cvtsi2ssl	8(%r12), %xmm7
	movl	%eax, 28(%rsp)
	cvtsi2ssl	(%r12), %xmm0
	movss	%xmm3, 24(%rsp)
	cvtsi2ssl	4(%r12), %xmm6
	movss	%xmm4, 20(%rsp)
	movss	%xmm2, 16(%rsp)
	divss	%xmm7, %xmm1
	addss	%xmm7, %xmm7
	addss	%xmm0, %xmm0
	mulss	8(%rsp), %xmm0
	addss	%xmm6, %xmm6
	mulss	12(%rsp), %xmm6
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm0, %xmm0
	cvtss2sd	%xmm6, %xmm6
	mulsd	%xmm6, %xmm6
	addsd	%xmm6, %xmm0
	mulss	%xmm7, %xmm1
	cvtss2sd	%xmm1, %xmm1
	mulsd	%xmm1, %xmm1
	addsd	%xmm1, %xmm0
	call	sqrt@PLT
	movl	28(%rsp), %eax
	movss	24(%rsp), %xmm3
	movss	.LC1(%rip), %xmm5
	cvtsd2ss	%xmm0, %xmm0
	movss	20(%rsp), %xmm4
	movss	%xmm0, (%r15,%rbp,4)
	movss	16(%rsp), %xmm2
	incl	%eax
	incq	%rbp
	jmp	.L17
.L43:
	incl	%r14d
	jmp	.L10
.L42:
	incl	%r13d
	jmp	.L3
.L41:
	addq	$40, %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
.LFE2008:
	.size	_Z8distancePfiPiS0_, .-_Z8distancePfiPiS0_
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2034:
	.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
.LFE2034:
	.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
.LC0:
	.long	0
	.long	1071644672
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC2:
	.long	1056964608
	.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 <stdlib.h>
#include <math.h>

void distance(float *dist,int dim,int *m,int *n) {
	int i,j,k,h=0;
	float x[3],dm[3];
	float voxel_side = 2.0f;
		

	h = 0;
	dm[0] = (float)m[0];
	dm[1] = (float)m[1];
	dm[2] = (float)m[2];
			
	for (i=0;i<m[0];i++) {
		x[0] = (float)i;
		if (dm[0]/2. < x[0] && x[0] < dm[0])
			x[0] -= dm[0];
		else if (dm[0]/2 < -x[0] && -x[0] < dm[0])
			x[0] += dm[0];
		x[0] /= (float)n[0];
				
		for (j=0;j<m[1];j++) {
			x[1] = (float)j;
			if (dm[1]/2. < x[1] && x[1] < dm[1])
				x[1] -= m[1];
			else if (dm[1]/2. < -x[1] && -x[1] < dm[1])
				x[1] += dm[1];
			x[1] /= (float)n[1];
					
			for (k=0;k<m[2];k++) {
				x[2] = (float)k;
				if (dm[2]/2. < x[2] && x[2] < dm[2])
					x[2] -= dm[2];
				else if (dm[2]/2. < -x[2] && -x[2] < dm[2])
					x[2] += dm[2];
				x[2] /= (float)n[2];
				dist[h] = sqrt( pow(voxel_side*n[0]*x[0],2)+pow(voxel_side*n[1]*x[1],2)+pow(voxel_side*n[2]*x[2],2)   );
                h++;
			}
		}
	}
}
	.text
	.file	"distance.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z8distancePfiPiS0_
.LCPI0_0:
	.quad	0x3fe0000000000000              # double 0.5
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI0_1:
	.long	0x3f000000                      # float 0.5
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI0_2:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.text
	.globl	_Z8distancePfiPiS0_
	.type	_Z8distancePfiPiS0_,@function
_Z8distancePfiPiS0_:                    # @_Z8distancePfiPiS0_
	.cfi_startproc
# %bb.0:
	movl	(%rdx), %eax
	testl	%eax, %eax
	jle	.LBB0_29
# %bb.1:                                # %.lr.ph94
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	4(%rdx), %esi
	cvtsi2ss	%eax, %xmm0
	cvtsi2ss	%esi, %xmm1
	movl	8(%rdx), %edx
	cvtsi2ss	%edx, %xmm2
	cvtss2sd	%xmm0, %xmm3
	movsd	.LCPI0_0(%rip), %xmm4           # xmm4 = mem[0],zero
	mulsd	%xmm4, %xmm3
	movss	.LCPI0_1(%rip), %xmm5           # xmm5 = mem[0],zero,zero,zero
	mulss	%xmm0, %xmm5
	movss	%xmm5, -12(%rsp)                # 4-byte Spill
	xorps	%xmm5, %xmm5
	cvtsi2ssl	(%rcx), %xmm5
	cvtss2sd	%xmm1, %xmm6
	mulsd	%xmm4, %xmm6
	cvtss2sd	%xmm2, %xmm7
	mulsd	%xmm4, %xmm7
	movss	%xmm5, -4(%rsp)                 # 4-byte Spill
	addss	%xmm5, %xmm5
	movss	%xmm5, -8(%rsp)                 # 4-byte Spill
	xorl	%r8d, %r8d
	movaps	.LCPI0_2(%rip), %xmm9           # xmm9 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
	xorl	%r9d, %r9d
.LBB0_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_10 Depth 2
                                        #       Child Loop BB0_18 Depth 3
	xorps	%xmm11, %xmm11
	cvtsi2ss	%r8d, %xmm11
	xorps	%xmm4, %xmm4
	cvtss2sd	%xmm11, %xmm4
	ucomisd	%xmm3, %xmm4
	jbe	.LBB0_5
# %bb.3:                                #   in Loop: Header=BB0_2 Depth=1
	ucomiss	%xmm11, %xmm0
	jbe	.LBB0_5
# %bb.4:                                #   in Loop: Header=BB0_2 Depth=1
	subss	%xmm0, %xmm11
	jmp	.LBB0_8
.LBB0_5:                                #   in Loop: Header=BB0_2 Depth=1
	movaps	%xmm11, %xmm4
	xorps	%xmm9, %xmm4
	ucomiss	-12(%rsp), %xmm4                # 4-byte Folded Reload
	jbe	.LBB0_8
# %bb.6:                                #   in Loop: Header=BB0_2 Depth=1
	ucomiss	%xmm4, %xmm0
	jbe	.LBB0_8
# %bb.7:                                #   in Loop: Header=BB0_2 Depth=1
	addss	%xmm0, %xmm11
.LBB0_8:                                #   in Loop: Header=BB0_2 Depth=1
	testl	%esi, %esi
	jle	.LBB0_27
# %bb.9:                                # %.lr.ph88
                                        #   in Loop: Header=BB0_2 Depth=1
	divss	-4(%rsp), %xmm11                # 4-byte Folded Reload
	mulss	-8(%rsp), %xmm11                # 4-byte Folded Reload
	xorps	%xmm10, %xmm10
	cvtsi2ssl	4(%rcx), %xmm10
	cvtss2sd	%xmm11, %xmm11
	mulsd	%xmm11, %xmm11
	movaps	%xmm10, %xmm12
	addss	%xmm10, %xmm12
	xorl	%r10d, %r10d
.LBB0_10:                               #   Parent Loop BB0_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_18 Depth 3
	xorps	%xmm14, %xmm14
	cvtsi2ss	%r10d, %xmm14
	xorps	%xmm4, %xmm4
	cvtss2sd	%xmm14, %xmm4
	ucomisd	%xmm6, %xmm4
	jbe	.LBB0_13
# %bb.11:                               #   in Loop: Header=BB0_10 Depth=2
	ucomiss	%xmm14, %xmm1
	jbe	.LBB0_13
# %bb.12:                               #   in Loop: Header=BB0_10 Depth=2
	subss	%xmm1, %xmm14
	jmp	.LBB0_16
.LBB0_13:                               #   in Loop: Header=BB0_10 Depth=2
	movaps	%xmm14, %xmm4
	xorps	%xmm9, %xmm4
	xorps	%xmm5, %xmm5
	cvtss2sd	%xmm4, %xmm5
	ucomisd	%xmm6, %xmm5
	jbe	.LBB0_16
# %bb.14:                               #   in Loop: Header=BB0_10 Depth=2
	ucomiss	%xmm4, %xmm1
	jbe	.LBB0_16
# %bb.15:                               #   in Loop: Header=BB0_10 Depth=2
	addss	%xmm1, %xmm14
.LBB0_16:                               #   in Loop: Header=BB0_10 Depth=2
	testl	%edx, %edx
	jle	.LBB0_26
# %bb.17:                               # %.lr.ph
                                        #   in Loop: Header=BB0_10 Depth=2
	divss	%xmm10, %xmm14
	mulss	%xmm12, %xmm14
	xorps	%xmm13, %xmm13
	cvtsi2ssl	8(%rcx), %xmm13
	cvtss2sd	%xmm14, %xmm14
	mulsd	%xmm14, %xmm14
	addsd	%xmm11, %xmm14
	movaps	%xmm13, %xmm15
	addss	%xmm13, %xmm15
	movslq	%r9d, %r11
	leaq	(%rdi,%r11,4), %rbx
	xorl	%r11d, %r11d
.LBB0_18:                               #   Parent Loop BB0_2 Depth=1
                                        #     Parent Loop BB0_10 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	xorps	%xmm4, %xmm4
	cvtsi2ss	%r11d, %xmm4
	xorps	%xmm5, %xmm5
	cvtss2sd	%xmm4, %xmm5
	ucomisd	%xmm7, %xmm5
	jbe	.LBB0_21
# %bb.19:                               #   in Loop: Header=BB0_18 Depth=3
	ucomiss	%xmm4, %xmm2
	jbe	.LBB0_21
# %bb.20:                               #   in Loop: Header=BB0_18 Depth=3
	subss	%xmm2, %xmm4
	jmp	.LBB0_24
.LBB0_21:                               #   in Loop: Header=BB0_18 Depth=3
	movaps	%xmm4, %xmm5
	xorps	%xmm9, %xmm5
	xorps	%xmm8, %xmm8
	cvtss2sd	%xmm5, %xmm8
	ucomisd	%xmm7, %xmm8
	jbe	.LBB0_24
# %bb.22:                               #   in Loop: Header=BB0_18 Depth=3
	ucomiss	%xmm5, %xmm2
	jbe	.LBB0_24
# %bb.23:                               #   in Loop: Header=BB0_18 Depth=3
	addss	%xmm2, %xmm4
.LBB0_24:                               #   in Loop: Header=BB0_18 Depth=3
	divss	%xmm13, %xmm4
	mulss	%xmm15, %xmm4
	cvtss2sd	%xmm4, %xmm4
	mulsd	%xmm4, %xmm4
	addsd	%xmm14, %xmm4
	sqrtsd	%xmm4, %xmm4
	cvtsd2ss	%xmm4, %xmm4
	movss	%xmm4, (%rbx,%r11,4)
	incq	%r11
	cmpl	%r11d, %edx
	jne	.LBB0_18
# %bb.25:                               # %._crit_edge.loopexit
                                        #   in Loop: Header=BB0_10 Depth=2
	addl	%r11d, %r9d
.LBB0_26:                               # %._crit_edge
                                        #   in Loop: Header=BB0_10 Depth=2
	incl	%r10d
	cmpl	%esi, %r10d
	jne	.LBB0_10
.LBB0_27:                               # %._crit_edge89
                                        #   in Loop: Header=BB0_2 Depth=1
	incl	%r8d
	cmpl	%eax, %r8d
	jne	.LBB0_2
# %bb.28:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB0_29:                               # %._crit_edge95
	retq
.Lfunc_end0:
	.size	_Z8distancePfiPiS0_, .Lfunc_end0-_Z8distancePfiPiS0_
	.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
