#include <stdio.h>
//#include <cuda.h>
//#include "cuda_runtime_api.h"
//#include <stdint.h>
//#include <stdlib.h>

//This is the working matrix multiplication code - very basic
/****

Done:
- printing of matrix in a more pleasant manner using printMatrix function
- command line arguments
- opens matrix files and reads the matrix successfully
- working array passing from main to auxiliary (loadMatrixFile) function :)
- fixed printing of matrix
- fixed erroneous matrix values by moving loading into host matrix multiplication function!
- basic move towards SN P simulation: multiplication of s0 and Msnp
- moving from multiplication to finally simulating an SN P (sort of) in a very basic manner

Problems:
- (fixed)  MatA and MatB values are overlapping and erroneous

TODOS:
- error checking of switch case input ( scanf of int and char )
- use multiple files + make file
- see code comments

****/


/***
**** START of AUXILIARY functions
***/

/*
START of KERNEL functions
*/
//START vector addition kernel function
__global__ void MatrixAddKernel ( int  *Md, int *Nd, int *Pd, int Width ){
	// MatrixAddKernel<<< dimGrid, dimBlock >>>( Md, Nd, Pd, Width );
	//dim3 dimBlock( Width, Width ); dim3 dimGrid( 1, 1 );
	//int tx = threadIdx.x;
	int ty = threadIdx.y;
	//due to row-major ordering of matrix elements
	//int Pvalue = 0;
	for ( int k = 0; k < Width; ++k ){
		int Mdelement = Md[ ty * Width + k ];
		int Ndelement = Nd[ ty * Width + k ];
		Pd[ ty * Width + k ] = Mdelement + Ndelement;
	}
	//Pd[ ty * Width + tx  ] = Pvalue;
}							
//END of kernel addition


//START of kernel multiplication
__global__ void MatrixMulKernel ( int  *Md, int *Nd, int *Pd, int Width ){
	int tx = threadIdx.x;
	int ty = threadIdx.y;
	//due to row-major ordering of matrix elements
	int Pvalue = 0;
	for ( int k = 0; k < Width; ++k ){
		int Mdelement = Md[ ty * Width + k ];
		int Ndelement = Nd[ k * Width + tx ];
		Pvalue += Mdelement * Ndelement;
	}
	Pd[ ty * Width + tx  ] = Pvalue; 
}
//END of kernel multiplication


/*
END of KERNEL functions
*/


//function to print matrix
void printMatrix ( int *M, int rows, int columns ){
	//assumes matrix is in row-major format
	int index;
	printf ( "\n \n " );
	for ( int v = 0; v < rows; v++  ){
	//assumes a square matrix
		for ( int w = 0; w < columns; w++   ) {
			index = v * columns + w;
			printf ( " %02d", M[ index ]  );
		}
		printf ( " \n\n " );
	}
}//End of printMatrix function


//START of loadMatrixFile
void loadMatrixFile( char *filename, int *z, int matWidth, int matHeight ){
	int y = 0;
	int w = 0;
	int x;
	int offset = 0;
	FILE *ptr1 = fopen( filename, "r" );
	fscanf( ptr1, " %d", &x  );
	while( !feof( ptr1 ) && y < ( matWidth * matHeight ) + 1 ){
		if ( y > offset ){
			fscanf( ptr1, " %d", &z[ w - offset ]  );
			w++;
		}
		else{
			fscanf( ptr1, " %d", &x );
		}
		y++;
	}
	fclose( ptr1 );
}
//END of loadMatrixFile


//Start of matrix multiplication host function MatrixMul
void MatrixMul( char *filename0, char *filename1, char *filename2, int Width ){
	int size = Width * Width * sizeof( int );
	int *Md, *Nd, *Pd;

	dim3 dimBlock( Width, Width );
	dim3 dimGrid( 1, 1 );

	int *matA = ( int * )malloc( size );
	//printf( "Width and height of Matrix A: %d %d and init values are\n", Width, Width );
	//printMatrix( matA, Width, Width );
	loadMatrixFile( filename1, matA, Width, Width );

	printf( " \n%s after loading from file: \n", filename1 );
	printMatrix( matA, Width, Width );
			
	int *matB = ( int * )malloc( size );
	loadMatrixFile( filename2, matB, Width, Width );
		
	printf( " \n%s after loading from file: \n", filename2 );
	printMatrix( matB, Width, Width );
			
	//assumes a square matrix
	int *matC = ( int * )malloc( size );
	
	cudaMalloc( (void**) &Md, size );
	cudaMemcpy( Md, matA, size, cudaMemcpyHostToDevice );
	cudaMalloc( (void**) &Nd, size );
        cudaMemcpy( Nd, matB, size, cudaMemcpyHostToDevice );
	cudaMalloc( (void**) &Pd, size );	
	
	//MatrixMulKernel<<< dimGrid, dimBlock >>>( Md, Nd, Pd, Width );
	MatrixAddKernel<<< dimGrid, dimBlock >>>( Md, Nd, Pd, Width );

	cudaMemcpy( matC, Pd, size, cudaMemcpyDeviceToHost );

	printf( " \n %s * %s : \n", filename1, filename2 );
	printMatrix( matC, Width, Width );

	free( matA ); free( matB ); free( matC );
	cudaFree( Md ); cudaFree( Nd ); cudaFree ( Pd );
}
//End of Matrix multiplication function MatrixMul


/***
****END of AUXILIARY functions
****/




/***
****START of MAIN function
****/
int main ( void ) {
	int x;
	while( x != 2 ) {
		printf( "\n Type \n 1 to enter filenames < 20 in length \n 2 to quit \n: " );
		scanf( "%d", &x );
		switch( x ){
			case 1:
				char a[ 20 ], b[ 20 ], c[ 20 ];
				int d;
				printf( " Please enter spiking vector file: \n" );
				scanf( " %s", &a );
				printf( " Please enter configuration vector file: \n" );
				scanf( " %s", &b );
				printf( " Please enter spiking transition matrix file: \n" );
				scanf( " %s", &c ); 
				printf( " Please enter the square matrix width: \n" );
				scanf( " %d", &d ); 

				if( ( strlen( a ) ) > 20 && ( strlen( b ) ) > 20 && ( strlen( c ) ) > 20  ) {
					printf( " Filename/s was/were too long ( > 20 char )  " );
					// TODO: Do something about segmentation fault here when input filename is > 20 chars
					//spikVec = { "\0" }; // doesn't work
					//*confVec = NULL; // doesn't work
					break;
				}
				else {
					printf( " You entered the file %s for the spiking vector \n", a );
					printf( " You entered the file %s for the configuration vector \n", b );
					printf( " You entered the file %s for the spiking transition matrix \n ", c );
					char *confVec = b;
					char *spikVec = a;
					char *spikTransMat = c;
					int width = d;
		
					printf( "\nYou have entered files %s, %s, and %s and square matrix width %d \n", spikVec, confVec, spikTransMat, width );

					//load matrices from files
					FILE *ptr1 = fopen( confVec, "r" );
					FILE *ptr2 = fopen( spikVec, "r" );
					FILE *ptr3 = fopen( spikTransMat, "r" );

					if ( ptr1 == 0 && ptr2 == 0 && ptr3 == 0 ) {
						printf( "\n could not open one of the following files: %s %s %s \n", a, b, c );
						break;
					}
					else {
						MatrixMul( confVec, spikVec, spikTransMat, width );
					}
					fclose( ptr1 ); fclose( ptr2 ); fclose( ptr3 );
					break;				
				}
			case 2: 
				printf( " You entered quit. Bye! \n\n" );
				break;
			default:
				printf( " You entered an invalid choice \n\n" );
				break;
		}
	}
}
/***
****END of MAIN function
***/

	.file	"tmpxft_00303a64_00000000-6_snp-v12.13.10.1.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\n \n "
.LC1:
	.string	" %02d"
.LC2:
	.string	" \n\n "
	.text
	.globl	_Z11printMatrixPiii
	.type	_Z11printMatrixPiii, @function
_Z11printMatrixPiii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	leaq	.LC0(%rip), %rsi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	movl	$2, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	__printf_chk@PLT
.L3:
	cmpl	%r14d, %r13d
	jge	.L2
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,4), %r8
.L6:
	cmpl	%r15d, %ebx
	jle	.L9
	movl	(%r8,%r15,4), %edx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	incq	%r15
	movl	$2, %edi
	movq	%r8, 8(%rsp)
	call	__printf_chk@PLT
	movq	8(%rsp), %r8
	jmp	.L6
.L9:
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	incl	%r13d
	addl	%ebx, %r12d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L3
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z11printMatrixPiii, .-_Z11printMatrixPiii
	.section	.rodata.str1.1
.LC3:
	.string	"r"
.LC4:
	.string	" %d"
	.text
	.globl	_Z14loadMatrixFilePcPiii
	.type	_Z14loadMatrixFilePcPiii, @function
_Z14loadMatrixFilePcPiii:
.LFB2028:
	.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	.LC4(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	leaq	.LC3(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	imull	%ebp, %ebx
	xorl	%ebp, %ebp
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %r15
	call	fopen@PLT
	movq	%r15, %rdx
	movq	%r14, %rsi
	movq	%rax, 8(%rsp)
	movq	%rax, %rdi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
.L11:
	movq	8(%rsp), %rdi
	call	feof@PLT
	testl	%eax, %eax
	jne	.L13
	cmpl	%ebp, %ebx
	jl	.L13
	testl	%ebp, %ebp
	je	.L19
	movslq	%r12d, %rax
	movq	8(%rsp), %rdi
	movq	%r14, %rsi
	incl	%r12d
	leaq	0(%r13,%rax,4), %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	jmp	.L12
.L19:
	movq	8(%rsp), %rdi
	movq	%r15, %rdx
	movq	%r14, %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
.L12:
	incl	%ebp
	jmp	.L11
.L13:
	movq	8(%rsp), %rdi
	call	fclose@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z14loadMatrixFilePcPiii, .-_Z14loadMatrixFilePcPiii
	.globl	_Z40__device_stub__Z15MatrixAddKernelPiS_S_iPiS_S_i
	.type	_Z40__device_stub__Z15MatrixAddKernelPiS_S_iPiS_S_i, @function
_Z40__device_stub__Z15MatrixAddKernelPiS_S_iPiS_S_i:
.LFB2055:
	.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
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%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	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%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	.L20
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z15MatrixAddKernelPiS_S_i(%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
.L20:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z40__device_stub__Z15MatrixAddKernelPiS_S_iPiS_S_i, .-_Z40__device_stub__Z15MatrixAddKernelPiS_S_iPiS_S_i
	.globl	_Z15MatrixAddKernelPiS_S_i
	.type	_Z15MatrixAddKernelPiS_S_i, @function
_Z15MatrixAddKernelPiS_S_i:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z15MatrixAddKernelPiS_S_iPiS_S_i
	.cfi_endproc
.LFE2056:
	.size	_Z15MatrixAddKernelPiS_S_i, .-_Z15MatrixAddKernelPiS_S_i
	.section	.rodata.str1.1
.LC5:
	.string	" \n%s after loading from file: \n"
.LC6:
	.string	" \n %s * %s : \n"
	.text
	.globl	_Z9MatrixMulPcS_S_i
	.type	_Z9MatrixMulPcS_S_i, @function
_Z9MatrixMulPcS_S_i:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC5(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdx, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%ecx, %ebp
	imull	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	sall	$2, %ebp
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	movslq	%ebp, %rbp
	movl	%ecx, 48(%rsp)
	movabsq	$4294967297, %rax
	movq	%rbp, %rdi
	movl	%ecx, 52(%rsp)
	movl	$1, 56(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	malloc@PLT
	movl	%ebx, %ecx
	movl	%ebx, %edx
	movq	%r13, %rdi
	movq	%rax, %rsi
	movq	%rax, %r12
	call	_Z14loadMatrixFilePcPiii
	movq	%r15, %rsi
	movq	%r13, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %edx
	movl	%ebx, %esi
	movq	%r12, %rdi
	call	_Z11printMatrixPiii
	movq	%rbp, %rdi
	call	malloc@PLT
	movl	%ebx, %ecx
	movl	%ebx, %edx
	movq	%r14, %rdi
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	_Z14loadMatrixFilePcPiii
	movq	%r15, %rsi
	movq	%r14, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	movl	%ebx, %edx
	movl	%ebx, %esi
	call	_Z11printMatrixPiii
	movq	%rbp, %rdi
	call	malloc@PLT
	leaq	24(%rsp), %rdi
	movq	%rbp, %rsi
	movq	%rax, %r15
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movq	%rbp, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	32(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	movq	32(%rsp), %rdi
	movq	%rbp, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	leaq	40(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@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	.L26
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	%ebx, %ecx
	movq	24(%rsp), %rdi
	call	_Z40__device_stub__Z15MatrixAddKernelPiS_S_iPiS_S_i
.L26:
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdx
	movq	%r15, %rdi
	call	cudaMemcpy@PLT
	movq	%r14, %rcx
	movq	%r13, %rdx
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebx, %edx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	_Z11printMatrixPiii
	movq	%r12, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	%r15, %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z9MatrixMulPcS_S_i, .-_Z9MatrixMulPcS_S_i
	.section	.rodata.str1.1
.LC7:
	.string	"\n Type \n 1 to enter filenames < 20 in length \n 2 to quit \n: "
.LC8:
	.string	"%d"
.LC9:
	.string	" Please enter spiking vector file: \n"
.LC10:
	.string	" %s"
.LC11:
	.string	" Please enter configuration vector file: \n"
.LC12:
	.string	" Please enter spiking transition matrix file: \n"
.LC13:
	.string	" Please enter the square matrix width: \n"
.LC14:
	.string	" You entered the file %s for the spiking vector \n"
.LC15:
	.string	" You entered the file %s for the configuration vector \n"
.LC16:
	.string	" You entered the file %s for the spiking transition matrix \n "
.LC17:
	.string	"\nYou have entered files %s, %s, and %s and square matrix width %d \n"
.LC18:
	.string	"\n could not open one of the following files: %s %s %s \n"
.LC19:
	.string	" You entered quit. Bye! \n\n"
.LC20:
	.string	" You entered an invalid choice \n\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
.L30:
	cmpl	$2, 20(%rsp)
	je	.L41
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	20(%rsp), %rsi
	leaq	.LC8(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	20(%rsp), %eax
	cmpl	$1, %eax
	je	.L31
	leaq	.LC19(%rip), %rsi
	cmpl	$2, %eax
	je	.L40
	leaq	.LC20(%rip), %rsi
	jmp	.L40
.L31:
	leaq	28(%rsp), %rbp
	leaq	.LC10(%rip), %r13
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC9(%rip), %rsi
	leaq	48(%rsp), %rbx
	call	__printf_chk@PLT
	movq	%r13, %rdi
	movq	%rbp, %rsi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r13, %rdi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	68(%rsp), %r12
	leaq	.LC12(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%r13, %rdi
	movq	%r12, %rsi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC13(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	24(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rdi
	call	__isoc23_scanf@PLT
	movq	%rbp, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC14(%rip), %rsi
	leaq	.LC3(%rip), %r13
	call	__printf_chk@PLT
	movq	%rbx, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC15(%rip), %rsi
	call	__printf_chk@PLT
	movq	%r12, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC16(%rip), %rsi
	call	__printf_chk@PLT
	movl	24(%rsp), %r9d
	movq	%r12, %r8
	movq	%rbx, %rcx
	movq	%rbp, %rdx
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movl	%r9d, 12(%rsp)
	call	__printf_chk@PLT
	movq	%r13, %rsi
	movq	%rbx, %rdi
	call	fopen@PLT
	movq	%r13, %rsi
	movq	%rbp, %rdi
	movq	%rax, %r15
	call	fopen@PLT
	movq	%r13, %rsi
	movq	%r12, %rdi
	movq	%rax, %r14
	call	fopen@PLT
	movl	12(%rsp), %r9d
	movq	%rax, %r13
	movq	%r15, %rax
	orq	%r14, %rax
	orq	%r13, %rax
	jne	.L34
	movq	%r12, %r8
	movq	%rbx, %rcx
	movq	%rbp, %rdx
	movl	$2, %edi
	leaq	.LC18(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L30
.L34:
	movl	%r9d, %ecx
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	call	_Z9MatrixMulPcS_S_i
	movq	%r15, %rdi
	call	fclose@PLT
	movq	%r14, %rdi
	call	fclose@PLT
	movq	%r13, %rdi
	call	fclose@PLT
	jmp	.L30
.L40:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L30
.L41:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	addq	$104, %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
.LFE2030:
	.size	main, .-main
	.text
	.globl	_Z40__device_stub__Z15MatrixMulKernelPiS_S_iPiS_S_i
	.type	_Z40__device_stub__Z15MatrixMulKernelPiS_S_iPiS_S_i, @function
_Z40__device_stub__Z15MatrixMulKernelPiS_S_iPiS_S_i:
.LFB2057:
	.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
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%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	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%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	.L42
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z15MatrixMulKernelPiS_S_i(%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
.L42:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L44
	call	__stack_chk_fail@PLT
.L44:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z40__device_stub__Z15MatrixMulKernelPiS_S_iPiS_S_i, .-_Z40__device_stub__Z15MatrixMulKernelPiS_S_iPiS_S_i
	.globl	_Z15MatrixMulKernelPiS_S_i
	.type	_Z15MatrixMulKernelPiS_S_i, @function
_Z15MatrixMulKernelPiS_S_i:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z15MatrixMulKernelPiS_S_iPiS_S_i
	.cfi_endproc
.LFE2058:
	.size	_Z15MatrixMulKernelPiS_S_i, .-_Z15MatrixMulKernelPiS_S_i
	.section	.rodata.str1.1
.LC21:
	.string	"_Z15MatrixMulKernelPiS_S_i"
.LC22:
	.string	"_Z15MatrixAddKernelPiS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.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	.LC21(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z15MatrixMulKernelPiS_S_i(%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	.LC22(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z15MatrixAddKernelPiS_S_i(%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
.LFE2060:
	.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 <hip/hip_runtime.h>
#include <stdio.h>
//#include <cuda.h>
//#include "cuda_runtime_api.h"
//#include <stdint.h>
//#include <stdlib.h>

//This is the working matrix multiplication code - very basic
/****

Done:
- printing of matrix in a more pleasant manner using printMatrix function
- command line arguments
- opens matrix files and reads the matrix successfully
- working array passing from main to auxiliary (loadMatrixFile) function :)
- fixed printing of matrix
- fixed erroneous matrix values by moving loading into host matrix multiplication function!
- basic move towards SN P simulation: multiplication of s0 and Msnp
- moving from multiplication to finally simulating an SN P (sort of) in a very basic manner

Problems:
- (fixed)  MatA and MatB values are overlapping and erroneous

TODOS:
- error checking of switch case input ( scanf of int and char )
- use multiple files + make file
- see code comments

****/


/***
**** START of AUXILIARY functions
***/

/*
START of KERNEL functions
*/
//START vector addition kernel function
__global__ void MatrixAddKernel ( int  *Md, int *Nd, int *Pd, int Width ){
	// MatrixAddKernel<<< dimGrid, dimBlock >>>( Md, Nd, Pd, Width );
	//dim3 dimBlock( Width, Width ); dim3 dimGrid( 1, 1 );
	//int tx = threadIdx.x;
	int ty = threadIdx.y;
	//due to row-major ordering of matrix elements
	//int Pvalue = 0;
	for ( int k = 0; k < Width; ++k ){
		int Mdelement = Md[ ty * Width + k ];
		int Ndelement = Nd[ ty * Width + k ];
		Pd[ ty * Width + k ] = Mdelement + Ndelement;
	}
	//Pd[ ty * Width + tx  ] = Pvalue;
}							
//END of kernel addition


//START of kernel multiplication
__global__ void MatrixMulKernel ( int  *Md, int *Nd, int *Pd, int Width ){
	int tx = threadIdx.x;
	int ty = threadIdx.y;
	//due to row-major ordering of matrix elements
	int Pvalue = 0;
	for ( int k = 0; k < Width; ++k ){
		int Mdelement = Md[ ty * Width + k ];
		int Ndelement = Nd[ k * Width + tx ];
		Pvalue += Mdelement * Ndelement;
	}
	Pd[ ty * Width + tx  ] = Pvalue; 
}
//END of kernel multiplication


/*
END of KERNEL functions
*/


//function to print matrix
void printMatrix ( int *M, int rows, int columns ){
	//assumes matrix is in row-major format
	int index;
	printf ( "\n \n " );
	for ( int v = 0; v < rows; v++  ){
	//assumes a square matrix
		for ( int w = 0; w < columns; w++   ) {
			index = v * columns + w;
			printf ( " %02d", M[ index ]  );
		}
		printf ( " \n\n " );
	}
}//End of printMatrix function


//START of loadMatrixFile
void loadMatrixFile( char *filename, int *z, int matWidth, int matHeight ){
	int y = 0;
	int w = 0;
	int x;
	int offset = 0;
	FILE *ptr1 = fopen( filename, "r" );
	fscanf( ptr1, " %d", &x  );
	while( !feof( ptr1 ) && y < ( matWidth * matHeight ) + 1 ){
		if ( y > offset ){
			fscanf( ptr1, " %d", &z[ w - offset ]  );
			w++;
		}
		else{
			fscanf( ptr1, " %d", &x );
		}
		y++;
	}
	fclose( ptr1 );
}
//END of loadMatrixFile


//Start of matrix multiplication host function MatrixMul
void MatrixMul( char *filename0, char *filename1, char *filename2, int Width ){
	int size = Width * Width * sizeof( int );
	int *Md, *Nd, *Pd;

	dim3 dimBlock( Width, Width );
	dim3 dimGrid( 1, 1 );

	int *matA = ( int * )malloc( size );
	//printf( "Width and height of Matrix A: %d %d and init values are\n", Width, Width );
	//printMatrix( matA, Width, Width );
	loadMatrixFile( filename1, matA, Width, Width );

	printf( " \n%s after loading from file: \n", filename1 );
	printMatrix( matA, Width, Width );
			
	int *matB = ( int * )malloc( size );
	loadMatrixFile( filename2, matB, Width, Width );
		
	printf( " \n%s after loading from file: \n", filename2 );
	printMatrix( matB, Width, Width );
			
	//assumes a square matrix
	int *matC = ( int * )malloc( size );
	
	hipMalloc( (void**) &Md, size );
	hipMemcpy( Md, matA, size, hipMemcpyHostToDevice );
	hipMalloc( (void**) &Nd, size );
        hipMemcpy( Nd, matB, size, hipMemcpyHostToDevice );
	hipMalloc( (void**) &Pd, size );	
	
	//MatrixMulKernel<<< dimGrid, dimBlock >>>( Md, Nd, Pd, Width );
	MatrixAddKernel<<< dimGrid, dimBlock >>>( Md, Nd, Pd, Width );

	hipMemcpy( matC, Pd, size, hipMemcpyDeviceToHost );

	printf( " \n %s * %s : \n", filename1, filename2 );
	printMatrix( matC, Width, Width );

	free( matA ); free( matB ); free( matC );
	hipFree( Md ); hipFree( Nd ); hipFree ( Pd );
}
//End of Matrix multiplication function MatrixMul


/***
****END of AUXILIARY functions
****/




/***
****START of MAIN function
****/
int main ( void ) {
	int x;
	while( x != 2 ) {
		printf( "\n Type \n 1 to enter filenames < 20 in length \n 2 to quit \n: " );
		scanf( "%d", &x );
		switch( x ){
			case 1:
				char a[ 20 ], b[ 20 ], c[ 20 ];
				int d;
				printf( " Please enter spiking vector file: \n" );
				scanf( " %s", &a );
				printf( " Please enter configuration vector file: \n" );
				scanf( " %s", &b );
				printf( " Please enter spiking transition matrix file: \n" );
				scanf( " %s", &c ); 
				printf( " Please enter the square matrix width: \n" );
				scanf( " %d", &d ); 

				if( ( strlen( a ) ) > 20 && ( strlen( b ) ) > 20 && ( strlen( c ) ) > 20  ) {
					printf( " Filename/s was/were too long ( > 20 char )  " );
					// TODO: Do something about segmentation fault here when input filename is > 20 chars
					//spikVec = { "\0" }; // doesn't work
					//*confVec = NULL; // doesn't work
					break;
				}
				else {
					printf( " You entered the file %s for the spiking vector \n", a );
					printf( " You entered the file %s for the configuration vector \n", b );
					printf( " You entered the file %s for the spiking transition matrix \n ", c );
					char *confVec = b;
					char *spikVec = a;
					char *spikTransMat = c;
					int width = d;
		
					printf( "\nYou have entered files %s, %s, and %s and square matrix width %d \n", spikVec, confVec, spikTransMat, width );

					//load matrices from files
					FILE *ptr1 = fopen( confVec, "r" );
					FILE *ptr2 = fopen( spikVec, "r" );
					FILE *ptr3 = fopen( spikTransMat, "r" );

					if ( ptr1 == 0 && ptr2 == 0 && ptr3 == 0 ) {
						printf( "\n could not open one of the following files: %s %s %s \n", a, b, c );
						break;
					}
					else {
						MatrixMul( confVec, spikVec, spikTransMat, width );
					}
					fclose( ptr1 ); fclose( ptr2 ); fclose( ptr3 );
					break;				
				}
			case 2: 
				printf( " You entered quit. Bye! \n\n" );
				break;
			default:
				printf( " You entered an invalid choice \n\n" );
				break;
		}
	}
}
/***
****END of MAIN function
***/

	.text
	.file	"snp-v12.13.10.1.hip"
	.globl	_Z30__device_stub__MatrixAddKernelPiS_S_i # -- Begin function _Z30__device_stub__MatrixAddKernelPiS_S_i
	.type	_Z30__device_stub__MatrixAddKernelPiS_S_i,@function
_Z30__device_stub__MatrixAddKernelPiS_S_i: # @_Z30__device_stub__MatrixAddKernelPiS_S_i
	.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	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%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	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z15MatrixAddKernelPiS_S_i, %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	_Z30__device_stub__MatrixAddKernelPiS_S_i, .Lfunc_end0-_Z30__device_stub__MatrixAddKernelPiS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z30__device_stub__MatrixMulKernelPiS_S_i # -- Begin function _Z30__device_stub__MatrixMulKernelPiS_S_i
	.type	_Z30__device_stub__MatrixMulKernelPiS_S_i,@function
_Z30__device_stub__MatrixMulKernelPiS_S_i: # @_Z30__device_stub__MatrixMulKernelPiS_S_i
	.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	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%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	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z15MatrixMulKernelPiS_S_i, %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_end1:
	.size	_Z30__device_stub__MatrixMulKernelPiS_S_i, .Lfunc_end1-_Z30__device_stub__MatrixMulKernelPiS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z11printMatrixPiii             # -- Begin function _Z11printMatrixPiii
	.type	_Z11printMatrixPiii,@function
_Z11printMatrixPiii:                    # @_Z11printMatrixPiii
	.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, 8(%rsp)                   # 8-byte Spill
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	testl	%ebp, %ebp
	jle	.LBB2_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebp, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%ebx, %r12d
	xorl	%ebp, %ebp
	xorl	%r13d, %r13d
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB2_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%ebp, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB2_4:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r14,%r15,4), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB2_4
.LBB2_5:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r13
	addl	%ebx, %ebp
	cmpq	16(%rsp), %r13                  # 8-byte Folded Reload
	jne	.LBB2_2
.LBB2_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_end2:
	.size	_Z11printMatrixPiii, .Lfunc_end2-_Z11printMatrixPiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z14loadMatrixFilePcPiii        # -- Begin function _Z14loadMatrixFilePcPiii
	.type	_Z14loadMatrixFilePcPiii,@function
_Z14loadMatrixFilePcPiii:               # @_Z14loadMatrixFilePcPiii
	.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	%ecx, %ebx
	movl	%edx, %ebp
	movq	%rsi, %r14
	movl	$.L.str.3, %esi
	callq	fopen
	movq	%rax, %r15
	leaq	4(%rsp), %rdx
	movl	$.L.str.4, %esi
	movq	%rax, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movq	%r15, %rdi
	callq	feof
	testl	%eax, %eax
	jne	.LBB3_8
# %bb.1:
	imull	%ebp, %ebx
	testl	%ebx, %ebx
	js	.LBB3_8
# %bb.2:                                # %.lr.ph.preheader
	leaq	4(%rsp), %r12
	xorl	%ebp, %ebp
	xorl	%r13d, %r13d
.LBB3_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	testl	%ebp, %ebp
	je	.LBB3_5
# %bb.4:                                #   in Loop: Header=BB3_3 Depth=1
	movslq	%r13d, %r13
	leaq	(%r14,%r13,4), %rdx
	movl	$.L.str.4, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	incl	%r13d
	jmp	.LBB3_6
.LBB3_5:                                #   in Loop: Header=BB3_3 Depth=1
	movl	$.L.str.4, %esi
	movq	%r15, %rdi
	movq	%r12, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
.LBB3_6:                                #   in Loop: Header=BB3_3 Depth=1
	movq	%r15, %rdi
	callq	feof
	testl	%eax, %eax
	jne	.LBB3_8
# %bb.7:                                #   in Loop: Header=BB3_3 Depth=1
	leal	1(%rbp), %eax
	cmpl	%ebx, %ebp
	movl	%eax, %ebp
	jl	.LBB3_3
.LBB3_8:                                # %.critedge
	movq	%r15, %rdi
	callq	fclose
	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_end3:
	.size	_Z14loadMatrixFilePcPiii, .Lfunc_end3-_Z14loadMatrixFilePcPiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z9MatrixMulPcS_S_i             # -- Begin function _Z9MatrixMulPcS_S_i
	.type	_Z9MatrixMulPcS_S_i,@function
_Z9MatrixMulPcS_S_i:                    # @_Z9MatrixMulPcS_S_i
	.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	%ecx, %ebx
	movq	%rdx, %r15
	movq	%rsi, %r12
	movl	%ecx, %eax
	imull	%ecx, %eax
	shll	$2, %eax
	movl	%ecx, %ecx
	movq	%rcx, %r14
	shlq	$32, %r14
	orq	%rcx, %r14
	movslq	%eax, %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %rbp
	movq	%r12, %rdi
	movq	%rax, %rsi
	movl	%ebx, %edx
	movl	%ebx, %ecx
	callq	_Z14loadMatrixFilePcPiii
	movl	$.L.str.5, %edi
	movq	%r12, 40(%rsp)                  # 8-byte Spill
	movq	%r12, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	%rbp, %rdi
	movl	%ebx, %esi
	movl	%ebx, %edx
	callq	_Z11printMatrixPiii
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%r15, %rdi
	movq	%rax, %rsi
	movl	%ebx, %edx
	movl	%ebx, %ecx
	callq	_Z14loadMatrixFilePcPiii
	movl	$.L.str.5, %edi
	movq	%r15, 48(%rsp)                  # 8-byte Spill
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	%r12, %rdi
	movl	%ebx, %esi
	movl	%ebx, %edx
	callq	_Z11printMatrixPiii
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	leaq	16(%rsp), %r15
	movq	%r15, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r15), %rdi
	movq	%rbp, 32(%rsp)                  # 8-byte Spill
	movq	%rbp, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %r15
	movq	%r15, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r15), %rdi
	movq	%r12, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%rsp, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_2
# %bb.1:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	movl	%ebx, %ecx
	callq	_Z30__device_stub__MatrixAddKernelPiS_S_i
.LBB4_2:
	movq	(%rsp), %rsi
	movq	24(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.6, %edi
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movq	48(%rsp), %rdx                  # 8-byte Reload
	xorl	%eax, %eax
	callq	printf
	movq	%r14, %rdi
	movl	%ebx, %esi
	movl	%ebx, %edx
	callq	_Z11printMatrixPiii
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%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_end4:
	.size	_Z9MatrixMulPcS_S_i, .Lfunc_end4-_Z9MatrixMulPcS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15MatrixAddKernelPiS_S_i, %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	$_Z15MatrixMulKernelPiS_S_i, %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_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z15MatrixAddKernelPiS_S_i,@object # @_Z15MatrixAddKernelPiS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z15MatrixAddKernelPiS_S_i
	.p2align	3, 0x0
_Z15MatrixAddKernelPiS_S_i:
	.quad	_Z30__device_stub__MatrixAddKernelPiS_S_i
	.size	_Z15MatrixAddKernelPiS_S_i, 8

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"\n \n "
	.size	.L.str, 5

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

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

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	" \n%s after loading from file: \n"
	.size	.L.str.5, 32

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	" \n %s * %s : \n"
	.size	.L.str.6, 15

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z15MatrixAddKernelPiS_S_i"
	.size	.L__unnamed_1, 27

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z15MatrixMulKernelPiS_S_i"
	.size	.L__unnamed_2, 27

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

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

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

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z15MatrixAddKernelPiS_S_i ; -- Begin function _Z15MatrixAddKernelPiS_S_i
	.globl	_Z15MatrixAddKernelPiS_S_i
	.p2align	8
	.type	_Z15MatrixAddKernelPiS_S_i,@function
_Z15MatrixAddKernelPiS_S_i:             ; @_Z15MatrixAddKernelPiS_S_i
; %bb.0:
	s_load_b32 s2, s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s2, 1
	s_cbranch_scc1 .LBB0_3
; %bb.1:                                ; %.lr.ph
	s_clause 0x1
	s_load_b64 s[8:9], s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	v_bfe_u32 v0, v0, 10, 10
	v_mov_b32_e32 v1, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v0, v0, s2
	v_lshlrev_b64 v[4:5], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s8, v4
	v_add_co_ci_u32_e32 v1, vcc_lo, s9, v5, vcc_lo
	v_add_co_u32 v2, vcc_lo, s6, v4
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v5, vcc_lo
	v_add_co_u32 v4, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	global_load_b32 v6, v[4:5], off
	global_load_b32 v7, v[2:3], off
	v_add_co_u32 v2, vcc_lo, v2, 4
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	v_add_co_u32 v4, vcc_lo, v4, 4
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
	s_add_i32 s2, s2, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s2, 0
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v6, v7, v6
	global_store_b32 v[0:1], v6, off
	v_add_co_u32 v0, vcc_lo, v0, 4
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
	s_cbranch_scc0 .LBB0_2
.LBB0_3:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15MatrixAddKernelPiS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 1
		.amdhsa_next_free_vgpr 8
		.amdhsa_next_free_sgpr 10
		.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	_Z15MatrixAddKernelPiS_S_i, .Lfunc_end0-_Z15MatrixAddKernelPiS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 212
; NumSgprs: 12
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 12
; 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: 1
	.text
	.protected	_Z15MatrixMulKernelPiS_S_i ; -- Begin function _Z15MatrixMulKernelPiS_S_i
	.globl	_Z15MatrixMulKernelPiS_S_i
	.p2align	8
	.type	_Z15MatrixMulKernelPiS_S_i,@function
_Z15MatrixMulKernelPiS_S_i:             ; @_Z15MatrixMulKernelPiS_S_i
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x18
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v6, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2)
	v_mul_lo_u32 v1, v1, s2
	s_cmp_lt_i32 s2, 1
	s_cbranch_scc1 .LBB1_3
; %bb.1:                                ; %.lr.ph.preheader
	v_mov_b32_e32 v3, 0
	s_mov_b32 s3, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mov_b32_e32 v2, v3
	v_lshlrev_b64 v[4:5], 2, v[1:2]
	v_mov_b32_e32 v2, v6
	v_mov_b32_e32 v0, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(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
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_lshlrev_b64 v[7:8], 2, v[2:3]
	v_add_nc_u32_e32 v2, s2, v2
	s_add_i32 s3, s3, -1
	s_cmp_eq_u32 s3, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v7, vcc_lo, s6, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s7, v8, vcc_lo
	global_load_b32 v9, v[4:5], off
	global_load_b32 v10, v[7:8], off
	v_add_co_u32 v4, vcc_lo, v4, 4
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[7:8], null, v10, v9, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v0, v7
	s_cbranch_scc0 .LBB1_2
	s_branch .LBB1_4
.LBB1_3:
	v_mov_b32_e32 v0, 0
.LBB1_4:                                ; %Flow39
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v1, v1, v6
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_store_b32 v[1:2], v0, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15MatrixMulKernelPiS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 1
		.amdhsa_next_free_vgpr 11
		.amdhsa_next_free_sgpr 8
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z15MatrixMulKernelPiS_S_i, .Lfunc_end1-_Z15MatrixMulKernelPiS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 276
; NumSgprs: 10
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 10
; NumVGPRsForWavesPerEU: 11
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15MatrixAddKernelPiS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     12
    .sgpr_spill_count: 0
    .symbol:         _Z15MatrixAddKernelPiS_S_i.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
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15MatrixMulKernelPiS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     10
    .sgpr_spill_count: 0
    .symbol:         _Z15MatrixMulKernelPiS_S_i.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
