#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <time.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>

using namespace std;

struct Node{
	int key;
	int nextIdx;
	int nextLevel;
};

__global__ void assign(Node *sl, Node *data)
{
	int i = blockIdx.x * blockDim.x + threadIdx.x;
	int k = data[i].key;
	sl[k - 1].key = k;
	sl[k - 1].nextIdx = k;
}

__global__ void connect(Node *sl, int N)
{
	int id = blockIdx.x * blockDim.x + threadIdx.x;
	int level = 1;
	for (int i = 2; i < N+1; i = i * 2)
	{
		if (id%i == 0)
		{
			int newid = id + level*N;
			sl[newid].key = sl[id].key;
			sl[newid].nextIdx = newid + i;
			sl[newid].nextLevel = newid - N;
		}
		level++;
	}

}


struct timespec diff(timespec start, timespec end)
{
	struct timespec temp;
	if ((end.tv_nsec - start.tv_nsec) < 0) {
		temp.tv_sec = end.tv_sec - start.tv_sec - 1;
		temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
	}
	else {
		temp.tv_sec = end.tv_sec - start.tv_sec;
		temp.tv_nsec = end.tv_nsec - start.tv_nsec;
	}
	return temp;
}


void print(Node *sl, int N, int MAX_LEVEL)
{
	cout << "Index:" << endl;
	for (int i = 0; i<N*MAX_LEVEL; i++)
	{
		cout << setw(4) << sl[i].key;
		if ((i + 1) % N == 0)
			cout << endl;
	}
	printf("NextIndex:\n");
	for (int i = 0; i<N*MAX_LEVEL; i++)
	{
		cout << setw(4) << sl[i].nextIdx;
		if ((i + 1) % N == 0)
			cout << endl;
	}
	printf("NextLevel:\n");
	for (int i = 0; i<N*MAX_LEVEL; i++)
	{
	    cout << setw(4) << sl[i].nextLevel;
		if ((i + 1) % N == 0)
			cout << endl;
	}
}

int main()
{
	int N=1024*1024*16, MAX_LEVEL=25;
//	cin >> N >> MAX_LEVEL;
//	for(MAX_LEVEL=26;MAX_LEVEL<26;MAX_LEVEL++)
//	{
	Node *sl, *d_sl;
	Node *data, *d_data;
	struct timespec start, end, temp;
	cudaError_t err = cudaSuccess;
	double time_used, sum = 0;
	int loop;
	
	sl = (Node *)malloc(N * sizeof(Node) * MAX_LEVEL);
	data = (Node *)malloc(N * sizeof(Node));
 	for(loop=1;loop<2;loop++)
	{
		for (int i = 0; i < N; i++)
		{
			data[i].key =i+1;
		}
		int random = 1000;
		while (random--) {
			int i = rand() % N;
			int j = rand() % N;
			int tmp = data[i].key;
			data[i].key = data[j].key;
			data[j].key = tmp;
		}

		for (int i = 0; i < MAX_LEVEL * N; i++) {
			sl[i].key = -1;
			sl[i].nextLevel = -1;
			sl[i].nextIdx = -1;
		}

		clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
	
	//	size_t free, max;
//		cudaMemGetInfo(&free, &max);
  //    	cout << "free: " << free << " total: " << max << endl;

		err = cudaMalloc(&d_data, N * sizeof(Node));
		if (err != cudaSuccess) 
		{
     		//cout << "Failed to malloc data in loop " << loop << " : " << cudaGetErrorString(err);
			fprintf(stderr, "Failed to malloc data in loop %d : %s\n", loop, cudaGetErrorString(err));
      		exit(EXIT_FAILURE);
    	}

		err = cudaMalloc(&d_sl, N * sizeof(Node) * MAX_LEVEL * 2 );
		if (err != cudaSuccess) 
		{
     		fprintf(stderr, "Failed to malloc sl in loop %d : %s\n", loop, cudaGetErrorString(err));
     	    exit(EXIT_FAILURE);
        }
	
	//	int memoryused = N * sizeof(Node) * MAX_LEVEL*2 + N * sizeof(Node);
	//	cudaMemGetInfo(&free, &max);
	//	cout << "free: " << free << " total: " << max << endl;
	//	cout << "Memory Used: " << memoryused << endl;
	//	cout << free + memoryused;

		cudaMemcpy(d_data, data, N * sizeof(Node), cudaMemcpyHostToDevice);
		if (err != cudaSuccess) 
		{
			fprintf(stderr, "Failed to copy data in loop %d : %s\n", loop, cudaGetErrorString(err));
            exit(EXIT_FAILURE);
    	}

		cudaMemcpy(d_sl, sl, N * sizeof(Node) * MAX_LEVEL, cudaMemcpyHostToDevice);
		if (err != cudaSuccess) 
		{
      		fprintf(stderr, "Failed to copy sl in loop %d : %s\n", loop, cudaGetErrorString(err));
            exit(EXIT_FAILURE);
        }
		int block = N/1024;
		assign <<< block, 1024 >>> (d_sl,d_data);
		err = cudaGetLastError();
		if (err != cudaSuccess) 
		{
            fprintf(stderr, "Failed to assign in loop %d : %s\n", loop, cudaGetErrorString(err));
            exit(EXIT_FAILURE);
        }

		connect <<< block,1024 >>> (d_sl, N);
		err = cudaGetLastError();
		
		if (err != cudaSuccess) 
		{
    	    fprintf(stderr, "Failed to connect in loop %d : %s\n", loop, cudaGetErrorString(err));
            exit(EXIT_FAILURE);
        }

		cudaMemcpy(sl, d_sl, N * sizeof(Node) * MAX_LEVEL, cudaMemcpyDeviceToHost);
		if (err != cudaSuccess) 
		{
            fprintf(stderr, "Failed to memory copy back to host in loop %d : %s\n", loop, cudaGetErrorString(err));
            exit(EXIT_FAILURE);
        }

		clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
		temp = diff(start, end);
		time_used = 1000 * (temp.tv_sec + (double)temp.tv_nsec / 1000000000.0);
		sum += time_used;

		//print(sl, N, MAX_ELVEL);

		cudaFree(d_sl);
		cudaFree(d_data);
		cout << "loop: " << loop << " time: " << time_used << endl;	
	}

	cout << "Data:" << N << endl << "Maxlevel: " << MAX_LEVEL << endl << sum/(loop-1) << endl << endl;
	free(sl);
	free(data);
//	N=N*2;
//	}
//	system("pause");
    return 0;
}

	.file	"tmpxft_00360f70_00000000-6_newskiplist.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3920:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3920:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z4diff8timespecS_
	.type	_Z4diff8timespecS_, @function
_Z4diff8timespecS_:
.LFB3915:
	.cfi_startproc
	endbr64
	movq	%rdx, %rax
	movq	%rcx, %rdx
	subq	%rdi, %rax
	subq	%rsi, %rdx
	jns	.L3
	leaq	1000000000(%rcx), %rdx
	decq	%rax
	subq	%rsi, %rdx
.L3:
	ret
	.cfi_endproc
.LFE3915:
	.size	_Z4diff8timespecS_, .-_Z4diff8timespecS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Index:"
.LC1:
	.string	"NextIndex:\n"
.LC2:
	.string	"NextLevel:\n"
	.text
	.globl	_Z5printP4Nodeii
	.type	_Z5printP4Nodeii, @function
_Z5printP4Nodeii:
.LFB3916:
	.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
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%r14, %r15
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	imull	%ebp, %r12d
	leaq	_ZSt4cout(%rip), %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 64
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
.L6:
	cmpl	%r13d, %r12d
	jle	.L16
	movq	(%rbx), %rax
	movl	(%r15), %esi
	movq	%rbx, %rdi
	incl	%r13d
	movq	-24(%rax), %rax
	movq	$4, 16(%rbx,%rax)
	call	_ZNSolsEi@PLT
	movl	%r13d, %eax
	cltd
	idivl	%ebp
	testl	%edx, %edx
	jne	.L7
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
.L7:
	addq	$12, %r15
	jmp	.L6
.L16:
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	leaq	4(%r14), %r15
	xorl	%r13d, %r13d
	movl	$2, %edi
	call	__printf_chk@PLT
.L9:
	cmpl	%r13d, %r12d
	jle	.L17
	movq	(%rbx), %rax
	movl	(%r15), %esi
	movq	%rbx, %rdi
	incl	%r13d
	movq	-24(%rax), %rax
	movq	$4, 16(%rbx,%rax)
	call	_ZNSolsEi@PLT
	movl	%r13d, %eax
	cltd
	idivl	%ebp
	testl	%edx, %edx
	jne	.L10
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
.L10:
	addq	$12, %r15
	jmp	.L9
.L17:
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	addq	$8, %r14
	xorl	%r13d, %r13d
	movl	$2, %edi
	call	__printf_chk@PLT
.L12:
	cmpl	%r13d, %r12d
	jle	.L18
	movq	(%rbx), %rax
	movl	(%r14), %esi
	movq	%rbx, %rdi
	incl	%r13d
	movq	-24(%rax), %rax
	movq	$4, 16(%rbx,%rax)
	call	_ZNSolsEi@PLT
	movl	%r13d, %eax
	cltd
	idivl	%ebp
	testl	%edx, %edx
	jne	.L13
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
.L13:
	addq	$12, %r14
	jmp	.L12
.L18:
	popq	%rax
	.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
.LFE3916:
	.size	_Z5printP4Nodeii, .-_Z5printP4Nodeii
	.globl	_Z32__device_stub__Z6assignP4NodeS0_P4NodeS0_
	.type	_Z32__device_stub__Z6assignP4NodeS0_P4NodeS0_, @function
_Z32__device_stub__Z6assignP4NodeS0_P4NodeS0_:
.LFB3942:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z6assignP4NodeS0_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L19:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3942:
	.size	_Z32__device_stub__Z6assignP4NodeS0_P4NodeS0_, .-_Z32__device_stub__Z6assignP4NodeS0_P4NodeS0_
	.globl	_Z6assignP4NodeS0_
	.type	_Z6assignP4NodeS0_, @function
_Z6assignP4NodeS0_:
.LFB3943:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z6assignP4NodeS0_P4NodeS0_
	.cfi_endproc
.LFE3943:
	.size	_Z6assignP4NodeS0_, .-_Z6assignP4NodeS0_
	.globl	_Z31__device_stub__Z7connectP4NodeiP4Nodei
	.type	_Z31__device_stub__Z7connectP4NodeiP4Nodei, @function
_Z31__device_stub__Z7connectP4NodeiP4Nodei:
.LFB3944:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z7connectP4Nodei(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L24:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3944:
	.size	_Z31__device_stub__Z7connectP4NodeiP4Nodei, .-_Z31__device_stub__Z7connectP4NodeiP4Nodei
	.globl	_Z7connectP4Nodei
	.type	_Z7connectP4Nodei, @function
_Z7connectP4Nodei:
.LFB3945:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z7connectP4NodeiP4Nodei
	.cfi_endproc
.LFE3945:
	.size	_Z7connectP4Nodei, .-_Z7connectP4Nodei
	.section	.rodata.str1.1
.LC3:
	.string	"Failed to malloc data in loop %d : %s\n"
.LC4:
	.string	"Failed to malloc sl in loop %d : %s\n"
.LC5:
	.string	"Failed to assign in loop %d : %s\n"
.LC6:
	.string	"Failed to connect in loop %d : %s\n"
.LC10:
	.string	"loop: "
.LC11:
	.string	" time: "
.LC12:
	.string	"Data:"
.LC13:
	.string	"Maxlevel: "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3917:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$75, %edi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	salq	$26, %rdi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$96, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$201326592, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movq	%rax, %rbx
	movl	$1, %eax
.L30:
	imulq	$12, %rax, %rdx
	movl	%eax, -12(%rbx,%rdx)
	incq	%rax
	cmpq	$16777217, %rax
	jne	.L30
	movl	$1000, %r14d
	movl	$16777216, %r13d
.L31:
	call	rand@PLT
	movl	%eax, %r12d
	call	rand@PLT
	movl	%eax, %esi
	movl	%r12d, %eax
	cltd
	idivl	%r13d
	movl	%esi, %eax
	movslq	%edx, %rcx
	cltd
	idivl	%r13d
	imulq	$12, %rcx, %rcx
	addq	%rbx, %rcx
	movl	(%rcx), %edi
	movslq	%edx, %rdx
	imulq	$12, %rdx, %rdx
	addq	%rbx, %rdx
	movl	(%rdx), %eax
	movl	%eax, (%rcx)
	movl	%edi, (%rdx)
	decl	%r14d
	jne	.L31
	movl	$75, %edx
	movq	%rbp, %rax
	salq	$26, %rdx
	addq	%rbp, %rdx
.L32:
	movl	$-1, (%rax)
	addq	$12, %rax
	movl	$-1, -4(%rax)
	movl	$-1, -8(%rax)
	cmpq	%rdx, %rax
	jne	.L32
	leaq	56(%rsp), %rsi
	movl	$2, %edi
	call	clock_gettime@PLT
	leaq	32(%rsp), %rdi
	movl	$201326592, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L33
	call	cudaGetErrorString@PLT
	movl	$1, %ecx
	leaq	.LC3(%rip), %rdx
	movq	%rax, %r8
	jmp	.L44
.L33:
	movl	$75, %esi
	leaq	24(%rsp), %rdi
	salq	$27, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L34
	call	cudaGetErrorString@PLT
	movl	$1, %ecx
	leaq	.LC4(%rip), %rdx
	movq	%rax, %r8
.L44:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L34:
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movl	$201326592, %edx
	movq	%rbx, %rsi
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	movl	$75, %edx
	movq	%rbp, %rsi
	salq	$26, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$262145, %edi
	salq	$10, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	salq	$14, %rdi
	movq	%rdx, 72(%rsp)
	movl	$1, 80(%rsp)
	movq	%rdi, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L35
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z32__device_stub__Z6assignP4NodeS0_P4NodeS0_
.L35:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L36
	call	cudaGetErrorString@PLT
	movl	$1, %ecx
	leaq	.LC5(%rip), %rdx
	movq	%rax, %r8
	jmp	.L44
.L36:
	movl	$4194305, %edx
	movl	$262145, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$10, %rdx
	salq	$14, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	movq	%rdx, 72(%rsp)
	movl	$1, 80(%rsp)
	movq	%rdi, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	movq	24(%rsp), %rdi
	movl	$16777216, %esi
	call	_Z31__device_stub__Z7connectP4NodeiP4Nodei
.L37:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L38
	call	cudaGetErrorString@PLT
	movl	$1, %ecx
	leaq	.LC6(%rip), %rdx
	movq	%rax, %r8
	jmp	.L44
.L38:
	movq	24(%rsp), %rsi
	movl	$75, %edx
	movl	$2, %ecx
	movq	%rbp, %rdi
	salq	$26, %rdx
	leaq	_ZSt4cout(%rip), %r13
	call	cudaMemcpy@PLT
	leaq	72(%rsp), %rsi
	movl	$2, %edi
	call	clock_gettime@PLT
	movq	80(%rsp), %rcx
	movq	64(%rsp), %rsi
	movq	56(%rsp), %rdi
	movq	72(%rsp), %rdx
	call	_Z4diff8timespecS_
	movq	24(%rsp), %rdi
	cvtsi2sdq	%rax, %xmm1
	cvtsi2sdq	%rdx, %xmm0
	divsd	.LC7(%rip), %xmm0
	addsd	%xmm1, %xmm0
	mulsd	.LC8(%rip), %xmm0
	xorps	%xmm1, %xmm1
	addsd	%xmm0, %xmm1
	movsd	%xmm0, 8(%rsp)
	movq	%xmm1, %r12
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC10(%rip), %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$1, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	leaq	.LC12(%rip), %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$16777216, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$25, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	movq	%r12, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$96, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3917:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z7connectP4Nodei"
.LC15:
	.string	"_Z6assignP4NodeS0_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3947:
	.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	.LC14(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7connectP4Nodei(%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	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC15(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z6assignP4NodeS0_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3947:
	.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
.LC7:
	.long	0
	.long	1104006501
	.align 8
.LC8:
	.long	0
	.long	1083129856
	.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 <time.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>

using namespace std;

struct Node{
	int key;
	int nextIdx;
	int nextLevel;
};

__global__ void assign(Node *sl, Node *data)
{
	int i = blockIdx.x * blockDim.x + threadIdx.x;
	int k = data[i].key;
	sl[k - 1].key = k;
	sl[k - 1].nextIdx = k;
}

__global__ void connect(Node *sl, int N)
{
	int id = blockIdx.x * blockDim.x + threadIdx.x;
	int level = 1;
	for (int i = 2; i < N+1; i = i * 2)
	{
		if (id%i == 0)
		{
			int newid = id + level*N;
			sl[newid].key = sl[id].key;
			sl[newid].nextIdx = newid + i;
			sl[newid].nextLevel = newid - N;
		}
		level++;
	}

}


struct timespec diff(timespec start, timespec end)
{
	struct timespec temp;
	if ((end.tv_nsec - start.tv_nsec) < 0) {
		temp.tv_sec = end.tv_sec - start.tv_sec - 1;
		temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec;
	}
	else {
		temp.tv_sec = end.tv_sec - start.tv_sec;
		temp.tv_nsec = end.tv_nsec - start.tv_nsec;
	}
	return temp;
}


void print(Node *sl, int N, int MAX_LEVEL)
{
	cout << "Index:" << endl;
	for (int i = 0; i<N*MAX_LEVEL; i++)
	{
		cout << setw(4) << sl[i].key;
		if ((i + 1) % N == 0)
			cout << endl;
	}
	printf("NextIndex:\n");
	for (int i = 0; i<N*MAX_LEVEL; i++)
	{
		cout << setw(4) << sl[i].nextIdx;
		if ((i + 1) % N == 0)
			cout << endl;
	}
	printf("NextLevel:\n");
	for (int i = 0; i<N*MAX_LEVEL; i++)
	{
	    cout << setw(4) << sl[i].nextLevel;
		if ((i + 1) % N == 0)
			cout << endl;
	}
}

int main()
{
	int N=1024*1024*16, MAX_LEVEL=25;
//	cin >> N >> MAX_LEVEL;
//	for(MAX_LEVEL=26;MAX_LEVEL<26;MAX_LEVEL++)
//	{
	Node *sl, *d_sl;
	Node *data, *d_data;
	struct timespec start, end, temp;
	hipError_t err = hipSuccess;
	double time_used, sum = 0;
	int loop;
	
	sl = (Node *)malloc(N * sizeof(Node) * MAX_LEVEL);
	data = (Node *)malloc(N * sizeof(Node));
 	for(loop=1;loop<2;loop++)
	{
		for (int i = 0; i < N; i++)
		{
			data[i].key =i+1;
		}
		int random = 1000;
		while (random--) {
			int i = rand() % N;
			int j = rand() % N;
			int tmp = data[i].key;
			data[i].key = data[j].key;
			data[j].key = tmp;
		}

		for (int i = 0; i < MAX_LEVEL * N; i++) {
			sl[i].key = -1;
			sl[i].nextLevel = -1;
			sl[i].nextIdx = -1;
		}

		clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
	
	//	size_t free, max;
//		cudaMemGetInfo(&free, &max);
  //    	cout << "free: " << free << " total: " << max << endl;

		err = hipMalloc(&d_data, N * sizeof(Node));
		if (err != hipSuccess) 
		{
     		//cout << "Failed to malloc data in loop " << loop << " : " << cudaGetErrorString(err);
			fprintf(stderr, "Failed to malloc data in loop %d : %s\n", loop, hipGetErrorString(err));
      		exit(EXIT_FAILURE);
    	}

		err = hipMalloc(&d_sl, N * sizeof(Node) * MAX_LEVEL * 2 );
		if (err != hipSuccess) 
		{
     		fprintf(stderr, "Failed to malloc sl in loop %d : %s\n", loop, hipGetErrorString(err));
     	    exit(EXIT_FAILURE);
        }
	
	//	int memoryused = N * sizeof(Node) * MAX_LEVEL*2 + N * sizeof(Node);
	//	cudaMemGetInfo(&free, &max);
	//	cout << "free: " << free << " total: " << max << endl;
	//	cout << "Memory Used: " << memoryused << endl;
	//	cout << free + memoryused;

		hipMemcpy(d_data, data, N * sizeof(Node), hipMemcpyHostToDevice);
		if (err != hipSuccess) 
		{
			fprintf(stderr, "Failed to copy data in loop %d : %s\n", loop, hipGetErrorString(err));
            exit(EXIT_FAILURE);
    	}

		hipMemcpy(d_sl, sl, N * sizeof(Node) * MAX_LEVEL, hipMemcpyHostToDevice);
		if (err != hipSuccess) 
		{
      		fprintf(stderr, "Failed to copy sl in loop %d : %s\n", loop, hipGetErrorString(err));
            exit(EXIT_FAILURE);
        }
		int block = N/1024;
		assign <<< block, 1024 >>> (d_sl,d_data);
		err = hipGetLastError();
		if (err != hipSuccess) 
		{
            fprintf(stderr, "Failed to assign in loop %d : %s\n", loop, hipGetErrorString(err));
            exit(EXIT_FAILURE);
        }

		connect <<< block,1024 >>> (d_sl, N);
		err = hipGetLastError();
		
		if (err != hipSuccess) 
		{
    	    fprintf(stderr, "Failed to connect in loop %d : %s\n", loop, hipGetErrorString(err));
            exit(EXIT_FAILURE);
        }

		hipMemcpy(sl, d_sl, N * sizeof(Node) * MAX_LEVEL, hipMemcpyDeviceToHost);
		if (err != hipSuccess) 
		{
            fprintf(stderr, "Failed to memory copy back to host in loop %d : %s\n", loop, hipGetErrorString(err));
            exit(EXIT_FAILURE);
        }

		clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end);
		temp = diff(start, end);
		time_used = 1000 * (temp.tv_sec + (double)temp.tv_nsec / 1000000000.0);
		sum += time_used;

		//print(sl, N, MAX_ELVEL);

		hipFree(d_sl);
		hipFree(d_data);
		cout << "loop: " << loop << " time: " << time_used << endl;	
	}

	cout << "Data:" << N << endl << "Maxlevel: " << MAX_LEVEL << endl << sum/(loop-1) << endl << endl;
	free(sl);
	free(data);
//	N=N*2;
//	}
//	system("pause");
    return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z21__device_stub__assignP4NodeS0_ # -- Begin function _Z21__device_stub__assignP4NodeS0_
	.type	_Z21__device_stub__assignP4NodeS0_,@function
_Z21__device_stub__assignP4NodeS0_:     # @_Z21__device_stub__assignP4NodeS0_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.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	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z6assignP4NodeS0_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z21__device_stub__assignP4NodeS0_, .Lfunc_end0-_Z21__device_stub__assignP4NodeS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__connectP4Nodei # -- Begin function _Z22__device_stub__connectP4Nodei
	.type	_Z22__device_stub__connectP4Nodei,@function
_Z22__device_stub__connectP4Nodei:      # @_Z22__device_stub__connectP4Nodei
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.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)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%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	$_Z7connectP4Nodei, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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_end1:
	.size	_Z22__device_stub__connectP4Nodei, .Lfunc_end1-_Z22__device_stub__connectP4Nodei
	.cfi_endproc
                                        # -- End function
	.globl	_Z4diff8timespecS_              # -- Begin function _Z4diff8timespecS_
	.type	_Z4diff8timespecS_,@function
_Z4diff8timespecS_:                     # @_Z4diff8timespecS_
	.cfi_startproc
# %bb.0:
	subq	%rsi, %rcx
	leaq	1000000000(%rcx), %rsi
	movq	%rdi, %rax
	negq	%rax
	testq	%rcx, %rcx
	notq	%rdi
	cmovsq	%rdi, %rax
	cmovnsq	%rcx, %rsi
	addq	%rdx, %rax
	movq	%rsi, %rdx
	retq
.Lfunc_end2:
	.size	_Z4diff8timespecS_, .Lfunc_end2-_Z4diff8timespecS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z5printP4Nodeii                # -- Begin function _Z5printP4Nodeii
	.type	_Z5printP4Nodeii,@function
_Z5printP4Nodeii:                       # @_Z5printP4Nodeii
	.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
	movl	%edx, %ebp
	movl	%esi, %ebx
	movq	%rdi, %r14
	movl	$_ZSt4cout, %r12d
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$6, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	imull	%ebx, %ebp
	testl	%ebp, %ebp
	jle	.LBB3_1
# %bb.14:                               # %.lr.ph.preheader
	movl	%ebp, 12(%rsp)                  # 4-byte Spill
	movl	%ebp, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	leaq	(,%rax,4), %rax
	leaq	(%rax,%rax,2), %r13
	movl	$1, %r15d
	xorl	%ebp, %ebp
.LBB3_15:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	movq	$4, _ZSt4cout+16(%rax)
	movl	(%r14,%rbp), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movl	%r15d, %eax
	cltd
	idivl	%ebx
	testl	%edx, %edx
	jne	.LBB3_17
# %bb.16:                               #   in Loop: Header=BB3_15 Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB3_17:                               #   in Loop: Header=BB3_15 Depth=1
	addq	$12, %rbp
	incl	%r15d
	cmpq	%rbp, %r13
	jne	.LBB3_15
# %bb.3:                                # %._crit_edge
	movl	$.Lstr, %edi
	callq	puts@PLT
	cmpl	$0, 12(%rsp)                    # 4-byte Folded Reload
	jle	.LBB3_2
# %bb.4:                                # %.lr.ph33.preheader
	movl	$1, %r15d
	xorl	%r12d, %r12d
	movl	$_ZSt4cout, %ebp
.LBB3_5:                                # %.lr.ph33
                                        # =>This Inner Loop Header: Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	movq	$4, _ZSt4cout+16(%rax)
	movl	4(%r14,%r12), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movl	%r15d, %eax
	cltd
	idivl	%ebx
	testl	%edx, %edx
	jne	.LBB3_7
# %bb.6:                                #   in Loop: Header=BB3_5 Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbp, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB3_7:                                #   in Loop: Header=BB3_5 Depth=1
	addq	$12, %r12
	incl	%r15d
	cmpq	%r12, %r13
	jne	.LBB3_5
# %bb.8:                                # %._crit_edge34
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	cmpl	$0, 12(%rsp)                    # 4-byte Folded Reload
	jle	.LBB3_13
# %bb.9:                                # %.lr.ph38.preheader
	movq	16(%rsp), %rax                  # 8-byte Reload
	shlq	$2, %rax
	leaq	(%rax,%rax,2), %r15
	movl	$1, %ebp
	xorl	%r12d, %r12d
	movl	$_ZSt4cout, %r13d
.LBB3_10:                               # %.lr.ph38
                                        # =>This Inner Loop Header: Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	movq	$4, _ZSt4cout+16(%rax)
	movl	8(%r14,%r12), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movl	%ebp, %eax
	cltd
	idivl	%ebx
	testl	%edx, %edx
	jne	.LBB3_12
# %bb.11:                               #   in Loop: Header=BB3_10 Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r13, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB3_12:                               #   in Loop: Header=BB3_10 Depth=1
	addq	$12, %r12
	incl	%ebp
	cmpq	%r12, %r15
	jne	.LBB3_10
.LBB3_13:                               # %._crit_edge39
	addq	$24, %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
.LBB3_1:                                # %._crit_edge.thread
	.cfi_def_cfa_offset 80
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB3_2:                                # %._crit_edge34.thread
	movl	$.Lstr.1, %edi
	addq	$24, %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
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end3:
	.size	_Z5printP4Nodeii, .Lfunc_end3-_Z5printP4Nodeii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI4_0:
	.quad	0x41cdcd6500000000              # double 1.0E+9
.LCPI4_1:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:                                # %.preheader116
	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	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movabsq	$5033164800, %rdi               # imm = 0x12C000000
	callq	malloc
	movq	%rax, %r15
	movl	$201326592, %edi                # imm = 0xC000000
	callq	malloc
	movq	%rax, %r14
	movl	$1, %eax
	xorl	%ecx, %ecx
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	movl	%eax, (%r14,%rcx)
	addq	$12, %rcx
	incl	%eax
	cmpq	$201326592, %rcx                # imm = 0xC000000
	jne	.LBB4_1
# %bb.2:                                # %.preheader115.preheader
	movl	$-1000, %ebp                    # imm = 0xFC18
	movl	$16777215, %r13d                # imm = 0xFFFFFF
	movl	$-16777216, %ebx                # imm = 0xFF000000
.LBB4_3:                                # %.preheader115
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movl	%eax, %r12d
	leal	(%r12,%r13), %eax
	testl	%r12d, %r12d
	cmovnsl	%r12d, %eax
	andl	%ebx, %eax
	subl	%eax, %r12d
	callq	rand
                                        # kill: def $eax killed $eax def $rax
	leal	(%rax,%r13), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	andl	%ebx, %ecx
	subl	%ecx, %eax
	movslq	%r12d, %rcx
	leaq	(%rcx,%rcx,2), %rcx
	movl	(%r14,%rcx,4), %edx
	cltq
	leaq	(%rax,%rax,2), %rax
	movl	(%r14,%rax,4), %esi
	movl	%esi, (%r14,%rcx,4)
	movl	%edx, (%r14,%rax,4)
	incl	%ebp
	jne	.LBB4_3
# %bb.4:                                # %.preheader.preheader
	movabsq	$5033164800, %rdx               # imm = 0x12C000000
	movq	%r15, %rbx
	movq	%r15, %rdi
	movl	$255, %esi
	callq	memset@PLT
	leaq	40(%rsp), %rsi
	movl	$2, %edi
	callq	clock_gettime
	leaq	16(%rsp), %rdi
	movl	$201326592, %esi                # imm = 0xC000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB4_5
# %bb.7:
	leaq	8(%rsp), %rdi
	movabsq	$10066329600, %rsi              # imm = 0x258000000
	callq	hipMalloc
	testl	%eax, %eax
	movabsq	$5033164800, %r15               # imm = 0x12C000000
	jne	.LBB4_8
# %bb.9:
	movq	16(%rsp), %rdi
	movl	$201326592, %edx                # imm = 0xC000000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	-738196480(%r15), %r12
	leaq	-738181120(%r15), %r13
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_11
# %bb.10:
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	callq	_Z21__device_stub__assignP4NodeS0_
.LBB4_11:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB4_12
# %bb.13:
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_15
# %bb.14:
	movq	8(%rsp), %rdi
	movl	$16777216, %esi                 # imm = 0x1000000
	callq	_Z22__device_stub__connectP4Nodei
.LBB4_15:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB4_16
# %bb.17:
	movq	8(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	56(%rsp), %r15
	movl	$2, %edi
	movq	%r15, %rsi
	callq	clock_gettime
	movq	40(%rsp), %rax
	movq	8(%r15), %rcx
	subq	48(%rsp), %rcx
	leaq	1000000000(%rcx), %rdx
	movq	%rax, %rsi
	negq	%rsi
	testq	%rcx, %rcx
	notq	%rax
	cmovnsq	%rsi, %rax
	cmovnsq	%rcx, %rdx
	addq	(%r15), %rax
	cvtsi2sd	%rax, %xmm0
	cvtsi2sd	%rdx, %xmm1
	divsd	.LCPI4_0(%rip), %xmm1
	addsd	%xmm0, %xmm1
	mulsd	.LCPI4_1(%rip), %xmm1
	movsd	%xmm1, 24(%rsp)                 # 8-byte Spill
	xorpd	%xmm0, %xmm0
	addsd	%xmm1, %xmm0
	movsd	%xmm0, 32(%rsp)                 # 8-byte Spill
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	movl	$6, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$1, %esi
	callq	_ZNSolsEi
	movq	%rax, %r15
	movl	$.L.str.11, %esi
	movl	$7, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r15, %rdi
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.12, %esi
	movl	$5, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$16777216, %esi                 # imm = 0x1000000
	callq	_ZNSolsEi
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rax, %r15
	movl	$.L.str.13, %esi
	movl	$10, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r15, %rdi
	movl	$25, %esi
	callq	_ZNSolsEi
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rax, %rdi
	movsd	32(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$72, %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
.LBB4_5:
	.cfi_def_cfa_offset 128
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	jmp	.LBB4_6
.LBB4_8:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	jmp	.LBB4_6
.LBB4_12:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.7, %esi
	jmp	.LBB4_6
.LBB4_16:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
.LBB4_6:
	movq	%rbx, %rdi
	movl	$1, %edx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6assignP4NodeS0_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7connectP4Nodei, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z6assignP4NodeS0_,@object      # @_Z6assignP4NodeS0_
	.section	.rodata,"a",@progbits
	.globl	_Z6assignP4NodeS0_
	.p2align	3, 0x0
_Z6assignP4NodeS0_:
	.quad	_Z21__device_stub__assignP4NodeS0_
	.size	_Z6assignP4NodeS0_, 8

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Index:"
	.size	.L.str, 7

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Failed to malloc data in loop %d : %s\n"
	.size	.L.str.3, 39

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Failed to malloc sl in loop %d : %s\n"
	.size	.L.str.4, 37

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Failed to assign in loop %d : %s\n"
	.size	.L.str.7, 34

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Failed to connect in loop %d : %s\n"
	.size	.L.str.8, 35

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"loop: "
	.size	.L.str.10, 7

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	" time: "
	.size	.L.str.11, 8

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Data:"
	.size	.L.str.12, 6

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Maxlevel: "
	.size	.L.str.13, 11

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6assignP4NodeS0_"
	.size	.L__unnamed_1, 19

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z7connectP4Nodei"
	.size	.L__unnamed_2, 18

	.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	"NextIndex:"
	.size	.Lstr, 11

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"NextLevel:"
	.size	.Lstr.1, 11

	.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 _Z21__device_stub__assignP4NodeS0_
	.addrsig_sym _Z22__device_stub__connectP4Nodei
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6assignP4NodeS0_
	.addrsig_sym _Z7connectP4Nodei
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6assignP4NodeS0_      ; -- Begin function _Z6assignP4NodeS0_
	.globl	_Z6assignP4NodeS0_
	.p2align	8
	.type	_Z6assignP4NodeS0_,@function
_Z6assignP4NodeS0_:                     ; @_Z6assignP4NodeS0_
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_mad_i64_i32 v[2:3], null, v1, 12, s[2:3]
	global_load_b32 v0, v[2:3], off
	s_waitcnt vmcnt(0)
	v_mad_i64_i32 v[2:3], null, v0, 12, s[0:1]
	v_mov_b32_e32 v1, v0
	global_store_b64 v[2:3], v[0:1], off offset:-12
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6assignP4NodeS0_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 4
		.amdhsa_next_free_sgpr 16
		.amdhsa_reserve_vcc 0
		.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	_Z6assignP4NodeS0_, .Lfunc_end0-_Z6assignP4NodeS0_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 96
; NumSgprs: 16
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 16
; NumVGPRsForWavesPerEU: 4
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z7connectP4Nodei       ; -- Begin function _Z7connectP4Nodei
	.globl	_Z7connectP4Nodei
	.p2align	8
	.type	_Z7connectP4Nodei,@function
_Z7connectP4Nodei:                      ; @_Z7connectP4Nodei
; %bb.0:
	s_load_b32 s2, s[0:1], 0x8
	s_mov_b32 s3, 2
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s2, 2
	s_cbranch_scc1 .LBB1_5
; %bb.1:                                ; %.lr.ph
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b64 s[0:1], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_mov_b32 s4, 0
	v_mad_i64_i32 v[2:3], null, v1, 12, s[0:1]
	v_add_nc_u32_e32 v0, s2, v1
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_add_i32 s5, s3, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_and_b32_e32 v4, s5, v1
	s_mov_b32 s5, exec_lo
	v_cmpx_eq_u32_e32 0, v4
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	global_load_b32 v10, v[2:3], off
	v_add_nc_u32_e32 v8, s4, v0
	s_add_i32 s6, s2, s4
	v_add_nc_u32_e32 v9, s4, v1
	v_mad_i64_i32 v[4:5], null, s6, 12, v[2:3]
	s_delay_alu instid0(VALU_DEP_3)
	v_mad_i64_i32 v[6:7], null, v8, 12, s[0:1]
	v_add_nc_u32_e32 v8, s3, v8
	s_waitcnt vmcnt(0)
	s_clause 0x1
	global_store_b32 v[4:5], v10, off
	global_store_b64 v[6:7], v[8:9], off offset:4
.LBB1_4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
	s_lshl_b32 s3, s3, 1
	s_add_i32 s4, s4, s2
	s_cmp_gt_i32 s3, s2
	s_cbranch_scc0 .LBB1_2
.LBB1_5:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7connectP4Nodei
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 11
		.amdhsa_next_free_sgpr 16
		.amdhsa_reserve_vcc 0
		.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_end1:
	.size	_Z7connectP4Nodei, .Lfunc_end1-_Z7connectP4Nodei
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 208
; NumSgprs: 16
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 16
; NumVGPRsForWavesPerEU: 11
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     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:           _Z6assignP4NodeS0_
    .private_segment_fixed_size: 0
    .sgpr_count:     16
    .sgpr_spill_count: 0
    .symbol:         _Z6assignP4NodeS0_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .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: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7connectP4Nodei
    .private_segment_fixed_size: 0
    .sgpr_count:     16
    .sgpr_spill_count: 0
    .symbol:         _Z7connectP4Nodei.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
