/* Command to compile on Windows:
nvcc .\lab5_3.cu -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64"

Output should be:
A: [
[3.00, 5.00, 2.00, 0.00],
[2.00, 4.00, 5.00, 1.00],
[0.00, 3.00, 3.00, 1.00],
[3.00, 5.00, 4.00, 4.00],
[4.00, 5.00, 5.00, 3.00],
[10.00, 13.00, 21.00, 16.00],
[9.00, 11.00, 15.00, 8.00]]
b: [
[29.99],
[14.99],
[9.99],
[24.99]]
c: [
[184.90],
[194.88],
[99.93],
[304.84],
[319.83],
[1104.40],
[784.57]]
*/

#include <stdio.h>

__global__ void mat_mul(double *C, double *A, double *B) {
    extern __shared__ double tmp[];
    tmp[blockDim.y * (blockIdx.x * gridDim.y + blockIdx.y) + threadIdx.y] = A[blockIdx.x * blockDim.y + threadIdx.y] * B[threadIdx.x * gridDim.y + blockIdx.y];
    __syncthreads();
    if (threadIdx.x == 0 && threadIdx.y == 0) {
        C[blockIdx.x * gridDim.y + blockIdx.y] = 0;
        for (int i = 0; i <= blockDim.y; i++) {
            C[blockIdx.x * gridDim.y + blockIdx.y] += tmp[blockDim.y * (blockIdx.x * gridDim.y + blockIdx.y) + i];
        }
    }
}

void mat2str(char *str, void *mat, int m, int n, int str_size) {
    double *mat_p = (double *) mat;
    int written = 0;
    written += snprintf(str + written, str_size - written, "[\n");
    for (int idx = 0; idx < m - 1; idx++) {
        written += snprintf(str + written, str_size - written, "[");
        for (int jdx = 0; jdx < n - 1; jdx++) {
            written += snprintf(str + written, str_size - written, "%.2f, ", *(mat_p + idx * n + jdx));
        }
        written += snprintf(str + written, str_size - written, "%.2f],\n", *(mat_p + idx * n + n - 1));
    }
    written += snprintf(str + written, str_size - written, "[");
    for (int jdx = 0; jdx < n - 1; jdx++) {
        written += snprintf(str + written, str_size - written, "%.2f, ", *(mat_p + (m - 1) * n + jdx));
    }
    written += snprintf(str + written, str_size - written, "%.2f]]", *(mat_p + (m - 1) * n + n - 1));
}

int main(void) {
    /* Intiialize inputs (CPU) */
    const int M = 7;
    const int N = 4;
    const int O = 1;
    double A[M][N] {
        {3, 5, 2, 0},
        {2, 4, 5, 1},
        {0, 3, 3, 1},
        {3, 5, 4, 4},
        {4, 5, 5, 3},
        {10, 13, 21, 16},
        {9, 11, 15, 8}
    };        
    double b[N][O] {
        {29.99},
        {14.99},
        {9.99},
        {24.99}
    };
    double c[M][O];
    char str_A[320];
    char str_b[320];
    mat2str(str_A, A, M, N, 320);
    mat2str(str_b, b, N, O, 320);
    printf("A: %s\n", str_A);
    printf("b: %s\n", str_b);

    /* Allocate memory for calculation on GPU */
    double *gpu_A;
    double *gpu_B;
    double *gpu_C;
    cudaMalloc((void**) &gpu_A, sizeof(double) * M * N);
    cudaMalloc((void**) &gpu_B, sizeof(double) * N * O);
    cudaMalloc((void**) &gpu_C, sizeof(double) * M * O);

    /* Copy inputs to GPU */
    cudaMemcpy(gpu_A, A, sizeof(double) * M * N, cudaMemcpyHostToDevice);
    cudaMemcpy(gpu_B, b, sizeof(double) * N * O, cudaMemcpyHostToDevice);
 
    /* Do the thing */
    dim3 out_dim(M, O);
    dim3 block_dim(M, N);
    mat_mul<<<out_dim, block_dim, sizeof(double) * M * N * O>>>(gpu_C, gpu_A, gpu_B);
    cudaMemcpy(c, gpu_C, sizeof(double) * M * O, cudaMemcpyDeviceToHost);

    /* Remember to clean up after ourselves */
    cudaFree(gpu_A);
    cudaFree(gpu_B);
    cudaFree(gpu_C);

    /* Print result */
    char str_c[80];
    mat2str(str_c, c, M, O, 80);
    printf("c: %s\n", str_c);
    return 0;
}

	.file	"tmpxft_002a1188_00000000-6_lab5_3.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"[\n"
.LC2:
	.string	"["
.LC3:
	.string	"%.2f, "
.LC4:
	.string	"%.2f],\n"
.LC5:
	.string	"%.2f]]"
	.text
	.globl	_Z7mat2strPcPviii
	.type	_Z7mat2strPcPviii, @function
_Z7mat2strPcPviii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	movslq	%r8d, %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movl	%edx, 32(%rsp)
	leaq	.LC1(%rip), %rdx
	movl	%r8d, 4(%rsp)
	call	snprintf@PLT
	movl	%eax, %r15d
	movslq	%ebp, %rax
	movq	%rax, 24(%rsp)
	salq	$3, %rax
	movq	%rax, 8(%rsp)
	leaq	(%r12,%rax), %r14
	xorl	%eax, %eax
	movl	%eax, 16(%rsp)
	movl	%eax, 20(%rsp)
.L3:
	movl	32(%rsp), %eax
	movl	4(%rsp), %esi
	movslq	%r15d, %rdi
	leaq	.LC2(%rip), %rdx
	addq	%r13, %rdi
	leal	-1(%rax), %ebx
	movl	20(%rsp), %eax
	subl	%r15d, %esi
	movslq	%esi, %rsi
	cmpl	%eax, %ebx
	movb	$0, %al
	jle	.L11
	call	snprintf@PLT
	xorl	%ebx, %ebx
	addl	%eax, %r15d
	movslq	16(%rsp), %rax
	leaq	(%r12,%rax,8), %r10
	leal	-1(%rbp), %eax
	movl	%eax, 36(%rsp)
.L4:
	movl	4(%rsp), %esi
	movslq	%r15d, %rdi
	addq	%r13, %rdi
	subl	%r15d, %esi
	movslq	%esi, %rsi
	cmpl	%ebx, 36(%rsp)
	jle	.L12
	orq	$-1, %rcx
	movl	$2, %edx
	movb	$1, %al
	movq	%r10, 40(%rsp)
	movsd	(%r10,%rbx,8), %xmm0
	leaq	.LC3(%rip), %r8
	incq	%rbx
	call	__snprintf_chk@PLT
	movq	40(%rsp), %r10
	addl	%eax, %r15d
	jmp	.L4
.L12:
	movsd	-8(%r14), %xmm0
	orq	$-1, %rcx
	movl	$2, %edx
	movb	$1, %al
	leaq	.LC4(%rip), %r8
	call	__snprintf_chk@PLT
	incl	20(%rsp)
	addl	%eax, %r15d
	movq	8(%rsp), %rax
	addl	%ebp, 16(%rsp)
	addq	%rax, %r14
	jmp	.L3
.L11:
	call	snprintf@PLT
	xorl	%r14d, %r14d
	addl	%eax, %r15d
	movl	%ebx, %eax
	imull	%ebp, %eax
	cltq
	leaq	(%r12,%rax,8), %r10
	leal	-1(%rbp), %eax
	movl	%eax, 16(%rsp)
.L7:
	movl	4(%rsp), %esi
	movslq	%r15d, %rdi
	addq	%r13, %rdi
	subl	%r15d, %esi
	movslq	%esi, %rsi
	cmpl	%r14d, 16(%rsp)
	jle	.L13
	orq	$-1, %rcx
	movl	$2, %edx
	movb	$1, %al
	movq	%r10, 8(%rsp)
	movsd	(%r10,%r14,8), %xmm0
	leaq	.LC3(%rip), %r8
	incq	%r14
	call	__snprintf_chk@PLT
	movq	8(%rsp), %r10
	addl	%eax, %r15d
	jmp	.L7
.L13:
	imull	%ebp, %ebx
	movq	24(%rsp), %rax
	leaq	.LC5(%rip), %r8
	orq	$-1, %rcx
	movl	$2, %edx
	movslq	%ebx, %rbx
	addq	%rax, %rbx
	movb	$1, %al
	movsd	-8(%r12,%rbx,8), %xmm0
	addq	$56, %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
	jmp	__snprintf_chk@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z7mat2strPcPviii, .-_Z7mat2strPcPviii
	.globl	_Z30__device_stub__Z7mat_mulPdS_S_PdS_S_
	.type	_Z30__device_stub__Z7mat_mulPdS_S_PdS_S_, @function
_Z30__device_stub__Z7mat_mulPdS_S_PdS_S_:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%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)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z7mat_mulPdS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	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 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L14:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z30__device_stub__Z7mat_mulPdS_S_PdS_S_, .-_Z30__device_stub__Z7mat_mulPdS_S_PdS_S_
	.globl	_Z7mat_mulPdS_S_
	.type	_Z7mat_mulPdS_S_, @function
_Z7mat_mulPdS_S_:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z30__device_stub__Z7mat_mulPdS_S_PdS_S_
	.cfi_endproc
.LFE2054:
	.size	_Z7mat_mulPdS_S_, .-_Z7mat_mulPdS_S_
	.section	.rodata.str1.1
.LC10:
	.string	"A: %s\n"
.LC11:
	.string	"b: %s\n"
.LC12:
	.string	"c: %s\n"
	.section	.rodata
	.align 32
.LC0:
	.long	0
	.long	1074266112
	.long	0
	.long	1075052544
	.long	0
	.long	1073741824
	.long	0
	.long	0
	.long	0
	.long	1073741824
	.long	0
	.long	1074790400
	.long	0
	.long	1075052544
	.long	0
	.long	1072693248
	.long	0
	.long	0
	.long	0
	.long	1074266112
	.long	0
	.long	1074266112
	.long	0
	.long	1072693248
	.long	0
	.long	1074266112
	.long	0
	.long	1075052544
	.long	0
	.long	1074790400
	.long	0
	.long	1074790400
	.long	0
	.long	1074790400
	.long	0
	.long	1075052544
	.long	0
	.long	1075052544
	.long	0
	.long	1074266112
	.long	0
	.long	1076101120
	.long	0
	.long	1076494336
	.long	0
	.long	1077215232
	.long	0
	.long	1076887552
	.long	0
	.long	1075970048
	.long	0
	.long	1076232192
	.long	0
	.long	1076756480
	.long	0
	.long	1075838976
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$320, %r8d
	movl	$7, %edx
	leaq	.LC0(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	$56, %ecx
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$1096, %rsp
	.cfi_def_cfa_offset 1136
	movq	%fs:40, %rax
	movq	%rax, 1080(%rsp)
	xorl	%eax, %eax
	movq	.LC6(%rip), %rax
	leaq	48(%rsp), %rbx
	leaq	136(%rsp), %rbp
	leaq	440(%rsp), %r13
	leaq	760(%rsp), %r12
	movq	%rax, 48(%rsp)
	movq	.LC7(%rip), %rax
	leaq	136(%rsp), %rdi
	rep movsl
	movl	$4, %ecx
	movq	%rbp, %rsi
	movq	%r13, %rdi
	movq	%rax, 56(%rsp)
	movq	.LC8(%rip), %rax
	movq	%rax, 64(%rsp)
	movq	.LC9(%rip), %rax
	movq	%rax, 72(%rsp)
	call	_Z7mat2strPcPviii
	movl	$1, %ecx
	movq	%rbx, %rsi
	movq	%r12, %rdi
	movl	$320, %r8d
	movl	$4, %edx
	call	_Z7mat2strPcPviii
	movq	%r13, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC10(%rip), %rsi
	call	__printf_chk@PLT
	movq	%r12, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC11(%rip), %rsi
	call	__printf_chk@PLT
	movq	%rsp, %rdi
	movl	$224, %esi
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movl	$32, %esi
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movl	$56, %esi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$224, %edx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$32, %edx
	call	cudaMemcpy@PLT
	xorl	%r9d, %r9d
	movl	$224, %r8d
	movabsq	$17179869191, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4294967303, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L20
	movq	8(%rsp), %rdx
	movq	(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z30__device_stub__Z7mat_mulPdS_S_PdS_S_
.L20:
	movq	16(%rsp), %rsi
	leaq	80(%rsp), %rbp
	movl	$2, %ecx
	movl	$56, %edx
	movq	%rbp, %rdi
	leaq	360(%rsp), %rbx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	$7, %edx
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	movl	$80, %r8d
	movl	$1, %ecx
	call	_Z7mat2strPcPviii
	xorl	%eax, %eax
	movq	%rbx, %rdx
	movl	$2, %edi
	leaq	.LC12(%rip), %rsi
	call	__printf_chk@PLT
	movq	1080(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$1096, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z7mat_mulPdS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.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	.LC14(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z7mat_mulPdS_S_(%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
.LFE2056:
	.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.cst8,"aM",@progbits,8
	.align 8
.LC6:
	.long	-1546188227
	.long	1077804400
	.align 8
.LC7:
	.long	1202590843
	.long	1076755169
	.align 8
.LC8:
	.long	1202590843
	.long	1076099809
	.align 8
.LC9:
	.long	-1546188227
	.long	1077476720
	.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:

/* Command to compile on Windows:
nvcc .\lab5_3.cu -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64"

Output should be:
A: [
[3.00, 5.00, 2.00, 0.00],
[2.00, 4.00, 5.00, 1.00],
[0.00, 3.00, 3.00, 1.00],
[3.00, 5.00, 4.00, 4.00],
[4.00, 5.00, 5.00, 3.00],
[10.00, 13.00, 21.00, 16.00],
[9.00, 11.00, 15.00, 8.00]]
b: [
[29.99],
[14.99],
[9.99],
[24.99]]
c: [
[184.90],
[194.88],
[99.93],
[304.84],
[319.83],
[1104.40],
[784.57]]
*/


#include <hip/hip_runtime.h>
#include <stdio.h>

__global__ void mat_mul(double *C, double *A, double *B) {
    extern __shared__ double tmp[];
    tmp[blockDim.y * (blockIdx.x * gridDim.y + blockIdx.y) + threadIdx.y] = A[blockIdx.x * blockDim.y + threadIdx.y] * B[threadIdx.x * gridDim.y + blockIdx.y];
    __syncthreads();
    if (threadIdx.x == 0 && threadIdx.y == 0) {
        C[blockIdx.x * gridDim.y + blockIdx.y] = 0;
        for (int i = 0; i <= blockDim.y; i++) {
            C[blockIdx.x * gridDim.y + blockIdx.y] += tmp[blockDim.y * (blockIdx.x * gridDim.y + blockIdx.y) + i];
        }
    }
}

void mat2str(char *str, void *mat, int m, int n, int str_size) {
    double *mat_p = (double *) mat;
    int written = 0;
    written += snprintf(str + written, str_size - written, "[\n");
    for (int idx = 0; idx < m - 1; idx++) {
        written += snprintf(str + written, str_size - written, "[");
        for (int jdx = 0; jdx < n - 1; jdx++) {
            written += snprintf(str + written, str_size - written, "%.2f, ", *(mat_p + idx * n + jdx));
        }
        written += snprintf(str + written, str_size - written, "%.2f],\n", *(mat_p + idx * n + n - 1));
    }
    written += snprintf(str + written, str_size - written, "[");
    for (int jdx = 0; jdx < n - 1; jdx++) {
        written += snprintf(str + written, str_size - written, "%.2f, ", *(mat_p + (m - 1) * n + jdx));
    }
    written += snprintf(str + written, str_size - written, "%.2f]]", *(mat_p + (m - 1) * n + n - 1));
}

int main(void) {
    /* Intiialize inputs (CPU) */
    const int M = 7;
    const int N = 4;
    const int O = 1;
    double A[M][N] {
        {3, 5, 2, 0},
        {2, 4, 5, 1},
        {0, 3, 3, 1},
        {3, 5, 4, 4},
        {4, 5, 5, 3},
        {10, 13, 21, 16},
        {9, 11, 15, 8}
    };        
    double b[N][O] {
        {29.99},
        {14.99},
        {9.99},
        {24.99}
    };
    double c[M][O];
    char str_A[320];
    char str_b[320];
    mat2str(str_A, A, M, N, 320);
    mat2str(str_b, b, N, O, 320);
    printf("A: %s\n", str_A);
    printf("b: %s\n", str_b);

    /* Allocate memory for calculation on GPU */
    double *gpu_A;
    double *gpu_B;
    double *gpu_C;
    hipMalloc((void**) &gpu_A, sizeof(double) * M * N);
    hipMalloc((void**) &gpu_B, sizeof(double) * N * O);
    hipMalloc((void**) &gpu_C, sizeof(double) * M * O);

    /* Copy inputs to GPU */
    hipMemcpy(gpu_A, A, sizeof(double) * M * N, hipMemcpyHostToDevice);
    hipMemcpy(gpu_B, b, sizeof(double) * N * O, hipMemcpyHostToDevice);
 
    /* Do the thing */
    dim3 out_dim(M, O);
    dim3 block_dim(M, N);
    mat_mul<<<out_dim, block_dim, sizeof(double) * M * N * O>>>(gpu_C, gpu_A, gpu_B);
    hipMemcpy(c, gpu_C, sizeof(double) * M * O, hipMemcpyDeviceToHost);

    /* Remember to clean up after ourselves */
    hipFree(gpu_A);
    hipFree(gpu_B);
    hipFree(gpu_C);

    /* Print result */
    char str_c[80];
    mat2str(str_c, c, M, O, 80);
    printf("c: %s\n", str_c);
    return 0;
}

	.text
	.file	"lab5_3.hip"
	.globl	_Z22__device_stub__mat_mulPdS_S_ # -- Begin function _Z22__device_stub__mat_mulPdS_S_
	.type	_Z22__device_stub__mat_mulPdS_S_,@function
_Z22__device_stub__mat_mulPdS_S_:       # @_Z22__device_stub__mat_mulPdS_S_
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z7mat_mulPdS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z22__device_stub__mat_mulPdS_S_, .Lfunc_end0-_Z22__device_stub__mat_mulPdS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z7mat2strPcPviii               # -- Begin function _Z7mat2strPcPviii
	.type	_Z7mat2strPcPviii,@function
_Z7mat2strPcPviii:                      # @_Z7mat2strPcPviii
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%r8d, %ebp
	movl	%ecx, %r14d
	movl	%edx, %r12d
	movq	%rsi, %r13
	movq	%rdi, %rbx
	movslq	%r8d, %rsi
	movl	$.L.str, %edx
	xorl	%eax, %eax
	callq	snprintf
	leal	-1(%r12), %esi
	leal	-1(%r14), %ecx
	movq	%r14, 16(%rsp)                  # 8-byte Spill
	movslq	%r14d, %rdx
	movl	%ecx, %r15d
	cmpl	$2, %r12d
	movq	%rdx, 24(%rsp)                  # 8-byte Spill
	movq	%r13, 32(%rsp)                  # 8-byte Spill
	movl	%esi, 12(%rsp)                  # 4-byte Spill
	jl	.LBB1_6
# %bb.1:                                # %.lr.ph69
	leaq	-8(,%rdx,8), %rcx
	addq	%r13, %rcx
	movq	%rcx, 56(%rsp)                  # 8-byte Spill
	movl	%esi, %ecx
	movq	%rcx, 48(%rsp)                  # 8-byte Spill
	leaq	(,%rdx,8), %rcx
	movq	%rcx, 40(%rsp)                  # 8-byte Spill
	movq	%r13, %r12
	xorl	%r13d, %r13d
.LBB1_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	movq	%r13, 64(%rsp)                  # 8-byte Spill
	movslq	%eax, %r14
	leaq	(%rbx,%r14), %rdi
	movl	%ebp, %eax
	subl	%r14d, %eax
	movslq	%eax, %rsi
	movl	$.L.str.1, %edx
	xorl	%eax, %eax
	callq	snprintf
	addl	%r14d, %eax
	cmpl	$2, 16(%rsp)                    # 4-byte Folded Reload
	jl	.LBB1_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	xorl	%r14d, %r14d
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movslq	%eax, %r13
	leaq	(%rbx,%r13), %rdi
	movl	%ebp, %eax
	subl	%r13d, %eax
	movslq	%eax, %rsi
	movsd	(%r12,%r14,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.2, %edx
	movb	$1, %al
	callq	snprintf
	addl	%r13d, %eax
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	movq	64(%rsp), %r13                  # 8-byte Reload
	movq	%r13, %rcx
	imulq	24(%rsp), %rcx                  # 8-byte Folded Reload
	movslq	%eax, %r14
	leaq	(%rbx,%r14), %rdi
	movl	%ebp, %eax
	subl	%r14d, %eax
	movslq	%eax, %rsi
	movq	56(%rsp), %rax                  # 8-byte Reload
	movsd	(%rax,%rcx,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.3, %edx
	movb	$1, %al
	callq	snprintf
	addl	%r14d, %eax
	incq	%r13
	addq	40(%rsp), %r12                  # 8-byte Folded Reload
	cmpq	48(%rsp), %r13                  # 8-byte Folded Reload
	jne	.LBB1_2
.LBB1_6:                                # %._crit_edge70
	movslq	%eax, %r14
	leaq	(%rbx,%r14), %rdi
	movl	%ebp, %eax
	subl	%r14d, %eax
	movslq	%eax, %rsi
	movl	$.L.str.1, %edx
	xorl	%eax, %eax
	callq	snprintf
	addl	%r14d, %eax
	movq	16(%rsp), %rdx                  # 8-byte Reload
	movl	12(%rsp), %ecx                  # 4-byte Reload
	imull	%edx, %ecx
	movslq	%ecx, %rcx
	movq	32(%rsp), %rsi                  # 8-byte Reload
	leaq	(%rsi,%rcx,8), %r14
	cmpl	$2, %edx
	jl	.LBB1_9
# %bb.7:                                # %.lr.ph78
	xorl	%r12d, %r12d
.LBB1_8:                                # =>This Inner Loop Header: Depth=1
	movslq	%eax, %r13
	leaq	(%rbx,%r13), %rdi
	movl	%ebp, %eax
	subl	%r13d, %eax
	movslq	%eax, %rsi
	movsd	(%r14,%r12,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.2, %edx
	movb	$1, %al
	callq	snprintf
	addl	%r13d, %eax
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB1_8
.LBB1_9:                                # %._crit_edge79
	cltq
	addq	%rax, %rbx
	subl	%eax, %ebp
	movslq	%ebp, %rsi
	movq	24(%rsp), %rax                  # 8-byte Reload
	movsd	-8(%r14,%rax,8), %xmm0          # xmm0 = mem[0],zero
	movl	$.L.str.4, %edx
	movq	%rbx, %rdi
	movb	$1, %al
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	snprintf                        # TAILCALL
.Lfunc_end1:
	.size	_Z7mat2strPcPviii, .Lfunc_end1-_Z7mat2strPcPviii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$1080, %rsp                     # imm = 0x438
	.cfi_def_cfa_offset 1120
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	208(%rsp), %r14
	movl	$.L__const.main.A, %esi
	movl	$224, %edx
	movq	%r14, %rdi
	callq	memcpy@PLT
	movabsq	$4629134652233681469, %rax      # imm = 0x403DFD70A3D70A3D
	leaq	32(%rsp), %rbx
	movq	%rax, (%rbx)
	movabsq	$4624628237856543867, %rax      # imm = 0x402DFAE147AE147B
	movq	%rax, 8(%rbx)
	movabsq	$4621813488089437307, %rax      # imm = 0x4023FAE147AE147B
	movq	%rax, 16(%rbx)
	movabsq	$4627727277350128189, %rax      # imm = 0x4038FD70A3D70A3D
	movq	%rax, 24(%rbx)
	leaq	752(%rsp), %r15
	movq	%r15, %rdi
	movq	%r14, %rsi
	movl	$7, %edx
	movl	$4, %ecx
	movl	$320, %r8d                      # imm = 0x140
	callq	_Z7mat2strPcPviii
	leaq	432(%rsp), %r12
	movq	%r12, %rdi
	movq	%rbx, %rsi
	movl	$4, %edx
	movl	$1, %ecx
	movl	$320, %r8d                      # imm = 0x140
	callq	_Z7mat2strPcPviii
	movl	$.L.str.5, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.6, %edi
	movq	%r12, %rsi
	xorl	%eax, %eax
	callq	printf
	leaq	24(%rsp), %r15
	movl	$224, %esi
	movq	%r15, %rdi
	callq	hipMalloc
	leaq	16(%rsp), %r12
	movl	$32, %esi
	movq	%r12, %rdi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$56, %esi
	callq	hipMalloc
	movq	(%r15), %rdi
	movl	$224, %edx
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r12), %rdi
	movl	$32, %edx
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$4294967303, %rdi               # imm = 0x100000007
	movabsq	$17179869191, %rdx              # imm = 0x400000007
	movl	$224, %r8d
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	movq	8(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	callq	_Z22__device_stub__mat_mulPdS_S_
.LBB2_2:
	movq	8(%rsp), %rsi
	leaq	64(%rsp), %rbx
	movl	$56, %edx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	leaq	128(%rsp), %r14
	movq	%r14, %rdi
	movq	%rbx, %rsi
	movl	$7, %edx
	movl	$1, %ecx
	movl	$80, %r8d
	callq	_Z7mat2strPcPviii
	movl	$.L.str.7, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	xorl	%eax, %eax
	addq	$1080, %rsp                     # imm = 0x438
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7mat_mulPdS_S_, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z7mat_mulPdS_S_,@object        # @_Z7mat_mulPdS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z7mat_mulPdS_S_
	.p2align	3, 0x0
_Z7mat_mulPdS_S_:
	.quad	_Z22__device_stub__mat_mulPdS_S_
	.size	_Z7mat_mulPdS_S_, 8

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"["
	.size	.L.str.1, 2

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%.2f],\n"
	.size	.L.str.3, 8

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%.2f]]"
	.size	.L.str.4, 7

	.type	.L__const.main.A,@object        # @__const.main.A
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
.L__const.main.A:
	.quad	0x4008000000000000              # double 3
	.quad	0x4014000000000000              # double 5
	.quad	0x4000000000000000              # double 2
	.quad	0x0000000000000000              # double 0
	.quad	0x4000000000000000              # double 2
	.quad	0x4010000000000000              # double 4
	.quad	0x4014000000000000              # double 5
	.quad	0x3ff0000000000000              # double 1
	.quad	0x0000000000000000              # double 0
	.quad	0x4008000000000000              # double 3
	.quad	0x4008000000000000              # double 3
	.quad	0x3ff0000000000000              # double 1
	.quad	0x4008000000000000              # double 3
	.quad	0x4014000000000000              # double 5
	.quad	0x4010000000000000              # double 4
	.quad	0x4010000000000000              # double 4
	.quad	0x4010000000000000              # double 4
	.quad	0x4014000000000000              # double 5
	.quad	0x4014000000000000              # double 5
	.quad	0x4008000000000000              # double 3
	.quad	0x4024000000000000              # double 10
	.quad	0x402a000000000000              # double 13
	.quad	0x4035000000000000              # double 21
	.quad	0x4030000000000000              # double 16
	.quad	0x4022000000000000              # double 9
	.quad	0x4026000000000000              # double 11
	.quad	0x402e000000000000              # double 15
	.quad	0x4020000000000000              # double 8
	.size	.L__const.main.A, 224

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

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"c: %s\n"
	.size	.L.str.7, 7

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7mat_mulPdS_S_"
	.size	.L__unnamed_1, 17

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

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

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

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7mat_mulPdS_S_        ; -- Begin function _Z7mat_mulPdS_S_
	.globl	_Z7mat_mulPdS_S_
	.p2align	8
	.type	_Z7mat_mulPdS_S_,@function
_Z7mat_mulPdS_S_:                       ; @_Z7mat_mulPdS_S_
; %bb.0:
	s_clause 0x2
	s_load_b32 s3, s[0:1], 0x24
	s_load_b32 s10, s[0:1], 0x1c
	s_load_b128 s[4:7], s[0:1], 0x0
	v_bfe_u32 v1, v0, 10, 10
	s_load_b64 s[8:9], s[0:1], 0x10
	v_and_b32_e32 v0, 0x3ff, v0
	s_mov_b32 s2, s15
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s1, s3, 16
	s_mul_i32 s0, s10, s14
	v_mad_u64_u32 v[2:3], null, s14, s1, v[1:2]
	v_mov_b32_e32 v3, 0
	v_mad_u64_u32 v[4:5], null, s10, v0, s[2:3]
	s_add_i32 s0, s0, s15
	v_or_b32_e32 v0, v0, v1
	s_mul_i32 s2, s0, s1
	v_mov_b32_e32 v5, v3
	v_lshlrev_b64 v[2:3], 3, v[2:3]
	s_mov_b32 s3, exec_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[4:5], 3, v[4:5]
	v_add_co_u32 v2, vcc_lo, s6, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	v_add_co_u32 v4, vcc_lo, s8, v4
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v5, vcc_lo, s9, v5, vcc_lo
	global_load_b64 v[2:3], v[2:3], off
	global_load_b64 v[4:5], v[4:5], off
	s_waitcnt vmcnt(0)
	v_mul_f64 v[2:3], v[2:3], v[4:5]
	v_add_nc_u32_e32 v4, s2, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_lshl_add_u32 v1, v4, 3, 0
	ds_store_b64 v1, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_4
; %bb.1:
	v_mov_b32_e32 v0, 0
	v_mov_b32_e32 v1, 0
	s_lshl_b32 s2, s2, 3
	s_add_i32 s1, s1, 1
	s_add_i32 s2, s2, 0
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mov_b32_e32 v2, s2
	s_add_i32 s1, s1, -1
	s_add_i32 s2, s2, 8
	s_cmp_lg_u32 s1, 0
	ds_load_b64 v[2:3], v2
	s_waitcnt lgkmcnt(0)
	v_add_f64 v[0:1], v[2:3], v[0:1]
	s_cbranch_scc1 .LBB0_2
; %bb.3:                                ; %.loopexit
	s_mov_b32 s1, 0
	v_mov_b32_e32 v2, 0
	s_lshl_b64 s[0:1], s[0:1], 3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s4, s0
	s_addc_u32 s1, s5, s1
	global_store_b64 v2, v[0:1], s[0:1]
.LBB0_4:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7mat_mulPdS_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 6
		.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	_Z7mat_mulPdS_S_, .Lfunc_end0-_Z7mat_mulPdS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 344
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; 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:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7mat_mulPdS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7mat_mulPdS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
