/**
 * Inaki Urruta Sanchez
 * Pedro Alexandre Simoes dos Reis
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>

#define BLOCK_SIZE 16

/**
 * Initialize matrix M with dimension dim with n in all matrix's entries
 */
void initWith(float* M, int dim, float n) {
	for (int i = 0; i < dim; i++) {
		for (int j = 0; j < dim; j++) {
			M[i * dim + j] = n;
		}
	}
}

/**
 * Initialize matrix M with dimension dim with a random number between 0 and 9 in all matrix's entries
 */
void init(float* M, int dim) {
	for (int i = 0; i < dim; i++	) {
		for (int j = 0; j < dim; j++) {
			M[i * dim + j] = (rand() % 10);
		}
	}
}

/**
 * Multiplies matrix left by the matrix right, both with dimensions dim and stores the result in matrix res
 * Operation is done in GPU
 */
__global__
void matrixMul(float* left, float* right, float* res, int dim) {
    int i, j, idx;
    float temp = 0;

    __shared__ float Left_shared_t [BLOCK_SIZE][BLOCK_SIZE];
    __shared__ float Right_shared_t[BLOCK_SIZE][BLOCK_SIZE];

    // Row i of matrix left
    int row = blockIdx.y * blockDim.y + threadIdx.y;
    int col = blockIdx.x * blockDim.x + threadIdx.x;


    for (int tileNUM = 0; tileNUM < gridDim.x; tileNUM++) {

        // Column j of matrix left
        j = tileNUM * BLOCK_SIZE + threadIdx.x;
        i = tileNUM * BLOCK_SIZE + threadIdx.y;

        // Load left[i][j] to shared mem
        idx = row * dim  + tileNUM * BLOCK_SIZE + threadIdx.x;

        if (idx >= dim * dim) {
        	Left_shared_t[threadIdx.y][threadIdx.x] = 0;// Coalesced access
        } else {
        	Left_shared_t[threadIdx.y][threadIdx.x] = left[row * dim + j];// Coalesced access
        }

        // Load right[i][j] to shared mem
        idx = (tileNUM * BLOCK_SIZE + threadIdx.y) * dim + col;

        if (idx >= dim * dim) {
        	Right_shared_t[threadIdx.y][threadIdx.x] = 0;
        } else {
        	Right_shared_t[threadIdx.y][threadIdx.x] = right[i * dim + col]; // Coalesced access
        }

        // Synchronize before computation
        __syncthreads();

        // Accumulate one tile of res from tiles of left and right in shared mem
        for (int k = 0; k < BLOCK_SIZE; k++) {
            temp += Left_shared_t[threadIdx.y][k] * Right_shared_t[k][threadIdx.x]; //no shared memory bank conflict
        }

        // Synchronize
        __syncthreads();
    }

    if ((row < dim) && (col < dim)) {
		// Store accumulated value to res
		res[row * dim + col] = temp;
    }
}

/**
 * Multiplies matrix A by matrix B, both with dimension dim X dim and stores the result in matrix C with dimension dim X dim
 * Operation is done in CPU
 */
__host__
void matrixMulCPU(float* A, float* B, float* C, int dim) {
	for (int i = 0; i < dim; i++) {
		for (int j = 0; j < dim; j++) {
			float tmp = 0.0;
			for (int k = 0; k < dim; k++) {
				tmp += A[i * dim + k] * B[k * dim + j];
			}
			C[i * dim + j]  = tmp;
		}
	}
}

/**
 * Given two matrices A and B, both with dimensions dim X dim, prints in stdout if the result stored in matrix C with dimension dim X dim
 *   is the same as the result given in matrix C_cpu
 */
void checkResult(float* A, float* B, float* C, float* C_cpu, int dim) {
	for (int i = 0; i < dim; i++) {
		for (int j = 0; j < dim; j++) {
			if (abs(C[i * dim + j] - C_cpu[i * dim + j]) > 0.001) {
				printf("ERROR: Incorrect Results!\n");
				return;
			}
		}
	}

	printf("Everything is OK! :D\n");
}

/**
 * Returns the current time in milliseconds
 * Used to calculate elapsed time
 */
double cpuTimer() {
	struct timeval clock;
	gettimeofday(&clock, NULL);
	return ((double) clock.tv_sec + (double) clock.tv_usec * 1e-6);
}

int main(int argc, char** argv) {
	// Set random seed
	srand(time(0));

	cudaError_t error;

	cudaDeviceProp prop;
	int numDevices = 0;

	error = cudaGetDeviceCount(&numDevices);

	if (error != cudaSuccess) {
		printf("ERROR: %s\n", cudaGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	int totalMemory = 0;

	for (int i = 0; i < numDevices; i++) {
		error = cudaGetDeviceProperties(&prop, i);

		if (error != cudaSuccess) {
			printf("ERROR: %s\n", cudaGetErrorString(error));
			exit(EXIT_FAILURE);
		}

		totalMemory += prop.totalGlobalMem;
	}

	// Matrix size definition and calculation
	const int N = 10;
	size_t size = N * N * sizeof(float);

	int allMatrixSizes = (N * N) * 3;
	if (allMatrixSizes > totalMemory) {
		printf("ERROR");
		exit(EXIT_FAILURE);
	}

	// Matrix allocation
	float *A, *B, *C, *C_cpu;
	error = cudaMallocManaged(&A, size);

	if (error != cudaSuccess) {
		printf("ERROR: %s\n", cudaGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	error = cudaMallocManaged(&B, size);

	if (error != cudaSuccess) {
		printf("ERROR: %s\n", cudaGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	error = cudaMallocManaged(&C, size);

	if (error != cudaSuccess) {
		printf("ERROR: %s\n", cudaGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	error =cudaMallocManaged(&C_cpu, size);

	if (error != cudaSuccess) {
		printf("ERROR: %s\n", cudaGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	// Matrix initialization
	init(A, N);
	init(B, N);

	// Cuda layout definition
	dim3 threadsPerBlock(BLOCK_SIZE, BLOCK_SIZE);
	dim3 blocksPerGrid((N + BLOCK_SIZE - 1) /  BLOCK_SIZE, (N + BLOCK_SIZE - 1) / BLOCK_SIZE);

	// Start timer
	double start = cpuTimer();
	matrixMul<<<blocksPerGrid, threadsPerBlock>>>(A, B, C, N);
	cudaDeviceSynchronize();
	// Stop timer
	double stop = cpuTimer();

	error = cudaGetLastError();

	if (error != cudaSuccess) {
		printf("ERROR: %s\n", cudaGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	// Print time interval
	float gpu_milliseconds = stop - start;

	printf("Matrix Multiplication @ GPU: %f ms\n", gpu_milliseconds);

	// Start timer
	double begin = cpuTimer();

	// Matrix multiplication in CPU
	matrixMulCPU(A, B, C_cpu, N);

	// Stop timer
	double end = cpuTimer();

	// Print time interval
	float cpu_milliseconds = end - begin;
	printf("Matrix Multiplication @ CPU: %f ms\n", cpu_milliseconds);

	checkResult(A, B, C, C_cpu, N);

	// Free memory
	cudaFree(A);
	cudaFree(B);
	cudaFree(C);
	cudaFree(C_cpu);

	return 0;
}

	.file	"tmpxft_00290a86_00000000-6_matrix_mul_naive.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z8initWithPfif
	.type	_Z8initWithPfif, @function
_Z8initWithPfif:
.LFB2027:
	.cfi_startproc
	endbr64
	movslq	%esi, %rcx
	xorl	%edx, %edx
	salq	$2, %rcx
.L3:
	cmpl	%esi, %edx
	jge	.L8
	xorl	%eax, %eax
.L4:
	movss	%xmm0, (%rdi,%rax,4)
	incq	%rax
	cmpl	%eax, %esi
	jg	.L4
	incl	%edx
	addq	%rcx, %rdi
	jmp	.L3
.L8:
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z8initWithPfif, .-_Z8initWithPfif
	.globl	_Z4initPfi
	.type	_Z4initPfi, @function
_Z4initPfi:
.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
	movl	$10, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%esi, %r13
	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	%r13, %rbp
	salq	$2, %r13
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 64
.L10:
	cmpl	%ebp, %r12d
	jge	.L15
	leaq	(%rbx,%r13), %r15
.L11:
	call	rand@PLT
	addq	$4, %rbx
	cltd
	idivl	%r14d
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, -4(%rbx)
	cmpq	%r15, %rbx
	jne	.L11
	incl	%r12d
	jmp	.L10
.L15:
	popq	%rax
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z4initPfi, .-_Z4initPfi
	.globl	_Z12matrixMulCPUPfS_S_i
	.type	_Z12matrixMulCPUPfS_S_i, @function
_Z12matrixMulCPUPfS_S_i:
.LFB2029:
	.cfi_startproc
	endbr64
	movq	%rdi, %r10
	xorl	%r9d, %r9d
	movslq	%ecx, %rdi
	movq	%rsi, %r11
	salq	$2, %rdi
	xorl	%esi, %esi
	cmpl	%ecx, %r9d
	jl	.L25
	ret
.L25:
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
.L21:
	xorl	%eax, %eax
	leaq	(%r10,%rsi), %rbp
	leaq	(%rdx,%rsi), %r12
.L20:
	leaq	(%r11,%rax,4), %rbx
	xorl	%r8d, %r8d
	xorps	%xmm0, %xmm0
.L18:
	movss	0(%rbp,%r8,4), %xmm1
	mulss	(%rbx), %xmm1
	incq	%r8
	addq	%rdi, %rbx
	addss	%xmm1, %xmm0
	cmpl	%r8d, %ecx
	jg	.L18
	movss	%xmm0, (%r12,%rax,4)
	incq	%rax
	cmpl	%eax, %ecx
	jg	.L20
	incl	%r9d
	addq	%rdi, %rsi
	cmpl	%ecx, %r9d
	jl	.L21
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z12matrixMulCPUPfS_S_i, .-_Z12matrixMulCPUPfS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	"ERROR: Incorrect Results!\n"
.LC4:
	.string	"Everything is OK! :D\n"
	.text
	.globl	_Z11checkResultPfS_S_S_i
	.type	_Z11checkResultPfS_S_S_i, @function
_Z11checkResultPfS_S_S_i:
.LFB2030:
	.cfi_startproc
	endbr64
	movslq	%r8d, %rsi
	movsd	.LC2(%rip), %xmm2
	movq	%rdx, %r9
	xorl	%edi, %edi
	salq	$2, %rsi
	xorl	%edx, %edx
	movss	.LC1(%rip), %xmm1
.L27:
	cmpl	%r8d, %edx
	jge	.L36
	movq	%rdi, %rax
	xorl	%r10d, %r10d
.L30:
	movss	(%r9,%rax), %xmm0
	subss	(%rcx,%rax), %xmm0
	andps	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	comisd	%xmm2, %xmm0
	jbe	.L34
	leaq	.LC3(%rip), %rsi
	jmp	.L35
.L34:
	incl	%r10d
	addq	$4, %rax
	cmpl	%r10d, %r8d
	jne	.L30
	incl	%edx
	addq	%rsi, %rdi
	jmp	.L27
.L36:
	leaq	.LC4(%rip), %rsi
.L35:
	movl	$2, %edi
	xorl	%eax, %eax
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z11checkResultPfS_S_S_i, .-_Z11checkResultPfS_S_S_i
	.globl	_Z8cpuTimerv
	.type	_Z8cpuTimerv, @function
_Z8cpuTimerv:
.LFB2031:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	cvtsi2sdq	16(%rsp), %xmm0
	mulsd	.LC5(%rip), %xmm0
	cvtsi2sdq	8(%rsp), %xmm1
	addsd	%xmm1, %xmm0
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L38
	call	__stack_chk_fail@PLT
.L38:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z8cpuTimerv, .-_Z8cpuTimerv
	.globl	_Z33__device_stub__Z9matrixMulPfS_S_iPfS_S_i
	.type	_Z33__device_stub__Z9matrixMulPfS_S_iPfS_S_i, @function
_Z33__device_stub__Z9matrixMulPfS_S_iPfS_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	.L40
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z9matrixMulPfS_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
.L40:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L42
	call	__stack_chk_fail@PLT
.L42:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z33__device_stub__Z9matrixMulPfS_S_iPfS_S_i, .-_Z33__device_stub__Z9matrixMulPfS_S_iPfS_S_i
	.globl	_Z9matrixMulPfS_S_i
	.type	_Z9matrixMulPfS_S_i, @function
_Z9matrixMulPfS_S_i:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z9matrixMulPfS_S_iPfS_S_i
	.cfi_endproc
.LFE2058:
	.size	_Z9matrixMulPfS_S_i, .-_Z9matrixMulPfS_S_i
	.section	.rodata.str1.1
.LC6:
	.string	"ERROR: %s\n"
.LC7:
	.string	"ERROR"
.LC8:
	.string	"Matrix Multiplication @ GPU: %f ms\n"
.LC9:
	.string	"Matrix Multiplication @ CPU: %f ms\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorl	%edi, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$1120, %rsp
	.cfi_def_cfa_offset 1152
	movq	%fs:40, %rax
	movq	%rax, 1112(%rsp)
	xorl	%eax, %eax
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	xorl	%eax, %eax
	leaq	20(%rsp), %rdi
	movl	%eax, 20(%rsp)
	call	cudaGetDeviceCount@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L63
	xorl	%ebx, %ebx
	xorl	%ebp, %ebp
	leaq	80(%rsp), %r12
.L46:
	cmpl	%ebx, 20(%rsp)
	jle	.L64
	movq	%r12, %rdi
	movl	%ebx, %esi
	call	cudaGetDeviceProperties_v2@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L63
	addl	368(%rsp), %ebp
	incl	%ebx
	jmp	.L46
.L64:
	cmpl	$299, %ebp
	jg	.L49
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L62:
	movl	$1, %edi
	call	exit@PLT
.L49:
	leaq	24(%rsp), %rdi
	movl	$1, %edx
	movl	$400, %esi
	call	cudaMallocManaged@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L63
	leaq	32(%rsp), %rdi
	movl	$1, %edx
	movl	$400, %esi
	call	cudaMallocManaged@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L63
	leaq	40(%rsp), %rdi
	movl	$1, %edx
	movl	$400, %esi
	call	cudaMallocManaged@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L63
	leaq	48(%rsp), %rdi
	movl	$1, %edx
	movl	$400, %esi
	call	cudaMallocManaged@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L63
	movq	24(%rsp), %rdi
	movl	$10, %esi
	call	_Z4initPfi
	movq	32(%rsp), %rdi
	movl	$10, %esi
	call	_Z4initPfi
	movl	$1, 64(%rsp)
	movabsq	$68719476752, %rax
	movq	%rax, 56(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	_Z8cpuTimerv
	movl	64(%rsp), %ecx
	movl	76(%rsp), %esi
	xorl	%r9d, %r9d
	movq	56(%rsp), %rdx
	movq	68(%rsp), %rdi
	xorl	%r8d, %r8d
	movsd	%xmm0, (%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L54
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$10, %ecx
	movq	24(%rsp), %rdi
	call	_Z33__device_stub__Z9matrixMulPfS_S_iPfS_S_i
.L54:
	call	cudaDeviceSynchronize@PLT
	call	_Z8cpuTimerv
	movsd	%xmm0, 8(%rsp)
	call	cudaGetLastError@PLT
	movsd	8(%rsp), %xmm0
	testl	%eax, %eax
	movl	%eax, %edi
	je	.L55
.L63:
	call	cudaGetErrorString@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L62
.L55:
	subsd	(%rsp), %xmm0
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	call	_Z8cpuTimerv
	movq	48(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$10, %ecx
	movq	24(%rsp), %rdi
	movsd	%xmm0, (%rsp)
	call	_Z12matrixMulCPUPfS_S_i
	call	_Z8cpuTimerv
	subsd	(%rsp), %xmm0
	leaq	.LC9(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	48(%rsp), %rcx
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$10, %r8d
	movq	24(%rsp), %rdi
	call	_Z11checkResultPfS_S_S_i
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	1112(%rsp), %rax
	subq	%fs:40, %rax
	je	.L56
	call	__stack_chk_fail@PLT
.L56:
	addq	$1120, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z9matrixMulPfS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.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	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9matrixMulPfS_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
.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
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	-755914244
	.long	1062232653
	.align 8
.LC5:
	.long	-1598689907
	.long	1051772663
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

/**
 * Inaki Urruta Sanchez
 * Pedro Alexandre Simoes dos Reis
 */


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>

#define BLOCK_SIZE 16

/**
 * Initialize matrix M with dimension dim with n in all matrix's entries
 */
void initWith(float* M, int dim, float n) {
	for (int i = 0; i < dim; i++) {
		for (int j = 0; j < dim; j++) {
			M[i * dim + j] = n;
		}
	}
}

/**
 * Initialize matrix M with dimension dim with a random number between 0 and 9 in all matrix's entries
 */
void init(float* M, int dim) {
	for (int i = 0; i < dim; i++	) {
		for (int j = 0; j < dim; j++) {
			M[i * dim + j] = (rand() % 10);
		}
	}
}

/**
 * Multiplies matrix left by the matrix right, both with dimensions dim and stores the result in matrix res
 * Operation is done in GPU
 */
__global__
void matrixMul(float* left, float* right, float* res, int dim) {
    int i, j, idx;
    float temp = 0;

    __shared__ float Left_shared_t [BLOCK_SIZE][BLOCK_SIZE];
    __shared__ float Right_shared_t[BLOCK_SIZE][BLOCK_SIZE];

    // Row i of matrix left
    int row = blockIdx.y * blockDim.y + threadIdx.y;
    int col = blockIdx.x * blockDim.x + threadIdx.x;


    for (int tileNUM = 0; tileNUM < gridDim.x; tileNUM++) {

        // Column j of matrix left
        j = tileNUM * BLOCK_SIZE + threadIdx.x;
        i = tileNUM * BLOCK_SIZE + threadIdx.y;

        // Load left[i][j] to shared mem
        idx = row * dim  + tileNUM * BLOCK_SIZE + threadIdx.x;

        if (idx >= dim * dim) {
        	Left_shared_t[threadIdx.y][threadIdx.x] = 0;// Coalesced access
        } else {
        	Left_shared_t[threadIdx.y][threadIdx.x] = left[row * dim + j];// Coalesced access
        }

        // Load right[i][j] to shared mem
        idx = (tileNUM * BLOCK_SIZE + threadIdx.y) * dim + col;

        if (idx >= dim * dim) {
        	Right_shared_t[threadIdx.y][threadIdx.x] = 0;
        } else {
        	Right_shared_t[threadIdx.y][threadIdx.x] = right[i * dim + col]; // Coalesced access
        }

        // Synchronize before computation
        __syncthreads();

        // Accumulate one tile of res from tiles of left and right in shared mem
        for (int k = 0; k < BLOCK_SIZE; k++) {
            temp += Left_shared_t[threadIdx.y][k] * Right_shared_t[k][threadIdx.x]; //no shared memory bank conflict
        }

        // Synchronize
        __syncthreads();
    }

    if ((row < dim) && (col < dim)) {
		// Store accumulated value to res
		res[row * dim + col] = temp;
    }
}

/**
 * Multiplies matrix A by matrix B, both with dimension dim X dim and stores the result in matrix C with dimension dim X dim
 * Operation is done in CPU
 */
__host__
void matrixMulCPU(float* A, float* B, float* C, int dim) {
	for (int i = 0; i < dim; i++) {
		for (int j = 0; j < dim; j++) {
			float tmp = 0.0;
			for (int k = 0; k < dim; k++) {
				tmp += A[i * dim + k] * B[k * dim + j];
			}
			C[i * dim + j]  = tmp;
		}
	}
}

/**
 * Given two matrices A and B, both with dimensions dim X dim, prints in stdout if the result stored in matrix C with dimension dim X dim
 *   is the same as the result given in matrix C_cpu
 */
void checkResult(float* A, float* B, float* C, float* C_cpu, int dim) {
	for (int i = 0; i < dim; i++) {
		for (int j = 0; j < dim; j++) {
			if (abs(C[i * dim + j] - C_cpu[i * dim + j]) > 0.001) {
				printf("ERROR: Incorrect Results!\n");
				return;
			}
		}
	}

	printf("Everything is OK! :D\n");
}

/**
 * Returns the current time in milliseconds
 * Used to calculate elapsed time
 */
double cpuTimer() {
	struct timeval clock;
	gettimeofday(&clock, NULL);
	return ((double) clock.tv_sec + (double) clock.tv_usec * 1e-6);
}

int main(int argc, char** argv) {
	// Set random seed
	srand(time(0));

	hipError_t error;

	hipDeviceProp_t prop;
	int numDevices = 0;

	error = hipGetDeviceCount(&numDevices);

	if (error != hipSuccess) {
		printf("ERROR: %s\n", hipGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	int totalMemory = 0;

	for (int i = 0; i < numDevices; i++) {
		error = hipGetDeviceProperties(&prop, i);

		if (error != hipSuccess) {
			printf("ERROR: %s\n", hipGetErrorString(error));
			exit(EXIT_FAILURE);
		}

		totalMemory += prop.totalGlobalMem;
	}

	// Matrix size definition and calculation
	const int N = 10;
	size_t size = N * N * sizeof(float);

	int allMatrixSizes = (N * N) * 3;
	if (allMatrixSizes > totalMemory) {
		printf("ERROR");
		exit(EXIT_FAILURE);
	}

	// Matrix allocation
	float *A, *B, *C, *C_cpu;
	error = hipMallocManaged(&A, size);

	if (error != hipSuccess) {
		printf("ERROR: %s\n", hipGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	error = hipMallocManaged(&B, size);

	if (error != hipSuccess) {
		printf("ERROR: %s\n", hipGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	error = hipMallocManaged(&C, size);

	if (error != hipSuccess) {
		printf("ERROR: %s\n", hipGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	error =hipMallocManaged(&C_cpu, size);

	if (error != hipSuccess) {
		printf("ERROR: %s\n", hipGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	// Matrix initialization
	init(A, N);
	init(B, N);

	// Cuda layout definition
	dim3 threadsPerBlock(BLOCK_SIZE, BLOCK_SIZE);
	dim3 blocksPerGrid((N + BLOCK_SIZE - 1) /  BLOCK_SIZE, (N + BLOCK_SIZE - 1) / BLOCK_SIZE);

	// Start timer
	double start = cpuTimer();
	matrixMul<<<blocksPerGrid, threadsPerBlock>>>(A, B, C, N);
	hipDeviceSynchronize();
	// Stop timer
	double stop = cpuTimer();

	error = hipGetLastError();

	if (error != hipSuccess) {
		printf("ERROR: %s\n", hipGetErrorString(error));
		exit(EXIT_FAILURE);
	}

	// Print time interval
	float gpu_milliseconds = stop - start;

	printf("Matrix Multiplication @ GPU: %f ms\n", gpu_milliseconds);

	// Start timer
	double begin = cpuTimer();

	// Matrix multiplication in CPU
	matrixMulCPU(A, B, C_cpu, N);

	// Stop timer
	double end = cpuTimer();

	// Print time interval
	float cpu_milliseconds = end - begin;
	printf("Matrix Multiplication @ CPU: %f ms\n", cpu_milliseconds);

	checkResult(A, B, C, C_cpu, N);

	// Free memory
	hipFree(A);
	hipFree(B);
	hipFree(C);
	hipFree(C_cpu);

	return 0;
}

	.text
	.file	"matrix_mul_naive.hip"
	.globl	_Z8initWithPfif                 # -- Begin function _Z8initWithPfif
	.type	_Z8initWithPfif,@function
_Z8initWithPfif:                        # @_Z8initWithPfif
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB0_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%esi, %eax
	xorl	%ecx, %ecx
	xorl	%edx, %edx
.LBB0_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_3 Depth 2
	movl	%ecx, %r8d
	leaq	(%rdi,%r8,4), %r8
	xorl	%r9d, %r9d
.LBB0_3:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	%xmm0, (%r8,%r9,4)
	incq	%r9
	cmpq	%r9, %rax
	jne	.LBB0_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	incq	%rdx
	addl	%esi, %ecx
	cmpq	%rax, %rdx
	jne	.LBB0_2
.LBB0_5:                                # %._crit_edge14
	retq
.Lfunc_end0:
	.size	_Z8initWithPfif, .Lfunc_end0-_Z8initWithPfif
	.cfi_endproc
                                        # -- End function
	.globl	_Z4initPfi                      # -- Begin function _Z4initPfi
	.type	_Z4initPfi,@function
_Z4initPfi:                             # @_Z4initPfi
	.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
	movq	%rdi, (%rsp)                    # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB1_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%esi, %ebx
	movl	%esi, %r15d
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB1_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_3 Depth 2
	movl	%r12d, %eax
	movq	(%rsp), %rcx                    # 8-byte Reload
	leaq	(%rcx,%rax,4), %rbp
	xorl	%r14d, %r14d
.LBB1_3:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%rbp,%r14,4)
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB1_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	incq	%r13
	addl	%ebx, %r12d
	cmpq	%r15, %r13
	jne	.LBB1_2
.LBB1_5:                                # %._crit_edge13
	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_end1:
	.size	_Z4initPfi, .Lfunc_end1-_Z4initPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__matrixMulPfS_S_i # -- Begin function _Z24__device_stub__matrixMulPfS_S_i
	.type	_Z24__device_stub__matrixMulPfS_S_i,@function
_Z24__device_stub__matrixMulPfS_S_i:    # @_Z24__device_stub__matrixMulPfS_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	$_Z9matrixMulPfS_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_end2:
	.size	_Z24__device_stub__matrixMulPfS_S_i, .Lfunc_end2-_Z24__device_stub__matrixMulPfS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z12matrixMulCPUPfS_S_i         # -- Begin function _Z12matrixMulCPUPfS_S_i
	.type	_Z12matrixMulCPUPfS_S_i,@function
_Z12matrixMulCPUPfS_S_i:                # @_Z12matrixMulCPUPfS_S_i
	.cfi_startproc
# %bb.0:
	testl	%ecx, %ecx
	jle	.LBB3_8
# %bb.1:                                # %.preheader26.lr.ph
	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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%ecx, %eax
	leaq	(,%rax,4), %r8
	xorl	%r9d, %r9d
	xorl	%r10d, %r10d
.LBB3_2:                                # %.preheader.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_3 Depth 2
                                        #       Child Loop BB3_4 Depth 3
	movl	%r9d, %r11d
	leaq	(%rdi,%r11,4), %r11
	movq	%r10, %rbx
	imulq	%rax, %rbx
	leaq	(%rdx,%rbx,4), %rbx
	movq	%rsi, %r14
	xorl	%r15d, %r15d
.LBB3_3:                                # %.preheader
                                        #   Parent Loop BB3_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_4 Depth 3
	xorps	%xmm0, %xmm0
	movq	%r14, %r12
	xorl	%r13d, %r13d
.LBB3_4:                                #   Parent Loop BB3_2 Depth=1
                                        #     Parent Loop BB3_3 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r11,%r13,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%r12), %xmm1
	addss	%xmm1, %xmm0
	incq	%r13
	addq	%r8, %r12
	cmpq	%r13, %rax
	jne	.LBB3_4
# %bb.5:                                # %._crit_edge
                                        #   in Loop: Header=BB3_3 Depth=2
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	addq	$4, %r14
	cmpq	%rax, %r15
	jne	.LBB3_3
# %bb.6:                                # %._crit_edge30
                                        #   in Loop: Header=BB3_2 Depth=1
	incq	%r10
	addl	%ecx, %r9d
	cmpq	%rax, %r10
	jne	.LBB3_2
# %bb.7:
	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
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
.LBB3_8:                                # %._crit_edge32
	retq
.Lfunc_end3:
	.size	_Z12matrixMulCPUPfS_S_i, .Lfunc_end3-_Z12matrixMulCPUPfS_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z11checkResultPfS_S_S_i
.LCPI4_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI4_1:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
	.text
	.globl	_Z11checkResultPfS_S_S_i
	.type	_Z11checkResultPfS_S_S_i,@function
_Z11checkResultPfS_S_S_i:               # @_Z11checkResultPfS_S_S_i
	.cfi_startproc
# %bb.0:
	movl	$.Lstr.1, %edi
	testl	%r8d, %r8d
	jle	puts@PLT                        # TAILCALL
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%r8d, %eax
	xorl	%esi, %esi
	movaps	.LCPI4_0(%rip), %xmm0           # xmm0 = [NaN,NaN,NaN,NaN]
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	xorl	%r9d, %r9d
.LBB4_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_4 Depth 2
	movl	%esi, %r11d
	leaq	(%rcx,%r11,4), %r10
	leaq	(%rdx,%r11,4), %r11
	xorl	%ebx, %ebx
.LBB4_4:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r11,%rbx,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	(%r10,%rbx,4), %xmm2
	andps	%xmm0, %xmm2
	cvtss2sd	%xmm2, %xmm2
	ucomisd	%xmm1, %xmm2
	ja	.LBB4_5
# %bb.3:                                #   in Loop: Header=BB4_4 Depth=2
	incq	%rbx
	cmpq	%rbx, %rax
	jne	.LBB4_4
# %bb.7:                                # %._crit_edge
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%r9
	addl	%r8d, %esi
	cmpq	%rax, %r9
	jne	.LBB4_2
	jmp	.LBB4_6
.LBB4_5:
	movl	$.Lstr, %edi
.LBB4_6:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end4:
	.size	_Z11checkResultPfS_S_S_i, .Lfunc_end4-_Z11checkResultPfS_S_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z8cpuTimerv
.LCPI5_0:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.text
	.globl	_Z8cpuTimerv
	.type	_Z8cpuTimerv,@function
_Z8cpuTimerv:                           # @_Z8cpuTimerv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cvtsi2sdq	(%rbx), %xmm1
	cvtsi2sdq	8(%rbx), %xmm0
	mulsd	.LCPI5_0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z8cpuTimerv, .Lfunc_end5-_Z8cpuTimerv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI6_0:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$1544, %rsp                     # imm = 0x608
	.cfi_def_cfa_offset 1584
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	leaq	4(%rsp), %rdi
	movl	$0, (%rdi)
	callq	hipGetDeviceCount
	testl	%eax, %eax
	jne	.LBB6_28
# %bb.1:                                # %.preheader
	cmpl	$0, 4(%rsp)
	jle	.LBB6_29
# %bb.2:                                # %.lr.ph
	xorl	%r14d, %r14d
	leaq	72(%rsp), %rbx
	xorl	%ebp, %ebp
.LBB6_3:                                # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	testl	%eax, %eax
	jne	.LBB6_28
# %bb.4:                                #   in Loop: Header=BB6_3 Depth=1
	addl	360(%rsp), %r14d
	incl	%ebp
	cmpl	4(%rsp), %ebp
	jl	.LBB6_3
# %bb.5:                                # %._crit_edge
	cmpl	$300, %r14d                     # imm = 0x12C
	jl	.LBB6_29
# %bb.6:
	leaq	16(%rsp), %rdi
	movl	$400, %esi                      # imm = 0x190
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB6_28
# %bb.7:
	leaq	8(%rsp), %rdi
	movl	$400, %esi                      # imm = 0x190
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB6_28
# %bb.8:
	leaq	40(%rsp), %rdi
	movl	$400, %esi                      # imm = 0x190
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB6_28
# %bb.9:
	leaq	32(%rsp), %rdi
	movl	$400, %esi                      # imm = 0x190
	movl	$1, %edx
	callq	hipMallocManaged
	testl	%eax, %eax
	jne	.LBB6_28
# %bb.10:
	movq	16(%rsp), %rbx
	xorl	%r14d, %r14d
.LBB6_11:                               # %.lr.ph.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_12 Depth 2
	xorl	%r15d, %r15d
.LBB6_12:                               #   Parent Loop BB6_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	$10, %r15
	jne	.LBB6_12
# %bb.13:                               # %._crit_edge.i
                                        #   in Loop: Header=BB6_11 Depth=1
	incq	%r14
	addq	$40, %rbx
	cmpq	$10, %r14
	jne	.LBB6_11
# %bb.14:                               # %_Z4initPfi.exit
	movq	8(%rsp), %rbx
	xorl	%r14d, %r14d
.LBB6_15:                               # %.lr.ph.i50
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_16 Depth 2
	xorl	%r15d, %r15d
.LBB6_16:                               #   Parent Loop BB6_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	$10, %r15
	jne	.LBB6_16
# %bb.17:                               # %._crit_edge.i57
                                        #   in Loop: Header=BB6_15 Depth=1
	incq	%r14
	addq	$40, %rbx
	cmpq	$10, %r14
	jne	.LBB6_15
# %bb.18:                               # %_Z4initPfi.exit60
	leaq	56(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	xorps	%xmm0, %xmm0
	cvtsi2sdq	(%rbx), %xmm0
	movsd	%xmm0, 48(%rsp)                 # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2sdq	8(%rbx), %xmm0
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_20
# %bb.19:
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	40(%rsp), %rdx
	movl	$10, %ecx
	callq	_Z24__device_stub__matrixMulPfS_S_i
.LBB6_20:
	callq	hipDeviceSynchronize
	leaq	56(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx), %r14
	movq	8(%rbx), %rbx
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB6_28
# %bb.21:
	movsd	24(%rsp), %xmm2                 # 8-byte Reload
                                        # xmm2 = mem[0],zero
	mulsd	.LCPI6_0(%rip), %xmm2
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rbx, %xmm0
	mulsd	.LCPI6_0(%rip), %xmm0
	addsd	48(%rsp), %xmm2                 # 8-byte Folded Reload
	cvtsi2sd	%r14, %xmm1
	addsd	%xmm0, %xmm1
	subsd	%xmm2, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	xorl	%r14d, %r14d
	leaq	56(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx), %rax
	movq	8(%rbx), %rcx
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movq	32(%rsp), %rdi
.LBB6_22:                               # %.preheader.lr.ph.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_23 Depth 2
                                        #       Child Loop BB6_24 Depth 3
	leaq	(%r14,%r14,4), %r8
	leaq	(%rdi,%r8,8), %r8
	movq	%rsi, %r9
	xorl	%r10d, %r10d
.LBB6_23:                               # %.preheader.i
                                        #   Parent Loop BB6_22 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB6_24 Depth 3
	xorps	%xmm0, %xmm0
	movq	%r9, %r11
	xorl	%ebx, %ebx
.LBB6_24:                               #   Parent Loop BB6_22 Depth=1
                                        #     Parent Loop BB6_23 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%rdx,%rbx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%r11), %xmm1
	addss	%xmm1, %xmm0
	incq	%rbx
	addq	$40, %r11
	cmpq	$10, %rbx
	jne	.LBB6_24
# %bb.25:                               # %._crit_edge.i66
                                        #   in Loop: Header=BB6_23 Depth=2
	movss	%xmm0, (%r8,%r10,4)
	incq	%r10
	addq	$4, %r9
	cmpq	$10, %r10
	jne	.LBB6_23
# %bb.26:                               # %._crit_edge30.i
                                        #   in Loop: Header=BB6_22 Depth=1
	incq	%r14
	addq	$40, %rdx
	cmpq	$10, %r14
	jne	.LBB6_22
# %bb.27:                               # %_Z12matrixMulCPUPfS_S_i.exit
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rcx, %xmm0
	mulsd	.LCPI6_0(%rip), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	addsd	%xmm0, %xmm1
	movsd	%xmm1, 24(%rsp)                 # 8-byte Spill
	leaq	56(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	xorps	%xmm0, %xmm0
	cvtsi2sdq	(%rbx), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sdq	8(%rbx), %xmm1
	mulsd	.LCPI6_0(%rip), %xmm1
	addsd	%xmm0, %xmm1
	subsd	24(%rsp), %xmm1                 # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rcx
	movl	$10, %r8d
	callq	_Z11checkResultPfS_S_S_i
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$1544, %rsp                     # imm = 0x608
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
.LBB6_28:
	.cfi_def_cfa_offset 1584
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB6_30:                               # %._crit_edge.thread
	movl	$1, %edi
	callq	exit
.LBB6_29:                               # %._crit_edge.thread
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB6_30
.Lfunc_end6:
	.size	main, .Lfunc_end6-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	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9matrixMulPfS_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_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9matrixMulPfS_S_i,@object     # @_Z9matrixMulPfS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z9matrixMulPfS_S_i
	.p2align	3, 0x0
_Z9matrixMulPfS_S_i:
	.quad	_Z24__device_stub__matrixMulPfS_S_i
	.size	_Z9matrixMulPfS_S_i, 8

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"ERROR: %s\n"
	.size	.L.str.2, 11

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Matrix Multiplication @ GPU: %f ms\n"
	.size	.L.str.4, 36

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Matrix Multiplication @ CPU: %f ms\n"
	.size	.L.str.5, 36

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9matrixMulPfS_S_i"
	.size	.L__unnamed_1, 20

	.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	"ERROR: Incorrect Results!"
	.size	.Lstr, 26

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Everything is OK! :D"
	.size	.Lstr.1, 21

	.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 _Z24__device_stub__matrixMulPfS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9matrixMulPfS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9matrixMulPfS_S_i     ; -- Begin function _Z9matrixMulPfS_S_i
	.globl	_Z9matrixMulPfS_S_i
	.p2align	8
	.type	_Z9matrixMulPfS_S_i,@function
_Z9matrixMulPfS_S_i:                    ; @_Z9matrixMulPfS_S_i
; %bb.0:
	s_clause 0x4
	s_load_b32 s8, s[0:1], 0x2c
	s_load_b32 s3, s[0:1], 0x20
	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 v3, v0, 10, 10
	v_and_b32_e32 v6, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s9, s8, 16
	s_and_b32 s8, s8, 0xffff
	v_mad_u64_u32 v[0:1], null, s15, s9, v[3:4]
	v_mad_u64_u32 v[1:2], null, s14, s8, v[6:7]
	s_cmp_eq_u32 s3, 0
	s_mov_b32 s8, 0
	s_cbranch_scc1 .LBB0_9
; %bb.1:                                ; %.lr.ph
	v_lshlrev_b32_e32 v2, 2, v6
	v_lshlrev_b32_e32 v7, 6, v3
	s_mul_i32 s9, s2, s2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v8, 0x400, v2
	v_dual_mov_b32 v2, 0 :: v_dual_add_nc_u32 v9, v7, v2
	v_mad_u64_u32 v[4:5], null, v0, s2, v[6:7]
	s_delay_alu instid0(VALU_DEP_3)
	v_add_nc_u32_e32 v10, v8, v7
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_7 Depth 2
	s_lshl_b32 s10, s8, 4
	v_mov_b32_e32 v11, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v5, s10, v4
	s_mov_b32 s11, exec_lo
	v_cmpx_gt_i32_e64 s9, v5
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	v_add_co_u32 v5, vcc_lo, s4, v5
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v6, vcc_lo
	global_load_b32 v11, v[5:6], off
.LBB0_4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s11
	v_add_nc_u32_e32 v12, s10, v3
	s_mov_b32 s10, exec_lo
	s_waitcnt vmcnt(0)
	ds_store_b32 v9, v11
	v_mad_u64_u32 v[5:6], null, v12, s2, v[1:2]
	v_mov_b32_e32 v6, 0
	s_delay_alu instid0(VALU_DEP_2)
	v_cmpx_gt_i32_e64 s9, v5
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_2 Depth=1
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	v_add_co_u32 v5, vcc_lo, s6, v5
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v6, vcc_lo, s7, v6, vcc_lo
	global_load_b32 v6, v[5:6], off
.LBB0_6:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	v_mov_b32_e32 v5, v8
	s_mov_b32 s10, 0
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v6
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_7:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v6, s10, v7
	s_add_i32 s10, s10, 4
	ds_load_b32 v11, v5
	ds_load_b32 v6, v6
	v_add_nc_u32_e32 v5, 64, v5
	s_cmp_eq_u32 s10, 64
	s_waitcnt lgkmcnt(0)
	v_fmac_f32_e32 v2, v6, v11
	s_cbranch_scc0 .LBB0_7
; %bb.8:                                ;   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
	s_branch .LBB0_10
.LBB0_9:
	v_mov_b32_e32 v2, 0
.LBB0_10:                               ; %Flow70
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_max_i32_e32 v3, v0, v1
	s_mov_b32 s3, exec_lo
	v_cmpx_gt_i32_e64 s2, v3
	s_cbranch_execz .LBB0_12
; %bb.11:
	v_mad_u64_u32 v[3:4], null, v0, s2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[0:1], 2, v[3:4]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB0_12:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9matrixMulPfS_S_i
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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	_Z9matrixMulPfS_S_i, .Lfunc_end0-_Z9matrixMulPfS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 520
; 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
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9matrixMulPfS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9matrixMulPfS_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
