#include <iostream>
#include <cstdio>
#include <fstream>
#include <cstdlib>
using namespace std;
//#include <cuda_runtime.h>
#include "cuda.h"
//#include <sdkHelper.h> 
#define TIMES 1

#ifdef GEM5_FUSION
#include <stdint.h>
extern "C" {
void m5_work_begin(uint64_t workid, uint64_t threadid);
void m5_work_end(uint64_t workid, uint64_t threadid);
}
#endif

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////HELP FUNCTIONS/////////////////////////////////////////////////
void RandomInit(float* data, int n)
{
    for (int i=0; i<n; i++)
	{
        data[i] = rand() / (float)RAND_MAX;
	}
}

#define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
inline void __checkCudaErrors(cudaError err, const char *file, const int line )
{
    if(cudaSuccess != err)
    {
        fprintf(stderr, "%s(%i) : CUDA Runtime API error %d: %s.\n",file, line, (int)err, cudaGetErrorString( err ) );
        exit(-1);        
    }
}

// This will output the proper error string when calling cudaGetLastError
#define getLastCudaError(msg)      __getLastCudaError (msg, __FILE__, __LINE__)

inline void __getLastCudaError(const char *errorMessage, const char *file, const int line )
{
    cudaError_t err = cudaGetLastError();
    if (cudaSuccess != err)
    {
        fprintf(stderr, "%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n",
        file, line, errorMessage, (int)err, cudaGetErrorString( err ) );
        exit(-1);
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////__NAIVE_MATRIX_MULTIPLICATION_///////////////////////////////////////////////
// Device code
// Compute C = A * B

#define TILEWIDTH_X 16
#define TILEWIDTH_Y 16
#define TILE_WIDTH 16

__global__ void matrixMultiply(float* d_M, float* d_N, float* d_P,
			        int Width) {
	 __shared__ float ds_M[TILE_WIDTH][TILE_WIDTH];
	 __shared__ float ds_N[TILE_WIDTH][TILE_WIDTH];
	 int bx = blockIdx.x; int by = blockIdx.y;
	 int tx = threadIdx.x; int ty = threadIdx.y;
	// Identify the row and column of the Pd element to work on
	 int Row = by * TILE_WIDTH + ty;
	 int Col = bx * TILE_WIDTH + tx;
	 float Pvalue = 0;
	// Loop over the M and N tiles required to compute the Pd element
	 for (int m = 0; m < Width/TILE_WIDTH; ++m) {
	// Coolaborative loading of Md and Nd tiles into shared memory
	   ds_M[ty][tx] = d_M[Row*Width + m*TILE_WIDTH+tx];
	  ds_N[ty][tx] = d_N[(m*TILE_WIDTH+ty)*Width+Col];
	   __syncthreads();
	 for (int k = 0; k < TILE_WIDTH; ++k)
	    Pvalue += ds_M[ty][k] * ds_N[k][tx];
	   __syncthreads();
	} 
	  d_P[Row*Width+Col] = Pvalue;
}

void MatrixMulOnHost(float * A, float * B, float * C,
			       int numARows, int numAColumns,
			       int numBRows, int numBColumns,
			       int numCRows, int numCColumns)
{
	for (int i = 0; i < numARows; ++i)
	for (int j = 0; j < numBColumns; ++j) {
	float sum = 0;
	for (int k = 0; k < numAColumns; ++k) {
	float a = A[i * numAColumns + k];
	float b = B[k * numBColumns + j];
	sum += a * b;
	}
	C[i * numCColumns + j] = sum;
	}
}

int MatrixMulti(int numARows, int numAColumns, int numBRows, int numBColumns, int blockx, int blocky, bool optimzed, bool define=false) 
{
	if(!optimzed)
		printf("NAIVE MATRIX MULTIPLICATION\n");
	else if(define)
		printf("Optimzed MATRIX MULTIPLICATION with static shared memory allocation\n");
	else
		printf("Optimzed MATRIX MULTIPLICATION with static dynamic memory allocation\n");

    float * hostA; // The A matrix
    float * hostB; // The B matrix
    float * hostC; // The output C matrix
    float * deviceA;
    float * deviceB;
    float * deviceC;
    int numCRows = numARows;; // number of rows in the matrix C (you have to set this)
    int numCColumns = numBColumns;; // number of columns in the matrix C (you have to set this)
	double total_time=0;
	//StopWatchInterface* timer;
    int sizeA = numARows*numAColumns*sizeof(float);
	int sizeB = numBRows*numBColumns*sizeof(float);
	int sizeC = numCRows*numCColumns*sizeof(float);

	if(numAColumns != numBRows)
	{
		cout<<"Error in inputs dimension! A columns != B rows"<<endl;
		exit(-1);
	}
    // Allocate input vectors h_A and h_B in host memory
    hostA = (float*)malloc(sizeA);
    hostB = (float*)malloc(sizeB);
    hostC = (float*)malloc(sizeC);
    
    // Initialize input vectors
    RandomInit(hostA, numARows*numAColumns);
    RandomInit(hostB, numBRows*numBColumns);
    RandomInit(hostC, numBRows*numBColumns);

    cout<<"The dimensions of A are "<<numARows<<" x "<<numAColumns<<endl;
    cout<<"The dimensions of B are "<<numBRows<<" x "<<numBColumns<<endl;

    //Allocate GPU memory here
   // checkCudaErrors(cudaMalloc(&deviceA, sizeA));
  //	checkCudaErrors(cudaMalloc(&deviceB, sizeB));
  //	checkCudaErrors(cudaMalloc(&deviceC, sizeC));

    //@@ Copy memory to the GPU here
	//checkCudaErrors(cudaMemcpy(deviceA, hostA, sizeA, cudaMemcpyHostToDevice));
  //	checkCudaErrors(cudaMemcpy(deviceB, hostB, sizeB, cudaMemcpyHostToDevice));
    
#ifdef GEM5_FUSION
    m5_work_begin(0, 0);
#endif
	dim3 dimBlock, dimGrid;

	dimBlock = dim3(blockx, blocky);
	dimGrid = dim3((numCColumns+blockx-1)/blockx, (numCRows+blocky-1)/blocky);

	//matrixMultiply<<<dimGrid, dimBlock>>>(deviceA, deviceB, deviceC,numAColumns);
        matrixMultiply<<<dimGrid, dimBlock>>>(hostA, hostB, hostC, numAColumns);
	getLastCudaError("kernel launch failure");
	checkCudaErrors(cudaThreadSynchronize());

#ifdef GEM5_FUSION
    m5_work_end(0, 0);
#endif


	double dSeconds = total_time/((double)TIMES * 1000);
	double dNumOps = 2.0 * (double)numARows * (double)numAColumns * (double)numBColumns;
	double gflops = 1.0e-9 * dNumOps/dSeconds;
	cout<<"Time = "<<dSeconds*1.0e3<< "msec"<<endl<<"gflops = "<<gflops<<endl;

    //@@ Copy the GPU memory back to the CPU here
	//checkCudaErrors(cudaMemcpy(hostC, deviceC, sizeC, cudaMemcpyDeviceToHost));

	// Verify result
	//float* hostcpu = (float*)malloc(sizeC);
	/*MatrixMulOnHost(hostA,hostB,hostcpu,numARows,numAColumns,numBRows,numBColumns,numCRows,numCColumns);
    int i;
	int j;
    for (i = 0; i < numCRows; ++i) 
	for(j=0; j<numCColumns; j++)
	{
        if (fabs(hostC[i*numCColumns + j] - hostcpu[i*numCColumns + j]) > 1e-3)
		{
            break;
		}
    }*/

    //@@ Free the GPU memory here
	///checkCudaErrors(cudaFree(deviceA));
  //	checkCudaErrors(cudaFree(deviceB));
  	//checkCudaErrors(cudaFree(deviceC));
//	cudaDeviceReset();

    free(hostA);
    free(hostB);
    free(hostC);
	//free(hostcpu);
	/*if(i == numCRows && j == numCColumns)
		cout<<"SUCCSESS"<<endl;
	else 
		cout<<"FAILED"<<endl; */

    return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc,char *argv[])
{ 

if(argc < 6)
     printf("Unsuffcient number of arguments!\n");
else
	{
		MatrixMulti(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), false);
	}
}

	.file	"tmpxft_0022e340_00000000-6_MatrixMultiplication.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3774:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3774:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z10RandomInitPfi
	.type	_Z10RandomInitPfi, @function
_Z10RandomInitPfi:
.LFB3766:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L3:
	cmpl	%ebx, %ebp
	jle	.L7
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L3
.L7:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3766:
	.size	_Z10RandomInitPfi, .-_Z10RandomInitPfi
	.globl	_Z15MatrixMulOnHostPfS_S_iiiiii
	.type	_Z15MatrixMulOnHostPfS_S_iiiiii, @function
_Z15MatrixMulOnHostPfS_S_iiiiii:
.LFB3769:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	xorl	%r9d, %r9d
	xorl	%r10d, %r10d
	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
	movl	%ecx, %ebp
	xorl	%ecx, %ecx
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movslq	48(%rsp), %r11
	movq	%rsi, %rbx
	movq	%rdx, %rsi
	salq	$2, %r11
.L9:
	cmpl	%ebp, %r10d
	jge	.L8
	movslq	%r9d, %rax
	leaq	(%rsi,%rax,4), %r14
	movslq	%ecx, %rax
	leaq	(%rdi,%rax,4), %r13
	xorl	%eax, %eax
.L14:
	cmpl	%eax, 48(%rsp)
	jle	.L11
	leaq	(%rbx,%rax,4), %r12
	xorl	%edx, %edx
	xorps	%xmm0, %xmm0
.L12:
	cmpl	%edx, %r8d
	jle	.L16
	movss	0(%r13,%rdx,4), %xmm1
	mulss	(%r12), %xmm1
	incq	%rdx
	addq	%r11, %r12
	addss	%xmm1, %xmm0
	jmp	.L12
.L16:
	movss	%xmm0, (%r14,%rax,4)
	incq	%rax
	jmp	.L14
.L11:
	incl	%r10d
	addl	64(%rsp), %r9d
	addl	%r8d, %ecx
	jmp	.L9
.L8:
	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
.LFE3769:
	.size	_Z15MatrixMulOnHostPfS_S_iiiiii, .-_Z15MatrixMulOnHostPfS_S_iiiiii
	.globl	_Z39__device_stub__Z14matrixMultiplyPfS_S_iPfS_S_i
	.type	_Z39__device_stub__Z14matrixMultiplyPfS_S_iPfS_S_i, @function
_Z39__device_stub__Z14matrixMultiplyPfS_S_iPfS_S_i:
.LFB3796:
	.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	.L17
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z14matrixMultiplyPfS_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
.L17:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3796:
	.size	_Z39__device_stub__Z14matrixMultiplyPfS_S_iPfS_S_i, .-_Z39__device_stub__Z14matrixMultiplyPfS_S_iPfS_S_i
	.globl	_Z14matrixMultiplyPfS_S_i
	.type	_Z14matrixMultiplyPfS_S_i, @function
_Z14matrixMultiplyPfS_S_i:
.LFB3797:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z14matrixMultiplyPfS_S_iPfS_S_i
	.cfi_endproc
.LFE3797:
	.size	_Z14matrixMultiplyPfS_S_i, .-_Z14matrixMultiplyPfS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"NAIVE MATRIX MULTIPLICATION\n"
.LC3:
	.string	"Optimzed MATRIX MULTIPLICATION with static shared memory allocation\n"
.LC4:
	.string	"Optimzed MATRIX MULTIPLICATION with static dynamic memory allocation\n"
.LC5:
	.string	"Error in inputs dimension! A columns != B rows"
.LC6:
	.string	"The dimensions of A are "
.LC7:
	.string	" x "
.LC8:
	.string	"The dimensions of B are "
.LC9:
	.string	"kernel launch failure"
.LC10:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/mkhairy/gem5-gpu/master/benchmarks/rodinia-nocopy/MM_Optimzed/MatrixMultiplication.cu"
.LC11:
	.string	"%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n"
.LC12:
	.string	"%s(%i) : CUDA Runtime API error %d: %s.\n"
.LC15:
	.string	"Time = "
.LC16:
	.string	"msec"
.LC17:
	.string	"gflops = "
	.text
	.globl	_Z11MatrixMultiiiiiiibb
	.type	_Z11MatrixMultiiiiiiibb, @function
_Z11MatrixMultiiiiiiibb:
.LFB3770:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edx, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%r8d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%r9d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edi, %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	%esi, %ebx
	leaq	.LC2(%rip), %rsi
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	cmpb	$0, 128(%rsp)
	movl	136(%rsp), %eax
	je	.L31
	leaq	.LC3(%rip), %rsi
	testb	%al, %al
	jne	.L31
	leaq	.LC4(%rip), %rsi
.L31:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebp, %eax
	movl	%r12d, %esi
	imull	%r15d, %eax
	imull	%ebx, %esi
	movl	%eax, 24(%rsp)
	sall	$2, %eax
	movl	%eax, 8(%rsp)
	movl	%r12d, %eax
	leal	0(,%rsi,4), %edi
	imull	%ebp, %eax
	sall	$2, %eax
	movl	%eax, 16(%rsp)
	cmpl	%r15d, %ebx
	je	.L26
	leaq	.LC5(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	orl	$-1, %edi
	call	exit@PLT
.L26:
	movslq	%edi, %rdi
	movl	%esi, 28(%rsp)
	leaq	.LC7(%rip), %r15
	call	malloc@PLT
	movslq	8(%rsp), %rdi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movslq	16(%rsp), %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movl	28(%rsp), %esi
	movq	(%rsp), %rdi
	movq	%rax, 16(%rsp)
	call	_Z10RandomInitPfi
	movl	24(%rsp), %esi
	movq	8(%rsp), %rdi
	call	_Z10RandomInitPfi
	movl	24(%rsp), %esi
	movq	16(%rsp), %rdi
	call	_Z10RandomInitPfi
	leaq	.LC6(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r12d, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%r15, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	leaq	.LC8(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%r15, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	leal	-1(%rbp,%r14), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cltd
	movl	%r14d, 40(%rsp)
	movl	$1, %ecx
	movl	$1, %esi
	idivl	%r14d
	movl	%r13d, 44(%rsp)
	movl	%eax, 52(%rsp)
	leal	-1(%r12,%r13), %eax
	cltd
	idivl	%r13d
	movq	40(%rsp), %rdx
	movl	%eax, 56(%rsp)
	movq	52(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	%ebx, %ecx
	movq	(%rsp), %rdi
	call	_Z39__device_stub__Z14matrixMultiplyPfS_S_iPfS_S_i
.L27:
	call	cudaGetLastError@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L28
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$163, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC9(%rip), %r9
	pushq	%rax
	.cfi_remember_state
	.cfi_def_cfa_offset 136
	leaq	.LC10(%rip), %rcx
	leaq	.LC11(%rip), %rdx
	xorl	%eax, %eax
	pushq	%r13
	.cfi_def_cfa_offset 144
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L32
.L28:
	.cfi_restore_state
	call	cudaThreadSynchronize@PLT
	testl	%eax, %eax
	je	.L29
	movl	%eax, %edi
	movl	%eax, 24(%rsp)
	call	cudaGetErrorString@PLT
	movl	$164, %r8d
	movl	$2, %esi
	movq	stderr(%rip), %rdi
	pushq	%rdx
	.cfi_def_cfa_offset 136
	leaq	.LC10(%rip), %rcx
	leaq	.LC12(%rip), %rdx
	pushq	%rax
	.cfi_def_cfa_offset 144
	movl	40(%rsp), %r9d
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L32:
	orl	$-1, %edi
	call	exit@PLT
.L29:
	.cfi_def_cfa_offset 128
	cvtsi2sdl	%r12d, %xmm0
	leaq	.LC15(%rip), %rsi
	cvtsi2sdl	%ebx, %xmm1
	leaq	_ZSt4cout(%rip), %rdi
	addsd	%xmm0, %xmm0
	mulsd	%xmm1, %xmm0
	cvtsi2sdl	%ebp, %xmm1
	mulsd	%xmm1, %xmm0
	xorps	%xmm1, %xmm1
	mulsd	.LC13(%rip), %xmm0
	divsd	%xmm1, %xmm0
	movq	%xmm0, %rbx
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	xorps	%xmm0, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC16(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	leaq	.LC17(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbx, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E@PLT
	movq	(%rsp), %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	free@PLT
	addq	$72, %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
.LFE3770:
	.size	_Z11MatrixMultiiiiiiibb, .-_Z11MatrixMultiiiiiiibb
	.section	.rodata.str1.1
.LC18:
	.string	"Unsuffcient number of arguments!\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3771:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	cmpl	$5, %edi
	jg	.L34
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L35
.L34:
	movq	48(%rsi), %rdi
	movq	%rsi, %rbx
	call	atoi@PLT
	movq	40(%rbx), %rdi
	movl	%eax, 12(%rsp)
	call	atoi@PLT
	movq	32(%rbx), %rdi
	movl	%eax, 8(%rsp)
	call	atoi@PLT
	movq	24(%rbx), %rdi
	movl	%eax, %r13d
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %r12d
	call	atoi@PLT
	movq	8(%rbx), %rdi
	movl	%eax, %ebp
	call	atoi@PLT
	pushq	$0
	.cfi_def_cfa_offset 72
	movl	%r12d, %edx
	movl	%r13d, %ecx
	pushq	$0
	.cfi_def_cfa_offset 80
	movl	28(%rsp), %r9d
	movl	%eax, %edi
	movl	%ebp, %esi
	movl	24(%rsp), %r8d
	call	_Z11MatrixMultiiiiiiibb
	popq	%rax
	.cfi_def_cfa_offset 72
	popq	%rdx
	.cfi_def_cfa_offset 64
.L35:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.LFE3771:
	.size	main, .-main
	.section	.rodata.str1.1
.LC19:
	.string	"_Z14matrixMultiplyPfS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3799:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 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	.LC19(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14matrixMultiplyPfS_S_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	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	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3799:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC13:
	.long	-400107883
	.long	1041313291
	.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 <iostream>
#include <cstdio>
#include <fstream>
#include <cstdlib>
using namespace std;
//#include <cuda_runtime.h>
#include "hip/hip_runtime.h"
//#include <sdkHelper.h> 
#define TIMES 1

#ifdef GEM5_FUSION
#include <stdint.h>
extern "C" {
void m5_work_begin(uint64_t workid, uint64_t threadid);
void m5_work_end(uint64_t workid, uint64_t threadid);
}
#endif

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////HELP FUNCTIONS/////////////////////////////////////////////////
void RandomInit(float* data, int n)
{
    for (int i=0; i<n; i++)
	{
        data[i] = rand() / (float)RAND_MAX;
	}
}

#define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)
inline void __checkCudaErrors(hipError_t err, const char *file, const int line )
{
    if(hipSuccess != err)
    {
        fprintf(stderr, "%s(%i) : CUDA Runtime API error %d: %s.\n",file, line, (int)err, hipGetErrorString( err ) );
        exit(-1);        
    }
}

// This will output the proper error string when calling cudaGetLastError
#define getLastCudaError(msg)      __getLastCudaError (msg, __FILE__, __LINE__)

inline void __getLastCudaError(const char *errorMessage, const char *file, const int line )
{
    hipError_t err = hipGetLastError();
    if (hipSuccess != err)
    {
        fprintf(stderr, "%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n",
        file, line, errorMessage, (int)err, hipGetErrorString( err ) );
        exit(-1);
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////__NAIVE_MATRIX_MULTIPLICATION_///////////////////////////////////////////////
// Device code
// Compute C = A * B

#define TILEWIDTH_X 16
#define TILEWIDTH_Y 16
#define TILE_WIDTH 16

__global__ void matrixMultiply(float* d_M, float* d_N, float* d_P,
			        int Width) {
	 __shared__ float ds_M[TILE_WIDTH][TILE_WIDTH];
	 __shared__ float ds_N[TILE_WIDTH][TILE_WIDTH];
	 int bx = blockIdx.x; int by = blockIdx.y;
	 int tx = threadIdx.x; int ty = threadIdx.y;
	// Identify the row and column of the Pd element to work on
	 int Row = by * TILE_WIDTH + ty;
	 int Col = bx * TILE_WIDTH + tx;
	 float Pvalue = 0;
	// Loop over the M and N tiles required to compute the Pd element
	 for (int m = 0; m < Width/TILE_WIDTH; ++m) {
	// Coolaborative loading of Md and Nd tiles into shared memory
	   ds_M[ty][tx] = d_M[Row*Width + m*TILE_WIDTH+tx];
	  ds_N[ty][tx] = d_N[(m*TILE_WIDTH+ty)*Width+Col];
	   __syncthreads();
	 for (int k = 0; k < TILE_WIDTH; ++k)
	    Pvalue += ds_M[ty][k] * ds_N[k][tx];
	   __syncthreads();
	} 
	  d_P[Row*Width+Col] = Pvalue;
}

void MatrixMulOnHost(float * A, float * B, float * C,
			       int numARows, int numAColumns,
			       int numBRows, int numBColumns,
			       int numCRows, int numCColumns)
{
	for (int i = 0; i < numARows; ++i)
	for (int j = 0; j < numBColumns; ++j) {
	float sum = 0;
	for (int k = 0; k < numAColumns; ++k) {
	float a = A[i * numAColumns + k];
	float b = B[k * numBColumns + j];
	sum += a * b;
	}
	C[i * numCColumns + j] = sum;
	}
}

int MatrixMulti(int numARows, int numAColumns, int numBRows, int numBColumns, int blockx, int blocky, bool optimzed, bool define=false) 
{
	if(!optimzed)
		printf("NAIVE MATRIX MULTIPLICATION\n");
	else if(define)
		printf("Optimzed MATRIX MULTIPLICATION with static shared memory allocation\n");
	else
		printf("Optimzed MATRIX MULTIPLICATION with static dynamic memory allocation\n");

    float * hostA; // The A matrix
    float * hostB; // The B matrix
    float * hostC; // The output C matrix
    float * deviceA;
    float * deviceB;
    float * deviceC;
    int numCRows = numARows;; // number of rows in the matrix C (you have to set this)
    int numCColumns = numBColumns;; // number of columns in the matrix C (you have to set this)
	double total_time=0;
	//StopWatchInterface* timer;
    int sizeA = numARows*numAColumns*sizeof(float);
	int sizeB = numBRows*numBColumns*sizeof(float);
	int sizeC = numCRows*numCColumns*sizeof(float);

	if(numAColumns != numBRows)
	{
		cout<<"Error in inputs dimension! A columns != B rows"<<endl;
		exit(-1);
	}
    // Allocate input vectors h_A and h_B in host memory
    hostA = (float*)malloc(sizeA);
    hostB = (float*)malloc(sizeB);
    hostC = (float*)malloc(sizeC);
    
    // Initialize input vectors
    RandomInit(hostA, numARows*numAColumns);
    RandomInit(hostB, numBRows*numBColumns);
    RandomInit(hostC, numBRows*numBColumns);

    cout<<"The dimensions of A are "<<numARows<<" x "<<numAColumns<<endl;
    cout<<"The dimensions of B are "<<numBRows<<" x "<<numBColumns<<endl;

    //Allocate GPU memory here
   // checkCudaErrors(cudaMalloc(&deviceA, sizeA));
  //	checkCudaErrors(cudaMalloc(&deviceB, sizeB));
  //	checkCudaErrors(cudaMalloc(&deviceC, sizeC));

    //@@ Copy memory to the GPU here
	//checkCudaErrors(cudaMemcpy(deviceA, hostA, sizeA, cudaMemcpyHostToDevice));
  //	checkCudaErrors(cudaMemcpy(deviceB, hostB, sizeB, cudaMemcpyHostToDevice));
    
#ifdef GEM5_FUSION
    m5_work_begin(0, 0);
#endif
	dim3 dimBlock, dimGrid;

	dimBlock = dim3(blockx, blocky);
	dimGrid = dim3((numCColumns+blockx-1)/blockx, (numCRows+blocky-1)/blocky);

	//matrixMultiply<<<dimGrid, dimBlock>>>(deviceA, deviceB, deviceC,numAColumns);
        matrixMultiply<<<dimGrid, dimBlock>>>(hostA, hostB, hostC, numAColumns);
	getLastCudaError("kernel launch failure");
	checkCudaErrors(hipDeviceSynchronize());

#ifdef GEM5_FUSION
    m5_work_end(0, 0);
#endif


	double dSeconds = total_time/((double)TIMES * 1000);
	double dNumOps = 2.0 * (double)numARows * (double)numAColumns * (double)numBColumns;
	double gflops = 1.0e-9 * dNumOps/dSeconds;
	cout<<"Time = "<<dSeconds*1.0e3<< "msec"<<endl<<"gflops = "<<gflops<<endl;

    //@@ Copy the GPU memory back to the CPU here
	//checkCudaErrors(cudaMemcpy(hostC, deviceC, sizeC, cudaMemcpyDeviceToHost));

	// Verify result
	//float* hostcpu = (float*)malloc(sizeC);
	/*MatrixMulOnHost(hostA,hostB,hostcpu,numARows,numAColumns,numBRows,numBColumns,numCRows,numCColumns);
    int i;
	int j;
    for (i = 0; i < numCRows; ++i) 
	for(j=0; j<numCColumns; j++)
	{
        if (fabs(hostC[i*numCColumns + j] - hostcpu[i*numCColumns + j]) > 1e-3)
		{
            break;
		}
    }*/

    //@@ Free the GPU memory here
	///checkCudaErrors(cudaFree(deviceA));
  //	checkCudaErrors(cudaFree(deviceB));
  	//checkCudaErrors(cudaFree(deviceC));
//	cudaDeviceReset();

    free(hostA);
    free(hostB);
    free(hostC);
	//free(hostcpu);
	/*if(i == numCRows && j == numCColumns)
		cout<<"SUCCSESS"<<endl;
	else 
		cout<<"FAILED"<<endl; */

    return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc,char *argv[])
{ 

if(argc < 6)
     printf("Unsuffcient number of arguments!\n");
else
	{
		MatrixMulti(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), false);
	}
}

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

                                        # End of file scope inline assembly
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z10RandomInitPfi
.LCPI0_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	_Z10RandomInitPfi
	.type	_Z10RandomInitPfi,@function
_Z10RandomInitPfi:                      # @_Z10RandomInitPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB0_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
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB0_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
.LBB0_4:                                # %._crit_edge
	retq
.Lfunc_end0:
	.size	_Z10RandomInitPfi, .Lfunc_end0-_Z10RandomInitPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__matrixMultiplyPfS_S_i # -- Begin function _Z29__device_stub__matrixMultiplyPfS_S_i
	.type	_Z29__device_stub__matrixMultiplyPfS_S_i,@function
_Z29__device_stub__matrixMultiplyPfS_S_i: # @_Z29__device_stub__matrixMultiplyPfS_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	$_Z14matrixMultiplyPfS_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	_Z29__device_stub__matrixMultiplyPfS_S_i, .Lfunc_end1-_Z29__device_stub__matrixMultiplyPfS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z15MatrixMulOnHostPfS_S_iiiiii # -- Begin function _Z15MatrixMulOnHostPfS_S_iiiiii
	.type	_Z15MatrixMulOnHostPfS_S_iiiiii,@function
_Z15MatrixMulOnHostPfS_S_iiiiii:        # @_Z15MatrixMulOnHostPfS_S_iiiiii
	.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
	.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	%rdx, -8(%rsp)                  # 8-byte Spill
	movq	%rsi, -16(%rsp)                 # 8-byte Spill
	testl	%ecx, %ecx
	jle	.LBB2_9
# %bb.1:                                # %.preheader29.lr.ph
	movslq	56(%rsp), %r9
	movslq	72(%rsp), %r10
	movl	%ecx, %ecx
	movl	%r9d, %r11d
	movl	%r8d, %ebx
	shlq	$2, %r9
	xorl	%r14d, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.preheader29
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
                                        #       Child Loop BB2_6 Depth 3
	cmpl	$0, 56(%rsp)
	jle	.LBB2_8
# %bb.3:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%r14d, %eax
	leaq	(%rdi,%rax,4), %r12
	movq	%r15, %rax
	imulq	%r10, %rax
	movq	-8(%rsp), %rdx                  # 8-byte Reload
	leaq	(%rdx,%rax,4), %r13
	movq	-16(%rsp), %rsi                 # 8-byte Reload
	xorl	%eax, %eax
.LBB2_4:                                # %.preheader
                                        #   Parent Loop BB2_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB2_6 Depth 3
	xorps	%xmm0, %xmm0
	testl	%r8d, %r8d
	jle	.LBB2_7
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB2_4 Depth=2
	movq	%rsi, %rbp
	xorl	%edx, %edx
.LBB2_6:                                # %.lr.ph
                                        #   Parent Loop BB2_2 Depth=1
                                        #     Parent Loop BB2_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r12,%rdx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%rbp), %xmm1
	addss	%xmm1, %xmm0
	incq	%rdx
	addq	%r9, %rbp
	cmpq	%rdx, %rbx
	jne	.LBB2_6
.LBB2_7:                                # %._crit_edge
                                        #   in Loop: Header=BB2_4 Depth=2
	movss	%xmm0, (%r13,%rax,4)
	incq	%rax
	addq	$4, %rsi
	cmpq	%r11, %rax
	jne	.LBB2_4
.LBB2_8:                                # %._crit_edge33
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r15
	addl	%r8d, %r14d
	cmpq	%rcx, %r15
	jne	.LBB2_2
.LBB2_9:                                # %._crit_edge35
	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	_Z15MatrixMulOnHostPfS_S_iiiiii, .Lfunc_end2-_Z15MatrixMulOnHostPfS_S_iiiiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z11MatrixMultiiiiiiibb
.LCPI3_0:
	.long	0x30000000                      # float 4.65661287E-10
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI3_1:
	.quad	0x3e112e0be826d695              # double 1.0000000000000001E-9
	.text
	.globl	_Z11MatrixMultiiiiiiibb
	.type	_Z11MatrixMultiiiiiiibb,@function
_Z11MatrixMultiiiiiiibb:                # @_Z11MatrixMultiiiiiiibb
	.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
                                        # kill: def $r9d killed $r9d def $r9
	movq	%r9, 48(%rsp)                   # 8-byte Spill
                                        # kill: def $r8d killed $r8d def $r8
	movq	%r8, 40(%rsp)                   # 8-byte Spill
	movl	%ecx, %r12d
	movl	%edx, %ebx
	movl	%esi, %r15d
	movl	%edi, %r14d
	movl	$.Lstr.2, %eax
	cmpb	$0, 120(%rsp)
	movl	$.Lstr.1, %ecx
	cmovneq	%rax, %rcx
	movl	$.Lstr, %edi
	cmpb	$0, 112(%rsp)
	cmovneq	%rcx, %rdi
	callq	puts@PLT
	cmpl	%ebx, %r15d
	jne	.LBB3_14
# %bb.1:
	movl	%r14d, %ebp
	imull	%r12d, %ebp
	shll	$2, %ebp
	movq	%r12, 32(%rsp)                  # 8-byte Spill
                                        # kill: def $r12d killed $r12d killed $r12 def $r12
	imull	%r15d, %r12d
	movq	%r14, %rax
	leal	(,%r12,4), %r14d
	movl	%r15d, 16(%rsp)                 # 4-byte Spill
	movl	%r15d, %r13d
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	imull	%eax, %r13d
	leal	(,%r13,4), %eax
	movslq	%eax, %rdi
	callq	malloc
	movq	%rax, %rbx
	movslq	%r14d, %rdi
	callq	malloc
	movq	%rax, %r14
	movslq	%ebp, %rdi
	callq	malloc
	movq	%rax, %r15
	testl	%r13d, %r13d
	jle	.LBB3_4
# %bb.2:                                # %.lr.ph.preheader.i
	movl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB3_3:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	movss	%xmm0, (%rbx,%rbp,4)
	incq	%rbp
	cmpq	%rbp, %r13
	jne	.LBB3_3
.LBB3_4:                                # %_Z10RandomInitPfi.exit
	testl	%r12d, %r12d
	jle	.LBB3_9
# %bb.5:                                # %.lr.ph.preheader.i60
	movl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB3_6:                                # %.lr.ph.i62
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movss	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%r14,%r13,4)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB3_6
# %bb.7:                                # %.lr.ph.i69.preheader
	xorl	%r13d, %r13d
.LBB3_8:                                # %.lr.ph.i69
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	movss	%xmm0, (%r15,%r13,4)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB3_8
.LBB3_9:                                # %_Z10RandomInitPfi.exit73
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$24, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movq	24(%rsp), %rbp                  # 8-byte Reload
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movq	%rax, %r12
	movl	$.L.str.5, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r12, %rdi
	movl	16(%rsp), %r13d                 # 4-byte Reload
	movl	%r13d, %esi
	callq	_ZNSolsEi
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$24, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%r13d, %esi
	callq	_ZNSolsEi
	movq	%rax, %r12
	movl	$.L.str.5, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r12, %rdi
	movq	32(%rsp), %r13                  # 8-byte Reload
	movl	%r13d, %esi
	callq	_ZNSolsEi
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movl	%edi, %eax
	movq	48(%rsp), %rsi                  # 8-byte Reload
	movq	%rsi, %rcx
	shlq	$32, %rcx
	orq	%rax, %rcx
	leal	(%rdi,%r13), %eax
	decl	%eax
	cltd
	idivl	%edi
	movl	%eax, %edi
	leal	(%rsi,%rbp), %eax
	decl	%eax
	cltd
	idivl	%esi
                                        # kill: def $eax killed $eax def $rax
	shlq	$32, %rax
	orq	%rax, %rdi
	movl	$1, %esi
	movq	%rcx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_11
# %bb.10:
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	16(%rsp), %ecx                  # 4-byte Reload
	callq	_Z29__device_stub__matrixMultiplyPfS_S_i
.LBB3_11:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB3_16
# %bb.12:                               # %_Z18__getLastCudaErrorPKcS0_i.exit
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB3_17
# %bb.13:                               # %_Z17__checkCudaErrors10hipError_tPKci.exit
	cvtsi2sdl	24(%rsp), %xmm0         # 4-byte Folded Reload
	addsd	%xmm0, %xmm0
	cvtsi2sdl	16(%rsp), %xmm1         # 4-byte Folded Reload
	mulsd	%xmm0, %xmm1
	cvtsi2sd	%r13d, %xmm2
	mulsd	%xmm1, %xmm2
	mulsd	.LCPI3_1(%rip), %xmm2
	xorpd	%xmm0, %xmm0
	divsd	%xmm0, %xmm2
	movsd	%xmm2, 16(%rsp)                 # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$7, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	xorpd	%xmm0, %xmm0
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movl	$.L.str.10, %esi
	movl	$4, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r12), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rax, %r12
	movl	$.L.str.11, %esi
	movl	$9, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r12, %rdi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	xorl	%eax, %eax
	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
.LBB3_14:
	.cfi_def_cfa_offset 112
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	jmp	.LBB3_15
.LBB3_16:
	movl	%eax, %r12d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movq	%rax, (%rsp)
	movl	$.L.str.13, %esi
	movl	$.L.str.8, %edx
	movl	$.L.str.7, %r8d
	movq	%rbx, %rdi
	movl	$163, %ecx
	movl	%r12d, %r9d
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB3_15
.LBB3_17:
	movl	%eax, %r12d
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.14, %esi
	movl	$.L.str.8, %edx
	movq	%rbx, %rdi
	movl	$164, %ecx
	movl	%r12d, %r8d
	movq	%rax, %r9
	xorl	%eax, %eax
	callq	fprintf
.LBB3_15:
	movl	$-1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z11MatrixMultiiiiiiibb, .Lfunc_end3-_Z11MatrixMultiiiiiiibb
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	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
	cmpl	$5, %edi
	jg	.LBB4_2
# %bb.1:
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	jmp	.LBB4_3
.LBB4_2:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %r14d
	movq	24(%rbx), %rdi
	callq	atoi
	movl	%eax, %r15d
	movq	32(%rbx), %rdi
	callq	atoi
	movl	%eax, %r12d
	movq	40(%rbx), %rdi
	callq	atoi
	movl	%eax, %r13d
	movq	48(%rbx), %rdi
	callq	atoi
	xorl	%r10d, %r10d
	movl	%ebp, %edi
	movl	%r14d, %esi
	movl	%r15d, %edx
	movl	%r12d, %ecx
	movl	%r13d, %r8d
	movl	%eax, %r9d
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	callq	_Z11MatrixMultiiiiiiibb
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.LBB4_3:
	xorl	%eax, %eax
	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_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14matrixMultiplyPfS_S_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z14matrixMultiplyPfS_S_i,@object # @_Z14matrixMultiplyPfS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z14matrixMultiplyPfS_S_i
	.p2align	3, 0x0
_Z14matrixMultiplyPfS_S_i:
	.quad	_Z29__device_stub__matrixMultiplyPfS_S_i
	.size	_Z14matrixMultiplyPfS_S_i, 8

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"Error in inputs dimension! A columns != B rows"
	.size	.L.str.3, 47

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"The dimensions of A are "
	.size	.L.str.4, 25

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	" x "
	.size	.L.str.5, 4

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"The dimensions of B are "
	.size	.L.str.6, 25

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"kernel launch failure"
	.size	.L.str.7, 22

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/mkhairy/gem5-gpu/master/benchmarks/rodinia-nocopy/MM_Optimzed/MatrixMultiplication.hip"
	.size	.L.str.8, 149

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Time = "
	.size	.L.str.9, 8

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"msec"
	.size	.L.str.10, 5

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"gflops = "
	.size	.L.str.11, 10

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n"
	.size	.L.str.13, 56

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"%s(%i) : CUDA Runtime API error %d: %s.\n"
	.size	.L.str.14, 41

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14matrixMultiplyPfS_S_i"
	.size	.L__unnamed_1, 26

	.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	"NAIVE MATRIX MULTIPLICATION"
	.size	.Lstr, 28

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Optimzed MATRIX MULTIPLICATION with static dynamic memory allocation"
	.size	.Lstr.1, 69

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Optimzed MATRIX MULTIPLICATION with static shared memory allocation"
	.size	.Lstr.2, 68

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Unsuffcient number of arguments!"
	.size	.Lstr.3, 33

	.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 _Z29__device_stub__matrixMultiplyPfS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14matrixMultiplyPfS_S_i
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14matrixMultiplyPfS_S_i ; -- Begin function _Z14matrixMultiplyPfS_S_i
	.globl	_Z14matrixMultiplyPfS_S_i
	.p2align	8
	.type	_Z14matrixMultiplyPfS_S_i,@function
_Z14matrixMultiplyPfS_S_i:              ; @_Z14matrixMultiplyPfS_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 v2, v0, 10, 10
	v_dual_mov_b32 v3, 0 :: v_dual_and_b32 v6, 0x3ff, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshl_add_u32 v1, s15, 4, v2
	v_lshl_add_u32 v0, s14, 4, v6
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2)
	v_mul_lo_u32 v1, v1, s2
	s_cmp_lt_i32 s2, 16
	s_cbranch_scc1 .LBB0_5
; %bb.1:                                ; %.lr.ph
	v_lshlrev_b32_e32 v3, 2, v6
	v_lshlrev_b32_e32 v4, 6, v2
	s_ashr_i32 s3, s2, 31
	s_delay_alu instid0(VALU_DEP_3)
	v_add_nc_u32_e32 v6, v1, v6
	s_lshr_b32 s3, s3, 28
	v_add_nc_u32_e32 v5, 0x400, v3
	v_add_nc_u32_e32 v7, v4, v3
	v_mov_b32_e32 v3, 0
	s_add_i32 s3, s2, s3
	s_mov_b32 s8, 0
	v_add_nc_u32_e32 v8, v5, v4
	s_ashr_i32 s3, s3, 4
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	s_lshl_b32 s9, s8, 4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v10, s9, v2
	v_add_nc_u32_e32 v9, s9, v6
	s_mov_b32 s9, 0
	v_mad_u64_u32 v[11:12], null, v10, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v10, 31, v9
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v12, 31, v11
	v_add_co_u32 v9, vcc_lo, s4, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[11:12], 2, v[11:12]
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v11, vcc_lo, s6, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, s7, v12, vcc_lo
	global_load_b32 v10, v[9:10], off
	global_load_b32 v11, v[11:12], off
	v_mov_b32_e32 v9, v5
	s_waitcnt vmcnt(1)
	ds_store_b32 v7, v10
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v11
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_3:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v10, s9, v4
	s_add_i32 s9, s9, 4
	ds_load_b32 v11, v9
	ds_load_b32 v10, v10
	v_add_nc_u32_e32 v9, 64, v9
	s_cmp_eq_u32 s9, 64
	s_waitcnt lgkmcnt(0)
	v_fmac_f32_e32 v3, v10, v11
	s_cbranch_scc0 .LBB0_3
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s8, s8, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s8, s3
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_2
.LBB0_5:                                ; %Flow56
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v1, v0
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v3, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14matrixMultiplyPfS_S_i
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 13
		.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	_Z14matrixMultiplyPfS_S_i, .Lfunc_end0-_Z14matrixMultiplyPfS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 432
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; 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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14matrixMultiplyPfS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14matrixMultiplyPfS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
