#include <stdio.h>
#include <assert.h>
#include <iostream>
#include <chrono>

// CUDA runtime
#include <cuda_runtime.h>
#include <curand.h>


template <int BLOCK_SIZE> __global__ void MatrixMulCUDA(float *C, float *A, float *B, int wA, int wB) {
    // Block index
    int bx = blockIdx.x;
    int by = blockIdx.y;

    // Thread index
    int tx = threadIdx.x;
    int ty = threadIdx.y;

    int aBegin = wA * BLOCK_SIZE * by;
    int aEnd   = aBegin + wA - 1;
    int aStep  = BLOCK_SIZE;

    int bBegin = BLOCK_SIZE * bx;
    int bStep  = BLOCK_SIZE * wB;

    float Csub = 0;

    for (int a = aBegin, b = bBegin;
            a <= aEnd;
            a += aStep, b += bStep) {
        __shared__ float As[BLOCK_SIZE][BLOCK_SIZE];
        __shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE];


        As[ty][tx] = A[a + wA * ty + tx];
        Bs[ty][tx] = B[b + wB * ty + tx];

    // Synchronize to make sure the matrices are loaded
        __syncthreads();
#pragma unroll

        for (int k = 0; k < BLOCK_SIZE; ++k) {
            Csub += As[ty][k] * Bs[k][tx];
        }

        __syncthreads();
    }

    // Write the block sub-matrix to device memory;
    // each thread writes one element
    int c = wB * BLOCK_SIZE * by + BLOCK_SIZE * bx;
    C[c + wB * ty + tx] = Csub;
}


void GPU_fill_rand(float *A, int nr_rows_A, int nr_cols_A) {
     // Create a pseudo-random number generator
     curandGenerator_t prng;
     curandCreateGenerator(&prng, CURAND_RNG_PSEUDO_DEFAULT);

     // Set the seed for the random number generator using the system clock
     curandSetPseudoRandomGeneratorSeed(prng, (unsigned long long) clock());

     // Fill the array with random numbers on the device
     curandGenerateUniform(prng, A, nr_rows_A * nr_cols_A);
 }

int MatrixMultiply(int argc, char **argv,
                   int block_size, const dim3 &dimsA,
                   const dim3 &dimsB) {
    // Allocate host memory for matrices A and B
    unsigned int size_A = dimsA.x * dimsA.y;
    unsigned int mem_size_A = sizeof(float) * size_A;
    float *h_A = reinterpret_cast<float *>(malloc(mem_size_A));
    unsigned int size_B = dimsB.x * dimsB.y;
    unsigned int mem_size_B = sizeof(float) * size_B;
    float *h_B = reinterpret_cast<float *>(malloc(mem_size_B));

    // Allocate device memory
    float *d_A, *d_B, *d_C;

    // Allocate host matrix C
    dim3 dimsC(dimsB.x, dimsA.y, 1);
    unsigned int mem_size_C = dimsC.x * dimsC.y * sizeof(float);
    float *h_C = reinterpret_cast<float *>(malloc(mem_size_C));
    float *h_C_test = reinterpret_cast<float *>(malloc(mem_size_C));

    for (int i = 0; i < static_cast<int>(dimsC.x * dimsC.y); i++) {
        h_C_test[i]=0;
    }

    if (h_C == NULL) {
        fprintf(stderr, "Failed to allocate host matrix C!\n");
        exit(EXIT_FAILURE);
    }

    cudaEvent_t start;
    cudaEventCreate(&start);

    cudaEvent_t stop;
    cudaEventCreate(&stop);

    // Record the start event
    cudaEventRecord(start, NULL);

    cudaMalloc(&d_A, mem_size_A);

    cudaMalloc(&d_B, mem_size_B);

    cudaMalloc(&d_C, mem_size_C);


    GPU_fill_rand(d_A, dimsA.x, dimsA.y);
    GPU_fill_rand(d_B, dimsB.x, dimsB.y);

    // Only for tests purposes
    cudaMemcpy(h_A,d_A, mem_size_A,cudaMemcpyDeviceToHost);
    cudaMemcpy(h_B,d_B, mem_size_A,cudaMemcpyDeviceToHost);

    // Setup execution parameters
    dim3 threads(block_size, block_size);
    dim3 grid(dimsB.x / threads.x, dimsA.y / threads.y);

    // Create and start timer
    printf("Computing result using CUDA Kernel...\n");

    cudaDeviceSynchronize();

    MatrixMulCUDA<32> <<< grid, threads >>>(d_C, d_A, d_B,
                                                    dimsA.x, dimsB.x);


    // Record the stop event
    cudaEventRecord(stop, NULL);

    // Wait for the stop event to complete
    cudaEventSynchronize(stop);

    printf("done\n");

    float msecTotal = 0.0f;
    cudaEventElapsedTime(&msecTotal, start, stop);

    // Compute and print the performance
    float msecPerMatrixMul = msecTotal;


    printf(
        "Time spent executing by the GPU = %.3f msec," \
        " WorkgroupSize= %u threads/block\n",
        msecPerMatrixMul,
        threads.x * threads.y);

    // Copy result from device to host
    cudaMemcpy(h_C, d_C, mem_size_C, cudaMemcpyDeviceToHost);

    bool correct = true;

    unsigned int cpu_start = clock();
    for(int i = 0; i < dimsA.x; ++i)
        for(int j = 0; j < dimsA.y; ++j)
            for(int k = 0; k < dimsA.x; ++k)
            {
                h_C_test[j + i * dimsA.x] += h_A[i * dimsA.x + k] * h_B[k* dimsA.x +j];
            }

    unsigned int cpu_end = clock();
    double cpuTime = (double)(cpu_end - cpu_start);
    printf("Time spent executing by the CPU: %.3f msec\n", cpuTime);

    printf("Checking computed result for correctness: ");

    // test relative error by the formula
    //     |<x, y>_cpu - <x,y>_gpu|/<|x|, |y|>  < eps
    double eps = 1.e-6;  // machine zero
    const float valB = 0.01f;
    for (int i = 0; i < static_cast<int>(dimsC.x * dimsC.y); i++) {
        double abs_err = fabs(h_C[i] - h_C_test[i]);
        double dot_length = dimsA.x;
        double abs_val = fabs(h_C[i]);
        double rel_err = abs_err / abs_val / dot_length;

        if (rel_err > eps) {
            printf("Error! Matrix[%05d]=%.8f, ref=%.8f error term is > %E\n",
                   i, h_C[i], dimsA.x * valB, eps);
            correct = false;
            break;
        }
    }

    printf("%s\n", correct ? "Result = PASS" : "Result = FAIL");

    // Clean up memory
    free(h_A);
    free(h_B);
    free(h_C);
    cudaFree(d_A);
    cudaFree(d_B);
    cudaFree(d_C);

    if (correct) {
        return EXIT_SUCCESS;
    } else {
        return EXIT_FAILURE;
    }
}

int main(int argc, char **argv) {
    printf("[Matrix Multiply Using CUDA] - Starting...\n");

    int block_size = 32;

    dim3 dimsA(10 * block_size, 10 * block_size, 1);
    dim3 dimsB(10 * block_size, 10 * block_size, 1);


    printf("MatrixA(%d,%d), MatrixB(%d,%d)\n", dimsA.x, dimsA.y,
                                               dimsB.x, dimsB.y);

    int matrix_result = MatrixMultiply(argc, argv, block_size, dimsA, dimsB);

    exit(matrix_result);
}



	.file	"tmpxft_002a8bdc_00000000-6_matrixMul.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3741:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3741:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_ZL49__device_stub__Z13MatrixMulCUDAILi32EEvPfS0_S0_iiPfS_S_ii, @function
_ZL49__device_stub__Z13MatrixMulCUDAILi32EEvPfS0_S0_iiPfS_S_ii:
.LFB3763:
	.cfi_startproc
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3763:
	.size	_ZL49__device_stub__Z13MatrixMulCUDAILi32EEvPfS0_S0_iiPfS_S_ii, .-_ZL49__device_stub__Z13MatrixMulCUDAILi32EEvPfS0_S0_iiPfS_S_ii
	.section	.text._Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,"axG",@progbits,_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,comdat
	.weak	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
	.type	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii, @function
_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii:
.LFB4095:
	.cfi_startproc
	endbr64
	jmp	_ZL49__device_stub__Z13MatrixMulCUDAILi32EEvPfS0_S0_iiPfS_S_ii
	.cfi_endproc
.LFE4095:
	.size	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii, .-_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
	.text
	.globl	_Z13GPU_fill_randPfii
	.type	_Z13GPU_fill_randPfii, @function
_Z13GPU_fill_randPfii:
.LFB3736:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%esi, %ebx
	movl	$100, %esi
	imull	%r12d, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	curandCreateGenerator@PLT
	call	clock@PLT
	movq	(%rsp), %rdi
	movq	%rax, %rsi
	call	curandSetPseudoRandomGeneratorSeed@PLT
	movq	(%rsp), %rdi
	movslq	%ebx, %rdx
	movq	%rbp, %rsi
	call	curandGenerateUniform@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3736:
	.size	_Z13GPU_fill_randPfii, .-_Z13GPU_fill_randPfii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Result = PASS"
.LC1:
	.string	"Result = FAIL"
.LC3:
	.string	"Failed to allocate host matrix C!\n"
.LC4:
	.string	"Computing result using CUDA Kernel...\n"
.LC5:
	.string	"done\n"
.LC6:
	.string	"Time spent executing by the GPU = %.3f msec, WorkgroupSize= %u threads/block\n"
.LC7:
	.string	"Time spent executing by the CPU: %.3f msec\n"
.LC8:
	.string	"Checking computed result for correctness: "
.LC12:
	.string	"Error! Matrix[%05d]=%.8f, ref=%.8f error term is > %E\n"
.LC13:
	.string	"%s\n"
	.text
	.globl	_Z14MatrixMultiplyiPPciRK4dim3S3_
	.type	_Z14MatrixMultiplyiPPciRK4dim3S3_, @function
_Z14MatrixMultiplyiPPciRK4dim3S3_:
.LFB3737:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r8, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rcx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movl	4(%rcx), %r14d
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	movl	(%rcx), %eax
	imull	%r14d, %eax
	leal	0(,%rax,4), %eax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movl	(%r12), %r13d
	movq	%rax, %r15
	movl	4(%r12), %eax
	imull	%r13d, %eax
	imull	%r14d, %r13d
	leal	0(,%rax,4), %eax
	movq	%rax, %rdi
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	movq	%rax, 32(%rsp)
	leal	0(,%r13,4), %eax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	16(%rsp), %rdi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	movq	%rax, %r14
	xorl	%eax, %eax
.L12:
	cmpl	%eax, %r13d
	jle	.L37
	movl	$0x00000000, (%r14,%rax,4)
	incq	%rax
	jmp	.L12
.L37:
	cmpq	$0, 24(%rsp)
	jne	.L14
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L14:
	leaq	80(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	88(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	8(%rsp), %rsi
	leaq	56(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	40(%rsp), %rsi
	leaq	64(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rsi
	leaq	72(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	4(%rbp), %edx
	movl	0(%rbp), %esi
	movq	56(%rsp), %rdi
	call	_Z13GPU_fill_randPfii
	movl	4(%r12), %edx
	movl	(%r12), %esi
	movq	64(%rsp), %rdi
	call	_Z13GPU_fill_randPfii
	movq	8(%rsp), %rdx
	movq	56(%rsp), %rsi
	movq	%r15, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	64(%rsp), %rsi
	movl	$2, %ecx
	movq	32(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	4(%rbp), %eax
	xorl	%edx, %edx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	movl	$1, 104(%rsp)
	divl	%ebx
	movl	$1, 116(%rsp)
	xorl	%edx, %edx
	movl	%eax, %ecx
	movl	(%r12), %eax
	movl	%ecx, 112(%rsp)
	divl	%ebx
	movl	%eax, 108(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	cudaDeviceSynchronize@PLT
	movl	%ebx, 96(%rsp)
	movl	104(%rsp), %ecx
	xorl	%r9d, %r9d
	movq	108(%rsp), %rdi
	movl	116(%rsp), %esi
	movl	%ebx, 100(%rsp)
	xorl	%r8d, %r8d
	movq	96(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	movl	(%r12), %r8d
	movl	0(%rbp), %ecx
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	movq	72(%rsp), %rdi
	call	_ZL49__device_stub__Z13MatrixMulCUDAILi32EEvPfS0_S0_iiPfS_S_ii
.L15:
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	imull	%ebx, %ebx
	call	cudaEventRecord@PLT
	movq	88(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rsi
	leaq	52(%rsp), %rdi
	movl	$0x00000000, 52(%rsp)
	call	cudaEventElapsedTime@PLT
	movl	%ebx, %edx
	leaq	.LC6(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	cvtss2sd	52(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rdx
	movq	24(%rsp), %rdi
	movl	$2, %ecx
	movq	72(%rsp), %rsi
	call	cudaMemcpy@PLT
	call	clock@PLT
	movl	0(%rbp), %edx
	xorl	%ecx, %ecx
	xorl	%edi, %edi
	movq	%rax, %rbx
.L16:
	cmpl	%edx, %edi
	je	.L19
	movl	4(%rbp), %r10d
	xorl	%eax, %eax
.L20:
	cmpl	%r10d, %eax
	je	.L38
	leal	(%rcx,%rax), %esi
	movl	%eax, %r8d
	leaq	(%r14,%rsi,4), %r9
	xorl	%esi, %esi
	movss	(%r9), %xmm0
.L17:
	leal	(%rsi,%rcx), %r12d
	movl	%r8d, %r11d
	incl	%esi
	addl	%edx, %r8d
	movss	(%r15,%r12,4), %xmm1
	movq	32(%rsp), %r12
	mulss	(%r12,%r11,4), %xmm1
	addss	%xmm1, %xmm0
	cmpl	%edx, %esi
	jne	.L17
	movss	%xmm0, (%r9)
	incl	%eax
	jmp	.L20
.L38:
	incl	%edi
	addl	%edx, %ecx
	jmp	.L16
.L19:
	call	clock@PLT
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	subl	%ebx, %eax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movsd	.LC10(%rip), %xmm2
	xorl	%eax, %eax
	movss	.LC9(%rip), %xmm4
.L23:
	cmpl	%eax, %r13d
	jle	.L39
	movq	24(%rsp), %rbx
	movl	0(%rbp), %ecx
	leaq	1(%rax), %rdx
	movss	(%rbx,%rax,4), %xmm0
	movaps	%xmm0, %xmm1
	subss	(%r14,%rax,4), %xmm1
	movaps	%xmm0, %xmm3
	andps	%xmm4, %xmm3
	cvtss2sd	%xmm3, %xmm3
	andps	%xmm4, %xmm1
	cvtss2sd	%xmm1, %xmm1
	divsd	%xmm3, %xmm1
	cvtsi2sdq	%rcx, %xmm3
	divsd	%xmm3, %xmm1
	comisd	%xmm2, %xmm1
	jbe	.L35
	cvtsi2ssq	%rcx, %xmm1
	movl	%eax, %edx
	leaq	.LC12(%rip), %rsi
	movb	$3, %al
	mulss	.LC11(%rip), %xmm1
	movl	$2, %edi
	cvtss2sd	%xmm0, %xmm0
	xorl	%ebx, %ebx
	cvtss2sd	%xmm1, %xmm1
	call	__printf_chk@PLT
	leaq	.LC1(%rip), %rdx
	jmp	.L29
.L35:
	movq	%rdx, %rax
	jmp	.L23
.L39:
	movb	$1, %bl
	leaq	.LC0(%rip), %rdx
.L29:
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	$1, %ebx
	call	__printf_chk@PLT
	movq	%r15, %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movzbl	%bl, %eax
	movq	120(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3737:
	.size	_Z14MatrixMultiplyiPPciRK4dim3S3_, .-_Z14MatrixMultiplyiPPciRK4dim3S3_
	.section	.rodata.str1.1
.LC14:
	.string	"[Matrix Multiply Using CUDA] - Starting...\n"
.LC15:
	.string	"MatrixA(%d,%d), MatrixB(%d,%d)\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3738:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	leaq	.LC14(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	movl	$2, %edi
	subq	$40, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$320, %r9d
	movl	$320, %r8d
	movabsq	$1374389535040, %rax
	movq	%rax, (%rsp)
	movl	$320, %ecx
	movl	$320, %edx
	leaq	.LC15(%rip), %rsi
	movq	%rax, 12(%rsp)
	movl	$2, %edi
	xorl	%eax, %eax
	movl	$1, 8(%rsp)
	movl	$1, 20(%rsp)
	call	__printf_chk@PLT
	movl	%ebx, %edi
	movq	%rsp, %rcx
	leaq	12(%rsp), %r8
	movl	$32, %edx
	movq	%rbp, %rsi
	call	_Z14MatrixMultiplyiPPciRK4dim3S3_
	movl	%eax, %edi
	call	exit@PLT
	.cfi_endproc
.LFE3738:
	.size	main, .-main
	.section	.rodata.str1.1
.LC16:
	.string	"_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3766:
	.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	.LC16(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii(%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
.LFE3766:
	.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
.LC9:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC10:
	.long	-1598689907
	.long	1051772663
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC11:
	.long	1008981770
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <assert.h>
#include <iostream>
#include <chrono>

// CUDA runtime
#include <hip/hip_runtime.h>
#include <hiprand/hiprand.h>


template <int BLOCK_SIZE> __global__ void MatrixMulCUDA(float *C, float *A, float *B, int wA, int wB) {
    // Block index
    int bx = blockIdx.x;
    int by = blockIdx.y;

    // Thread index
    int tx = threadIdx.x;
    int ty = threadIdx.y;

    int aBegin = wA * BLOCK_SIZE * by;
    int aEnd   = aBegin + wA - 1;
    int aStep  = BLOCK_SIZE;

    int bBegin = BLOCK_SIZE * bx;
    int bStep  = BLOCK_SIZE * wB;

    float Csub = 0;

    for (int a = aBegin, b = bBegin;
            a <= aEnd;
            a += aStep, b += bStep) {
        __shared__ float As[BLOCK_SIZE][BLOCK_SIZE];
        __shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE];


        As[ty][tx] = A[a + wA * ty + tx];
        Bs[ty][tx] = B[b + wB * ty + tx];

    // Synchronize to make sure the matrices are loaded
        __syncthreads();
#pragma unroll

        for (int k = 0; k < BLOCK_SIZE; ++k) {
            Csub += As[ty][k] * Bs[k][tx];
        }

        __syncthreads();
    }

    // Write the block sub-matrix to device memory;
    // each thread writes one element
    int c = wB * BLOCK_SIZE * by + BLOCK_SIZE * bx;
    C[c + wB * ty + tx] = Csub;
}


void GPU_fill_rand(float *A, int nr_rows_A, int nr_cols_A) {
     // Create a pseudo-random number generator
     hiprandGenerator_t prng;
     hiprandCreateGenerator(&prng, HIPRAND_RNG_PSEUDO_DEFAULT);

     // Set the seed for the random number generator using the system clock
     hiprandSetPseudoRandomGeneratorSeed(prng, (unsigned long long) clock());

     // Fill the array with random numbers on the device
     hiprandGenerateUniform(prng, A, nr_rows_A * nr_cols_A);
 }

int MatrixMultiply(int argc, char **argv,
                   int block_size, const dim3 &dimsA,
                   const dim3 &dimsB) {
    // Allocate host memory for matrices A and B
    unsigned int size_A = dimsA.x * dimsA.y;
    unsigned int mem_size_A = sizeof(float) * size_A;
    float *h_A = reinterpret_cast<float *>(malloc(mem_size_A));
    unsigned int size_B = dimsB.x * dimsB.y;
    unsigned int mem_size_B = sizeof(float) * size_B;
    float *h_B = reinterpret_cast<float *>(malloc(mem_size_B));

    // Allocate device memory
    float *d_A, *d_B, *d_C;

    // Allocate host matrix C
    dim3 dimsC(dimsB.x, dimsA.y, 1);
    unsigned int mem_size_C = dimsC.x * dimsC.y * sizeof(float);
    float *h_C = reinterpret_cast<float *>(malloc(mem_size_C));
    float *h_C_test = reinterpret_cast<float *>(malloc(mem_size_C));

    for (int i = 0; i < static_cast<int>(dimsC.x * dimsC.y); i++) {
        h_C_test[i]=0;
    }

    if (h_C == NULL) {
        fprintf(stderr, "Failed to allocate host matrix C!\n");
        exit(EXIT_FAILURE);
    }

    hipEvent_t start;
    hipEventCreate(&start);

    hipEvent_t stop;
    hipEventCreate(&stop);

    // Record the start event
    hipEventRecord(start, NULL);

    hipMalloc(&d_A, mem_size_A);

    hipMalloc(&d_B, mem_size_B);

    hipMalloc(&d_C, mem_size_C);


    GPU_fill_rand(d_A, dimsA.x, dimsA.y);
    GPU_fill_rand(d_B, dimsB.x, dimsB.y);

    // Only for tests purposes
    hipMemcpy(h_A,d_A, mem_size_A,hipMemcpyDeviceToHost);
    hipMemcpy(h_B,d_B, mem_size_A,hipMemcpyDeviceToHost);

    // Setup execution parameters
    dim3 threads(block_size, block_size);
    dim3 grid(dimsB.x / threads.x, dimsA.y / threads.y);

    // Create and start timer
    printf("Computing result using CUDA Kernel...\n");

    hipDeviceSynchronize();

    MatrixMulCUDA<32> <<< grid, threads >>>(d_C, d_A, d_B,
                                                    dimsA.x, dimsB.x);


    // Record the stop event
    hipEventRecord(stop, NULL);

    // Wait for the stop event to complete
    hipEventSynchronize(stop);

    printf("done\n");

    float msecTotal = 0.0f;
    hipEventElapsedTime(&msecTotal, start, stop);

    // Compute and print the performance
    float msecPerMatrixMul = msecTotal;


    printf(
        "Time spent executing by the GPU = %.3f msec," \
        " WorkgroupSize= %u threads/block\n",
        msecPerMatrixMul,
        threads.x * threads.y);

    // Copy result from device to host
    hipMemcpy(h_C, d_C, mem_size_C, hipMemcpyDeviceToHost);

    bool correct = true;

    unsigned int cpu_start = clock();
    for(int i = 0; i < dimsA.x; ++i)
        for(int j = 0; j < dimsA.y; ++j)
            for(int k = 0; k < dimsA.x; ++k)
            {
                h_C_test[j + i * dimsA.x] += h_A[i * dimsA.x + k] * h_B[k* dimsA.x +j];
            }

    unsigned int cpu_end = clock();
    double cpuTime = (double)(cpu_end - cpu_start);
    printf("Time spent executing by the CPU: %.3f msec\n", cpuTime);

    printf("Checking computed result for correctness: ");

    // test relative error by the formula
    //     |<x, y>_cpu - <x,y>_gpu|/<|x|, |y|>  < eps
    double eps = 1.e-6;  // machine zero
    const float valB = 0.01f;
    for (int i = 0; i < static_cast<int>(dimsC.x * dimsC.y); i++) {
        double abs_err = fabs(h_C[i] - h_C_test[i]);
        double dot_length = dimsA.x;
        double abs_val = fabs(h_C[i]);
        double rel_err = abs_err / abs_val / dot_length;

        if (rel_err > eps) {
            printf("Error! Matrix[%05d]=%.8f, ref=%.8f error term is > %E\n",
                   i, h_C[i], dimsA.x * valB, eps);
            correct = false;
            break;
        }
    }

    printf("%s\n", correct ? "Result = PASS" : "Result = FAIL");

    // Clean up memory
    free(h_A);
    free(h_B);
    free(h_C);
    hipFree(d_A);
    hipFree(d_B);
    hipFree(d_C);

    if (correct) {
        return EXIT_SUCCESS;
    } else {
        return EXIT_FAILURE;
    }
}

int main(int argc, char **argv) {
    printf("[Matrix Multiply Using CUDA] - Starting...\n");

    int block_size = 32;

    dim3 dimsA(10 * block_size, 10 * block_size, 1);
    dim3 dimsB(10 * block_size, 10 * block_size, 1);


    printf("MatrixA(%d,%d), MatrixB(%d,%d)\n", dimsA.x, dimsA.y,
                                               dimsB.x, dimsB.y);

    int matrix_result = MatrixMultiply(argc, argv, block_size, dimsA, dimsB);

    exit(matrix_result);
}



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

                                        # End of file scope inline assembly
	.globl	_Z13GPU_fill_randPfii           # -- Begin function _Z13GPU_fill_randPfii
	.type	_Z13GPU_fill_randPfii,@function
_Z13GPU_fill_randPfii:                  # @_Z13GPU_fill_randPfii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, %r14
	leaq	8(%rsp), %r15
	movq	%r15, %rdi
	movl	$400, %esi                      # imm = 0x190
	callq	hiprandCreateGenerator
	movq	(%r15), %r12
	callq	clock
	movq	%r12, %rdi
	movq	%rax, %rsi
	callq	hiprandSetPseudoRandomGeneratorSeed
	movq	(%r15), %rdi
	imull	%ebx, %ebp
	movslq	%ebp, %rdx
	movq	%r14, %rsi
	callq	hiprandGenerateUniform
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z13GPU_fill_randPfii, .Lfunc_end0-_Z13GPU_fill_randPfii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z14MatrixMultiplyiPPciRK4dim3S3_
.LCPI1_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
.LCPI1_1:
	.quad	0x7fffffffffffffff              # double NaN
	.quad	0x7fffffffffffffff              # double NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_2:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI1_3:
	.long	0x3c23d70a                      # float 0.00999999977
	.text
	.globl	_Z14MatrixMultiplyiPPciRK4dim3S3_
	.type	_Z14MatrixMultiplyiPPciRK4dim3S3_,@function
_Z14MatrixMultiplyiPPciRK4dim3S3_:      # @_Z14MatrixMultiplyiPPciRK4dim3S3_
	.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	$120, %rsp
	.cfi_def_cfa_offset 176
	.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	%r8, %r14
	movl	%edx, 68(%rsp)                  # 4-byte Spill
	movl	4(%rcx), %r15d
	movq	%rcx, 8(%rsp)                   # 8-byte Spill
	movl	(%rcx), %edi
	imull	%r15d, %edi
	shll	$2, %edi
	movq	%rdi, 88(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, %rbx
	movl	(%r14), %r13d
	movq	%r14, 72(%rsp)                  # 8-byte Spill
	movl	4(%r14), %ebp
	imull	%r13d, %ebp
	shll	$2, %ebp
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r14
	imull	%r15d, %r13d
	leal	(,%r13,4), %r15d
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movq	%r15, 80(%rsp)                  # 8-byte Spill
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %r12
	movl	%r13d, %r15d
	movq	%r13, 96(%rsp)                  # 8-byte Spill
	testl	%r13d, %r13d
	jle	.LBB1_2
# %bb.1:                                # %.lr.ph.preheader
	leaq	(,%r15,4), %rdx
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB1_2:                                # %._crit_edge
	movq	%r15, 32(%rsp)                  # 8-byte Spill
	cmpq	$0, 16(%rsp)                    # 8-byte Folded Reload
	je	.LBB1_23
# %bb.3:
	leaq	104(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	56(%rsp), %r13
	movq	%r13, %rdi
	movq	88(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movq	80(%rsp), %rsi                  # 8-byte Reload
	callq	hipMalloc
	movq	(%r13), %rdi
	movq	8(%rsp), %rbp                   # 8-byte Reload
	movl	(%rbp), %esi
	movl	4(%rbp), %edx
	callq	_Z13GPU_fill_randPfii
	leaq	24(%rsp), %rax
	movq	(%rax), %rdi
	movq	72(%rsp), %r13                  # 8-byte Reload
	movl	(%r13), %esi
	movl	4(%r13), %edx
	callq	_Z13GPU_fill_randPfii
	leaq	56(%rsp), %rax
	movq	(%rax), %rsi
	movq	%rbx, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %rax
	movq	(%rax), %rsi
	movq	%r14, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	68(%rsp), %ecx                  # 4-byte Reload
	movl	%ecx, %eax
	movq	%rax, %r15
	shlq	$32, %r15
	orq	%rax, %r15
	movl	(%r13), %eax
	xorl	%edx, %edx
	divl	%ecx
	movl	%eax, %r13d
	movl	4(%rbp), %eax
	movl	%ecx, %ebp
	xorl	%edx, %edx
	divl	%ecx
                                        # kill: def $eax killed $eax def $rax
	shlq	$32, %rax
	orq	%rax, %r13
	movl	$.Lstr, %edi
	callq	puts@PLT
	callq	hipDeviceSynchronize
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_5
# %bb.4:
	movq	48(%rsp), %rdi
	movq	56(%rsp), %rsi
	movq	24(%rsp), %rdx
	movq	8(%rsp), %rax                   # 8-byte Reload
	movl	(%rax), %ecx
	movq	72(%rsp), %rax                  # 8-byte Reload
	movl	(%rax), %r8d
	callq	_Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii
.LBB1_5:
	movq	40(%rsp), %rdi
	xorl	%r13d, %r13d
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rdi
	callq	hipEventSynchronize
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	leaq	116(%rsp), %r15
	movl	$0, (%r15)
	movq	104(%rsp), %rsi
	movq	40(%rsp), %rdx
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%r15), %xmm0
	imull	%ebp, %ebp
	movl	$.L.str.3, %edi
	movl	%ebp, %esi
	movb	$1, %al
	callq	printf
	movq	48(%rsp), %rsi
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	80(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	callq	clock
	movq	%rax, %r15
	movq	8(%rsp), %rax                   # 8-byte Reload
	movl	(%rax), %eax
	testq	%rax, %rax
	je	.LBB1_13
# %bb.6:                                # %.preheader118.lr.ph
	movq	8(%rsp), %rcx                   # 8-byte Reload
	movl	4(%rcx), %ecx
	xorl	%edx, %edx
.LBB1_7:                                # %.preheader118
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_9 Depth 2
                                        #       Child Loop BB1_10 Depth 3
	testq	%rcx, %rcx
	je	.LBB1_12
# %bb.8:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB1_7 Depth=1
	movl	%eax, %esi
	imull	%edx, %esi
	xorl	%edi, %edi
.LBB1_9:                                # %.preheader
                                        #   Parent Loop BB1_7 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_10 Depth 3
	leal	(%rsi,%rdi), %r8d
	movss	(%r12,%r8,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	movq	%rax, %r9
	movl	%r13d, %r10d
	movl	%edi, %r11d
.LBB1_10:                               #   Parent Loop BB1_7 Depth=1
                                        #     Parent Loop BB1_9 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	%r10d, %ebp
	movss	(%rbx,%rbp,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	movl	%r11d, %ebp
	mulss	(%r14,%rbp,4), %xmm1
	addss	%xmm1, %xmm0
	addl	%eax, %r11d
	incl	%r10d
	decq	%r9
	jne	.LBB1_10
# %bb.11:                               #   in Loop: Header=BB1_9 Depth=2
	movss	%xmm0, (%r12,%r8,4)
	incq	%rdi
	cmpq	%rcx, %rdi
	jne	.LBB1_9
.LBB1_12:                               # %._crit_edge127
                                        #   in Loop: Header=BB1_7 Depth=1
	incl	%edx
	addl	%eax, %r13d
	cmpl	%eax, %edx
	jne	.LBB1_7
.LBB1_13:                               # %._crit_edge129
	callq	clock
	subl	%r15d, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	movb	$1, %bpl
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	xorl	%r15d, %r15d
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.8, %edi
	cmpl	$0, 96(%rsp)                    # 4-byte Folded Reload
	jle	.LBB1_14
# %bb.15:                               # %.lr.ph132
	movq	8(%rsp), %rax                   # 8-byte Reload
	movl	(%rax), %eax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	movq	16(%rsp), %r13                  # 8-byte Reload
	movss	(%r13), %xmm2                   # xmm2 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm2, %xmm0
	subss	(%r12), %xmm2
	andps	.LCPI1_0(%rip), %xmm2
	cvtss2sd	%xmm2, %xmm2
	movaps	.LCPI1_1(%rip), %xmm3           # xmm3 = [NaN,NaN]
	andps	%xmm0, %xmm3
	divsd	%xmm3, %xmm2
	divsd	%xmm1, %xmm2
	ucomisd	.LCPI1_2(%rip), %xmm2
	ja	.LBB1_21
# %bb.16:                               # %.lr.ph.preheader181
	movq	32(%rsp), %rcx                  # 8-byte Reload
	decq	%rcx
	xorl	%r15d, %r15d
	movaps	.LCPI1_0(%rip), %xmm2           # xmm2 = [NaN,NaN,NaN,NaN]
	movaps	.LCPI1_1(%rip), %xmm3           # xmm3 = [NaN,NaN]
	movsd	.LCPI1_2(%rip), %xmm4           # xmm4 = mem[0],zero
.LBB1_17:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	cmpq	%r15, %rcx
	je	.LBB1_18
# %bb.19:                               #   in Loop: Header=BB1_17 Depth=1
	movss	4(%r13,%r15,4), %xmm5           # xmm5 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm5, %xmm0
	subss	4(%r12,%r15,4), %xmm5
	andps	%xmm2, %xmm5
	cvtss2sd	%xmm5, %xmm5
	movaps	%xmm0, %xmm6
	andps	%xmm3, %xmm6
	divsd	%xmm6, %xmm5
	divsd	%xmm1, %xmm5
	incq	%r15
	ucomisd	%xmm4, %xmm5
	jbe	.LBB1_17
# %bb.20:                               # %._crit_edge166
	cmpq	32(%rsp), %r15                  # 8-byte Folded Reload
	setb	%bpl
.LBB1_21:
	movl	%eax, %eax
	xorps	%xmm1, %xmm1
	cvtsi2ss	%rax, %xmm1
	mulss	.LCPI1_3(%rip), %xmm1
	cvtss2sd	%xmm1, %xmm1
	movsd	.LCPI1_2(%rip), %xmm2           # xmm2 = mem[0],zero
	movl	$.L.str.6, %edi
	movl	%r15d, %esi
	movb	$3, %al
	callq	printf
	movl	$.L.str.9, %edi
	movl	%ebp, %r15d
	jmp	.LBB1_22
.LBB1_14:
	movq	16(%rsp), %r13                  # 8-byte Reload
	jmp	.LBB1_22
.LBB1_18:                               # %.loopexit.loopexit
	incq	%r15
	cmpq	32(%rsp), %r15                  # 8-byte Folded Reload
	setb	%r15b
.LBB1_22:                               # %.loopexit
	callq	puts@PLT
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movzbl	%r15b, %eax
	addq	$120, %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
.LBB1_23:
	.cfi_def_cfa_offset 176
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$34, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z14MatrixMultiplyiPPciRK4dim3S3_, .Lfunc_end1-_Z14MatrixMultiplyiPPciRK4dim3S3_
	.cfi_endproc
                                        # -- End function
	.section	.text._Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii,"axG",@progbits,_Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii,comdat
	.weak	_Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii # -- Begin function _Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii
	.type	_Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii,@function
_Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii: # @_Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.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)
	movq	%rsp, %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%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	$_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	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	_Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii, .Lfunc_end2-_Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii
	.cfi_endproc
                                        # -- End function
	.text
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movabsq	$1374389535040, %rax            # imm = 0x14000000140
	leaq	12(%rsp), %rbx
	movq	%rax, (%rbx)
	movl	$1, %ecx
	movl	%ecx, 8(%rbx)
	movq	%rsp, %r14
	movq	%rax, (%r14)
	movl	%ecx, 8(%r14)
	movl	$.L.str.11, %edi
	movl	$320, %esi                      # imm = 0x140
	movl	$320, %edx                      # imm = 0x140
	movl	$320, %ecx                      # imm = 0x140
	movl	$320, %r8d                      # imm = 0x140
	xorl	%eax, %eax
	callq	printf
	movl	$32, %edx
	movq	%rbx, %rcx
	movq	%r14, %r8
	callq	_Z14MatrixMultiplyiPPciRK4dim3S3_
	movl	%eax, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Failed to allocate host matrix C!\n"
	.size	.L.str, 35

	.type	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,@object # @_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
	.section	.rodata._Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,"aG",@progbits,_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,comdat
	.weak	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
	.p2align	3, 0x0
_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii:
	.quad	_Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii
	.size	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii, 8

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"Time spent executing by the GPU = %.3f msec, WorkgroupSize= %u threads/block\n"
	.size	.L.str.3, 78

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Time spent executing by the CPU: %.3f msec\n"
	.size	.L.str.4, 44

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Checking computed result for correctness: "
	.size	.L.str.5, 43

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Error! Matrix[%05d]=%.8f, ref=%.8f error term is > %E\n"
	.size	.L.str.6, 55

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Result = PASS"
	.size	.L.str.8, 14

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Result = FAIL"
	.size	.L.str.9, 14

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"MatrixA(%d,%d), MatrixB(%d,%d)\n"
	.size	.L.str.11, 32

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii"
	.size	.L__unnamed_1, 36

	.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	"Computing result using CUDA Kernel..."
	.size	.Lstr, 38

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"done"
	.size	.Lstr.1, 5

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"[Matrix Multiply Using CUDA] - Starting..."
	.size	.Lstr.2, 43

	.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 _Z28__device_stub__MatrixMulCUDAILi32EEvPfS0_S0_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.section	.text._Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,"axG",@progbits,_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,comdat
	.protected	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii ; -- Begin function _Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
	.globl	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
	.p2align	8
	.type	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,@function
_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii:    ; @_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
; %bb.0:
	s_load_b256 s[0:7], s[0:1], 0x0
	v_bfe_u32 v2, v0, 10, 10
	s_mov_b32 s9, 0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_lo_u32 v5, v2, s7
	s_cmp_gt_i32 s6, 0
	s_cbranch_scc1 .LBB0_2
; %bb.1:                                ; %.._crit_edge_crit_edge
	v_mul_lo_u32 v1, v2, s7
	s_mov_b32 s10, 0
	s_branch .LBB0_3
.LBB0_2:
	s_mov_b32 s9, -1
                                        ; implicit-def: $sgpr10
                                        ; implicit-def: $vgpr1
.LBB0_3:                                ; %Flow132
	v_and_b32_e32 v0, 0x3ff, v0
	s_lshl_b32 s8, s14, 5
	s_and_not1_b32 vcc_lo, exec_lo, s9
	s_lshl_b32 s7, s7, 5
	s_cbranch_vccnz .LBB0_7
; %bb.4:                                ; %.lr.ph
	v_dual_mov_b32 v6, 0 :: v_dual_lshlrev_b32 v3, 2, v0
	v_lshlrev_b32_e32 v7, 7, v2
	v_add3_u32 v1, v0, v5, s8
	v_lshl_add_u32 v2, s15, 5, v2
	s_delay_alu instid0(VALU_DEP_4)
	v_or_b32_e32 v8, 0x1000, v3
	s_mul_i32 s9, s6, s15
	v_add_nc_u32_e32 v9, v7, v3
	s_lshl_b32 s9, s9, 5
	v_mad_u64_u32 v[3:4], null, s6, v2, v[0:1]
	v_add_nc_u32_e32 v10, v8, v7
	v_add_nc_u32_e32 v11, 0x400, v8
	v_add_nc_u32_e32 v12, 0x800, v8
	v_add_nc_u32_e32 v13, 0xc00, v8
	s_add_i32 s6, s9, s6
.LBB0_5:                                ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v4, 31, v3
	v_ashrrev_i32_e32 v2, 31, v1
	s_add_i32 s9, s9, 32
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	s_cmp_ge_i32 s9, s6
	v_lshlrev_b64 v[14:15], 2, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[16:17], 2, v[1:2]
	v_add_nc_u32_e32 v1, s7, v1
	v_add_nc_u32_e32 v3, 32, v3
	v_add_co_u32 v14, vcc_lo, s2, v14
	v_add_co_ci_u32_e32 v15, vcc_lo, s3, v15, vcc_lo
	v_add_co_u32 v16, vcc_lo, s4, v16
	v_add_co_ci_u32_e32 v17, vcc_lo, s5, v17, vcc_lo
	global_load_b32 v2, v[14:15], off
	global_load_b32 v4, v[16:17], off
	s_waitcnt vmcnt(1)
	ds_store_b32 v9, v2
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v4
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_2addr_b32 v[22:23], v8 offset1:32
	ds_load_b128 v[14:17], v7
	ds_load_2addr_b32 v[24:25], v8 offset0:64 offset1:96
	ds_load_b128 v[18:21], v7 offset:16
	ds_load_2addr_b32 v[26:27], v8 offset0:128 offset1:160
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v14, v22
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v15, v23
	ds_load_2addr_b32 v[22:23], v8 offset0:192 offset1:224
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v16, v24
	v_fmac_f32_e32 v6, v17, v25
	ds_load_2addr_b32 v[24:25], v11 offset1:32
	ds_load_b128 v[14:17], v7 offset:32
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v18, v26
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v19, v27
	ds_load_2addr_b32 v[26:27], v11 offset0:64 offset1:96
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v20, v22
	v_fmac_f32_e32 v6, v21, v23
	ds_load_b128 v[18:21], v7 offset:48
	ds_load_2addr_b32 v[22:23], v11 offset0:128 offset1:160
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v14, v24
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v15, v25
	ds_load_2addr_b32 v[24:25], v11 offset0:192 offset1:224
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v16, v26
	v_fmac_f32_e32 v6, v17, v27
	ds_load_2addr_b32 v[26:27], v12 offset1:32
	ds_load_b128 v[14:17], v7 offset:64
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v18, v22
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v19, v23
	ds_load_2addr_b32 v[22:23], v12 offset0:64 offset1:96
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v20, v24
	v_fmac_f32_e32 v6, v21, v25
	ds_load_b128 v[18:21], v7 offset:80
	ds_load_2addr_b32 v[24:25], v12 offset0:128 offset1:160
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v14, v26
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v15, v27
	ds_load_2addr_b32 v[26:27], v12 offset0:192 offset1:224
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v16, v22
	v_fmac_f32_e32 v6, v17, v23
	ds_load_2addr_b32 v[22:23], v13 offset1:32
	ds_load_b128 v[14:17], v7 offset:96
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v18, v24
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v19, v25
	ds_load_2addr_b32 v[24:25], v13 offset0:64 offset1:96
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v20, v26
	v_fmac_f32_e32 v6, v21, v27
	ds_load_b128 v[18:21], v7 offset:112
	ds_load_2addr_b32 v[26:27], v13 offset0:128 offset1:160
	s_waitcnt lgkmcnt(3)
	v_fmac_f32_e32 v6, v14, v22
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v6, v15, v23
	ds_load_2addr_b32 v[14:15], v13 offset0:192 offset1:224
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_fmac_f32_e32 v6, v16, v24
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v17, v25
	v_fmac_f32_e32 v6, v18, v26
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v19, v27
	v_fmac_f32_e32 v6, v20, v14
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v6, v21, v15
	s_cbranch_scc0 .LBB0_5
; %bb.6:                                ; %Flow
	v_mov_b32_e32 v1, v5
	s_branch .LBB0_8
.LBB0_7:
	v_mov_b32_e32 v6, s10
.LBB0_8:                                ; %Flow133
	v_add_nc_u32_e32 v0, s8, v0
	s_mul_i32 s7, s7, s15
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_add3_u32 v0, v0, v1, s7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	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], v6, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
		.amdhsa_group_segment_fixed_size 8192
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.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 28
		.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
	.section	.text._Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,"axG",@progbits,_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii,comdat
.Lfunc_end0:
	.size	_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii, .Lfunc_end0-_Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 824
; NumSgprs: 18
; NumVgprs: 28
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 8192 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 3
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 28
; 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:         28
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 8192
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13MatrixMulCUDAILi32EEvPfS0_S0_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z13MatrixMulCUDAILi32EEvPfS0_S0_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     28
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
