#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#ifdef INFINITY
/* INFINITY is supported */
#endif

float **A, **D, *d2;
double elapsed_time;

void makeAdjacency(int n, float p, int w);

__global__ void calc(float *d_D, int n, int k){ //kernel (4  cells for every thread)
	__shared__ float s_d[4*3*256]; //Shared table within a block
	int i = blockIdx.x * blockDim.x + threadIdx.x; //Calculation of i and j
	int j = blockIdx.y * blockDim.y + threadIdx.y;
	int b_index = 4 * 3 * (threadIdx.x + blockDim.x*threadIdx.y); //Calculation of initial index of thread in the shared table within the block
	int istep = blockDim.x*gridDim.x, jstep = blockDim.y*gridDim.y;
	int l, m , v=0;
	for (l = 0; l<2; l++){
		for (m = 0; m<2; m++){ //Pass values from device table to shared block table for every one of the 4 cells
			s_d[b_index + 3 * v] = d_D[(i+l*istep)+(j+m*jstep)*n]; 
			s_d[b_index + (3 * v + 1)] = d_D[(i + l*istep) + k*n];
			s_d[b_index + (3 * v + 2)] = d_D[k + (j + m*jstep)*n];
			v++;
		}
	}
	for (v = 0; v<4; v++){ //Calculate the new cell values (4 for every thread)
		if (s_d[b_index + 3 * v] > s_d[b_index + (3 * v + 1)] + s_d[b_index + (3 * v + 2)]) s_d[b_index + 3 * v] = s_d[b_index + (3 * v + 1)] + s_d[b_index + (3 * v + 2)];
	}
	v = 0;
	for (l = 0; l<2; l++){ //Pass the new values to the device table
		for (m = 0; m<2; m++){
			d_D[(i+l*istep)+(j+m*jstep)*n] = s_d[b_index + 3 * v];
			v++;
		}
	}
}

int main(int argc, char **argv){
	int N, w;
	float p;

	N = atoi(argv[1]); //Read values from console
	p = atof(argv[2]);
	w = atoi(argv[3]);
	int n = pow(2, N);
	makeAdjacency(n, p, w); //Initialize distance values
	clock_t start = clock();
	int i, j, k;
	D = (float **)malloc(n*sizeof(float *)); //Allocation and initialization of D
	for (i = 0; i<n; i++) D[i] = (float *)malloc(n*sizeof(float));
	for (i = 0; i<n; i++){
		for (j = 0; j<n; j++){ 
			D[i][j] = INFINITY;
			if ((!isinf(A[i][j])) && A[i][j] != 0) D[i][j] = A[i][j];
			if (A[i][j] == 0) D[i][j] = 0;
		}
	}
	float *d_D;
	d2 = (float *)malloc(n*n*sizeof(float)); //Pass the values in the 1-d table
	int index = 0;
	for (j = 0; j<n; j++){
		for (i = 0; i<n; i++){
			d2[index++] = D[i][j];
		}
	}
        int gridx = pow(2, N - 4)/2, gridy = pow(2, N - 4)/2; //size of grid (n/4)*4 cells/thread=n cells
	int blockx = pow(2, 4), blocky = pow(2, 4);
	dim3 dimGrid(gridx, gridy);
	dim3 dimBlock(blockx, blocky);
	int size = n*n*sizeof(float);
	cudaMalloc((void**)&d_D, size); //Allocation of the device table
	cudaMemcpy(d_D, d2, size, cudaMemcpyHostToDevice); //Pass values from host to device
	for (k = 0; k<n; k++){
		
	    calc<<<dimGrid,dimBlock>>>(d_D,n,k); //Run kernel k times
		
	}
	cudaMemcpy(d2, d_D, size, cudaMemcpyDeviceToHost); //Return to host
	cudaFree(d_D);
	index = 0;
	for (j = 0; j<n; j++){
		for (i = 0; i<n; i++){
			D[i][j]=d2[index++];  //Pass the values to final table D[i][j]
		}
	}
	clock_t end = clock();
	float seconds = (float)(end - start) / CLOCKS_PER_SEC;
	printf("Elapsed wall time = %f sec\n", seconds); //Run wall time
	exit(0);
}

void makeAdjacency(int n, float p, int w){ //Function for initialization of distance table A
	int i, j;
	A = (float **)malloc(n*sizeof(float *));
	for (i = 0; i<n; i++) A[i] = (float *)malloc(n*sizeof(float));
	srand(time(NULL));
	for (i = 0; i<n; i++){
		for (j = 0; j<n; j++){
			if (((float)rand() / (RAND_MAX))>p) A[i][j] = INFINITY;
			else A[i][j] = ((float)rand() / (RAND_MAX)) * w;
		}
		A[i][i] = 0;
	}
}



	.file	"tmpxft_0029ef88_00000000-6_Cuda3.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z13makeAdjacencyifi
	.type	_Z13makeAdjacencyifi, @function
_Z13makeAdjacencyifi:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%edi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	0(,%r13,8), %rdi
	leaq	0(,%r13,4), %r15
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r13, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movss	%xmm0, 12(%rsp)
	call	malloc@PLT
	movq	%rax, A(%rip)
	movq	%rax, %r12
.L3:
	cmpl	%ebx, %ebp
	jle	.L16
	movq	%r15, %rdi
	call	malloc@PLT
	movq	%rax, (%r12,%rbx,8)
	incq	%rbx
	jmp	.L3
.L16:
	xorl	%edi, %edi
	xorl	%ebx, %ebx
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
.L5:
	cmpl	%ebx, %ebp
	jle	.L17
	leaq	0(,%rbx,8), %r15
	xorl	%r12d, %r12d
.L9:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	comiss	12(%rsp), %xmm0
	jbe	.L13
	movq	A(%rip), %rax
	movq	(%rax,%r15), %rax
	movl	$0x7f800000, (%rax,%r12,4)
	jmp	.L8
.L13:
	call	rand@PLT
	cvtsi2ssl	%r14d, %xmm1
	movl	%eax, %edx
	movq	A(%rip), %rax
	cvtsi2ssl	%edx, %xmm0
	mulss	.LC0(%rip), %xmm0
	movq	(%rax,%r15), %rax
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%rax,%r12,4)
.L8:
	incq	%r12
	cmpq	%r12, %r13
	jne	.L9
	movq	A(%rip), %rax
	movq	(%rax,%r15), %rax
	movl	$0x00000000, (%rax,%rbx,4)
	incq	%rbx
	jmp	.L5
.L17:
	addq	$24, %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
.LFE2029:
	.size	_Z13makeAdjacencyifi, .-_Z13makeAdjacencyifi
	.globl	_Z25__device_stub__Z4calcPfiiPfii
	.type	_Z25__device_stub__Z4calcPfiiPfii, @function
_Z25__device_stub__Z4calcPfiiPfii:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	32(%rsp), %rdi
	movl	%esi, 4(%rsp)
	leaq	44(%rsp), %rsi
	movl	%edx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	4(%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	.L18
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z4calcPfii(%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
.L18:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z25__device_stub__Z4calcPfiiPfii, .-_Z25__device_stub__Z4calcPfiiPfii
	.globl	_Z4calcPfii
	.type	_Z4calcPfii, @function
_Z4calcPfii:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z25__device_stub__Z4calcPfiiPfii
	.cfi_endproc
.LFE2055:
	.size	_Z4calcPfii, .-_Z4calcPfii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC8:
	.string	"Elapsed wall time = %f sec\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %r12d
	call	atof@PLT
	movq	24(%rbx), %rdi
	cvtsd2ss	%xmm0, %xmm5
	movd	%xmm5, %ebp
	call	atoi@PLT
	cvtsi2sdl	%r12d, %xmm1
	movsd	.LC3(%rip), %xmm0
	movl	%eax, %r13d
	call	pow@PLT
	movl	%r13d, %esi
	cvttsd2sil	%xmm0, %ebx
	movd	%ebp, %xmm0
	xorl	%ebp, %ebp
	movl	%ebx, %edi
	movslq	%ebx, %r15
	call	_Z13makeAdjacencyifi
	call	clock@PLT
	leaq	0(,%r15,8), %rdi
	salq	$2, %r15
	movq	%rax, %r13
	call	malloc@PLT
	movq	%rax, D(%rip)
	movq	%rax, %r14
.L24:
	cmpl	%ebp, %ebx
	jle	.L54
	movq	%r15, %rdi
	call	malloc@PLT
	movq	%rax, (%r14,%rbp,8)
	incq	%rbp
	jmp	.L24
.L54:
	movss	.LC1(%rip), %xmm2
	xorl	%eax, %eax
	xorps	%xmm1, %xmm1
	movb	$1, %r8b
	movss	.LC4(%rip), %xmm3
.L26:
	cmpl	%eax, %ebx
	jle	.L55
	leaq	0(,%rax,8), %r9
	xorl	%ecx, %ecx
.L30:
	movq	(%r14,%rax,8), %rsi
	movq	A(%rip), %rdi
	leaq	0(,%rcx,4), %rdx
	addq	%rdx, %rsi
	addq	(%rdi,%r9), %rdx
	movss	%xmm2, (%rsi)
	movss	(%rdx), %xmm0
	movaps	%xmm0, %xmm4
	andps	%xmm3, %xmm4
	ucomiss	.LC5(%rip), %xmm4
	ja	.L27
	ucomiss	%xmm1, %xmm0
	setp	%dil
	cmovne	%r8d, %edi
	testb	%dil, %dil
	je	.L27
	movss	%xmm0, (%rsi)
.L27:
	ucomiss	(%rdx), %xmm1
	jp	.L43
	xorps	%xmm0, %xmm0
	je	.L28
.L43:
	movss	(%rsi), %xmm0
.L28:
	incq	%rcx
	movss	%xmm0, (%rsi)
	cmpl	%ecx, %ebx
	jg	.L30
	incq	%rax
	jmp	.L26
.L55:
	movl	%ebx, %ebp
	imull	%ebx, %ebp
	movslq	%ebp, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	xorl	%ecx, %ecx
	xorl	%esi, %esi
	movq	%rax, d2(%rip)
.L32:
	cmpl	%ecx, %ebx
	jle	.L34
	movslq	%esi, %rdx
	leaq	0(,%rcx,4), %r8
	leaq	(%rax,%rdx,4), %rdi
	xorl	%edx, %edx
.L33:
	movq	(%r14,%rdx,8), %r9
	movss	(%r9,%r8), %xmm0
	movss	%xmm0, (%rdi,%rdx,4)
	incq	%rdx
	cmpl	%edx, %ebx
	jg	.L33
	addl	%ebx, %esi
	incq	%rcx
	jmp	.L32
.L34:
	subl	$4, %r12d
	movsd	.LC3(%rip), %xmm0
	sall	$2, %ebp
	cvtsi2sdl	%r12d, %xmm1
	movslq	%ebp, %rbp
	movsd	%xmm1, 8(%rsp)
	call	pow@PLT
	movsd	8(%rsp), %xmm1
	movq	%xmm0, %r12
	movsd	.LC3(%rip), %xmm0
	call	pow@PLT
	movsd	.LC6(%rip), %xmm2
	movq	%rbp, %rsi
	leaq	24(%rsp), %rdi
	movaps	%xmm0, %xmm1
	movq	%r12, %xmm0
	movl	$1, 40(%rsp)
	xorl	%r12d, %r12d
	mulsd	%xmm2, %xmm0
	movl	$1, 52(%rsp)
	mulsd	%xmm2, %xmm1
	cvttsd2sil	%xmm0, %eax
	movl	%eax, 32(%rsp)
	cvttsd2sil	%xmm1, %eax
	movl	%eax, 36(%rsp)
	movabsq	$68719476752, %rax
	movq	%rax, 44(%rsp)
	call	cudaMalloc@PLT
	movq	d2(%rip), %rsi
	movq	24(%rsp), %rdi
	movq	%rbp, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
.L35:
	cmpl	%ebx, %r12d
	je	.L56
	movl	52(%rsp), %ecx
	movq	44(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	32(%rsp), %rdi
	movl	40(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	movq	24(%rsp), %rdi
	movl	%r12d, %edx
	movl	%ebx, %esi
	call	_Z25__device_stub__Z4calcPfiiPfii
.L36:
	incl	%r12d
	jmp	.L35
.L56:
	movq	24(%rsp), %rsi
	movq	d2(%rip), %rdi
	movl	$2, %ecx
	movq	%rbp, %rdx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	d2(%rip), %rdi
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	movq	D(%rip), %r9
.L38:
	cmpl	%edx, %ebx
	jle	.L40
	movslq	%ecx, %rax
	leaq	0(,%rdx,4), %r8
	leaq	(%rdi,%rax,4), %rsi
	xorl	%eax, %eax
.L39:
	movss	(%rsi,%rax,4), %xmm0
	movq	(%r9,%rax,8), %r10
	incq	%rax
	movss	%xmm0, (%r10,%r8)
	cmpl	%eax, %ebx
	jg	.L39
	addl	%ebx, %ecx
	incq	%rdx
	jmp	.L38
.L40:
	call	clock@PLT
	movl	$2, %edi
	leaq	.LC8(%rip), %rsi
	subq	%r13, %rax
	cvtsi2ssq	%rax, %xmm0
	movb	$1, %al
	divss	.LC7(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z4calcPfii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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	.LC9(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z4calcPfii(%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
.LFE2057:
	.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
	.globl	elapsed_time
	.bss
	.align 8
	.type	elapsed_time, @object
	.size	elapsed_time, 8
elapsed_time:
	.zero	8
	.globl	d2
	.align 8
	.type	d2, @object
	.size	d2, 8
d2:
	.zero	8
	.globl	D
	.align 8
	.type	D, @object
	.size	D, 8
D:
	.zero	8
	.globl	A
	.align 8
	.type	A, @object
	.size	A, 8
A:
	.zero	8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.align 4
.LC1:
	.long	2139095040
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	0
	.long	1073741824
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC4:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4
	.align 4
.LC5:
	.long	2139095039
	.section	.rodata.cst8
	.align 8
.LC6:
	.long	0
	.long	1071644672
	.section	.rodata.cst4
	.align 4
.LC7:
	.long	1232348160
	.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 <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#ifdef INFINITY
/* INFINITY is supported */
#endif

float **A, **D, *d2;
double elapsed_time;

void makeAdjacency(int n, float p, int w);

__global__ void calc(float *d_D, int n, int k){ //kernel (4  cells for every thread)
	__shared__ float s_d[4*3*256]; //Shared table within a block
	int i = blockIdx.x * blockDim.x + threadIdx.x; //Calculation of i and j
	int j = blockIdx.y * blockDim.y + threadIdx.y;
	int b_index = 4 * 3 * (threadIdx.x + blockDim.x*threadIdx.y); //Calculation of initial index of thread in the shared table within the block
	int istep = blockDim.x*gridDim.x, jstep = blockDim.y*gridDim.y;
	int l, m , v=0;
	for (l = 0; l<2; l++){
		for (m = 0; m<2; m++){ //Pass values from device table to shared block table for every one of the 4 cells
			s_d[b_index + 3 * v] = d_D[(i+l*istep)+(j+m*jstep)*n]; 
			s_d[b_index + (3 * v + 1)] = d_D[(i + l*istep) + k*n];
			s_d[b_index + (3 * v + 2)] = d_D[k + (j + m*jstep)*n];
			v++;
		}
	}
	for (v = 0; v<4; v++){ //Calculate the new cell values (4 for every thread)
		if (s_d[b_index + 3 * v] > s_d[b_index + (3 * v + 1)] + s_d[b_index + (3 * v + 2)]) s_d[b_index + 3 * v] = s_d[b_index + (3 * v + 1)] + s_d[b_index + (3 * v + 2)];
	}
	v = 0;
	for (l = 0; l<2; l++){ //Pass the new values to the device table
		for (m = 0; m<2; m++){
			d_D[(i+l*istep)+(j+m*jstep)*n] = s_d[b_index + 3 * v];
			v++;
		}
	}
}

int main(int argc, char **argv){
	int N, w;
	float p;

	N = atoi(argv[1]); //Read values from console
	p = atof(argv[2]);
	w = atoi(argv[3]);
	int n = pow(2, N);
	makeAdjacency(n, p, w); //Initialize distance values
	clock_t start = clock();
	int i, j, k;
	D = (float **)malloc(n*sizeof(float *)); //Allocation and initialization of D
	for (i = 0; i<n; i++) D[i] = (float *)malloc(n*sizeof(float));
	for (i = 0; i<n; i++){
		for (j = 0; j<n; j++){ 
			D[i][j] = INFINITY;
			if ((!isinf(A[i][j])) && A[i][j] != 0) D[i][j] = A[i][j];
			if (A[i][j] == 0) D[i][j] = 0;
		}
	}
	float *d_D;
	d2 = (float *)malloc(n*n*sizeof(float)); //Pass the values in the 1-d table
	int index = 0;
	for (j = 0; j<n; j++){
		for (i = 0; i<n; i++){
			d2[index++] = D[i][j];
		}
	}
        int gridx = pow(2, N - 4)/2, gridy = pow(2, N - 4)/2; //size of grid (n/4)*4 cells/thread=n cells
	int blockx = pow(2, 4), blocky = pow(2, 4);
	dim3 dimGrid(gridx, gridy);
	dim3 dimBlock(blockx, blocky);
	int size = n*n*sizeof(float);
	hipMalloc((void**)&d_D, size); //Allocation of the device table
	hipMemcpy(d_D, d2, size, hipMemcpyHostToDevice); //Pass values from host to device
	for (k = 0; k<n; k++){
		
	    calc<<<dimGrid,dimBlock>>>(d_D,n,k); //Run kernel k times
		
	}
	hipMemcpy(d2, d_D, size, hipMemcpyDeviceToHost); //Return to host
	hipFree(d_D);
	index = 0;
	for (j = 0; j<n; j++){
		for (i = 0; i<n; i++){
			D[i][j]=d2[index++];  //Pass the values to final table D[i][j]
		}
	}
	clock_t end = clock();
	float seconds = (float)(end - start) / CLOCKS_PER_SEC;
	printf("Elapsed wall time = %f sec\n", seconds); //Run wall time
	exit(0);
}

void makeAdjacency(int n, float p, int w){ //Function for initialization of distance table A
	int i, j;
	A = (float **)malloc(n*sizeof(float *));
	for (i = 0; i<n; i++) A[i] = (float *)malloc(n*sizeof(float));
	srand(time(NULL));
	for (i = 0; i<n; i++){
		for (j = 0; j<n; j++){
			if (((float)rand() / (RAND_MAX))>p) A[i][j] = INFINITY;
			else A[i][j] = ((float)rand() / (RAND_MAX)) * w;
		}
		A[i][i] = 0;
	}
}



	.text
	.file	"Cuda3.hip"
	.globl	_Z19__device_stub__calcPfii     # -- Begin function _Z19__device_stub__calcPfii
	.type	_Z19__device_stub__calcPfii,@function
_Z19__device_stub__calcPfii:            # @_Z19__device_stub__calcPfii
	.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	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	movq	%rsp, %rsi
	movl	%edx, (%rsi)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 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	$_Z4calcPfii, %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	_Z19__device_stub__calcPfii, .Lfunc_end0-_Z19__device_stub__calcPfii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI1_0:
	.quad	0x3ff0000000000000              # double 1
.LCPI1_1:
	.quad	0x3fe0000000000000              # double 0.5
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI1_2:
	.long	0x49742400                      # float 1.0E+6
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r14d
	movq	16(%rbx), %rdi
	callq	atof
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	movq	24(%rbx), %rdi
	callq	atoi
	movl	%eax, %ebx
	movsd	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	%r14d, %edi
	callq	ldexp@PLT
	cvttsd2si	%xmm0, %ebp
	movl	%ebp, %edi
	movss	8(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movl	%ebx, %esi
	callq	_Z13makeAdjacencyifi
	callq	clock
	movq	%rax, %rbx
	movslq	%ebp, %r15
	leaq	(,%r15,8), %rdi
	callq	malloc
	movq	%rax, D(%rip)
	testl	%r15d, %r15d
	jle	.LBB1_12
# %bb.1:                                # %.lr.ph
	shlq	$2, %r15
	movl	%ebp, %r12d
	xorl	%r13d, %r13d
.LBB1_2:                                # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	callq	malloc
	movq	D(%rip), %rcx
	movq	%rax, (%rcx,%r13,8)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB1_2
# %bb.3:                                # %.preheader93
	testl	%ebp, %ebp
	jle	.LBB1_12
# %bb.4:                                # %.preheader92.lr.ph
	movq	D(%rip), %rax
	movq	A(%rip), %rcx
	xorl	%edx, %edx
	xorps	%xmm0, %xmm0
.LBB1_5:                                # %.lr.ph96
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_6 Depth 2
	movq	(%rax,%rdx,8), %rsi
	movq	(%rcx,%rdx,8), %rdi
	xorl	%r8d, %r8d
.LBB1_6:                                #   Parent Loop BB1_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$2139095040, (%rsi,%r8,4)       # imm = 0x7F800000
	movd	(%rdi,%r8,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
	movd	%xmm1, %r9d
	andl	$2147483647, %r9d               # imm = 0x7FFFFFFF
	leal	-8388608(%r9), %r10d
	cmpl	$2130706432, %r10d              # imm = 0x7F000000
	setae	%r10b
	leal	-1(%r9), %r11d
	cmpl	$8388607, %r11d                 # imm = 0x7FFFFF
	setae	%r11b
	andb	%r10b, %r11b
	cmpl	$2139095041, %r9d               # imm = 0x7F800001
	setl	%r9b
	testb	%r9b, %r11b
	jne	.LBB1_8
# %bb.7:                                #   in Loop: Header=BB1_6 Depth=2
	movd	%xmm1, (%rsi,%r8,4)
	movd	(%rdi,%r8,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
.LBB1_8:                                #   in Loop: Header=BB1_6 Depth=2
	ucomiss	%xmm0, %xmm1
	jne	.LBB1_10
	jp	.LBB1_10
# %bb.9:                                #   in Loop: Header=BB1_6 Depth=2
	movl	$0, (%rsi,%r8,4)
.LBB1_10:                               #   in Loop: Header=BB1_6 Depth=2
	incq	%r8
	cmpq	%r8, %r12
	jne	.LBB1_6
# %bb.11:                               # %._crit_edge
                                        #   in Loop: Header=BB1_5 Depth=1
	incq	%rdx
	cmpq	%r12, %rdx
	jne	.LBB1_5
.LBB1_12:                               # %._crit_edge98
	movl	%ebp, %r15d
	imull	%r15d, %r15d
	leaq	(,%r15,4), %rdi
	callq	malloc
	movq	%rax, d2(%rip)
	testl	%ebp, %ebp
	jle	.LBB1_17
# %bb.13:                               # %.preheader91.lr.ph
	movq	D(%rip), %rcx
	movl	%ebp, %edx
	xorl	%esi, %esi
	xorl	%edi, %edi
.LBB1_14:                               # %.lr.ph101
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_15 Depth 2
	movslq	%edi, %rdi
	leaq	(%rax,%rdi,4), %r9
	xorl	%r8d, %r8d
.LBB1_15:                               #   Parent Loop BB1_14 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%rcx,%r8,8), %r10
	movss	(%r10,%rsi,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%r9,%r8,4)
	incq	%r8
	cmpq	%r8, %rdx
	jne	.LBB1_15
# %bb.16:                               # %._crit_edge102
                                        #   in Loop: Header=BB1_14 Depth=1
	incq	%rsi
	addq	%r8, %rdi
	cmpq	%rdx, %rsi
	jne	.LBB1_14
.LBB1_17:                               # %._crit_edge105
	addl	$-4, %r14d
	movsd	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	%r14d, %edi
	callq	ldexp@PLT
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movsd	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	%r14d, %edi
	callq	ldexp@PLT
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	shlq	$34, %r15
	sarq	$32, %r15
	movq	%rsp, %r14
	movq	%r14, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	d2(%rip), %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%ebp, %ebp
	jle	.LBB1_27
# %bb.18:                               # %.lr.ph108.preheader
	movsd	.LCPI1_1(%rip), %xmm0           # xmm0 = mem[0],zero
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
	mulsd	%xmm0, %xmm1
	cvttsd2si	%xmm1, %eax
	movsd	16(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	mulsd	%xmm0, %xmm1
	cvttsd2si	%xmm1, %r14d
	shlq	$32, %r14
	orq	%rax, %r14
	xorl	%r12d, %r12d
	movabsq	$68719476752, %r13              # imm = 0x1000000010
.LBB1_19:                               # %.lr.ph108
                                        # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_21
# %bb.20:                               #   in Loop: Header=BB1_19 Depth=1
	movq	(%rsp), %rdi
	movl	%ebp, %esi
	movl	%r12d, %edx
	callq	_Z19__device_stub__calcPfii
.LBB1_21:                               #   in Loop: Header=BB1_19 Depth=1
	incl	%r12d
	cmpl	%r12d, %ebp
	jne	.LBB1_19
# %bb.22:                               # %._crit_edge109
	movq	d2(%rip), %rdi
	movq	(%rsp), %rsi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rdi
	callq	hipFree
	testl	%ebp, %ebp
	jle	.LBB1_28
# %bb.23:                               # %.preheader.lr.ph
	movq	d2(%rip), %rax
	movq	D(%rip), %rcx
	movl	%ebp, %edx
	xorl	%esi, %esi
	xorl	%edi, %edi
.LBB1_24:                               # %.lr.ph112
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_25 Depth 2
	movslq	%edi, %rdi
	leaq	(%rax,%rdi,4), %r9
	xorl	%r8d, %r8d
.LBB1_25:                               #   Parent Loop BB1_24 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r9,%r8,4), %xmm0              # xmm0 = mem[0],zero,zero,zero
	movq	(%rcx,%r8,8), %r10
	movss	%xmm0, (%r10,%rsi,4)
	incq	%r8
	cmpq	%r8, %rdx
	jne	.LBB1_25
# %bb.26:                               # %._crit_edge113
                                        #   in Loop: Header=BB1_24 Depth=1
	incq	%rsi
	addq	%r8, %rdi
	cmpq	%rdx, %rsi
	jne	.LBB1_24
	jmp	.LBB1_28
.LBB1_27:                               # %._crit_edge117.critedge
	movq	d2(%rip), %rdi
	movq	(%rsp), %rsi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rdi
	callq	hipFree
.LBB1_28:                               # %._crit_edge117
	callq	clock
	subq	%rbx, %rax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	divss	.LCPI1_2(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	xorl	%edi, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z13makeAdjacencyifi
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI2_1:
	.long	0x7f800000                      # float +Inf
	.text
	.globl	_Z13makeAdjacencyifi
	.type	_Z13makeAdjacencyifi,@function
_Z13makeAdjacencyifi:                   # @_Z13makeAdjacencyifi
	.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	%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 %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
	movl	%edi, %ebp
	movslq	%edi, %r15
	leaq	(,%r15,8), %rdi
	callq	malloc
	movq	%rax, A(%rip)
	testl	%r15d, %r15d
	jle	.LBB2_11
# %bb.1:                                # %.lr.ph
	leaq	(,%r15,4), %r14
	movl	%r15d, %r15d
	xorl	%r12d, %r12d
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	callq	malloc
	movq	A(%rip), %rcx
	movq	%rax, (%rcx,%r12,8)
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB2_2
# %bb.3:                                # %._crit_edge
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	testl	%ebp, %ebp
	jle	.LBB2_10
# %bb.4:                                # %.preheader.lr.ph
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebx, %xmm0
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	xorl	%ebx, %ebx
.LBB2_5:                                # %.lr.ph23
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_6 Depth 2
	xorl	%r14d, %r14d
.LBB2_6:                                #   Parent Loop BB2_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	ucomiss	12(%rsp), %xmm0                 # 4-byte Folded Reload
	movss	.LCPI2_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	ja	.LBB2_8
# %bb.7:                                #   in Loop: Header=BB2_6 Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	mulss	8(%rsp), %xmm0                  # 4-byte Folded Reload
.LBB2_8:                                #   in Loop: Header=BB2_6 Depth=2
	movq	A(%rip), %rax
	movq	(%rax,%rbx,8), %rax
	movss	%xmm0, (%rax,%r14,4)
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB2_6
# %bb.9:                                # %._crit_edge24
                                        #   in Loop: Header=BB2_5 Depth=1
	movl	$0, (%rax,%rbx,4)
	incq	%rbx
	cmpq	%r15, %rbx
	jne	.LBB2_5
.LBB2_10:                               # %._crit_edge26
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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
.LBB2_11:                               # %._crit_edge26.critedge
	.cfi_def_cfa_offset 64
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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
	jmp	srand                           # TAILCALL
.Lfunc_end2:
	.size	_Z13makeAdjacencyifi, .Lfunc_end2-_Z13makeAdjacencyifi
	.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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4calcPfii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB4_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	A,@object                       # @A
	.bss
	.globl	A
	.p2align	3, 0x0
A:
	.quad	0
	.size	A, 8

	.type	D,@object                       # @D
	.globl	D
	.p2align	3, 0x0
D:
	.quad	0
	.size	D, 8

	.type	d2,@object                      # @d2
	.globl	d2
	.p2align	3, 0x0
d2:
	.quad	0
	.size	d2, 8

	.type	elapsed_time,@object            # @elapsed_time
	.globl	elapsed_time
	.p2align	3, 0x0
elapsed_time:
	.quad	0x0000000000000000              # double 0
	.size	elapsed_time, 8

	.type	_Z4calcPfii,@object             # @_Z4calcPfii
	.section	.rodata,"a",@progbits
	.globl	_Z4calcPfii
	.p2align	3, 0x0
_Z4calcPfii:
	.quad	_Z19__device_stub__calcPfii
	.size	_Z4calcPfii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Elapsed wall time = %f sec\n"
	.size	.L.str, 28

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4calcPfii"
	.size	.L__unnamed_1, 12

	.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 _Z19__device_stub__calcPfii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z4calcPfii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4calcPfii             ; -- Begin function _Z4calcPfii
	.globl	_Z4calcPfii
	.p2align	8
	.type	_Z4calcPfii,@function
_Z4calcPfii:                            ; @_Z4calcPfii
; %bb.0:
	s_clause 0x2
	s_load_b32 s8, s[0:1], 0x1c
	s_load_b64 s[2:3], s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_mov_b32 s9, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s0, s8, 0xffff
	s_lshr_b32 s8, s8, 16
	v_mad_u32_u24 v4, v3, s0, v2
	v_mad_u64_u32 v[0:1], null, s14, s0, v[2:3]
	s_mul_i32 s1, s2, s0
	s_mul_i32 s2, s3, s8
	s_delay_alu instid0(VALU_DEP_2)
	v_mad_u64_u32 v[1:2], null, s15, s8, v[3:4]
	v_mul_lo_u32 v2, v4, 48
	s_mul_i32 s0, s7, s6
	s_mov_b32 s8, -1
	s_mov_b32 s3, 0
.LBB0_1:                                ; %.preheader73
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_2 Depth 2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[3:4], null, s9, s1, v[0:1]
	s_xor_b32 s8, s8, -1
	s_mov_b32 s9, -1
	s_mov_b32 s10, 0
	v_add_nc_u32_e32 v4, s0, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	global_load_b32 v6, v[4:5], off
	v_mad_u64_u32 v[4:5], null, s3, 12, v[2:3]
.LBB0_2:                                ;   Parent Loop BB0_1 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_mad_u64_u32 v[7:8], null, s10, s2, v[1:2]
	s_mov_b32 s10, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v5, v7, s6
	v_add_nc_u32_e32 v7, v5, v3
	v_add_nc_u32_e32 v9, s7, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v8, 31, v7
	v_ashrrev_i32_e32 v10, 31, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v7, vcc_lo, s4, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s5, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v9, vcc_lo, s4, v9
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	s_and_b32 vcc_lo, exec_lo, s9
	s_clause 0x1
	global_load_b32 v5, v[7:8], off
	global_load_b32 v7, v[9:10], off
	s_mov_b32 s9, 0
	s_waitcnt vmcnt(1)
	ds_store_2addr_b32 v4, v5, v6 offset1:1
	s_waitcnt vmcnt(0)
	ds_store_b32 v4, v7 offset:8
	v_add_nc_u32_e32 v4, 12, v4
	s_cbranch_vccnz .LBB0_2
; %bb.3:                                ;   in Loop: Header=BB0_1 Depth=1
	s_add_i32 s3, s3, 2
	s_mov_b32 s9, 1
	s_and_not1_b32 vcc_lo, exec_lo, s8
	s_mov_b32 s8, 0
	s_cbranch_vccnz .LBB0_1
; %bb.4:                                ; %.preheader72.preheader
	s_mov_b32 s0, 0
.LBB0_5:                                ; %.preheader72
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_nc_u32_e32 v3, s0, v2
	s_mov_b32 s3, exec_lo
	ds_load_2addr_b32 v[5:6], v3 offset1:1
	ds_load_b32 v4, v3 offset:8
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v4, v6, v4
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_f32_e32 v5, v4
	s_cbranch_execz .LBB0_7
; %bb.6:                                ;   in Loop: Header=BB0_5 Depth=1
	ds_store_b32 v3, v4
.LBB0_7:                                ;   in Loop: Header=BB0_5 Depth=1
	s_or_b32 exec_lo, exec_lo, s3
	s_add_i32 s0, s0, 12
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lg_u32 s0, 48
	s_cbranch_scc1 .LBB0_5
; %bb.8:                                ; %.preheader.preheader
	s_mov_b32 s0, -1
	s_mov_b32 s3, 0
	s_mov_b32 s8, 0
.LBB0_9:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_10 Depth 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[3:4], null, s8, s1, v[0:1]
	s_xor_b32 s7, s0, -1
	s_mov_b32 s0, -1
	s_mov_b32 s8, 0
	v_mad_u64_u32 v[4:5], null, s3, 12, v[2:3]
.LBB0_10:                               ;   Parent Loop BB0_9 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_mad_u64_u32 v[5:6], null, s8, s2, v[1:2]
	ds_load_b32 v8, v4
	v_add_nc_u32_e32 v4, 12, v4
	s_and_b32 vcc_lo, exec_lo, s0
	s_mov_b32 s8, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[6:7], null, v5, s6, v[3:4]
	v_ashrrev_i32_e32 v7, 31, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[6:7]
	v_add_co_u32 v5, s0, s4, v5
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v6, s0, s5, v6, s0
	s_mov_b32 s0, 0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[5:6], v8, off
	s_cbranch_vccnz .LBB0_10
; %bb.11:                               ;   in Loop: Header=BB0_9 Depth=1
	s_add_i32 s3, s3, 2
	s_and_not1_b32 vcc_lo, exec_lo, s7
	s_cbranch_vccnz .LBB0_9
; %bb.12:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4calcPfii
		.amdhsa_group_segment_fixed_size 12288
		.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 11
		.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	_Z4calcPfii, .Lfunc_end0-_Z4calcPfii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 616
; NumSgprs: 18
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 12288 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 11
; 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
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 12288
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4calcPfii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z4calcPfii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     11
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
