#include <stdlib.h>
#include <stdio.h>
#define L 100

__global__ void kernelcount_nonz(int size, double *A, int *nonz, int *rowptr)
{
	int tid = threadIdx.x, count = 0;
	for(int i = 0; i < size; i++)
	{
		if(A[tid*size + i] != 0.0)
		{
			count ++;
		}
	}
	nonz[tid] = count;

	__syncthreads();

	count = 0;
	for(int i = 0; i <= tid; i++)
	{
		count += nonz[i];
	}
	rowptr[tid + 1] = count;
}

__global__ void kernelCSR(int size, double *A, double *value, int *colidx, int *rowptr)
{
	int tid = threadIdx.x;
	int idx = rowptr[tid], count = 0;
	for(int i = 0; i < size; i++)
	{
		if(A[tid*size + i] != 0)
		{
			value[idx + count] = A[tid*size + i];
			colidx[idx + count] = i;
			count ++;
		}
	}
}

int main()
{
	int size;
	double *A, *d_A, *value, *d_value;
	float time;
	int *colidx, *d_colidx, *rowptr, *d_rowptr, *d_nonzero;
	char ans;
	FILE *fp;

	printf("Do you want to input the data from the file?\n");
	scanf("%c", &ans);

	if(ans == 'y' || ans == 'Y')
	{
		char filename[L];

		printf("\nWhat's your file name?\n");
		scanf("%s", filename);

		printf("What is the size of the matrix A?\n");
		scanf("%d", &size);

		A = (double*) malloc (size*size*sizeof(*A));
		rowptr = (int*) malloc ((size+1)*sizeof(*rowptr));
		rowptr[0] = 0;

		fp = fopen(filename, "r");
		if(!fp)
		{
			printf("Fail to open the file!\n");
			return 0;
		}
		else
			printf("Success to open the file!\n\n");

		printf("Start to input the dense matrix...\n");

		for(int i = 0; i < size; i++)
		{
			for(int j = 0; j < size; j++)
			{
				fscanf( fp, "%lf", &A[i*size + j]);
			}
		}
		printf("Done!\n");
		fclose(fp);
		printf("Close the file!\n");
	}
	else
	{
		int choice;
		printf("Ok, let's start to construct the matrix stored in dense.\n");
		printf("1. 0-1 criss-crossing matrix.\n");
		printf("2. 1D Poisson differential matrix.\n");
		printf("What's your choice?\n");
		scanf("%d", &choice);
		printf("What's the size of this matrix?\n");
		scanf("%d", &size);

		A = (double*) malloc (size*size*sizeof(*A));
		rowptr = (int*) malloc ((size+1)*sizeof(*rowptr));
		rowptr[0] = 0;

		if(choice == 1)
		{
			for(int i = 0; i < size; i++)
			{
				for(int j = 0; j < size; j++)
				{
					if((i + j)%2 == 0)
						A[i*size + j] = 0;
					else
						A[i*size + j] = 1;
				}
			}
		}
		else if (choice == 2)
		{
			for(int i = 0; i < size; i++)
			{
				for(int j = 0; j < size; j++)
				{
					A[i*size + j] = 0;
				}
			}

			for(int i = 0; i < size; i++)
			{
				A[i*size + i] = 2;
				A[i*size + i - 1] = -1;
				A[(i+1)*size + i] = -1;	
			}
			A[size*size - 1] = 2;
		}
		else
		{
			printf("No this choice!\n");
			return 0;
		}
		printf("Done\n");
	}

	printf("====================================\n\n");

	printf("Start to convert the dense matrix to sparse matrix with CSR!\n");

	cudaEvent_t start, stop;

	cudaEventCreate (&start);
	cudaEventCreate (&stop);
	cudaEventRecord(start, 0);

	cudaMalloc( (void**) &d_A, size*size*sizeof(double));
	cudaMalloc( (void**) &d_rowptr, (size+1)*sizeof(int));
	cudaMalloc( (void**) &d_nonzero, size*sizeof(int));

	cudaMemcpy( d_A, A, size*size*sizeof(double), cudaMemcpyHostToDevice);
	cudaMemcpy( d_rowptr, rowptr, (size+1)*sizeof(int), cudaMemcpyHostToDevice);

	dim3 block(size);
  	dim3 grid(1);

  	kernelcount_nonz<<< grid, block>>>(size, d_A, d_nonzero, d_rowptr);

  	cudaMemcpy( rowptr, d_rowptr, (size+1)*sizeof(int), cudaMemcpyDeviceToHost);

  	cudaMalloc( (void**) &d_value, rowptr[size]*sizeof(double));
	cudaMalloc( (void**) &d_colidx, rowptr[size]*sizeof(int));

  	kernelCSR<<< grid, block>>>(size, d_A, d_value, d_colidx, d_rowptr);

  	value = (double*) malloc (rowptr[size]*sizeof(*value));
  	colidx = (int*) malloc (rowptr[size]*sizeof(*colidx));

  	cudaMemcpy( value, d_value, rowptr[size]*sizeof(double), cudaMemcpyDeviceToHost);
  	cudaMemcpy( colidx, d_colidx, rowptr[size]*sizeof(int), cudaMemcpyDeviceToHost);

  	cudaThreadSynchronize();
	cudaEventRecord(stop, 0);

	cudaEventSynchronize(stop);
	cudaEventElapsedTime(&time, start, stop);
	printf( "Global memory processing time: %f (ms)\n" , time);

 	cudaFree(d_A);
  	cudaFree(d_value);
  	cudaFree(d_colidx);
  	cudaFree(d_rowptr);
  	cudaFree(d_nonzero);
  	printf("Successfully free the cuda memory\n");

	printf("====================================\n\n");

	char file[] = "CSR_gpu.txt";

	fp = fopen(file, "w");
	if(!fp)
	{
		printf("Fail to open the file!\n");
		return 0;
	}
	else
		printf("Start to write the file!\n");

	for(int i = 0; i < rowptr[size]; i++)
	{
		if(i < rowptr[size])
		{
			fprintf( fp,"%f,", value[i]);
		}
		else
		{
			fprintf( fp, "%f\n", value[i]);
		}
	}

	for(int i = 0; i < rowptr[size]; i++)
	{
		if(i < rowptr[size])
		{
			fprintf( fp, "%d,", colidx[i]);
		}
		else
		{
			fprintf( fp, "%d\n", colidx[i]);
		}
	}

	for(int i = 0; i < size + 1; i++)
	{
		if(i <= size)
		{
			fprintf( fp, "%d,", rowptr[i]);
		}
		else
		{
			fprintf( fp, "%d\n", rowptr[i]);
		}
	}

	fclose(fp);
	printf("Close the file!\n");
/*
	free(A);
	free(value);
	free(colidx);
	free(rowptr);
	printf("Successfully free the memory\n\n");
*/
	return 0;
}
	.file	"tmpxft_0028414d_00000000-6_ex4_gpu_v2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z42__device_stub__Z16kernelcount_nonziPdPiS0_iPdPiS0_
	.type	_Z42__device_stub__Z16kernelcount_nonziPdPiS0_iPdPiS0_, @function
_Z42__device_stub__Z16kernelcount_nonziPdPiS0_iPdPiS0_:
.LFB2052:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, 28(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z16kernelcount_nonziPdPiS0_(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z42__device_stub__Z16kernelcount_nonziPdPiS0_iPdPiS0_, .-_Z42__device_stub__Z16kernelcount_nonziPdPiS0_iPdPiS0_
	.globl	_Z16kernelcount_nonziPdPiS0_
	.type	_Z16kernelcount_nonziPdPiS0_, @function
_Z16kernelcount_nonziPdPiS0_:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z16kernelcount_nonziPdPiS0_iPdPiS0_
	.cfi_endproc
.LFE2053:
	.size	_Z16kernelcount_nonziPdPiS0_, .-_Z16kernelcount_nonziPdPiS0_
	.globl	_Z36__device_stub__Z9kernelCSRiPdS_PiS0_iPdS_PiS0_
	.type	_Z36__device_stub__Z9kernelCSRiPdS_PiS0_iPdS_PiS0_, @function
_Z36__device_stub__Z9kernelCSRiPdS_PiS0_iPdS_PiS0_:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movl	%edi, 44(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movq	%r8, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z9kernelCSRiPdS_PiS0_(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L8:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z36__device_stub__Z9kernelCSRiPdS_PiS0_iPdS_PiS0_, .-_Z36__device_stub__Z9kernelCSRiPdS_PiS0_iPdS_PiS0_
	.globl	_Z9kernelCSRiPdS_PiS0_
	.type	_Z9kernelCSRiPdS_PiS0_, @function
_Z9kernelCSRiPdS_PiS0_:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z9kernelCSRiPdS_PiS0_iPdS_PiS0_
	.cfi_endproc
.LFE2055:
	.size	_Z9kernelCSRiPdS_PiS0_, .-_Z9kernelCSRiPdS_PiS0_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"Do you want to input the data from the file?\n"
.LC3:
	.string	"%c"
.LC4:
	.string	"\nWhat's your file name?\n"
.LC5:
	.string	"%s"
.LC6:
	.string	"What is the size of the matrix A?\n"
.LC7:
	.string	"%d"
.LC8:
	.string	"r"
.LC9:
	.string	"Fail to open the file!\n"
.LC10:
	.string	"Success to open the file!\n\n"
.LC11:
	.string	"Start to input the dense matrix...\n"
.LC12:
	.string	"%lf"
.LC13:
	.string	"Done!\n"
.LC14:
	.string	"Close the file!\n"
.LC15:
	.string	"Ok, let's start to construct the matrix stored in dense.\n"
.LC16:
	.string	"1. 0-1 criss-crossing matrix.\n"
.LC17:
	.string	"2. 1D Poisson differential matrix.\n"
.LC18:
	.string	"What's your choice?\n"
.LC19:
	.string	"What's the size of this matrix?\n"
.LC22:
	.string	"No this choice!\n"
.LC23:
	.string	"Done\n"
.LC24:
	.string	"====================================\n\n"
.LC25:
	.string	"Start to convert the dense matrix to sparse matrix with CSR!\n"
.LC26:
	.string	"Global memory processing time: %f (ms)\n"
.LC27:
	.string	"Successfully free the cuda memory\n"
.LC28:
	.string	"w"
.LC29:
	.string	"Start to write the file!\n"
.LC30:
	.string	"%f,"
.LC31:
	.string	"%d,"
	.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
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	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
	leaq	.LC7(%rip), %rbx
	subq	$216, %rsp
	.cfi_def_cfa_offset 272
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rbp
	call	__printf_chk@PLT
	xorl	%eax, %eax
	leaq	7(%rsp), %rsi
	leaq	.LC3(%rip), %rdi
	call	__isoc23_scanf@PLT
	movb	7(%rsp), %al
	andl	$-33, %eax
	cmpb	$89, %al
	jne	.L14
	leaq	100(%rsp), %r12
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r12, %rsi
	leaq	.LC5(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	8(%rsp), %ebx
	movl	%ebx, %edi
	imull	%ebx, %edi
	movslq	%edi, %rdi
	salq	$3, %rdi
	call	malloc@PLT
	leal	1(%rbx), %edi
	movslq	%edi, %rdi
	movq	%rax, %rbp
	salq	$2, %rdi
	call	malloc@PLT
	xorl	%edx, %edx
	movq	%r12, %rdi
	leaq	.LC8(%rip), %rsi
	movl	%edx, (%rax)
	movq	%rax, %rbx
	call	fopen@PLT
	movq	%rax, %r12
	testq	%rax, %rax
	je	.L49
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r14d, %r14d
	call	__printf_chk@PLT
	leaq	.LC11(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC12(%rip), %r13
.L17:
	cmpl	%r14d, 8(%rsp)
	jle	.L50
	xorl	%r15d, %r15d
.L19:
	movl	8(%rsp), %eax
	cmpl	%r15d, %eax
	jle	.L51
	imull	%r14d, %eax
	movq	%r13, %rsi
	movq	%r12, %rdi
	addl	%r15d, %eax
	incl	%r15d
	cltq
	leaq	0(%rbp,%rax,8), %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	jmp	.L19
.L51:
	incl	%r14d
	jmp	.L17
.L50:
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	leaq	.LC14(%rip), %rsi
	jmp	.L47
.L14:
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	leaq	88(%rsp), %rsi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC19(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	8(%rsp), %r12d
	movl	%r12d, %r13d
	imull	%r12d, %r13d
	movslq	%r13d, %r13
	salq	$3, %r13
	movq	%r13, %rdi
	call	malloc@PLT
	leal	1(%r12), %edi
	movslq	%edi, %rdi
	movq	%rax, %rbp
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %rbx
	xorl	%eax, %eax
	movl	%eax, (%rbx)
	movl	88(%rsp), %eax
	cmpl	$1, %eax
	jne	.L21
	xorl	%ecx, %ecx
	xorl	%edx, %edx
.L22:
	cmpl	%edx, %r12d
	jle	.L26
	movslq	%ecx, %rax
	leaq	0(%rbp,%rax,8), %rsi
	xorl	%eax, %eax
.L24:
	leal	(%rdx,%rax), %edi
	xorps	%xmm0, %xmm0
	andl	$1, %edi
	je	.L23
	movsd	.LC1(%rip), %xmm0
.L23:
	movsd	%xmm0, (%rsi,%rax,8)
	incq	%rax
	cmpl	%eax, %r12d
	jg	.L24
	incl	%edx
	addl	%r12d, %ecx
	jmp	.L22
.L21:
	leaq	.LC22(%rip), %rsi
	cmpl	$2, %eax
	jne	.L48
	leal	-1(%r12), %eax
	movslq	%r12d, %r10
	movq	%rbp, %rdx
	movq	%rbp, %r8
	leaq	8(,%rax,8), %r11
	leaq	0(,%r10,8), %rsi
	xorl	%r9d, %r9d
	xorl	%eax, %eax
.L28:
	cmpl	%r9d, %r12d
	jle	.L52
	movq	%r8, %rdi
	movq	%r11, %rcx
	incl	%r9d
	addq	%rsi, %r8
	rep stosb
	jmp	.L28
.L52:
	movsd	.LC20(%rip), %xmm0
	movsd	.LC21(%rip), %xmm1
	addq	$8, %rsi
	xorl	%eax, %eax
.L30:
	cmpl	%eax, %r12d
	jle	.L53
	movsd	%xmm0, (%rdx)
	incl	%eax
	movsd	%xmm1, -8(%rdx)
	movsd	%xmm1, (%rdx,%r10,8)
	addq	%rsi, %rdx
	jmp	.L30
.L53:
	movsd	%xmm0, -8(%rbp,%r13)
.L26:
	leaq	.LC23(%rip), %rsi
.L47:
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC24(%rip), %r12
	call	__printf_chk@PLT
	movq	%r12, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC25(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	8(%rsp), %esi
	leaq	16(%rsp), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$3, %rsi
	call	cudaMalloc@PLT
	movl	8(%rsp), %eax
	leaq	40(%rsp), %rdi
	leal	1(%rax), %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movslq	8(%rsp), %rsi
	leaq	48(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	8(%rsp), %edx
	movq	16(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$3, %rdx
	call	cudaMemcpy@PLT
	movl	8(%rsp), %eax
	movq	40(%rsp), %rdi
	movq	%rbx, %rsi
	movl	$1, %ecx
	leal	1(%rax), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	8(%rsp), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movl	$1, 96(%rsp)
	movq	%rdi, 80(%rsp)
	movl	84(%rsp), %ecx
	movl	%eax, 76(%rsp)
	movq	76(%rsp), %rdx
	movq	%rdi, 88(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	movq	40(%rsp), %rcx
	movq	48(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	8(%rsp), %edi
	call	_Z42__device_stub__Z16kernelcount_nonziPdPiS0_iPdPiS0_
.L32:
	movl	8(%rsp), %eax
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	leal	1(%rax), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movslq	8(%rsp), %rax
	leaq	24(%rsp), %rdi
	movslq	(%rbx,%rax,4), %rsi
	salq	$3, %rsi
	call	cudaMalloc@PLT
	movslq	8(%rsp), %rax
	leaq	32(%rsp), %rdi
	movslq	(%rbx,%rax,4), %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	84(%rsp), %ecx
	movl	96(%rsp), %esi
	xorl	%r9d, %r9d
	movq	76(%rsp), %rdx
	movq	88(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	movq	40(%rsp), %r8
	movq	32(%rsp), %rcx
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	8(%rsp), %edi
	call	_Z36__device_stub__Z9kernelCSRiPdS_PiS0_iPdS_PiS0_
.L33:
	movslq	8(%rsp), %rax
	movslq	(%rbx,%rax,4), %rbp
	leaq	0(,%rbp,8), %r15
	movq	%r15, %rdi
	call	malloc@PLT
	leaq	0(,%rbp,4), %rdi
	movq	%rax, %r14
	call	malloc@PLT
	movq	24(%rsp), %rsi
	movq	%r15, %rdx
	movq	%r14, %rdi
	movl	$2, %ecx
	movq	%rax, %r13
	call	cudaMemcpy@PLT
	movslq	8(%rsp), %rax
	movq	32(%rsp), %rsi
	movq	%r13, %rdi
	movl	$2, %ecx
	movslq	(%rbx,%rax,4), %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	call	cudaThreadSynchronize@PLT
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	leaq	12(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC26(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC27(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r12, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	100(%rsp), %rdi
	movabsq	$3347705487303004995, %rax
	leaq	.LC28(%rip), %rsi
	movq	%rax, 100(%rsp)
	movl	$7633012, 108(%rsp)
	call	fopen@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L34
.L49:
	leaq	.LC9(%rip), %rsi
	jmp	.L48
.L34:
	leaq	.LC29(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	call	__printf_chk@PLT
	leaq	.LC30(%rip), %r15
.L35:
	movslq	8(%rsp), %rax
	cmpl	%r12d, (%rbx,%rax,4)
	jle	.L54
	movsd	(%r14,%r12,8), %xmm0
	movq	%r15, %rdx
	movl	$2, %esi
	movb	$1, %al
	movq	%rbp, %rdi
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L35
.L54:
	xorl	%r12d, %r12d
	leaq	.LC31(%rip), %r14
.L37:
	movslq	8(%rsp), %rax
	cmpl	%r12d, (%rbx,%rax,4)
	jle	.L55
	movl	0(%r13,%r12,4), %ecx
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L37
.L55:
	xorl	%r12d, %r12d
	leaq	.LC31(%rip), %r13
.L39:
	cmpl	%r12d, 8(%rsp)
	jl	.L56
	movl	(%rbx,%r12,4), %ecx
	movq	%r13, %rdx
	movl	$2, %esi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L39
.L56:
	movq	%rbp, %rdi
	call	fclose@PLT
	leaq	.LC14(%rip), %rsi
.L48:
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L41
	call	__stack_chk_fail@PLT
.L41:
	addq	$216, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC32:
	.string	"_Z9kernelCSRiPdS_PiS0_"
.LC33:
	.string	"_Z16kernelcount_nonziPdPiS0_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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	.LC32(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z9kernelCSRiPdS_PiS0_(%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	.LC33(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z16kernelcount_nonziPdPiS0_(%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
.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
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1072693248
	.align 8
.LC20:
	.long	0
	.long	1073741824
	.align 8
.LC21:
	.long	0
	.long	-1074790400
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdlib.h>
#include <stdio.h>
#define L 100

__global__ void kernelcount_nonz(int size, double *A, int *nonz, int *rowptr)
{
	int tid = threadIdx.x, count = 0;
	for(int i = 0; i < size; i++)
	{
		if(A[tid*size + i] != 0.0)
		{
			count ++;
		}
	}
	nonz[tid] = count;

	__syncthreads();

	count = 0;
	for(int i = 0; i <= tid; i++)
	{
		count += nonz[i];
	}
	rowptr[tid + 1] = count;
}

__global__ void kernelCSR(int size, double *A, double *value, int *colidx, int *rowptr)
{
	int tid = threadIdx.x;
	int idx = rowptr[tid], count = 0;
	for(int i = 0; i < size; i++)
	{
		if(A[tid*size + i] != 0)
		{
			value[idx + count] = A[tid*size + i];
			colidx[idx + count] = i;
			count ++;
		}
	}
}

int main()
{
	int size;
	double *A, *d_A, *value, *d_value;
	float time;
	int *colidx, *d_colidx, *rowptr, *d_rowptr, *d_nonzero;
	char ans;
	FILE *fp;

	printf("Do you want to input the data from the file?\n");
	scanf("%c", &ans);

	if(ans == 'y' || ans == 'Y')
	{
		char filename[L];

		printf("\nWhat's your file name?\n");
		scanf("%s", filename);

		printf("What is the size of the matrix A?\n");
		scanf("%d", &size);

		A = (double*) malloc (size*size*sizeof(*A));
		rowptr = (int*) malloc ((size+1)*sizeof(*rowptr));
		rowptr[0] = 0;

		fp = fopen(filename, "r");
		if(!fp)
		{
			printf("Fail to open the file!\n");
			return 0;
		}
		else
			printf("Success to open the file!\n\n");

		printf("Start to input the dense matrix...\n");

		for(int i = 0; i < size; i++)
		{
			for(int j = 0; j < size; j++)
			{
				fscanf( fp, "%lf", &A[i*size + j]);
			}
		}
		printf("Done!\n");
		fclose(fp);
		printf("Close the file!\n");
	}
	else
	{
		int choice;
		printf("Ok, let's start to construct the matrix stored in dense.\n");
		printf("1. 0-1 criss-crossing matrix.\n");
		printf("2. 1D Poisson differential matrix.\n");
		printf("What's your choice?\n");
		scanf("%d", &choice);
		printf("What's the size of this matrix?\n");
		scanf("%d", &size);

		A = (double*) malloc (size*size*sizeof(*A));
		rowptr = (int*) malloc ((size+1)*sizeof(*rowptr));
		rowptr[0] = 0;

		if(choice == 1)
		{
			for(int i = 0; i < size; i++)
			{
				for(int j = 0; j < size; j++)
				{
					if((i + j)%2 == 0)
						A[i*size + j] = 0;
					else
						A[i*size + j] = 1;
				}
			}
		}
		else if (choice == 2)
		{
			for(int i = 0; i < size; i++)
			{
				for(int j = 0; j < size; j++)
				{
					A[i*size + j] = 0;
				}
			}

			for(int i = 0; i < size; i++)
			{
				A[i*size + i] = 2;
				A[i*size + i - 1] = -1;
				A[(i+1)*size + i] = -1;	
			}
			A[size*size - 1] = 2;
		}
		else
		{
			printf("No this choice!\n");
			return 0;
		}
		printf("Done\n");
	}

	printf("====================================\n\n");

	printf("Start to convert the dense matrix to sparse matrix with CSR!\n");

	hipEvent_t start, stop;

	hipEventCreate (&start);
	hipEventCreate (&stop);
	hipEventRecord(start, 0);

	hipMalloc( (void**) &d_A, size*size*sizeof(double));
	hipMalloc( (void**) &d_rowptr, (size+1)*sizeof(int));
	hipMalloc( (void**) &d_nonzero, size*sizeof(int));

	hipMemcpy( d_A, A, size*size*sizeof(double), hipMemcpyHostToDevice);
	hipMemcpy( d_rowptr, rowptr, (size+1)*sizeof(int), hipMemcpyHostToDevice);

	dim3 block(size);
  	dim3 grid(1);

  	kernelcount_nonz<<< grid, block>>>(size, d_A, d_nonzero, d_rowptr);

  	hipMemcpy( rowptr, d_rowptr, (size+1)*sizeof(int), hipMemcpyDeviceToHost);

  	hipMalloc( (void**) &d_value, rowptr[size]*sizeof(double));
	hipMalloc( (void**) &d_colidx, rowptr[size]*sizeof(int));

  	kernelCSR<<< grid, block>>>(size, d_A, d_value, d_colidx, d_rowptr);

  	value = (double*) malloc (rowptr[size]*sizeof(*value));
  	colidx = (int*) malloc (rowptr[size]*sizeof(*colidx));

  	hipMemcpy( value, d_value, rowptr[size]*sizeof(double), hipMemcpyDeviceToHost);
  	hipMemcpy( colidx, d_colidx, rowptr[size]*sizeof(int), hipMemcpyDeviceToHost);

  	hipDeviceSynchronize();
	hipEventRecord(stop, 0);

	hipEventSynchronize(stop);
	hipEventElapsedTime(&time, start, stop);
	printf( "Global memory processing time: %f (ms)\n" , time);

 	hipFree(d_A);
  	hipFree(d_value);
  	hipFree(d_colidx);
  	hipFree(d_rowptr);
  	hipFree(d_nonzero);
  	printf("Successfully free the cuda memory\n");

	printf("====================================\n\n");

	char file[] = "CSR_gpu.txt";

	fp = fopen(file, "w");
	if(!fp)
	{
		printf("Fail to open the file!\n");
		return 0;
	}
	else
		printf("Start to write the file!\n");

	for(int i = 0; i < rowptr[size]; i++)
	{
		if(i < rowptr[size])
		{
			fprintf( fp,"%f,", value[i]);
		}
		else
		{
			fprintf( fp, "%f\n", value[i]);
		}
	}

	for(int i = 0; i < rowptr[size]; i++)
	{
		if(i < rowptr[size])
		{
			fprintf( fp, "%d,", colidx[i]);
		}
		else
		{
			fprintf( fp, "%d\n", colidx[i]);
		}
	}

	for(int i = 0; i < size + 1; i++)
	{
		if(i <= size)
		{
			fprintf( fp, "%d,", rowptr[i]);
		}
		else
		{
			fprintf( fp, "%d\n", rowptr[i]);
		}
	}

	fclose(fp);
	printf("Close the file!\n");
/*
	free(A);
	free(value);
	free(colidx);
	free(rowptr);
	printf("Successfully free the memory\n\n");
*/
	return 0;
}
	.text
	.file	"ex4_gpu_v2.hip"
	.globl	_Z31__device_stub__kernelcount_nonziPdPiS0_ # -- Begin function _Z31__device_stub__kernelcount_nonziPdPiS0_
	.type	_Z31__device_stub__kernelcount_nonziPdPiS0_,@function
_Z31__device_stub__kernelcount_nonziPdPiS0_: # @_Z31__device_stub__kernelcount_nonziPdPiS0_
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	4(%rsp), %rax
	movl	%edi, (%rax)
	leaq	40(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	24(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z16kernelcount_nonziPdPiS0_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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	_Z31__device_stub__kernelcount_nonziPdPiS0_, .Lfunc_end0-_Z31__device_stub__kernelcount_nonziPdPiS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__kernelCSRiPdS_PiS0_ # -- Begin function _Z24__device_stub__kernelCSRiPdS_PiS0_
	.type	_Z24__device_stub__kernelCSRiPdS_PiS0_,@function
_Z24__device_stub__kernelCSRiPdS_PiS0_: # @_Z24__device_stub__kernelCSRiPdS_PiS0_
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	56(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	48(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	32(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z9kernelCSRiPdS_PiS0_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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	_Z24__device_stub__kernelCSRiPdS_PiS0_, .Lfunc_end1-_Z24__device_stub__kernelCSRiPdS_PiS0_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI2_0:
	.quad	0x3ff0000000000000              # double 1
	.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	$200, %rsp
	.cfi_def_cfa_offset 256
	.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	$.Lstr, %edi
	callq	puts@PLT
	leaq	7(%rsp), %rbx
	movl	$.L.str.1, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movb	(%rbx), %al
	andb	$-33, %al
	cmpb	$89, %al
	jne	.LBB2_10
# %bb.1:
	movl	$.Lstr.8, %edi
	callq	puts@PLT
	leaq	96(%rsp), %r15
	movl	$.L.str.3, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	$.Lstr.9, %edi
	callq	puts@PLT
	movq	%rsp, %rbx
	movl	$.L.str.5, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movslq	(%rbx), %rbx
	movl	%ebx, %edi
	imull	%edi, %edi
	shlq	$3, %rdi
	callq	malloc
	movq	%rax, %r14
	leaq	4(,%rbx,4), %rdi
	callq	malloc
	movq	%rax, %rbx
	movl	$0, (%rax)
	movl	$.L.str.6, %esi
	movq	%r15, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB2_2
# %bb.3:
	movq	%rax, %r15
	movl	$.Lstr.11, %edi
	callq	puts@PLT
	movl	$.Lstr.12, %edi
	callq	puts@PLT
	movl	(%rsp), %eax
	testl	%eax, %eax
	jle	.LBB2_9
# %bb.4:                                # %.preheader160.preheader
	xorl	%ebp, %ebp
.LBB2_5:                                # %.preheader160
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_7 Depth 2
	testl	%eax, %eax
	jle	.LBB2_8
# %bb.6:                                # %.lr.ph176.preheader
                                        #   in Loop: Header=BB2_5 Depth=1
	xorl	%r12d, %r12d
.LBB2_7:                                # %.lr.ph176
                                        #   Parent Loop BB2_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	imull	%ebp, %eax
	cltq
	addq	%r12, %rax
	leaq	(%r14,%rax,8), %rdx
	movl	$.L.str.10, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	(%rsp), %eax
	incq	%r12
	cmpl	%eax, %r12d
	jl	.LBB2_7
.LBB2_8:                                # %._crit_edge177
                                        #   in Loop: Header=BB2_5 Depth=1
	incl	%ebp
	cmpl	%eax, %ebp
	jl	.LBB2_5
.LBB2_9:                                # %._crit_edge179
	movl	$.Lstr.13, %edi
	callq	puts@PLT
	movq	%r15, %rdi
	callq	fclose
	movl	$.Lstr.21, %edi
	callq	puts@PLT
	movq	%rbx, %rbp
	jmp	.LBB2_27
.LBB2_10:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	leaq	96(%rsp), %r15
	movl	$.L.str.5, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	movq	%rsp, %rbx
	movl	$.L.str.5, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movslq	(%rbx), %r12
	movl	%r12d, %r13d
	movl	%r12d, %ebx
	imull	%ebx, %ebx
	leaq	(,%rbx,8), %rdi
	callq	malloc
	movq	%rax, %r14
	leaq	4(,%r12,4), %rdi
	callq	malloc
	movq	%rax, %rbp
	movl	$0, (%rax)
	movl	(%r15), %eax
	cmpl	$1, %eax
	je	.LBB2_19
# %bb.11:
	cmpl	$2, %eax
	jne	.LBB2_42
# %bb.12:                               # %.preheader165
	movabsq	$4611686018427387904, %rdi      # imm = 0x4000000000000000
	testl	%r12d, %r12d
	jle	.LBB2_18
# %bb.13:                               # %.preheader164.lr.ph
	movq	%rbx, 64(%rsp)                  # 8-byte Spill
	movq	%rbp, 72(%rsp)                  # 8-byte Spill
	movq	%r12, %rax
	incq	%rax
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	leaq	(,%r13,8), %r15
	xorl	%ebp, %ebp
	movq	%r13, %rbx
.LBB2_14:                               # %._crit_edge
                                        # =>This Inner Loop Header: Depth=1
	movl	%ebp, %eax
	leaq	(%r14,%rax,8), %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	memset@PLT
	addl	%r12d, %ebp
	decq	%rbx
	jne	.LBB2_14
# %bb.15:                               # %.preheader163
	testl	%r12d, %r12d
	movq	72(%rsp), %rbp                  # 8-byte Reload
	movq	64(%rsp), %rbx                  # 8-byte Reload
	movabsq	$4611686018427387904, %rdi      # imm = 0x4000000000000000
	movq	56(%rsp), %r8                   # 8-byte Reload
	jle	.LBB2_18
# %bb.16:                               # %.lr.ph169.preheader
	xorl	%eax, %eax
	movabsq	$-4616189618054758400, %rcx     # imm = 0xBFF0000000000000
	movl	%r12d, %edx
	movq	%r14, %rsi
.LBB2_17:                               # %.lr.ph169
                                        # =>This Inner Loop Header: Depth=1
	movslq	%edx, %rdx
	cltq
	movq	%rdi, (%r14,%rax,8)
	movq	%rcx, -8(%r14,%rax,8)
	movq	%rcx, (%rsi,%rdx,8)
	addq	$8, %rsi
	addl	%r12d, %edx
	addl	%r8d, %eax
	decq	%r13
	jne	.LBB2_17
.LBB2_18:                               # %._crit_edge170
	movq	%rdi, -8(%r14,%rbx,8)
	jmp	.LBB2_26
.LBB2_19:                               # %.preheader162
	testl	%r12d, %r12d
	jle	.LBB2_26
# %bb.20:                               # %.preheader161.lr.ph
	xorl	%eax, %eax
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	xorl	%ecx, %ecx
.LBB2_21:                               # %.lr.ph172
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_22 Depth 2
	movl	%eax, %edx
	leaq	(%r14,%rdx,8), %rdx
	xorl	%esi, %esi
.LBB2_22:                               #   Parent Loop BB2_21 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leal	(%rcx,%rsi), %edi
	xorps	%xmm1, %xmm1
	testb	$1, %dil
	je	.LBB2_24
# %bb.23:                               #   in Loop: Header=BB2_22 Depth=2
	movaps	%xmm0, %xmm1
.LBB2_24:                               #   in Loop: Header=BB2_22 Depth=2
	movsd	%xmm1, (%rdx,%rsi,8)
	incq	%rsi
	cmpq	%rsi, %r13
	jne	.LBB2_22
# %bb.25:                               # %._crit_edge173
                                        #   in Loop: Header=BB2_21 Depth=1
	incq	%rcx
	addl	%r12d, %eax
	cmpq	%r13, %rcx
	jne	.LBB2_21
.LBB2_26:                               # %.critedge
	movl	$.Lstr.7, %edi
	callq	puts@PLT
.LBB2_27:
	movabsq	$4294967297, %r15               # imm = 0x100000001
	movl	$.Lstr.18, %edi
	callq	puts@PLT
	movl	$.Lstr.16, %edi
	callq	puts@PLT
	leaq	80(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	(%rsp), %esi
	imull	%esi, %esi
	shlq	$3, %rsi
	leaq	40(%rsp), %r12
	movq	%r12, %rdi
	callq	hipMalloc
	movslq	(%rsp), %rax
	leaq	4(,%rax,4), %rsi
	leaq	8(%rsp), %r13
	movq	%r13, %rdi
	callq	hipMalloc
	movslq	(%rsp), %rsi
	shlq	$2, %rsi
	leaq	48(%rsp), %rdi
	callq	hipMalloc
	movq	(%r12), %rdi
	movl	(%rsp), %edx
	imull	%edx, %edx
	shlq	$3, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	movslq	(%rsp), %rax
	leaq	4(,%rax,4), %rdx
	movq	%rbp, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	(%rsp), %eax
	leaq	(%rax,%r15), %r14
	decq	%r14
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_29
# %bb.28:
	movl	(%rsp), %edi
	movq	40(%rsp), %rsi
	movq	48(%rsp), %rdx
	movq	8(%rsp), %rcx
	callq	_Z31__device_stub__kernelcount_nonziPdPiS0_
.LBB2_29:
	movq	8(%rsp), %rsi
	movslq	(%rsp), %rax
	leaq	4(,%rax,4), %rdx
	movq	%rbp, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movslq	(%rsp), %rax
	movslq	(%rbp,%rax,4), %rsi
	shlq	$3, %rsi
	leaq	32(%rsp), %rdi
	callq	hipMalloc
	movslq	(%rsp), %rax
	movslq	(%rbp,%rax,4), %rsi
	shlq	$2, %rsi
	leaq	24(%rsp), %rdi
	callq	hipMalloc
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_31
# %bb.30:
	movl	(%rsp), %edi
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rcx
	movq	8(%rsp), %r8
	callq	_Z24__device_stub__kernelCSRiPdS_PiS0_
.LBB2_31:
	movslq	(%rsp), %rax
	movslq	(%rbp,%rax,4), %r14
	leaq	(,%r14,8), %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r15
	shlq	$2, %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	32(%rsp), %rsi
	movq	%r15, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rsi
	movslq	(%rsp), %rax
	movslq	(%rbp,%rax,4), %rdx
	shlq	$2, %rdx
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	80(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	92(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%r12), %xmm0
	movl	$.L.str.22, %edi
	movb	$1, %al
	callq	printf
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movl	$.Lstr.17, %edi
	callq	puts@PLT
	movl	$.Lstr.18, %edi
	callq	puts@PLT
	movabsq	$3347705487303004995, %rax      # imm = 0x2E7570675F525343
	leaq	96(%rsp), %rdi
	movq	%rax, (%rdi)
	movl	$7633012, 8(%rdi)               # imm = 0x747874
	movl	$.L.str.24, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB2_2
# %bb.32:
	movq	%rax, %r12
	movl	$.Lstr.20, %edi
	callq	puts@PLT
	movslq	(%rsp), %rax
	cmpl	$0, (%rbp,%rax,4)
	jle	.LBB2_38
# %bb.33:                               # %.lr.ph182.preheader
	xorl	%r13d, %r13d
.LBB2_34:                               # %.lr.ph182
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%r15,%r13,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.26, %esi
	movq	%r12, %rdi
	movb	$1, %al
	callq	fprintf
	incq	%r13
	movslq	(%rsp), %rax
	movslq	(%rbp,%rax,4), %rcx
	cmpq	%rcx, %r13
	jl	.LBB2_34
# %bb.35:                               # %.preheader159
	testl	%ecx, %ecx
	jle	.LBB2_38
# %bb.36:                               # %.lr.ph184.preheader
	xorl	%ebx, %ebx
.LBB2_37:                               # %.lr.ph184
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r14,%rbx,4), %edx
	movl	$.L.str.28, %esi
	movq	%r12, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%rbx
	movslq	(%rsp), %rax
	movslq	(%rbp,%rax,4), %rcx
	cmpq	%rcx, %rbx
	jl	.LBB2_37
.LBB2_38:                               # %.preheader
	testl	%eax, %eax
	js	.LBB2_41
# %bb.39:                               # %.lr.ph187.preheader
	movq	$-1, %r14
.LBB2_40:                               # %.lr.ph187
                                        # =>This Inner Loop Header: Depth=1
	movl	4(%rbp,%r14,4), %edx
	movl	$.L.str.28, %esi
	movq	%r12, %rdi
	xorl	%eax, %eax
	callq	fprintf
	movslq	(%rsp), %rax
	incq	%r14
	cmpq	%rax, %r14
	jl	.LBB2_40
.LBB2_41:                               # %._crit_edge188
	movq	%r12, %rdi
	callq	fclose
	movl	$.Lstr.21, %edi
	jmp	.LBB2_43
.LBB2_2:                                # %.thread
	movl	$.Lstr.19, %edi
	jmp	.LBB2_43
.LBB2_42:
	movl	$.Lstr.6, %edi
.LBB2_43:
	callq	puts@PLT
	xorl	%eax, %eax
	addq	$200, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16kernelcount_nonziPdPiS0_, %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	$_Z9kernelCSRiPdS_PiS0_, %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_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	_Z16kernelcount_nonziPdPiS0_,@object # @_Z16kernelcount_nonziPdPiS0_
	.section	.rodata,"a",@progbits
	.globl	_Z16kernelcount_nonziPdPiS0_
	.p2align	3, 0x0
_Z16kernelcount_nonziPdPiS0_:
	.quad	_Z31__device_stub__kernelcount_nonziPdPiS0_
	.size	_Z16kernelcount_nonziPdPiS0_, 8

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

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"%c"
	.size	.L.str.1, 3

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%s"
	.size	.L.str.3, 3

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%d"
	.size	.L.str.5, 3

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"r"
	.size	.L.str.6, 2

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"%lf"
	.size	.L.str.10, 4

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"Global memory processing time: %f (ms)\n"
	.size	.L.str.22, 40

	.type	.L.str.24,@object               # @.str.24
.L.str.24:
	.asciz	"w"
	.size	.L.str.24, 2

	.type	.L.str.26,@object               # @.str.26
.L.str.26:
	.asciz	"%f,"
	.size	.L.str.26, 4

	.type	.L.str.28,@object               # @.str.28
.L.str.28:
	.asciz	"%d,"
	.size	.L.str.28, 4

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16kernelcount_nonziPdPiS0_"
	.size	.L__unnamed_1, 29

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z9kernelCSRiPdS_PiS0_"
	.size	.L__unnamed_2, 23

	.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	"Do you want to input the data from the file?"
	.size	.Lstr, 45

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Ok, let's start to construct the matrix stored in dense."
	.size	.Lstr.1, 57

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"1. 0-1 criss-crossing matrix."
	.size	.Lstr.2, 30

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"2. 1D Poisson differential matrix."
	.size	.Lstr.3, 35

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"What's your choice?"
	.size	.Lstr.4, 20

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"What's the size of this matrix?"
	.size	.Lstr.5, 32

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"No this choice!"
	.size	.Lstr.6, 16

	.type	.Lstr.7,@object                 # @str.7
.Lstr.7:
	.asciz	"Done"
	.size	.Lstr.7, 5

	.type	.Lstr.8,@object                 # @str.8
.Lstr.8:
	.asciz	"\nWhat's your file name?"
	.size	.Lstr.8, 24

	.type	.Lstr.9,@object                 # @str.9
.Lstr.9:
	.asciz	"What is the size of the matrix A?"
	.size	.Lstr.9, 34

	.type	.Lstr.11,@object                # @str.11
.Lstr.11:
	.asciz	"Success to open the file!\n"
	.size	.Lstr.11, 27

	.type	.Lstr.12,@object                # @str.12
.Lstr.12:
	.asciz	"Start to input the dense matrix..."
	.size	.Lstr.12, 35

	.type	.Lstr.13,@object                # @str.13
.Lstr.13:
	.asciz	"Done!"
	.size	.Lstr.13, 6

	.type	.Lstr.16,@object                # @str.16
.Lstr.16:
	.asciz	"Start to convert the dense matrix to sparse matrix with CSR!"
	.size	.Lstr.16, 61

	.type	.Lstr.17,@object                # @str.17
.Lstr.17:
	.asciz	"Successfully free the cuda memory"
	.size	.Lstr.17, 34

	.type	.Lstr.18,@object                # @str.18
.Lstr.18:
	.asciz	"====================================\n"
	.size	.Lstr.18, 38

	.type	.Lstr.19,@object                # @str.19
.Lstr.19:
	.asciz	"Fail to open the file!"
	.size	.Lstr.19, 23

	.type	.Lstr.20,@object                # @str.20
.Lstr.20:
	.asciz	"Start to write the file!"
	.size	.Lstr.20, 25

	.type	.Lstr.21,@object                # @str.21
.Lstr.21:
	.asciz	"Close the file!"
	.size	.Lstr.21, 16

	.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 _Z31__device_stub__kernelcount_nonziPdPiS0_
	.addrsig_sym _Z24__device_stub__kernelCSRiPdS_PiS0_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z16kernelcount_nonziPdPiS0_
	.addrsig_sym _Z9kernelCSRiPdS_PiS0_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16kernelcount_nonziPdPiS0_ ; -- Begin function _Z16kernelcount_nonziPdPiS0_
	.globl	_Z16kernelcount_nonziPdPiS0_
	.p2align	8
	.type	_Z16kernelcount_nonziPdPiS0_,@function
_Z16kernelcount_nonziPdPiS0_:           ; @_Z16kernelcount_nonziPdPiS0_
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x0
	s_load_b128 s[4:7], s[0:1], 0x8
	s_load_b64 s[0:1], s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s2, 1
	s_cbranch_scc1 .LBB0_3
; %bb.1:                                ; %.lr.ph
	v_mul_lo_u32 v1, v0, s2
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 3, v[1:2]
	v_add_co_u32 v3, vcc_lo, s4, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	global_load_b64 v[5:6], v[3:4], off
	v_add_co_u32 v3, vcc_lo, v3, 8
	v_add_co_ci_u32_e32 v4, vcc_lo, 0, v4, vcc_lo
	s_add_i32 s2, s2, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s2, 0
	s_waitcnt vmcnt(0)
	v_cmp_neq_f64_e32 vcc_lo, 0, v[5:6]
	v_add_co_ci_u32_e32 v2, vcc_lo, 0, v2, vcc_lo
	s_cbranch_scc0 .LBB0_2
	s_branch .LBB0_4
.LBB0_3:
	v_mov_b32_e32 v2, 0
.LBB0_4:                                ; %Flow47
	v_lshlrev_b32_e32 v5, 2, v0
	v_dual_mov_b32 v1, 0 :: v_dual_add_nc_u32 v4, 1, v0
	v_mov_b32_e32 v3, 0
	s_mov_b32 s2, 0
	global_store_b32 v5, v2, s[6:7]
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
.LBB0_5:                                ; =>This Inner Loop Header: Depth=1
	global_load_b32 v2, v1, s[6:7]
	v_add_nc_u32_e32 v4, -1, v4
	s_add_u32 s6, s6, 4
	s_addc_u32 s7, s7, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_eq_u32_e32 vcc_lo, 0, v4
	s_or_b32 s2, vcc_lo, s2
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v3, v2, v3
	s_and_not1_b32 exec_lo, exec_lo, s2
	s_cbranch_execnz .LBB0_5
; %bb.6:
	s_or_b32 exec_lo, exec_lo, s2
	v_lshlrev_b32_e32 v0, 2, v0
	global_store_b32 v0, v3, s[0:1] offset:4
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16kernelcount_nonziPdPiS0_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.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 7
		.amdhsa_next_free_sgpr 8
		.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	_Z16kernelcount_nonziPdPiS0_, .Lfunc_end0-_Z16kernelcount_nonziPdPiS0_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 256
; NumSgprs: 10
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 10
; NumVGPRsForWavesPerEU: 7
; 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
	.protected	_Z9kernelCSRiPdS_PiS0_  ; -- Begin function _Z9kernelCSRiPdS_PiS0_
	.globl	_Z9kernelCSRiPdS_PiS0_
	.p2align	8
	.type	_Z9kernelCSRiPdS_PiS0_,@function
_Z9kernelCSRiPdS_PiS0_:                 ; @_Z9kernelCSRiPdS_PiS0_
; %bb.0:
	s_load_b32 s8, s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s8, 1
	s_cbranch_scc1 .LBB1_5
; %bb.1:                                ; %.lr.ph
	s_load_b256 s[0:7], s[0:1], 0x8
	v_dual_mov_b32 v2, 0 :: v_dual_lshlrev_b32 v1, 2, v0
	s_waitcnt lgkmcnt(0)
	global_load_b32 v5, v1, s[6:7]
	v_mul_lo_u32 v1, v0, s8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 3, v[1:2]
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_mov_b32 s0, 0
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	global_load_b64 v[3:4], v[0:1], off
	s_mov_b32 s1, exec_lo
	s_waitcnt vmcnt(0)
	v_cmpx_neq_f64_e32 0, v[3:4]
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_nc_u32_e32 v6, v2, v5
	v_add_nc_u32_e32 v2, 1, v2
	v_mov_b32_e32 v10, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v7, 31, v6
	v_lshlrev_b64 v[8:9], 3, v[6:7]
	v_lshlrev_b64 v[6:7], 2, v[6:7]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v8, vcc_lo, s2, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s3, v9, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v6, vcc_lo, s4, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v7, vcc_lo
	global_store_b64 v[8:9], v[3:4], off
	global_store_b32 v[6:7], v10, off
.LBB1_4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	v_add_co_u32 v0, vcc_lo, v0, 8
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
	s_add_i32 s0, s0, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s8, s0
	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 _Z9kernelCSRiPdS_PiS0_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 40
		.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 9
		.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	_Z9kernelCSRiPdS_PiS0_, .Lfunc_end1-_Z9kernelCSRiPdS_PiS0_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 240
; NumSgprs: 11
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 11
; NumVGPRsForWavesPerEU: 11
; 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
	.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:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16kernelcount_nonziPdPiS0_
    .private_segment_fixed_size: 0
    .sgpr_count:     10
    .sgpr_spill_count: 0
    .symbol:         _Z16kernelcount_nonziPdPiS0_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 40
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9kernelCSRiPdS_PiS0_
    .private_segment_fixed_size: 0
    .sgpr_count:     11
    .sgpr_spill_count: 0
    .symbol:         _Z9kernelCSRiPdS_PiS0_.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
