#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<time.h>
#include<cuda.h>
/*
__global__ void multiply(int *val, int *vec, int *result, int *cols, int *rowptr)
{
	int tid=threadIdx.x+blockIdx.x*blockDim.x;
        int sum=0;
        int i;
        for(i=0;i<cols[colidx];i++)
	{	

		sum += vec[rowptr[tid]+i]*val[rowptr[tid]+i];

	}
     	__syncthreads();
   	result[tid]=sum;
}

__global__ void printmatscreen(int* mat, int N)
{
	int i;
	for (i=0;i<N;i++)
	{	
		printf("%d ",mat[i]);
		
	}
	printf("\n");
}
*/
int** Make2DIntArray(int arraySizeX, int arraySizeY)
{
	int** theArray;
	theArray = (int**) malloc(arraySizeX*sizeof(int*));
	int i;
	for (i = 0; i < arraySizeX; i++)
  	 theArray[i] = (int*) malloc(arraySizeY*sizeof(int));
	int j;

	for (i=0;i<arraySizeX;i++)
	{
    	for (j=0;j<arraySizeY;j++)
    	{
       	 theArray[i][j]=0;
    	}
}

   return theArray;
}

void init_zeros(int** matrix, int N)
{
	int i,j;
	for (i=0;i<N;i++)
	{	
		for (j=0;j<N;j++)
		{
			matrix[i][j]=0;
		}
	}
}

void printmat(int** matrix, int N)
{
	int i,j;
	
	for (i=0;i<N;i++)
	{	
		printf("\n");
		for (j=0;j<N;j++)
		{
			printf("%d \t",matrix[i][j]);
		}
	}
	printf("\n");
}


int* Make1DIntArray(int arraySizeX) {
int* theArray;
theArray = (int*)malloc(arraySizeX*sizeof(int));
int i;
for (i=0;i<arraySizeX;i++)
{
    theArray[i]=0;
}

   return theArray;
}

void freese(int sizeX, int sizeY, double** ptr)
{
    int i;
     for (i=0;i<sizeX;i++)
        free(ptr[i]);
    free(ptr);
}

void printtofile1D(int* matrix, int K, char* filename)
{
	/*
	Prints resultant matrix to a file
	*/
	FILE *fp;
	fp=fopen(filename,"wt");
	int i;
	
	for (i=0;i<K;i++)
	{
		fprintf(fp, "%d\n", matrix[i]);
		
	}
	
}

int main()
{

	const int N=1000;

	FILE *arr, *vec;
	int i,j;
	int** a=Make2DIntArray(N,N);
	
	int* result=Make1DIntArray(N);
	int* vecX=Make1DIntArray(N);
	//int val[10],col[10],row[10];
	int* resultsordered=Make1DIntArray(N);
	
//	int sig=4,c=2;
//	int* rowwidth=Make1DIntArray(N);
//	int *dev_vec, *dev_scval, *dev_result, *dev_sccol, *dev_cols, *dev_rowptr;
	
	arr=fopen("matrix1000.txt","r");
	int k=0,cinrow=0;

	//row[0]=0;
	for(i=0;i<N;i++)
	{
		for(j=0;j<N;j++)
		{
			fscanf(arr,"%d",&a[i][j]);
			if(a[i][j])
			{
				k++;
			}	
			
		}
		cinrow=0;
		
	}

	
	int Dsize=k;
	int* val=Make1DIntArray(Dsize);
	int* col=Make1DIntArray(Dsize);
	int* row=Make1DIntArray(N+1);
       	printf("\n k = %d\n ", k);
       	//sleep(10);
       	
k=0;
	row[0]=0;
	for(i=0;i<N;i++)
	{
		for(j=0;j<N;j++)
		{
			if(a[i][j])
			{
				val[k]=a[i][j];
				col[k]=j;
				cinrow++;
				k++;
				
			}	
			
		}
		row[i+1]=row[i]+cinrow;
		cinrow=0;
		
	}
//	sleep(5);
	row[i]=k;

	vec=fopen("vector1000.txt","r");
	for (i=0;i<N;i++)
	{
		fscanf(vec,"%d",&vecX[i]);
	
	
			
		
	}
	

	
	
	/*printf("\n Vector is:\n");
	for (i=0;i<N;i++)
	{
		printf("%d\n",vecX[i]);
	}
//printing val, col and row
	/*
	printf("Val=");
	for(i=0;i<Dsize;i++)
	{
		printf("%d\t",val[i]);
	}
	printf("\n");
	
	printf("col=");
        for(i=0;i<Dsize;i++)
        {
                printf("%d\t",col[i]);
        }
        printf("\n");
	printf("row=");
	for(i=0;i<k;i++)
        {
                printf("%d\t",row[i]);
        }
        */
        printf("\n");


        /*Now the actual multiplication kernel*/
        
	/*struct timeval start, end;
	gettimeofday(&start, NULL);        
	*/
	
	cudaEvent_t start_kernel, stop_kernel;
	float time_kernel;
	cudaEventCreate(&start_kernel);
	cudaEventCreate(&stop_kernel);
	
	cudaEventRecord(start_kernel,0);
	
       	for (i=0;i<N;i++)
        {
        	for (j=row[i];j<row[i+1];j++)
        	{ 	
        		result[i]+=val[j]*vecX[col[j]];
        		
        	}
       	}

	cudaEventRecord(stop_kernel,0);




/*	gettimeofday(&end, NULL);

	double delta = ((end.tv_sec  - start.tv_sec) * 1000000u + 
	         end.tv_usec - start.tv_usec) / 1.e6;

	printf("\nTime spent=%f\n", delta);	

*/	cudaEventSynchronize(stop_kernel);

//	multiply<<<N,1>>>(val, vecX, result, col, row);

	cudaEventElapsedTime(&time_kernel, start_kernel, stop_kernel);
	
	printf("\nTime for kernel without data transfer = %f ms \n", time_kernel); 
	
	printtofile1D(result,N,"results.txt");

/*	printf("\n Result is:\n");
	for (i=0;i<N;i++)
	{
		printf("%d\n",result[i]);
	}      
*/
	return 0;

}


	.file	"tmpxft_00384b76_00000000-6_matrix.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2049:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2049:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z14Make2DIntArrayii
	.type	_Z14Make2DIntArrayii, @function
_Z14Make2DIntArrayii:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movslq	%edi, %rdi
	movslq	%esi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%r14, %r12
	salq	$2, %r14
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdi, %rbp
	salq	$3, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	call	malloc@PLT
	movq	%rax, %rbx
.L3:
	cmpl	%r13d, %ebp
	jle	.L11
	movq	%r14, %rdi
	call	malloc@PLT
	movq	%rax, (%rbx,%r13,8)
	incq	%r13
	jmp	.L3
.L11:
	xorl	%eax, %eax
.L5:
	cmpl	%eax, %ebp
	jle	.L12
	xorl	%edx, %edx
.L7:
	cmpl	%edx, %r12d
	jle	.L13
	movq	(%rbx,%rax,8), %rcx
	xorl	%esi, %esi
	movl	%esi, (%rcx,%rdx,4)
	incq	%rdx
	jmp	.L7
.L13:
	incq	%rax
	jmp	.L5
.L12:
	movq	%rbx, %rax
	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
.LFE2040:
	.size	_Z14Make2DIntArrayii, .-_Z14Make2DIntArrayii
	.globl	_Z10init_zerosPPii
	.type	_Z10init_zerosPPii, @function
_Z10init_zerosPPii:
.LFB2041:
	.cfi_startproc
	endbr64
	leal	-1(%rsi), %eax
	movq	%rdi, %r8
	xorl	%edx, %edx
	leaq	4(,%rax,4), %r9
	xorl	%eax, %eax
.L15:
	cmpl	%edx, %esi
	jle	.L17
	movq	(%r8,%rdx,8), %rdi
	movq	%r9, %rcx
	incq	%rdx
	rep stosb
	jmp	.L15
.L17:
	ret
	.cfi_endproc
.LFE2041:
	.size	_Z10init_zerosPPii, .-_Z10init_zerosPPii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\n"
.LC1:
	.string	"%d \t"
	.text
	.globl	_Z8printmatPPii
	.type	_Z8printmatPPii, @function
_Z8printmatPPii:
.LFB2042:
	.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
	movslq	%esi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r14, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 64
.L19:
	xorl	%eax, %eax
	cmpl	%ebx, %ebp
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	jle	.L24
	call	__printf_chk@PLT
	xorl	%r12d, %r12d
	leaq	.LC1(%rip), %r15
.L20:
	movq	0(%r13,%rbx,8), %rax
	movq	%r15, %rsi
	movl	$2, %edi
	movl	(%rax,%r12,4), %edx
	xorl	%eax, %eax
	incq	%r12
	call	__printf_chk@PLT
	cmpq	%r14, %r12
	jne	.L20
	incq	%rbx
	jmp	.L19
.L24:
	popq	%rdx
	.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
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2042:
	.size	_Z8printmatPPii, .-_Z8printmatPPii
	.globl	_Z14Make1DIntArrayi
	.type	_Z14Make1DIntArrayi, @function
_Z14Make1DIntArrayi:
.LFB2043:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movslq	%edi, %rdi
	movq	%rdi, %rbx
	salq	$2, %rdi
	call	malloc@PLT
	xorl	%edx, %edx
.L26:
	cmpl	%edx, %ebx
	jle	.L29
	xorl	%ecx, %ecx
	movl	%ecx, (%rax,%rdx,4)
	incq	%rdx
	jmp	.L26
.L29:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2043:
	.size	_Z14Make1DIntArrayi, .-_Z14Make1DIntArrayi
	.globl	_Z6freeseiiPPd
	.type	_Z6freeseiiPPd, @function
_Z6freeseiiPPd:
.LFB2044:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%edi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdx, %rbx
.L31:
	cmpl	%ebp, %r12d
	jle	.L34
	movq	(%rbx,%rbp,8), %rdi
	incq	%rbp
	call	free@PLT
	jmp	.L31
.L34:
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	free@PLT
	.cfi_endproc
.LFE2044:
	.size	_Z6freeseiiPPd, .-_Z6freeseiiPPd
	.section	.rodata.str1.1
.LC2:
	.string	"wt"
.LC3:
	.string	"%d\n"
	.text
	.globl	_Z13printtofile1DPiiPc
	.type	_Z13printtofile1DPiiPc, @function
_Z13printtofile1DPiiPc:
.LFB2045:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC3(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rdi, %r13
	movq	%rdx, %rdi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%esi, %ebp
	leaq	.LC2(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	xorl	%ebx, %ebx
	call	fopen@PLT
	movq	%rax, %r12
.L36:
	cmpl	%ebx, %ebp
	jle	.L39
	movl	0(%r13,%rbx,4), %ecx
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%r12, %rdi
	xorl	%eax, %eax
	incq	%rbx
	call	__fprintf_chk@PLT
	jmp	.L36
.L39:
	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
.LFE2045:
	.size	_Z13printtofile1DPiiPc, .-_Z13printtofile1DPiiPc
	.section	.rodata.str1.1
.LC4:
	.string	"r"
.LC5:
	.string	"matrix1000.txt"
.LC6:
	.string	"%d"
.LC7:
	.string	"\n k = %d\n "
.LC8:
	.string	"vector1000.txt"
.LC9:
	.string	"\nTime for kernel without data transfer = %f ms \n"
.LC10:
	.string	"results.txt"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2046:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$1000, %esi
	movl	$1000, %edi
	xorl	%r15d, %r15d
	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
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	_Z14Make2DIntArrayii
	movl	$1000, %edi
	movq	%rax, %r13
	call	_Z14Make1DIntArrayi
	movl	$1000, %edi
	movq	%rax, %rbp
	call	_Z14Make1DIntArrayi
	movl	$1000, %edi
	movq	%rax, %r12
	call	_Z14Make1DIntArrayi
	leaq	.LC4(%rip), %rsi
	leaq	.LC5(%rip), %rdi
	call	fopen@PLT
	xorl	%edx, %edx
	movl	%edx, (%rsp)
	movq	%rax, %rbx
.L41:
	xorl	%r14d, %r14d
.L43:
	movq	0(%r13,%r15,8), %rdx
	xorl	%eax, %eax
	leaq	.LC6(%rip), %rsi
	movq	%rbx, %rdi
	addq	%r14, %rdx
	call	__isoc23_fscanf@PLT
	movq	0(%r13,%r15,8), %rax
	cmpl	$0, (%rax,%r14)
	je	.L42
	incl	(%rsp)
.L42:
	addq	$4, %r14
	cmpq	$4000, %r14
	jne	.L43
	incq	%r15
	cmpq	$1000, %r15
	jne	.L41
	movl	(%rsp), %edi
	call	_Z14Make1DIntArrayi
	movl	(%rsp), %edi
	movq	%rax, %r14
	call	_Z14Make1DIntArrayi
	movl	$1001, %edi
	movq	%rax, %r15
	call	_Z14Make1DIntArrayi
	movl	(%rsp), %edx
	movl	$2, %edi
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rbx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	xorl	%esi, %esi
	movl	%eax, (%rbx)
	xorl	%eax, %eax
.L45:
	movq	0(%r13,%rax,2), %r9
	xorl	%ecx, %ecx
	xorl	%edx, %edx
.L47:
	movl	(%r9,%rcx,4), %r8d
	testl	%r8d, %r8d
	je	.L46
	movslq	%esi, %rdi
	incl	%edx
	incl	%esi
	movl	%r8d, (%r14,%rdi,4)
	movl	%ecx, (%r15,%rdi,4)
.L46:
	incq	%rcx
	cmpq	$1000, %rcx
	jne	.L47
	addl	(%rbx,%rax), %edx
	movl	%edx, 4(%rbx,%rax)
	addq	$4, %rax
	cmpq	$4000, %rax
	jne	.L45
	movl	%esi, 4000(%rbx)
	leaq	.LC8(%rip), %rdi
	leaq	.LC4(%rip), %rsi
	movq	%r12, %r13
	call	fopen@PLT
	movq	%rax, 8(%rsp)
	leaq	4000(%r12), %rax
	movq	%rax, (%rsp)
.L49:
	movq	8(%rsp), %rdi
	movq	%r13, %rdx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	addq	$4, %r13
	call	__isoc23_fscanf@PLT
	cmpq	%r13, (%rsp)
	jne	.L49
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	xorl	%eax, %eax
.L52:
	movslq	(%rbx,%rax), %rdx
.L50:
	cmpl	%edx, 4(%rbx,%rax)
	jle	.L62
	movslq	(%r15,%rdx,4), %rcx
	movl	(%r12,%rcx,4), %ecx
	imull	(%r14,%rdx,4), %ecx
	incq	%rdx
	addl	%ecx, 0(%rbp,%rax)
	jmp	.L50
.L62:
	addq	$4, %rax
	cmpq	$4000, %rax
	jne	.L52
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	leaq	20(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	20(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$1000, %esi
	leaq	.LC10(%rip), %rdx
	movq	%rbp, %rdi
	call	_Z13printtofile1DPiiPc
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L53
	call	__stack_chk_fail@PLT
.L53:
	addq	$56, %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
.LFE2046:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2072:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2072:
	.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
	.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<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<time.h>
#include<hip/hip_runtime.h>
/*
__global__ void multiply(int *val, int *vec, int *result, int *cols, int *rowptr)
{
	int tid=threadIdx.x+blockIdx.x*blockDim.x;
        int sum=0;
        int i;
        for(i=0;i<cols[colidx];i++)
	{	

		sum += vec[rowptr[tid]+i]*val[rowptr[tid]+i];

	}
     	__syncthreads();
   	result[tid]=sum;
}

__global__ void printmatscreen(int* mat, int N)
{
	int i;
	for (i=0;i<N;i++)
	{	
		printf("%d ",mat[i]);
		
	}
	printf("\n");
}
*/
int** Make2DIntArray(int arraySizeX, int arraySizeY)
{
	int** theArray;
	theArray = (int**) malloc(arraySizeX*sizeof(int*));
	int i;
	for (i = 0; i < arraySizeX; i++)
  	 theArray[i] = (int*) malloc(arraySizeY*sizeof(int));
	int j;

	for (i=0;i<arraySizeX;i++)
	{
    	for (j=0;j<arraySizeY;j++)
    	{
       	 theArray[i][j]=0;
    	}
}

   return theArray;
}

void init_zeros(int** matrix, int N)
{
	int i,j;
	for (i=0;i<N;i++)
	{	
		for (j=0;j<N;j++)
		{
			matrix[i][j]=0;
		}
	}
}

void printmat(int** matrix, int N)
{
	int i,j;
	
	for (i=0;i<N;i++)
	{	
		printf("\n");
		for (j=0;j<N;j++)
		{
			printf("%d \t",matrix[i][j]);
		}
	}
	printf("\n");
}


int* Make1DIntArray(int arraySizeX) {
int* theArray;
theArray = (int*)malloc(arraySizeX*sizeof(int));
int i;
for (i=0;i<arraySizeX;i++)
{
    theArray[i]=0;
}

   return theArray;
}

void freese(int sizeX, int sizeY, double** ptr)
{
    int i;
     for (i=0;i<sizeX;i++)
        free(ptr[i]);
    free(ptr);
}

void printtofile1D(int* matrix, int K, char* filename)
{
	/*
	Prints resultant matrix to a file
	*/
	FILE *fp;
	fp=fopen(filename,"wt");
	int i;
	
	for (i=0;i<K;i++)
	{
		fprintf(fp, "%d\n", matrix[i]);
		
	}
	
}

int main()
{

	const int N=1000;

	FILE *arr, *vec;
	int i,j;
	int** a=Make2DIntArray(N,N);
	
	int* result=Make1DIntArray(N);
	int* vecX=Make1DIntArray(N);
	//int val[10],col[10],row[10];
	int* resultsordered=Make1DIntArray(N);
	
//	int sig=4,c=2;
//	int* rowwidth=Make1DIntArray(N);
//	int *dev_vec, *dev_scval, *dev_result, *dev_sccol, *dev_cols, *dev_rowptr;
	
	arr=fopen("matrix1000.txt","r");
	int k=0,cinrow=0;

	//row[0]=0;
	for(i=0;i<N;i++)
	{
		for(j=0;j<N;j++)
		{
			fscanf(arr,"%d",&a[i][j]);
			if(a[i][j])
			{
				k++;
			}	
			
		}
		cinrow=0;
		
	}

	
	int Dsize=k;
	int* val=Make1DIntArray(Dsize);
	int* col=Make1DIntArray(Dsize);
	int* row=Make1DIntArray(N+1);
       	printf("\n k = %d\n ", k);
       	//sleep(10);
       	
k=0;
	row[0]=0;
	for(i=0;i<N;i++)
	{
		for(j=0;j<N;j++)
		{
			if(a[i][j])
			{
				val[k]=a[i][j];
				col[k]=j;
				cinrow++;
				k++;
				
			}	
			
		}
		row[i+1]=row[i]+cinrow;
		cinrow=0;
		
	}
//	sleep(5);
	row[i]=k;

	vec=fopen("vector1000.txt","r");
	for (i=0;i<N;i++)
	{
		fscanf(vec,"%d",&vecX[i]);
	
	
			
		
	}
	

	
	
	/*printf("\n Vector is:\n");
	for (i=0;i<N;i++)
	{
		printf("%d\n",vecX[i]);
	}
//printing val, col and row
	/*
	printf("Val=");
	for(i=0;i<Dsize;i++)
	{
		printf("%d\t",val[i]);
	}
	printf("\n");
	
	printf("col=");
        for(i=0;i<Dsize;i++)
        {
                printf("%d\t",col[i]);
        }
        printf("\n");
	printf("row=");
	for(i=0;i<k;i++)
        {
                printf("%d\t",row[i]);
        }
        */
        printf("\n");


        /*Now the actual multiplication kernel*/
        
	/*struct timeval start, end;
	gettimeofday(&start, NULL);        
	*/
	
	hipEvent_t start_kernel, stop_kernel;
	float time_kernel;
	hipEventCreate(&start_kernel);
	hipEventCreate(&stop_kernel);
	
	hipEventRecord(start_kernel,0);
	
       	for (i=0;i<N;i++)
        {
        	for (j=row[i];j<row[i+1];j++)
        	{ 	
        		result[i]+=val[j]*vecX[col[j]];
        		
        	}
       	}

	hipEventRecord(stop_kernel,0);




/*	gettimeofday(&end, NULL);

	double delta = ((end.tv_sec  - start.tv_sec) * 1000000u + 
	         end.tv_usec - start.tv_usec) / 1.e6;

	printf("\nTime spent=%f\n", delta);	

*/	hipEventSynchronize(stop_kernel);

//	multiply<<<N,1>>>(val, vecX, result, col, row);

	hipEventElapsedTime(&time_kernel, start_kernel, stop_kernel);
	
	printf("\nTime for kernel without data transfer = %f ms \n", time_kernel); 
	
	printtofile1D(result,N,"results.txt");

/*	printf("\n Result is:\n");
	for (i=0;i<N;i++)
	{
		printf("%d\n",result[i]);
	}      
*/
	return 0;

}


	.text
	.file	"matrix.hip"
	.globl	_Z14Make2DIntArrayii            # -- Begin function _Z14Make2DIntArrayii
	.type	_Z14Make2DIntArrayii,@function
_Z14Make2DIntArrayii:                   # @_Z14Make2DIntArrayii
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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	%esi, %ebx
	movl	%edi, %ebp
	movslq	%edi, %r15
	leaq	(,%r15,8), %rdi
	callq	malloc
	movq	%rax, %r14
	testl	%r15d, %r15d
	jle	.LBB0_8
# %bb.1:                                # %.lr.ph
	movslq	%ebx, %r15
	shlq	$2, %r15
	movl	%ebp, %r12d
	xorl	%r13d, %r13d
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, (%r14,%r13,8)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB0_2
# %bb.3:                                # %.preheader18
	testl	%ebp, %ebp
	jle	.LBB0_8
# %bb.4:                                # %.preheader.lr.ph
	movl	%ebx, %r15d
	shlq	$2, %r15
	xorl	%r13d, %r13d
.LBB0_5:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	testl	%ebx, %ebx
	jle	.LBB0_7
# %bb.6:                                # %.lr.ph21
                                        #   in Loop: Header=BB0_5 Depth=1
	movq	(%r14,%r13,8), %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	memset@PLT
.LBB0_7:                                # %._crit_edge
                                        #   in Loop: Header=BB0_5 Depth=1
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB0_5
.LBB0_8:                                # %._crit_edge23
	movq	%r14, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z14Make2DIntArrayii, .Lfunc_end0-_Z14Make2DIntArrayii
	.cfi_endproc
                                        # -- End function
	.globl	_Z10init_zerosPPii              # -- Begin function _Z10init_zerosPPii
	.type	_Z10init_zerosPPii,@function
_Z10init_zerosPPii:                     # @_Z10init_zerosPPii
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB1_4
# %bb.1:                                # %.preheader.lr.ph
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r15d
	leaq	(,%r15,4), %r14
	xorl	%r12d, %r12d
.LBB1_2:                                # %._crit_edge
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r12,8), %rdi
	xorl	%esi, %esi
	movq	%r14, %rdx
	callq	memset@PLT
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB1_2
# %bb.3:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r14
	.cfi_restore %r15
.LBB1_4:                                # %._crit_edge12
	retq
.Lfunc_end1:
	.size	_Z10init_zerosPPii, .Lfunc_end1-_Z10init_zerosPPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8printmatPPii                 # -- Begin function _Z8printmatPPii
	.type	_Z8printmatPPii,@function
_Z8printmatPPii:                        # @_Z8printmatPPii
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB2_6
# %bb.1:                                # %.lr.ph14
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_3 Depth 2
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%r12d, %r12d
.LBB2_3:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%rbx,%r15,8), %rax
	movl	(%rax,%r12,4), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r12
	cmpq	%r12, %r14
	jne	.LBB2_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r15
	cmpq	%r14, %r15
	jne	.LBB2_2
# %bb.5:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r14
	.cfi_restore %r15
.LBB2_6:                                # %._crit_edge15
	movl	$10, %edi
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end2:
	.size	_Z8printmatPPii, .Lfunc_end2-_Z8printmatPPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z14Make1DIntArrayi             # -- Begin function _Z14Make1DIntArrayi
	.type	_Z14Make1DIntArrayi,@function
_Z14Make1DIntArrayi:                    # @_Z14Make1DIntArrayi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	%edi, %ebp
	movslq	%edi, %r14
	leaq	(,%r14,4), %rdi
	callq	malloc
	movq	%rax, %rbx
	testl	%r14d, %r14d
	jle	.LBB3_2
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %edx
	shlq	$2, %rdx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB3_2:                                # %._crit_edge
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z14Make1DIntArrayi, .Lfunc_end3-_Z14Make1DIntArrayi
	.cfi_endproc
                                        # -- End function
	.globl	_Z6freeseiiPPd                  # -- Begin function _Z6freeseiiPPd
	.type	_Z6freeseiiPPd,@function
_Z6freeseiiPPd:                         # @_Z6freeseiiPPd
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %rbx
	testl	%edi, %edi
	jle	.LBB4_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%edi, %r14d
	xorl	%r15d, %r15d
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r15,8), %rdi
	callq	free
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB4_2
.LBB4_3:                                # %._crit_edge
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.Lfunc_end4:
	.size	_Z6freeseiiPPd, .Lfunc_end4-_Z6freeseiiPPd
	.cfi_endproc
                                        # -- End function
	.globl	_Z13printtofile1DPiiPc          # -- Begin function _Z13printtofile1DPiiPc
	.type	_Z13printtofile1DPiiPc,@function
_Z13printtofile1DPiiPc:                 # @_Z13printtofile1DPiiPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movq	%rdi, %rbx
	movl	$.L.str.2, %esi
	movq	%rdx, %rdi
	callq	fopen
	testl	%ebp, %ebp
	jle	.LBB5_3
# %bb.1:                                # %.lr.ph.preheader
	movq	%rax, %r14
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r12,4), %edx
	movl	$.L.str.3, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB5_2
.LBB5_3:                                # %._crit_edge
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z13printtofile1DPiiPc, .Lfunc_end5-_Z13printtofile1DPiiPc
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function 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	$40, %rsp
	.cfi_def_cfa_offset 96
	.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	$1000, %edi                     # imm = 0x3E8
	movl	$1000, %esi                     # imm = 0x3E8
	callq	_Z14Make2DIntArrayii
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movl	$1, %edi
	movl	$4000, %esi                     # imm = 0xFA0
	callq	calloc@PLT
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	$1, %edi
	movl	$4000, %esi                     # imm = 0xFA0
	callq	calloc@PLT
	movq	%rax, %r14
	movl	$.L.str.4, %edi
	movl	$.L.str.5, %esi
	callq	fopen
	movq	%rax, %r15
	xorl	%r12d, %r12d
	xorl	%ebx, %ebx
.LBB6_1:                                # %.preheader78
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_2 Depth 2
	movq	8(%rsp), %rax                   # 8-byte Reload
	movq	(%rax,%r12,8), %r13
	xorl	%ebp, %ebp
.LBB6_2:                                #   Parent Loop BB6_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r13, %rdx
	addq	%rbp, %rdx
	movl	$.L.str.6, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$1, (%r13,%rbp)
	sbbl	$-1, %ebx
	addq	$4, %rbp
	cmpq	$4000, %rbp                     # imm = 0xFA0
	jne	.LBB6_2
# %bb.3:                                #   in Loop: Header=BB6_1 Depth=1
	incq	%r12
	cmpq	$1000, %r12                     # imm = 0x3E8
	jne	.LBB6_1
# %bb.4:
	movslq	%ebx, %r12
	leaq	(,%r12,4), %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r15
	testl	%r12d, %r12d
	jle	.LBB6_5
# %bb.6:                                # %.lr.ph.preheader.i75
	movl	%ebx, %ebp
	shlq	$2, %rbp
	movq	%r15, %rdi
	xorl	%esi, %esi
	movq	%rbp, %rdx
	callq	memset@PLT
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r13
	movq	%rax, %rdi
	xorl	%esi, %esi
	movq	%rbp, %rdx
	callq	memset@PLT
	jmp	.LBB6_7
.LBB6_5:                                # %_Z14Make1DIntArrayi.exit
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r13
.LBB6_7:                                # %_Z14Make1DIntArrayi.exit76
	movl	$1, %edi
	movl	$4004, %esi                     # imm = 0xFA4
	callq	calloc@PLT
	movq	%rax, %rbp
	xorl	%r12d, %r12d
	movl	$.L.str.7, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	xorl	%ecx, %ecx
	xorl	%eax, %eax
.LBB6_8:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_9 Depth 2
	movq	8(%rsp), %rdx                   # 8-byte Reload
	movq	(%rdx,%rcx,8), %rdx
	xorl	%edi, %edi
	xorl	%esi, %esi
.LBB6_9:                                #   Parent Loop BB6_8 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rdx,%rdi,4), %r8d
	testl	%r8d, %r8d
	je	.LBB6_11
# %bb.10:                               #   in Loop: Header=BB6_9 Depth=2
	cltq
	movl	%r8d, (%r15,%rax,4)
	movl	%edi, (%r13,%rax,4)
	incl	%esi
	incl	%eax
.LBB6_11:                               #   in Loop: Header=BB6_9 Depth=2
	incq	%rdi
	cmpq	$1000, %rdi                     # imm = 0x3E8
	jne	.LBB6_9
# %bb.12:                               #   in Loop: Header=BB6_8 Depth=1
	addl	%esi, %r12d
	movl	%r12d, 4(%rbp,%rcx,4)
	incq	%rcx
	cmpq	$1000, %rcx                     # imm = 0x3E8
	jne	.LBB6_8
# %bb.13:
	movl	%eax, 4000(%rbp)
	movl	$.L.str.8, %edi
	movl	$.L.str.5, %esi
	callq	fopen
	movq	%rax, %rbx
	xorl	%r12d, %r12d
.LBB6_14:                               # =>This Inner Loop Header: Depth=1
	leaq	(%r14,%r12), %rdx
	movl	$.L.str.6, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %r12
	cmpq	$4000, %r12                     # imm = 0xFA0
	jne	.LBB6_14
# %bb.15:
	movl	$10, %edi
	callq	putchar@PLT
	leaq	24(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%ebx, %ebx
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	(%rbp), %eax
	movq	16(%rsp), %r12                  # 8-byte Reload
.LBB6_18:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_20 Depth 2
	movl	%eax, %esi
	movl	4(%rbp,%rbx,4), %eax
	cmpl	%eax, %esi
	jge	.LBB6_17
# %bb.19:                               # %.lr.ph
                                        #   in Loop: Header=BB6_18 Depth=1
	movslq	%eax, %rdx
	movl	(%r12,%rbx,4), %ecx
	movslq	%esi, %rsi
.LBB6_20:                               #   Parent Loop BB6_18 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movslq	(%r13,%rsi,4), %rdi
	movl	(%r14,%rdi,4), %edi
	imull	(%r15,%rsi,4), %edi
	addl	%edi, %ecx
	incq	%rsi
	cmpq	%rsi, %rdx
	jne	.LBB6_20
# %bb.16:                               # %..loopexit_crit_edge
                                        #   in Loop: Header=BB6_18 Depth=1
	movl	%ecx, (%r12,%rbx,4)
.LBB6_17:                               # %.loopexit
                                        #   in Loop: Header=BB6_18 Depth=1
	incq	%rbx
	cmpq	$1000, %rbx                     # imm = 0x3E8
	jne	.LBB6_18
# %bb.21:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	36(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.9, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.10, %edx
	movq	%r12, %rdi
	movl	$1000, %esi                     # imm = 0x3E8
	callq	_Z13printtofile1DPiiPc
	xorl	%eax, %eax
	addq	$40, %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_end6:
	.size	main, .Lfunc_end6-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"%d \t"
	.size	.L.str.1, 5

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"wt"
	.size	.L.str.2, 3

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%d\n"
	.size	.L.str.3, 4

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"matrix1000.txt"
	.size	.L.str.4, 15

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

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"\n k = %d\n "
	.size	.L.str.7, 11

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"vector1000.txt"
	.size	.L.str.8, 15

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"\nTime for kernel without data transfer = %f ms \n"
	.size	.L.str.9, 49

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"results.txt"
	.size	.L.str.10, 12

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
