#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <string.h>
#define MAXBLOCKSIZE 512
int Size;
float *a, *b, *finalVec;
float *m;

FILE *fp;

void InitProblemOnce(char *filename);
void InitPerRun();
void ForwardSub();
void BackSub();

/*
 Calculation of Multiplier matrix to introduce zero's in each of the columns.
 */
__global__ void multiplier(float *m_cuda, float *a_cuda, int Size, int t)
{   
	int idx = threadIdx.x + blockIdx.x * blockDim.x;
	if( idx>= Size-1-t) return;
	//printf(" multiplier: \nIndex %d a1: %f a2: %f \n",idx,*(a_cuda+Size*(idx+t+1)+t),*(a_cuda+Size*t+t));
	*(m_cuda+Size*(idx+t+1)+t) = *(a_cuda+Size*(idx+t+1)+t) / *(a_cuda+Size*t+t);
}

//Conversion of matrix to Upper Triangular Matrix

__global__ void upper(float *m_cuda, float *a_cuda, float *b_cuda,int Size, int j1, int t)
{
	int xidx = blockIdx.x * blockDim.x + threadIdx.x;
	int yidx = blockIdx.y * blockDim.y + threadIdx.y;

	if(xidx >= Size-1-t) return;
	if(yidx >= Size-t) return;	
	
	a_cuda[Size*(xidx+1+t)+(yidx+t)] -= m_cuda[Size*(xidx+1+t)+t] * a_cuda[Size*t+(yidx+t)];
	
	if(yidx == 0){
		b_cuda[xidx+1+t] -= m_cuda[Size*(xidx+1+t)+(yidx+t)] * b_cuda[t];
	}
}
void InitMat(float *ary, int nrow, int ncol);
void InitAry(float *ary, int ary_size);
void PrintMat(float *ary, int nrow, int ncolumn);
void PrintAry(float *ary, int ary_size);
void checkCUDAError(const char *msg);

unsigned int totalKernelTime = 0;

int main(int argc, char *argv[])
{
	if(argc<2){
		printf("Enter filename \n");
		return 1;
	}
    InitProblemOnce(argv[1]);//Input file
    InitPerRun(); //Initialize m with 0

    //begin timing
    struct timeval time_start;
    gettimeofday(&time_start, NULL);	
    
    // run kernels
    ForwardSub();
    
    //end timing
    struct timeval time_end;
    gettimeofday(&time_end, NULL);
    unsigned int time_total = (time_end.tv_sec * 1000000 + time_end.tv_usec) - (time_start.tv_sec * 1000000 + time_start.tv_usec);
    
    
        printf("Matrix m is: \n");
        PrintMat(m, Size, Size);

        printf("Matrix a is: \n");
        PrintMat(a, Size, Size);

        printf("Array b is: \n");
        PrintAry(b, Size);
    
    BackSub();
        printf("The final solution is: \n");
        PrintAry(finalVec,Size);
    
    printf("\nTime total (including memory transfers)\t%f sec\n", time_total * 1e-6);
    printf("Time for CUDA kernels:\t%f sec\n",totalKernelTime * 1e-6);   
    free(m);
    free(a);
    free(b);
}
/*Initializing all matrices and arrays
 */
void InitProblemOnce(char *filename)
{	
	fp = fopen(filename, "r");
	fscanf(fp, "%d", &Size);	
	a = (float *) malloc(Size * Size * sizeof(float));
	InitMat(a, Size, Size);
	b = (float *) malloc(Size * sizeof(float));
	
	InitAry(b, Size);		
	 m = (float *) malloc(Size * Size * sizeof(float));
}

/*------------------------------------------------------
 ** InitPerRun() -- Initialize the contents of the
 ** multipier matrix **m
 **------------------------------------------------------
 */
void InitPerRun() 
{
	int i;
	for (i=0; i<Size*Size; i++)
			*(m+i) = 0.0;
}


/*------------------------------------------------------
 ** ForwardSub() -- Forward substitution of Gaussian
 ** elimination.
 **------------------------------------------------------
 */
void ForwardSub()
{
	int t;
    float *m_cuda,*a_cuda,*b_cuda;
	
	// allocate memory on GPU
	cudaMalloc((void **) &m_cuda, Size * Size * sizeof(float));
	 
	cudaMalloc((void **) &a_cuda, Size * Size * sizeof(float));
	
	cudaMalloc((void **) &b_cuda, Size * sizeof(float));	

	// copy memory to GPU
	cudaMemcpy(m_cuda, m, Size * Size * sizeof(float),cudaMemcpyHostToDevice );
	cudaMemcpy(a_cuda, a, Size * Size * sizeof(float),cudaMemcpyHostToDevice );
	cudaMemcpy(b_cuda, b, Size * sizeof(float),cudaMemcpyHostToDevice );
	
	int block_size,grid_size;
	
	block_size = MAXBLOCKSIZE;
	grid_size = (Size/block_size) + (!(Size%block_size)? 0:1);

	dim3 dimBlock(block_size);
	dim3 dimGrid(grid_size);
	
	int blockSize2d, gridSize2d;
	blockSize2d = 4;
	gridSize2d = (Size/blockSize2d) + (!(Size%blockSize2d?0:1)); 
	
	dim3 dimBlockXY(blockSize2d,blockSize2d);
	dim3 dimGridXY(gridSize2d,gridSize2d);

    // begin timing kernels
    struct timeval time_start;
    gettimeofday(&time_start, NULL);
	for (t=0; t<(Size-1); t++) {
		multiplier<<<dimGrid,dimBlock>>>(m_cuda,a_cuda,Size,t);
		cudaThreadSynchronize();
		upper<<<dimGridXY,dimBlockXY>>>(m_cuda,a_cuda,b_cuda,Size,Size-t,t);
		cudaThreadSynchronize();
		checkCUDAError("Upper");
	}
	// end timing kernels
	struct timeval time_end;
    gettimeofday(&time_end, NULL);
    totalKernelTime = (time_end.tv_sec * 1000000 + time_end.tv_usec) - (time_start.tv_sec * 1000000 + time_start.tv_usec);
	
	// copy memory back to CPU
	cudaMemcpy(m, m_cuda, Size * Size * sizeof(float),cudaMemcpyDeviceToHost );
	cudaMemcpy(a, a_cuda, Size * Size * sizeof(float),cudaMemcpyDeviceToHost );
	cudaMemcpy(b, b_cuda, Size * sizeof(float),cudaMemcpyDeviceToHost );
	cudaFree(m_cuda);
	cudaFree(a_cuda);
	cudaFree(b_cuda);
}

/*------------------------------------------------------
 ** BackSub() -- Backward substitution
 **------------------------------------------------------
 */

void BackSub()
{
	// create a new vector to hold the final answer
	finalVec = (float *) malloc(Size * sizeof(float));
	// solve "bottom up"
	int i,j;
	for(i=0;i<Size;i++){
		finalVec[Size-i-1]=b[Size-i-1];
		for(j=0;j<i;j++)
		{
			finalVec[Size-i-1]-=*(a+Size*(Size-i-1)+(Size-j-1)) * finalVec[Size-j-1];
		}
		finalVec[Size-i-1]=finalVec[Size-i-1]/ *(a+Size*(Size-i-1)+(Size-i-1));
	}
}

void InitMat(float *ary, int nrow, int ncol)
{
	int i, j;
	printf("Initial Matrix A \n");
	for (i=0; i<nrow; i++) {
		for (j=0; j<ncol; j++) {
			fscanf(fp, "%f",  ary+Size*i+j);
			printf("%f ",*(ary+Size*i+j));
		}
		printf("\n");
	}  
}

/*------------------------------------------------------
 ** PrintMat() -- Print the contents of the matrix
 **------------------------------------------------------
 */
void PrintMat(float *ary, int nrow, int ncol)
{
	int i, j;
	
	for (i=0; i<nrow; i++) {
		for (j=0; j<ncol; j++) {
			printf("%f ", *(ary+Size*i+j));
		}
		printf("\n");
	}
	printf("\n");
}

/*------------------------------------------------------
 ** InitAry() -- Initialize the array (vector) by reading
 ** data from the data file
 **------------------------------------------------------
 */
void InitAry(float *ary, int ary_size)
{
	int i;
	printf("\n Vector B is \n");
	for (i=0; i<ary_size; i++) {
		fscanf(fp, "%f",  &ary[i]);
		printf("%f ",ary[i]);
	}
}  

/*------------------------------------------------------
 ** PrintAry() -- Print the contents of the array (vector)
 **------------------------------------------------------
 */
void PrintAry(float *ary, int ary_size)
{
	int i;
	for (i=0; i<ary_size; i++) {
		printf("%.2f ", ary[i]);
	}
	printf("\n\n");
}
void checkCUDAError(const char *msg)
{
    cudaError_t err = cudaGetLastError();
    if( cudaSuccess != err) 
    {
        fprintf(stderr, "Cuda error: %s: %s.\n", msg, 
                                  cudaGetErrorString( err) );
        exit(EXIT_FAILURE);
    }                         
}
	.file	"tmpxft_002561d7_00000000-6_gauss.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2039:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2039:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z10InitPerRunv
	.type	_Z10InitPerRunv, @function
_Z10InitPerRunv:
.LFB2029:
	.cfi_startproc
	endbr64
	movl	Size(%rip), %eax
	movq	m(%rip), %rcx
	imull	%eax, %eax
	movl	%eax, %edx
	xorl	%eax, %eax
.L3:
	cmpl	%eax, %edx
	jle	.L6
	movl	$0x00000000, (%rcx,%rax,4)
	incq	%rax
	jmp	.L3
.L6:
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z10InitPerRunv, .-_Z10InitPerRunv
	.globl	_Z7BackSubv
	.type	_Z7BackSubv, @function
_Z7BackSubv:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movslq	Size(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	0(,%rbp,4), %r13
	movq	%rbp, %rbx
	movq	%r13, %rdi
	call	malloc@PLT
	movq	a(%rip), %r9
	movq	b(%rip), %r10
	xorl	%esi, %esi
	movq	%rax, %rdi
	movq	%rax, finalVec(%rip)
	movl	%ebp, %eax
	leaq	-4(%r13), %r8
	negl	%eax
	cltq
	leaq	-4(,%rax,4), %r11
	leal	-1(%rbp), %eax
	imull	%ebp, %eax
	movslq	%eax, %rdx
	addq	%rbp, %rdx
	leaq	(%r9,%rdx,4), %r12
	leaq	(%rdi,%r13), %rdx
.L8:
	cmpl	%esi, %ebx
	jle	.L13
	movslq	%eax, %rcx
	imulq	$-4, %rsi, %r13
	movss	(%r10,%r8), %xmm0
	addq	%rbp, %rcx
	leaq	(%r9,%rcx,4), %r14
	xorl	%ecx, %ecx
.L9:
	movss	%xmm0, (%rdi,%r8)
	cmpq	%r13, %rcx
	je	.L14
	movss	-4(%r14,%rcx), %xmm1
	mulss	-4(%rdx,%rcx), %xmm1
	subq	$4, %rcx
	subss	%xmm1, %xmm0
	jmp	.L9
.L14:
	divss	-4(%r12), %xmm0
	incq	%rsi
	addq	%r11, %r12
	movss	%xmm0, (%rdi,%r8)
	subl	%ebx, %eax
	subq	$4, %r8
	jmp	.L8
.L13:
	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
.LFE2031:
	.size	_Z7BackSubv, .-_Z7BackSubv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Initial Matrix A \n"
.LC2:
	.string	"%f"
.LC3:
	.string	"%f "
.LC4:
	.string	"\n"
	.text
	.globl	_Z7InitMatPfii
	.type	_Z7InitMatPfii, @function
_Z7InitMatPfii:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	leaq	.LC2(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%esi, %r13d
	leaq	.LC1(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	movl	$2, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 64
	call	__printf_chk@PLT
.L16:
	cmpl	%r13d, %ebx
	jge	.L21
	xorl	%ebp, %ebp
.L18:
	cmpl	%ebp, %r14d
	jle	.L22
	movl	Size(%rip), %eax
	movq	fp(%rip), %rdi
	movq	%r15, %rsi
	imull	%ebx, %eax
	cltq
	addq	%rbp, %rax
	leaq	(%r12,%rax,4), %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movl	Size(%rip), %eax
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	imull	%ebx, %eax
	cltq
	addq	%rbp, %rax
	incq	%rbp
	cvtss2sd	(%r12,%rax,4), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	jmp	.L18
.L22:
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%ebx
	call	__printf_chk@PLT
	jmp	.L16
.L21:
	popq	%rax
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z7InitMatPfii, .-_Z7InitMatPfii
	.globl	_Z8PrintMatPfii
	.type	_Z8PrintMatPfii, @function
_Z8PrintMatPfii:
.LFB2033:
	.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
	leaq	.LC3(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 64
.L24:
	cmpl	%ebp, %ebx
	jge	.L29
	xorl	%r15d, %r15d
.L26:
	cmpl	%r15d, %r13d
	jle	.L30
	movl	Size(%rip), %eax
	movq	%r14, %rsi
	movl	$2, %edi
	imull	%ebx, %eax
	cltq
	addq	%r15, %rax
	incq	%r15
	cvtss2sd	(%r12,%rax,4), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	jmp	.L26
.L30:
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%ebx
	call	__printf_chk@PLT
	jmp	.L24
.L29:
	popq	%rdx
	.cfi_def_cfa_offset 56
	leaq	.LC4(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 48
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.LFE2033:
	.size	_Z8PrintMatPfii, .-_Z8PrintMatPfii
	.section	.rodata.str1.1
.LC5:
	.string	"\n Vector B is \n"
	.text
	.globl	_Z7InitAryPfi
	.type	_Z7InitAryPfi, @function
_Z7InitAryPfi:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%eax, %eax
	leaq	.LC2(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%esi, %ebp
	leaq	.LC5(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	movl	$2, %edi
	pushq	%rdx
	.cfi_def_cfa_offset 48
	call	__printf_chk@PLT
.L32:
	cmpl	%ebp, %r12d
	jge	.L35
	movq	fp(%rip), %rdi
	movq	%rbx, %rdx
	movq	%r13, %rsi
	xorl	%eax, %eax
	incl	%r12d
	addq	$4, %rbx
	call	__isoc23_fscanf@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	-4(%rbx), %xmm0
	call	__printf_chk@PLT
	jmp	.L32
.L35:
	popq	%rax
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z7InitAryPfi, .-_Z7InitAryPfi
	.section	.rodata.str1.1
.LC6:
	.string	"r"
.LC7:
	.string	"%d"
	.text
	.globl	_Z15InitProblemOncePc
	.type	_Z15InitProblemOncePc, @function
_Z15InitProblemOncePc:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	.LC6(%rip), %rsi
	call	fopen@PLT
	leaq	Size(%rip), %rdx
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdi
	movq	%rax, fp(%rip)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movl	Size(%rip), %ebx
	movl	%ebx, %edi
	imull	%ebx, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movl	%ebx, %edx
	movl	%ebx, %esi
	movq	%rax, %rdi
	movq	%rax, a(%rip)
	call	_Z7InitMatPfii
	movslq	Size(%rip), %rdi
	movq	%rdi, %rbx
	salq	$2, %rdi
	call	malloc@PLT
	movl	%ebx, %esi
	movq	%rax, %rdi
	movq	%rax, b(%rip)
	call	_Z7InitAryPfi
	movl	Size(%rip), %edi
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	popq	%rbx
	.cfi_def_cfa_offset 8
	movq	%rax, m(%rip)
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z15InitProblemOncePc, .-_Z15InitProblemOncePc
	.section	.rodata.str1.1
.LC8:
	.string	"%.2f "
.LC9:
	.string	"\n\n"
	.text
	.globl	_Z8PrintAryPfi
	.type	_Z8PrintAryPfi, @function
_Z8PrintAryPfi:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC8(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 48
.L39:
	cmpl	%ebx, %ebp
	jle	.L42
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%r12,%rbx,4), %xmm0
	call	__printf_chk@PLT
	incq	%rbx
	jmp	.L39
.L42:
	popq	%rdx
	.cfi_def_cfa_offset 40
	leaq	.LC9(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 32
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2035:
	.size	_Z8PrintAryPfi, .-_Z8PrintAryPfi
	.section	.rodata.str1.1
.LC10:
	.string	"Cuda error: %s: %s.\n"
	.text
	.globl	_Z14checkCUDAErrorPKc
	.type	_Z14checkCUDAErrorPKc, @function
_Z14checkCUDAErrorPKc:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L43
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rbx, %rcx
	leaq	.LC10(%rip), %rdx
	movq	%rax, %r8
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L43:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z14checkCUDAErrorPKc, .-_Z14checkCUDAErrorPKc
	.globl	_Z34__device_stub__Z10multiplierPfS_iiPfS_ii
	.type	_Z34__device_stub__Z10multiplierPfS_iiPfS_ii, @function
_Z34__device_stub__Z10multiplierPfS_iiPfS_ii:
.LFB2061:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%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	.L46
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z10multiplierPfS_ii(%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
.L46:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L48
	call	__stack_chk_fail@PLT
.L48:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2061:
	.size	_Z34__device_stub__Z10multiplierPfS_iiPfS_ii, .-_Z34__device_stub__Z10multiplierPfS_iiPfS_ii
	.globl	_Z10multiplierPfS_ii
	.type	_Z10multiplierPfS_ii, @function
_Z10multiplierPfS_ii:
.LFB2062:
	.cfi_startproc
	endbr64
	jmp	_Z34__device_stub__Z10multiplierPfS_iiPfS_ii
	.cfi_endproc
.LFE2062:
	.size	_Z10multiplierPfS_ii, .-_Z10multiplierPfS_ii
	.globl	_Z31__device_stub__Z5upperPfS_S_iiiPfS_S_iii
	.type	_Z31__device_stub__Z5upperPfS_S_iiiPfS_S_iii, @function
_Z31__device_stub__Z5upperPfS_S_iiiPfS_S_iii:
.LFB2063:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L51
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z5upperPfS_S_iii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L51:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L53
	call	__stack_chk_fail@PLT
.L53:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2063:
	.size	_Z31__device_stub__Z5upperPfS_S_iiiPfS_S_iii, .-_Z31__device_stub__Z5upperPfS_S_iiiPfS_S_iii
	.globl	_Z5upperPfS_S_iii
	.type	_Z5upperPfS_S_iii, @function
_Z5upperPfS_S_iii:
.LFB2064:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z5upperPfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE2064:
	.size	_Z5upperPfS_S_iii, .-_Z5upperPfS_S_iii
	.section	.rodata.str1.1
.LC11:
	.string	"Upper"
	.text
	.globl	_Z10ForwardSubv
	.type	_Z10ForwardSubv, @function
_Z10ForwardSubv:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC11(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$120, %rsp
	.cfi_def_cfa_offset 144
	movl	Size(%rip), %esi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	Size(%rip), %esi
	leaq	8(%rsp), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movslq	Size(%rip), %rsi
	leaq	16(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	Size(%rip), %edx
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movq	m(%rip), %rsi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	Size(%rip), %edx
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	a(%rip), %rsi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movslq	Size(%rip), %rdx
	movq	b(%rip), %rsi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	Size(%rip), %ecx
	movl	$8388609, %eax
	xorl	%esi, %esi
	salq	$9, %rax
	movl	$512, %edi
	movl	$1, 32(%rsp)
	testl	$511, %ecx
	movq	%rax, 24(%rsp)
	movl	%ecx, %eax
	setne	%sil
	cltd
	movl	$1, 56(%rsp)
	idivl	%edi
	movl	$1, 68(%rsp)
	movl	$4, %edi
	addl	%eax, %esi
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movabsq	$17179869188, %rax
	movl	%esi, 36(%rsp)
	xorl	%esi, %esi
	testb	$3, %cl
	movq	%rax, 48(%rsp)
	movl	%ecx, %eax
	setne	%sil
	xorl	%ebx, %ebx
	cltd
	idivl	%edi
	leaq	72(%rsp), %rdi
	addl	%esi, %eax
	xorl	%esi, %esi
	movl	%eax, 60(%rsp)
	movl	%eax, 64(%rsp)
	call	gettimeofday@PLT
.L57:
	movl	Size(%rip), %eax
	decl	%eax
	cmpl	%ebx, %eax
	jle	.L63
	movl	32(%rsp), %ecx
	movq	24(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	36(%rsp), %rdi
	movl	44(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L58
	movl	Size(%rip), %edx
	movq	8(%rsp), %rsi
	movl	%ebx, %ecx
	movq	(%rsp), %rdi
	call	_Z34__device_stub__Z10multiplierPfS_iiPfS_ii
.L58:
	call	cudaThreadSynchronize@PLT
	movl	56(%rsp), %ecx
	movl	68(%rsp), %esi
	xorl	%r9d, %r9d
	movq	48(%rsp), %rdx
	movq	60(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L59
	movl	Size(%rip), %ecx
	movq	16(%rsp), %rdx
	movl	%ebx, %r9d
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	%ecx, %r8d
	subl	%ebx, %r8d
	call	_Z31__device_stub__Z5upperPfS_S_iiiPfS_S_iii
.L59:
	call	cudaThreadSynchronize@PLT
	movq	%rbp, %rdi
	incl	%ebx
	call	_Z14checkCUDAErrorPKc
	jmp	.L57
.L63:
	xorl	%esi, %esi
	leaq	88(%rsp), %rdi
	call	gettimeofday@PLT
	movq	(%rsp), %rsi
	imull	$1000000, 72(%rsp), %edx
	movl	$2, %ecx
	imull	$1000000, 88(%rsp), %eax
	subl	80(%rsp), %eax
	addl	96(%rsp), %eax
	movq	m(%rip), %rdi
	subl	%edx, %eax
	movl	Size(%rip), %edx
	movl	%eax, totalKernelTime(%rip)
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	Size(%rip), %edx
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	a(%rip), %rdi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movslq	Size(%rip), %rdx
	movq	b(%rip), %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L61
	call	__stack_chk_fail@PLT
.L61:
	addq	$120, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z10ForwardSubv, .-_Z10ForwardSubv
	.section	.rodata.str1.1
.LC12:
	.string	"Enter filename \n"
.LC13:
	.string	"Matrix m is: \n"
.LC14:
	.string	"Matrix a is: \n"
.LC15:
	.string	"Array b is: \n"
.LC16:
	.string	"The final solution is: \n"
.LC18:
	.string	"\nTime total (including memory transfers)\t%f sec\n"
.LC19:
	.string	"Time for CUDA kernels:\t%f sec\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$48, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	decl	%edi
	jg	.L65
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L64
.L65:
	movq	8(%rsi), %rdi
	call	_Z15InitProblemOncePc
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	_Z10InitPerRunv
	call	gettimeofday@PLT
	call	_Z10ForwardSubv
	leaq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	imull	$1000000, 8(%rsp), %eax
	movl	$2, %edi
	leaq	.LC13(%rip), %rsi
	imull	$1000000, 24(%rsp), %ebx
	subl	16(%rsp), %ebx
	addl	32(%rsp), %ebx
	subl	%eax, %ebx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	Size(%rip), %esi
	movq	m(%rip), %rdi
	movl	%esi, %edx
	call	_Z8PrintMatPfii
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	Size(%rip), %esi
	movq	a(%rip), %rdi
	movl	%esi, %edx
	call	_Z8PrintMatPfii
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	Size(%rip), %esi
	movq	b(%rip), %rdi
	call	_Z8PrintAryPfi
	call	_Z7BackSubv
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	Size(%rip), %esi
	movq	finalVec(%rip), %rdi
	call	_Z8PrintAryPfi
	cvtsi2sdq	%rbx, %xmm0
	leaq	.LC18(%rip), %rsi
	movb	$1, %al
	mulsd	.LC17(%rip), %xmm0
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	totalKernelTime(%rip), %eax
	movl	$2, %edi
	leaq	.LC19(%rip), %rsi
	cvtsi2sdq	%rax, %xmm0
	mulsd	.LC17(%rip), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	movq	m(%rip), %rdi
	call	free@PLT
	movq	a(%rip), %rdi
	call	free@PLT
	movq	b(%rip), %rdi
	call	free@PLT
	xorl	%eax, %eax
.L64:
	movq	40(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L71
	call	__stack_chk_fail@PLT
.L71:
	addq	$48, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC20:
	.string	"_Z5upperPfS_S_iii"
.LC21:
	.string	"_Z10multiplierPfS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2066:
	.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	.LC20(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z5upperPfS_S_iii(%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	.LC21(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z10multiplierPfS_ii(%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
.LFE2066:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	totalKernelTime
	.bss
	.align 4
	.type	totalKernelTime, @object
	.size	totalKernelTime, 4
totalKernelTime:
	.zero	4
	.globl	fp
	.align 8
	.type	fp, @object
	.size	fp, 8
fp:
	.zero	8
	.globl	m
	.align 8
	.type	m, @object
	.size	m, 8
m:
	.zero	8
	.globl	finalVec
	.align 8
	.type	finalVec, @object
	.size	finalVec, 8
finalVec:
	.zero	8
	.globl	b
	.align 8
	.type	b, @object
	.size	b, 8
b:
	.zero	8
	.globl	a
	.align 8
	.type	a, @object
	.size	a, 8
a:
	.zero	8
	.globl	Size
	.align 4
	.type	Size, @object
	.size	Size, 4
Size:
	.zero	4
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC17:
	.long	-1598689907
	.long	1051772663
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <string.h>
#define MAXBLOCKSIZE 512
int Size;
float *a, *b, *finalVec;
float *m;

FILE *fp;

void InitProblemOnce(char *filename);
void InitPerRun();
void ForwardSub();
void BackSub();

/*
 Calculation of Multiplier matrix to introduce zero's in each of the columns.
 */
__global__ void multiplier(float *m_cuda, float *a_cuda, int Size, int t)
{   
	int idx = threadIdx.x + blockIdx.x * blockDim.x;
	if( idx>= Size-1-t) return;
	//printf(" multiplier: \nIndex %d a1: %f a2: %f \n",idx,*(a_cuda+Size*(idx+t+1)+t),*(a_cuda+Size*t+t));
	*(m_cuda+Size*(idx+t+1)+t) = *(a_cuda+Size*(idx+t+1)+t) / *(a_cuda+Size*t+t);
}

//Conversion of matrix to Upper Triangular Matrix

__global__ void upper(float *m_cuda, float *a_cuda, float *b_cuda,int Size, int j1, int t)
{
	int xidx = blockIdx.x * blockDim.x + threadIdx.x;
	int yidx = blockIdx.y * blockDim.y + threadIdx.y;

	if(xidx >= Size-1-t) return;
	if(yidx >= Size-t) return;	
	
	a_cuda[Size*(xidx+1+t)+(yidx+t)] -= m_cuda[Size*(xidx+1+t)+t] * a_cuda[Size*t+(yidx+t)];
	
	if(yidx == 0){
		b_cuda[xidx+1+t] -= m_cuda[Size*(xidx+1+t)+(yidx+t)] * b_cuda[t];
	}
}
void InitMat(float *ary, int nrow, int ncol);
void InitAry(float *ary, int ary_size);
void PrintMat(float *ary, int nrow, int ncolumn);
void PrintAry(float *ary, int ary_size);
void checkCUDAError(const char *msg);

unsigned int totalKernelTime = 0;

int main(int argc, char *argv[])
{
	if(argc<2){
		printf("Enter filename \n");
		return 1;
	}
    InitProblemOnce(argv[1]);//Input file
    InitPerRun(); //Initialize m with 0

    //begin timing
    struct timeval time_start;
    gettimeofday(&time_start, NULL);	
    
    // run kernels
    ForwardSub();
    
    //end timing
    struct timeval time_end;
    gettimeofday(&time_end, NULL);
    unsigned int time_total = (time_end.tv_sec * 1000000 + time_end.tv_usec) - (time_start.tv_sec * 1000000 + time_start.tv_usec);
    
    
        printf("Matrix m is: \n");
        PrintMat(m, Size, Size);

        printf("Matrix a is: \n");
        PrintMat(a, Size, Size);

        printf("Array b is: \n");
        PrintAry(b, Size);
    
    BackSub();
        printf("The final solution is: \n");
        PrintAry(finalVec,Size);
    
    printf("\nTime total (including memory transfers)\t%f sec\n", time_total * 1e-6);
    printf("Time for CUDA kernels:\t%f sec\n",totalKernelTime * 1e-6);   
    free(m);
    free(a);
    free(b);
}
/*Initializing all matrices and arrays
 */
void InitProblemOnce(char *filename)
{	
	fp = fopen(filename, "r");
	fscanf(fp, "%d", &Size);	
	a = (float *) malloc(Size * Size * sizeof(float));
	InitMat(a, Size, Size);
	b = (float *) malloc(Size * sizeof(float));
	
	InitAry(b, Size);		
	 m = (float *) malloc(Size * Size * sizeof(float));
}

/*------------------------------------------------------
 ** InitPerRun() -- Initialize the contents of the
 ** multipier matrix **m
 **------------------------------------------------------
 */
void InitPerRun() 
{
	int i;
	for (i=0; i<Size*Size; i++)
			*(m+i) = 0.0;
}


/*------------------------------------------------------
 ** ForwardSub() -- Forward substitution of Gaussian
 ** elimination.
 **------------------------------------------------------
 */
void ForwardSub()
{
	int t;
    float *m_cuda,*a_cuda,*b_cuda;
	
	// allocate memory on GPU
	hipMalloc((void **) &m_cuda, Size * Size * sizeof(float));
	 
	hipMalloc((void **) &a_cuda, Size * Size * sizeof(float));
	
	hipMalloc((void **) &b_cuda, Size * sizeof(float));	

	// copy memory to GPU
	hipMemcpy(m_cuda, m, Size * Size * sizeof(float),hipMemcpyHostToDevice );
	hipMemcpy(a_cuda, a, Size * Size * sizeof(float),hipMemcpyHostToDevice );
	hipMemcpy(b_cuda, b, Size * sizeof(float),hipMemcpyHostToDevice );
	
	int block_size,grid_size;
	
	block_size = MAXBLOCKSIZE;
	grid_size = (Size/block_size) + (!(Size%block_size)? 0:1);

	dim3 dimBlock(block_size);
	dim3 dimGrid(grid_size);
	
	int blockSize2d, gridSize2d;
	blockSize2d = 4;
	gridSize2d = (Size/blockSize2d) + (!(Size%blockSize2d?0:1)); 
	
	dim3 dimBlockXY(blockSize2d,blockSize2d);
	dim3 dimGridXY(gridSize2d,gridSize2d);

    // begin timing kernels
    struct timeval time_start;
    gettimeofday(&time_start, NULL);
	for (t=0; t<(Size-1); t++) {
		multiplier<<<dimGrid,dimBlock>>>(m_cuda,a_cuda,Size,t);
		hipDeviceSynchronize();
		upper<<<dimGridXY,dimBlockXY>>>(m_cuda,a_cuda,b_cuda,Size,Size-t,t);
		hipDeviceSynchronize();
		checkCUDAError("Upper");
	}
	// end timing kernels
	struct timeval time_end;
    gettimeofday(&time_end, NULL);
    totalKernelTime = (time_end.tv_sec * 1000000 + time_end.tv_usec) - (time_start.tv_sec * 1000000 + time_start.tv_usec);
	
	// copy memory back to CPU
	hipMemcpy(m, m_cuda, Size * Size * sizeof(float),hipMemcpyDeviceToHost );
	hipMemcpy(a, a_cuda, Size * Size * sizeof(float),hipMemcpyDeviceToHost );
	hipMemcpy(b, b_cuda, Size * sizeof(float),hipMemcpyDeviceToHost );
	hipFree(m_cuda);
	hipFree(a_cuda);
	hipFree(b_cuda);
}

/*------------------------------------------------------
 ** BackSub() -- Backward substitution
 **------------------------------------------------------
 */

void BackSub()
{
	// create a new vector to hold the final answer
	finalVec = (float *) malloc(Size * sizeof(float));
	// solve "bottom up"
	int i,j;
	for(i=0;i<Size;i++){
		finalVec[Size-i-1]=b[Size-i-1];
		for(j=0;j<i;j++)
		{
			finalVec[Size-i-1]-=*(a+Size*(Size-i-1)+(Size-j-1)) * finalVec[Size-j-1];
		}
		finalVec[Size-i-1]=finalVec[Size-i-1]/ *(a+Size*(Size-i-1)+(Size-i-1));
	}
}

void InitMat(float *ary, int nrow, int ncol)
{
	int i, j;
	printf("Initial Matrix A \n");
	for (i=0; i<nrow; i++) {
		for (j=0; j<ncol; j++) {
			fscanf(fp, "%f",  ary+Size*i+j);
			printf("%f ",*(ary+Size*i+j));
		}
		printf("\n");
	}  
}

/*------------------------------------------------------
 ** PrintMat() -- Print the contents of the matrix
 **------------------------------------------------------
 */
void PrintMat(float *ary, int nrow, int ncol)
{
	int i, j;
	
	for (i=0; i<nrow; i++) {
		for (j=0; j<ncol; j++) {
			printf("%f ", *(ary+Size*i+j));
		}
		printf("\n");
	}
	printf("\n");
}

/*------------------------------------------------------
 ** InitAry() -- Initialize the array (vector) by reading
 ** data from the data file
 **------------------------------------------------------
 */
void InitAry(float *ary, int ary_size)
{
	int i;
	printf("\n Vector B is \n");
	for (i=0; i<ary_size; i++) {
		fscanf(fp, "%f",  &ary[i]);
		printf("%f ",ary[i]);
	}
}  

/*------------------------------------------------------
 ** PrintAry() -- Print the contents of the array (vector)
 **------------------------------------------------------
 */
void PrintAry(float *ary, int ary_size)
{
	int i;
	for (i=0; i<ary_size; i++) {
		printf("%.2f ", ary[i]);
	}
	printf("\n\n");
}
void checkCUDAError(const char *msg)
{
    hipError_t err = hipGetLastError();
    if( hipSuccess != err) 
    {
        fprintf(stderr, "Cuda error: %s: %s.\n", msg, 
                                  hipGetErrorString( err) );
        exit(EXIT_FAILURE);
    }                         
}
	.text
	.file	"gauss.hip"
	.globl	_Z25__device_stub__multiplierPfS_ii # -- Begin function _Z25__device_stub__multiplierPfS_ii
	.type	_Z25__device_stub__multiplierPfS_ii,@function
_Z25__device_stub__multiplierPfS_ii:    # @_Z25__device_stub__multiplierPfS_ii
	.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	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%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	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	$_Z10multiplierPfS_ii, %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	_Z25__device_stub__multiplierPfS_ii, .Lfunc_end0-_Z25__device_stub__multiplierPfS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z20__device_stub__upperPfS_S_iii # -- Begin function _Z20__device_stub__upperPfS_S_iii
	.type	_Z20__device_stub__upperPfS_S_iii,@function
_Z20__device_stub__upperPfS_S_iii:      # @_Z20__device_stub__upperPfS_S_iii
	.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	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z5upperPfS_S_iii, %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	_Z20__device_stub__upperPfS_S_iii, .Lfunc_end1-_Z20__device_stub__upperPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI2_0:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.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
	subq	$32, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	cmpl	$1, %edi
	jg	.LBB2_2
# %bb.1:
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movl	$1, %ebx
	jmp	.LBB2_5
.LBB2_2:
	movq	8(%rsi), %rdi
	callq	_Z15InitProblemOncePc
	movl	Size(%rip), %edx
	testl	%edx, %edx
	je	.LBB2_4
# %bb.3:                                # %.lr.ph.i
	imull	%edx, %edx
	movq	m(%rip), %rdi
	cmpl	$1, %edx
	adcl	$0, %edx
	shlq	$2, %rdx
	xorl	%esi, %esi
	callq	memset@PLT
.LBB2_4:                                # %_Z10InitPerRunv.exit
	xorl	%ebx, %ebx
	leaq	16(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	callq	_Z10ForwardSubv
	movq	%rsp, %r15
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	(%r15), %eax
	movl	8(%r15), %r15d
	subl	(%r14), %eax
	imull	$1000000, %eax, %eax            # imm = 0xF4240
	subl	8(%r14), %r15d
	addl	%eax, %r15d
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	m(%rip), %rdi
	movl	Size(%rip), %edx
	movl	%edx, %esi
	callq	_Z8PrintMatPfii
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movq	a(%rip), %rdi
	movl	Size(%rip), %edx
	movl	%edx, %esi
	callq	_Z8PrintMatPfii
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movq	b(%rip), %rdi
	movl	Size(%rip), %esi
	callq	_Z8PrintAryPfi
	callq	_Z7BackSubv
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movq	finalVec(%rip), %rdi
	movl	Size(%rip), %esi
	callq	_Z8PrintAryPfi
	cvtsi2sd	%r15, %xmm0
	mulsd	.LCPI2_0(%rip), %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movl	totalKernelTime(%rip), %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	mulsd	.LCPI2_0(%rip), %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movq	m(%rip), %rdi
	callq	free
	movq	a(%rip), %rdi
	callq	free
	movq	b(%rip), %rdi
	callq	free
.LBB2_5:
	movl	%ebx, %eax
	addq	$32, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z15InitProblemOncePc           # -- Begin function _Z15InitProblemOncePc
	.type	_Z15InitProblemOncePc,@function
_Z15InitProblemOncePc:                  # @_Z15InitProblemOncePc
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	$.L.str.7, %esi
	callq	fopen
	movq	%rax, fp(%rip)
	movl	$.L.str.8, %esi
	movl	$Size, %edx
	movq	%rax, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	Size(%rip), %ebx
	movl	%ebx, %edi
	imull	%edi, %edi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, a(%rip)
	movq	%rax, %rdi
	movl	%ebx, %esi
	movl	%ebx, %edx
	callq	_Z7InitMatPfii
	movslq	Size(%rip), %rbx
	movq	%rbx, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, b(%rip)
	movq	%rax, %rdi
	movl	%ebx, %esi
	callq	_Z7InitAryPfi
	movl	Size(%rip), %edi
	imull	%edi, %edi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, m(%rip)
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z15InitProblemOncePc, .Lfunc_end3-_Z15InitProblemOncePc
	.cfi_endproc
                                        # -- End function
	.globl	_Z10InitPerRunv                 # -- Begin function _Z10InitPerRunv
	.type	_Z10InitPerRunv,@function
_Z10InitPerRunv:                        # @_Z10InitPerRunv
	.cfi_startproc
# %bb.0:
	movl	Size(%rip), %edx
	testl	%edx, %edx
	je	.LBB4_1
# %bb.2:                                # %.lr.ph
	imull	%edx, %edx
	movq	m(%rip), %rdi
	cmpl	$1, %edx
	adcl	$0, %edx
	shlq	$2, %rdx
	xorl	%esi, %esi
	jmp	memset@PLT                      # TAILCALL
.LBB4_1:                                # %._crit_edge
	retq
.Lfunc_end4:
	.size	_Z10InitPerRunv, .Lfunc_end4-_Z10InitPerRunv
	.cfi_endproc
                                        # -- End function
	.globl	_Z10ForwardSubv                 # -- Begin function _Z10ForwardSubv
	.type	_Z10ForwardSubv,@function
_Z10ForwardSubv:                        # @_Z10ForwardSubv
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	Size(%rip), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	callq	hipMalloc
	movl	Size(%rip), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	movq	%rsp, %r15
	movq	%r15, %rdi
	callq	hipMalloc
	movslq	Size(%rip), %rsi
	shlq	$2, %rsi
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	m(%rip), %rsi
	movl	Size(%rip), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	movq	a(%rip), %rsi
	movl	Size(%rip), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbx), %rdi
	movq	b(%rip), %rsi
	movslq	Size(%rip), %rdx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	Size(%rip), %eax
	movl	$511, %ecx                      # imm = 0x1FF
	leal	(%rax,%rcx), %ebx
	leal	3(%rax), %r12d
	testl	%eax, %eax
	cmovnsl	%eax, %ebx
	cmovnsl	%eax, %r12d
	sarl	$9, %ebx
	andl	%eax, %ecx
	cmpl	$1, %ecx
	sbbl	$-1, %ebx
	sarl	$2, %r12d
	andl	$3, %eax
	cmpl	$1, %eax
	sbbl	$-1, %r12d
	xorl	%r13d, %r13d
	leaq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cmpl	$2, Size(%rip)
	jl	.LBB5_7
# %bb.1:                                # %.lr.ph.preheader
	movabsq	$4294967296, %r14               # imm = 0x100000000
	btsq	$32, %rbx
	leaq	1(%r14), %r15
	imulq	%r12, %r15
	addq	$512, %r14                      # imm = 0x200
	movabsq	$17179869188, %r12              # imm = 0x400000004
	xorl	%ebp, %ebp
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_4
# %bb.3:                                #   in Loop: Header=BB5_2 Depth=1
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movl	Size(%rip), %edx
	movl	%ebp, %ecx
	callq	_Z25__device_stub__multiplierPfS_ii
.LBB5_4:                                #   in Loop: Header=BB5_2 Depth=1
	callq	hipDeviceSynchronize
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_6
# %bb.5:                                #   in Loop: Header=BB5_2 Depth=1
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movq	16(%rsp), %rdx
	movl	Size(%rip), %ecx
	leal	(%rcx,%r13), %r8d
                                        # kill: def $ecx killed $ecx killed $rcx
	movl	%ebp, %r9d
	callq	_Z20__device_stub__upperPfS_S_iii
.LBB5_6:                                #   in Loop: Header=BB5_2 Depth=1
	callq	hipDeviceSynchronize
	movl	$.L.str.9, %edi
	callq	_Z14checkCUDAErrorPKc
	incl	%ebp
	movl	Size(%rip), %eax
	decl	%eax
	decl	%r13d
	cmpl	%eax, %ebp
	jl	.LBB5_2
.LBB5_7:                                # %._crit_edge
	leaq	40(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	(%rbx), %eax
	movl	8(%rbx), %ecx
	subl	24(%rsp), %eax
	subl	32(%rsp), %ecx
	imull	$1000000, %eax, %eax            # imm = 0xF4240
	addl	%eax, %ecx
	movl	%ecx, totalKernelTime(%rip)
	movq	m(%rip), %rdi
	movq	8(%rsp), %rsi
	movl	Size(%rip), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	a(%rip), %rdi
	movq	(%rsp), %rsi
	movl	Size(%rip), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	b(%rip), %rdi
	movq	16(%rsp), %rsi
	movslq	Size(%rip), %rdx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	addq	$56, %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_end5:
	.size	_Z10ForwardSubv, .Lfunc_end5-_Z10ForwardSubv
	.cfi_endproc
                                        # -- End function
	.globl	_Z8PrintMatPfii                 # -- Begin function _Z8PrintMatPfii
	.type	_Z8PrintMatPfii,@function
_Z8PrintMatPfii:                        # @_Z8PrintMatPfii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB6_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %ebx
	movl	%esi, %ebp
	movl	%edx, %eax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	xorl	%r12d, %r12d
.LBB6_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB6_5
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB6_2 Depth=1
	movslq	%r12d, %r13
	movq	8(%rsp), %r15                   # 8-byte Reload
	movq	16(%rsp), %r14                  # 8-byte Reload
.LBB6_4:                                # %.lr.ph
                                        #   Parent Loop BB6_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movslq	Size(%rip), %rax
	imulq	%r13, %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rax,4), %xmm0
	movl	$.L.str.12, %edi
	movb	$1, %al
	callq	printf
	addq	$4, %r14
	decq	%r15
	jne	.LBB6_4
.LBB6_5:                                # %._crit_edge
                                        #   in Loop: Header=BB6_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incl	%r12d
	cmpl	%ebp, %r12d
	jne	.LBB6_2
.LBB6_6:                                # %._crit_edge12
	movl	$10, %edi
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end6:
	.size	_Z8PrintMatPfii, .Lfunc_end6-_Z8PrintMatPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8PrintAryPfi                  # -- Begin function _Z8PrintAryPfi
	.type	_Z8PrintAryPfi,@function
_Z8PrintAryPfi:                         # @_Z8PrintAryPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB7_4
# %bb.1:                                # %.lr.ph.preheader
	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	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB7_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r15,4), %xmm0
	movl	$.L.str.15, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB7_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB7_4:                                # %._crit_edge
	movl	$.Lstr.5, %edi
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end7:
	.size	_Z8PrintAryPfi, .Lfunc_end7-_Z8PrintAryPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z7BackSubv                     # -- Begin function _Z7BackSubv
	.type	_Z7BackSubv,@function
_Z7BackSubv:                            # @_Z7BackSubv
	.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
	movslq	Size(%rip), %r14
	leaq	(,%r14,4), %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, finalVec(%rip)
	testq	%r14, %r14
	jle	.LBB8_6
# %bb.1:                                # %.lr.ph20
	movq	b(%rip), %rcx
	movq	a(%rip), %rdx
	movl	%r14d, %esi
	movq	%r14, %rdi
	imulq	%r14, %rdi
	leaq	(%rdx,%rdi,4), %rdi
	addq	$-4, %rdi
	negq	%rbx
	leaq	(%rax,%r14,4), %r8
	addq	$-4, %r8
	xorl	%r9d, %r9d
.LBB8_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB8_4 Depth 2
	movq	%r9, %r10
	notq	%r10
	addq	%r14, %r10
	movss	(%rcx,%r10,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, (%rax,%r10,4)
	testq	%r9, %r9
	je	.LBB8_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB8_2 Depth=1
	xorl	%r11d, %r11d
.LBB8_4:                                #   Parent Loop BB8_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rdi,%r11,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%r8,%r11,4), %xmm1
	subss	%xmm1, %xmm0
	movss	%xmm0, (%rax,%r10,4)
	decq	%r11
	movq	%r9, %r15
	addq	%r11, %r15
	jne	.LBB8_4
.LBB8_5:                                # %._crit_edge
                                        #   in Loop: Header=BB8_2 Depth=1
	movq	%r10, %r11
	imulq	%r14, %r11
	leaq	(%rdx,%r11,4), %r11
	divss	(%r11,%r10,4), %xmm0
	movss	%xmm0, (%rax,%r10,4)
	incq	%r9
	addq	%rbx, %rdi
	cmpq	%rsi, %r9
	jne	.LBB8_2
.LBB8_6:                                # %._crit_edge21
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	_Z7BackSubv, .Lfunc_end8-_Z7BackSubv
	.cfi_endproc
                                        # -- End function
	.globl	_Z7InitMatPfii                  # -- Begin function _Z7InitMatPfii
	.type	_Z7InitMatPfii,@function
_Z7InitMatPfii:                         # @_Z7InitMatPfii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	movl	$.Lstr.6, %edi
	callq	puts@PLT
	testl	%ebp, %ebp
	jle	.LBB9_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebx, %eax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	xorl	%r12d, %r12d
.LBB9_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB9_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB9_5
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB9_2 Depth=1
	movslq	%r12d, %r13
	movq	8(%rsp), %r15                   # 8-byte Reload
	movq	16(%rsp), %r14                  # 8-byte Reload
.LBB9_4:                                # %.lr.ph
                                        #   Parent Loop BB9_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	fp(%rip), %rdi
	movslq	Size(%rip), %rax
	imulq	%r13, %rax
	leaq	(%r14,%rax,4), %rdx
	movl	$.L.str.11, %esi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	Size(%rip), %rax
	imulq	%r13, %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rax,4), %xmm0
	movl	$.L.str.12, %edi
	movb	$1, %al
	callq	printf
	addq	$4, %r14
	decq	%r15
	jne	.LBB9_4
.LBB9_5:                                # %._crit_edge
                                        #   in Loop: Header=BB9_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incl	%r12d
	cmpl	%ebp, %r12d
	jne	.LBB9_2
.LBB9_6:                                # %._crit_edge14
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end9:
	.size	_Z7InitMatPfii, .Lfunc_end9-_Z7InitMatPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z7InitAryPfi                   # -- Begin function _Z7InitAryPfi
	.type	_Z7InitAryPfi,@function
_Z7InitAryPfi:                          # @_Z7InitAryPfi
	.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	%esi, %ebp
	movq	%rdi, %rbx
	movl	$.Lstr.7, %edi
	callq	puts@PLT
	testl	%ebp, %ebp
	jle	.LBB10_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r14d
.LBB10_2:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	fp(%rip), %rdi
	movl	$.L.str.11, %esi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.12, %edi
	movb	$1, %al
	callq	printf
	addq	$4, %rbx
	decq	%r14
	jne	.LBB10_2
.LBB10_3:                               # %._crit_edge
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end10:
	.size	_Z7InitAryPfi, .Lfunc_end10-_Z7InitAryPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z14checkCUDAErrorPKc           # -- Begin function _Z14checkCUDAErrorPKc
	.type	_Z14checkCUDAErrorPKc,@function
_Z14checkCUDAErrorPKc:                  # @_Z14checkCUDAErrorPKc
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB11_2
# %bb.1:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB11_2:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.17, %esi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end11:
	.size	_Z14checkCUDAErrorPKc, .Lfunc_end11-_Z14checkCUDAErrorPKc
	.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	.LBB12_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB12_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10multiplierPfS_ii, %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	$_Z5upperPfS_S_iii, %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_end12:
	.size	__hip_module_ctor, .Lfunc_end12-__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	.LBB13_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
.LBB13_2:
	retq
.Lfunc_end13:
	.size	__hip_module_dtor, .Lfunc_end13-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	Size,@object                    # @Size
	.bss
	.globl	Size
	.p2align	2, 0x0
Size:
	.long	0                               # 0x0
	.size	Size, 4

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

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

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

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

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

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

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

	.type	totalKernelTime,@object         # @totalKernelTime
	.bss
	.globl	totalKernelTime
	.p2align	2, 0x0
totalKernelTime:
	.long	0                               # 0x0
	.size	totalKernelTime, 4

	.type	.L.str.5,@object                # @.str.5
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.5:
	.asciz	"\nTime total (including memory transfers)\t%f sec\n"
	.size	.L.str.5, 49

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Time for CUDA kernels:\t%f sec\n"
	.size	.L.str.6, 31

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

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Upper"
	.size	.L.str.9, 6

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

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

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"%.2f "
	.size	.L.str.15, 6

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"Cuda error: %s: %s.\n"
	.size	.L.str.17, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10multiplierPfS_ii"
	.size	.L__unnamed_1, 21

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

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Matrix m is: "
	.size	.Lstr, 14

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Matrix a is: "
	.size	.Lstr.1, 14

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Array b is: "
	.size	.Lstr.2, 13

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"The final solution is: "
	.size	.Lstr.3, 24

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Enter filename "
	.size	.Lstr.4, 16

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"\n"
	.size	.Lstr.5, 2

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"Initial Matrix A "
	.size	.Lstr.6, 18

	.type	.Lstr.7,@object                 # @str.7
.Lstr.7:
	.asciz	"\n Vector B is "
	.size	.Lstr.7, 15

	.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 _Z25__device_stub__multiplierPfS_ii
	.addrsig_sym _Z20__device_stub__upperPfS_S_iii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym Size
	.addrsig_sym _Z10multiplierPfS_ii
	.addrsig_sym _Z5upperPfS_S_iii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10multiplierPfS_ii    ; -- Begin function _Z10multiplierPfS_ii
	.globl	_Z10multiplierPfS_ii
	.p2align	8
	.type	_Z10multiplierPfS_ii,@function
_Z10multiplierPfS_ii:                   ; @_Z10multiplierPfS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b64 s[2:3], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_not_b32 s4, s3
	s_add_i32 s4, s4, s2
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_cmp_gt_i32_e32 vcc_lo, s4, v1
	s_and_saveexec_b32 s4, vcc_lo
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_add3_u32 v0, s3, 1, v1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_ashr_i32 s1, s3, 31
	s_mov_b32 s0, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_lshl_b64 s[0:1], s[0:1], 2
	v_mul_lo_u32 v0, v0, s2
	s_mul_i32 s2, s3, s2
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_add_u32 s8, s0, s6
	s_addc_u32 s9, s1, s7
	s_ashr_i32 s3, s2, 31
	v_add_co_u32 v2, vcc_lo, s8, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s9, v1, vcc_lo
	s_lshl_b64 s[2:3], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s2, s6, s2
	global_load_b32 v2, v[2:3], off
	s_addc_u32 s3, s7, s3
	s_add_u32 s2, s2, s0
	s_addc_u32 s3, s3, s1
	s_add_u32 s0, s0, s4
	s_load_b32 s2, s[2:3], 0x0
	s_addc_u32 s1, s1, s5
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_div_scale_f32 v3, null, s2, s2, v2
	v_div_scale_f32 v6, vcc_lo, v2, s2, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v4, v3
	s_waitcnt_depctr 0xfff
	v_fma_f32 v5, -v3, v4, 1.0
	v_fmac_f32_e32 v4, v5, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v5, v6, v4
	v_fma_f32 v7, -v3, v5, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v5, v7, v4
	v_fma_f32 v3, -v3, v5, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v3, v3, v4, v5
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	v_div_fixup_f32 v2, v3, s2, v2
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10multiplierPfS_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 8
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z10multiplierPfS_ii, .Lfunc_end0-_Z10multiplierPfS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 332
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; 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	_Z5upperPfS_S_iii       ; -- Begin function _Z5upperPfS_S_iii
	.globl	_Z5upperPfS_S_iii
	.p2align	8
	.type	_Z5upperPfS_S_iii,@function
_Z5upperPfS_S_iii:                      ; @_Z5upperPfS_S_iii
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x34
	s_load_b32 s8, s[0:1], 0x20
	s_load_b32 s3, s[0:1], 0x18
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s2, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s4, v[3:4]
	s_not_b32 s2, s8
	s_sub_i32 s4, s3, s8
	s_add_i32 s2, s2, s3
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	v_cmp_gt_i32_e32 vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s2, s4, v1
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s4, s2
	s_cbranch_execz .LBB1_3
; %bb.1:
	v_add3_u32 v0, s8, 1, v0
	v_add_nc_u32_e32 v2, s8, v1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v6, v0, s3
	v_mad_u64_u32 v[3:4], null, s8, s3, v[2:3]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, s8, v6
	v_ashrrev_i32_e32 v4, 31, v3
	v_add_nc_u32_e32 v7, v6, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_ashrrev_i32_e32 v6, 31, v5
	v_lshlrev_b64 v[9:10], 2, v[3:4]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_ashrrev_i32_e32 v8, 31, v7
	v_lshlrev_b64 v[4:5], 2, v[5:6]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[2:3], 2, v[7:8]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v6, vcc_lo, s6, v9
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_u32 v4, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	v_add_co_u32 v8, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v9, vcc_lo, s7, v3, vcc_lo
	global_load_b32 v4, v[4:5], off
	s_clause 0x1
	global_load_b32 v5, v[6:7], off
	global_load_b32 v6, v[8:9], off
	v_cmp_eq_u32_e32 vcc_lo, 0, v1
	s_waitcnt vmcnt(0)
	v_fma_f32 v4, -v4, v5, v6
	global_store_b32 v[8:9], v4, off
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_3
; %bb.2:
	s_load_b64 s[0:1], s[0:1], 0x10
	v_ashrrev_i32_e32 v1, 31, v0
	v_add_co_u32 v2, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_ashr_i32 s9, s8, 31
	v_mov_b32_e32 v4, 0
	s_lshl_b64 s[2:3], s[8:9], 2
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_add_u32 s0, s0, s2
	s_addc_u32 s1, s1, s3
	global_load_b32 v2, v[2:3], off
	s_clause 0x1
	global_load_b32 v3, v4, s[0:1]
	global_load_b32 v4, v[0:1], off
	s_waitcnt vmcnt(0)
	v_fma_f32 v2, -v2, v3, v4
	global_store_b32 v[0:1], v2, off
.LBB1_3:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z5upperPfS_S_iii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 11
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z5upperPfS_S_iii, .Lfunc_end1-_Z5upperPfS_S_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 464
; NumSgprs: 18
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 11
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10multiplierPfS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10multiplierPfS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z5upperPfS_S_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z5upperPfS_S_iii.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
