#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void cpu_matrixmult(double *a,double *b, double **c, int n, int m, int p) {

  int k,i,j;
  double r;

  /*kij*/
  for (k=0; k<p; k++){
      for (i=0; i<n; i++){
          r = a[i*p + k];
          for(j=0; j<m; j++){
              (*c)[i*m+j] += r * b[k*m+j];
          }
      }
  }
}


int main(int argc, char *argv[]) {

  int i, j; // loop counters

  //int gpucount = 0; // Count of available GPUs
  //int Grid_Dim = 1; //Grid dimension, x and y, square
  //int Block_Dim = 1; //Block dimension, x and y, square

  int n,m,p; // matrix dimension
  double *a,*b,*c;
  int size_a, size_b, size_c; // number of bytes in arrays

  cudaEvent_t start, stop; // using cuda events to measure time
  float elapsed_time_ms; // which is applicable for asynchronous code also
  //cudaError_t errorcode;

  // --------------------SET PARAMETERS AND DATA -----------------------


  if (argc<4) {
    printf("Usage: Task1GPUsp <n> <m> <p>\n");
    exit (-1);
  }

  n = atoi(argv[1]);
  m = atoi(argv[2]);
  p = atoi(argv[3]);
  
 /* 
  printf("A Matrix Dimension = %dx%d\n",n,p);
  printf("B Matrix Dimension = %dx%d\n",p,m);
  printf("C Matrix Dimension = %dx%d\n",n,m);
*/
  size_a = n * p * sizeof(double); // number of bytes in total in arrays
  size_b = p * m * sizeof(double); // number of bytes in total in arrays
  size_c = n * m * sizeof(double); // number of bytes in total in arrays

  a = (double*) malloc(size_a); // dynamically allocated memory for arrays on host
  b = (double*) malloc(size_b);
  c = (double*) malloc(size_c); // results from CPU

  srand(12345);
  //int p = n; //Used here only to illustrate proper initialization for non-square case
  
  //printf ("a\n");
  for(i=0;i < n;i++){
    for(j=0;j < p;j++) {
      a[i * p + j] = (double) rand() / (double) RAND_MAX;
      //a[i * p + j] = (double) (i+j);
      //printf("%.2f  ", a[i * p + j]);
    }
    //printf("\n");
  }

 // printf("b\n");
  for(i=0;i < p;i++){
    for(j=0;j < m;j++) {
      b[i * m + j] = (double) rand() / (double) RAND_MAX;
      //b[i * m + j] = (double) (i+j);
   //   printf("%.2f  ", b[i * m + j]);
    }
    //printf("\n");
  }

  // ------------- COMPUTATION DONE ON HOST CPU ----------------------------

  cudaEventCreate(&start); // instrument code to measure start time
  cudaEventCreate(&stop);
  
  cudaEventRecord(start, 0);

  cpu_matrixmult(a,b, &c, n, m, p); //kij implementation)

  cudaEventRecord(stop, 0); // instrument code to measure end time
  cudaEventSynchronize(stop);
  cudaEventElapsedTime(&elapsed_time_ms, start, stop );
  
  printf("Time to calculate results on CPU: %f ms.\n", elapsed_time_ms); // exec. time
  //printf("c\n");
  for(i=0;i < n;i++){
    for(j=0;j < m;j++) {
      printf("%.2f  ", c[i * m + j]);
    }
    printf("\n");
  }

  free(a);
  free(b);
  free(c);
  return 0;
}

	.file	"tmpxft_00214e61_00000000-6_Task1CPUdp.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
	.globl	_Z14cpu_matrixmultPdS_PS_iii
	.type	_Z14cpu_matrixmultPdS_PS_iii, @function
_Z14cpu_matrixmultPdS_PS_iii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rsi, %r11
	movq	%rdi, %rax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%ecx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdx, %r12
	movslq	%r9d, %rdx
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	0(,%rdx,8), %rbx
	movq	%rbx, -8(%rsp)
	xorl	%ebx, %ebx
.L3:
	cmpl	%r9d, %ebp
	jge	.L2
	movslq	%ebx, %rdx
	movq	%rax, %r10
	xorl	%edi, %edi
	xorl	%esi, %esi
	leaq	(%r11,%rdx,8), %r15
.L8:
	cmpl	%r13d, %esi
	jge	.L11
	movslq	%edi, %rdx
	movsd	(%r10), %xmm1
	xorl	%ecx, %ecx
	salq	$3, %rdx
.L4:
	cmpl	%ecx, %r8d
	jle	.L12
	movsd	(%r15,%rcx,8), %xmm0
	movq	(%r12), %r14
	incq	%rcx
	mulsd	%xmm1, %xmm0
	addq	%rdx, %r14
	addq	$8, %rdx
	addsd	(%r14), %xmm0
	movsd	%xmm0, (%r14)
	jmp	.L4
.L12:
	movq	-8(%rsp), %rcx
	incl	%esi
	addl	%r8d, %edi
	addq	%rcx, %r10
	jmp	.L8
.L11:
	incl	%ebp
	addq	$8, %rax
	addl	%r8d, %ebx
	jmp	.L3
.L2:
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z14cpu_matrixmultPdS_PS_iii, .-_Z14cpu_matrixmultPdS_PS_iii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Usage: Task1GPUsp <n> <m> <p>\n"
.LC2:
	.string	"Time to calculate results on CPU: %f ms.\n"
.LC3:
	.string	"%.2f  "
.LC4:
	.string	"\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	jg	.L14
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L14:
	movq	8(%rsi), %rdi
	movq	%rsi, %r12
	call	atoi@PLT
	movq	16(%r12), %rdi
	movl	%eax, %ebp
	call	atoi@PLT
	movq	24(%r12), %rdi
	movl	%eax, %ebx
	call	atoi@PLT
	movl	%ebp, %edi
	imull	%eax, %edi
	movl	%eax, %r14d
	sall	$3, %edi
	movslq	%edi, %rdi
	call	malloc@PLT
	movl	%ebx, %edi
	imull	%r14d, %edi
	movq	%rax, %r13
	sall	$3, %edi
	movslq	%edi, %rdi
	call	malloc@PLT
	movl	%ebp, %edi
	imull	%ebx, %edi
	movq	%rax, (%rsp)
	sall	$3, %edi
	movslq	%edi, %rdi
	call	malloc@PLT
	movl	$12345, %edi
	movq	%rax, 48(%rsp)
	movq	%rax, %r12
	call	srand@PLT
	xorl	%edx, %edx
	xorl	%ecx, %ecx
.L15:
	cmpl	%ebp, %ecx
	jge	.L17
	movslq	%edx, %rax
	xorl	%r15d, %r15d
	leaq	0(%r13,%rax,8), %rsi
.L18:
	cmpl	%r15d, %r14d
	jle	.L29
	movl	%edx, 28(%rsp)
	movq	%rsi, 16(%rsp)
	movl	%ecx, 8(%rsp)
	call	rand@PLT
	movq	16(%rsp), %rsi
	movl	28(%rsp), %edx
	cvtsi2sdl	%eax, %xmm0
	movl	8(%rsp), %ecx
	divsd	.LC1(%rip), %xmm0
	movsd	%xmm0, (%rsi,%r15,8)
	incq	%r15
	jmp	.L18
.L29:
	incl	%ecx
	addl	%r14d, %edx
	jmp	.L15
.L17:
	xorl	%edx, %edx
	xorl	%ecx, %ecx
.L19:
	cmpl	%r14d, %ecx
	jge	.L21
	movq	(%rsp), %rsi
	movslq	%edx, %rax
	xorl	%r15d, %r15d
	leaq	(%rsi,%rax,8), %rsi
.L22:
	cmpl	%r15d, %ebx
	jle	.L30
	movl	%edx, 28(%rsp)
	movq	%rsi, 16(%rsp)
	movl	%ecx, 8(%rsp)
	call	rand@PLT
	movq	16(%rsp), %rsi
	movl	28(%rsp), %edx
	cvtsi2sdl	%eax, %xmm0
	movl	8(%rsp), %ecx
	divsd	.LC1(%rip), %xmm0
	movsd	%xmm0, (%rsi,%r15,8)
	incq	%r15
	jmp	.L22
.L30:
	incl	%ecx
	addl	%ebx, %edx
	jmp	.L19
.L21:
	leaq	56(%rsp), %rdi
	xorl	%r15d, %r15d
	call	cudaEventCreate@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	(%rsp), %rsi
	movl	%r14d, %r9d
	movl	%ebx, %r8d
	movl	%ebp, %ecx
	leaq	48(%rsp), %rdx
	movq	%r13, %rdi
	xorl	%r14d, %r14d
	call	_Z14cpu_matrixmultPdS_PS_iii
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	leaq	44(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	44(%rsp), %xmm0
	call	__printf_chk@PLT
.L23:
	cmpl	%ebp, %r15d
	jge	.L25
	movslq	%r14d, %rax
	xorl	%edx, %edx
	leaq	(%r12,%rax,8), %rcx
.L26:
	cmpl	%edx, %ebx
	jle	.L31
	movsd	(%rcx,%rdx,8), %xmm0
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movq	%rcx, 16(%rsp)
	movq	%rdx, 8(%rsp)
	call	__printf_chk@PLT
	movq	8(%rsp), %rdx
	movq	16(%rsp), %rcx
	incq	%rdx
	jmp	.L26
.L31:
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	incl	%r15d
	addl	%ebx, %r14d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L23
.L25:
	movq	%r13, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2054:
	.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
.LC1:
	.long	-4194304
	.long	1105199103
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


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

void cpu_matrixmult(double *a,double *b, double **c, int n, int m, int p) {

  int k,i,j;
  double r;

  /*kij*/
  for (k=0; k<p; k++){
      for (i=0; i<n; i++){
          r = a[i*p + k];
          for(j=0; j<m; j++){
              (*c)[i*m+j] += r * b[k*m+j];
          }
      }
  }
}


int main(int argc, char *argv[]) {

  int i, j; // loop counters

  //int gpucount = 0; // Count of available GPUs
  //int Grid_Dim = 1; //Grid dimension, x and y, square
  //int Block_Dim = 1; //Block dimension, x and y, square

  int n,m,p; // matrix dimension
  double *a,*b,*c;
  int size_a, size_b, size_c; // number of bytes in arrays

  hipEvent_t start, stop; // using cuda events to measure time
  float elapsed_time_ms; // which is applicable for asynchronous code also
  //cudaError_t errorcode;

  // --------------------SET PARAMETERS AND DATA -----------------------


  if (argc<4) {
    printf("Usage: Task1GPUsp <n> <m> <p>\n");
    exit (-1);
  }

  n = atoi(argv[1]);
  m = atoi(argv[2]);
  p = atoi(argv[3]);
  
 /* 
  printf("A Matrix Dimension = %dx%d\n",n,p);
  printf("B Matrix Dimension = %dx%d\n",p,m);
  printf("C Matrix Dimension = %dx%d\n",n,m);
*/
  size_a = n * p * sizeof(double); // number of bytes in total in arrays
  size_b = p * m * sizeof(double); // number of bytes in total in arrays
  size_c = n * m * sizeof(double); // number of bytes in total in arrays

  a = (double*) malloc(size_a); // dynamically allocated memory for arrays on host
  b = (double*) malloc(size_b);
  c = (double*) malloc(size_c); // results from CPU

  srand(12345);
  //int p = n; //Used here only to illustrate proper initialization for non-square case
  
  //printf ("a\n");
  for(i=0;i < n;i++){
    for(j=0;j < p;j++) {
      a[i * p + j] = (double) rand() / (double) RAND_MAX;
      //a[i * p + j] = (double) (i+j);
      //printf("%.2f  ", a[i * p + j]);
    }
    //printf("\n");
  }

 // printf("b\n");
  for(i=0;i < p;i++){
    for(j=0;j < m;j++) {
      b[i * m + j] = (double) rand() / (double) RAND_MAX;
      //b[i * m + j] = (double) (i+j);
   //   printf("%.2f  ", b[i * m + j]);
    }
    //printf("\n");
  }

  // ------------- COMPUTATION DONE ON HOST CPU ----------------------------

  hipEventCreate(&start); // instrument code to measure start time
  hipEventCreate(&stop);
  
  hipEventRecord(start, 0);

  cpu_matrixmult(a,b, &c, n, m, p); //kij implementation)

  hipEventRecord(stop, 0); // instrument code to measure end time
  hipEventSynchronize(stop);
  hipEventElapsedTime(&elapsed_time_ms, start, stop );
  
  printf("Time to calculate results on CPU: %f ms.\n", elapsed_time_ms); // exec. time
  //printf("c\n");
  for(i=0;i < n;i++){
    for(j=0;j < m;j++) {
      printf("%.2f  ", c[i * m + j]);
    }
    printf("\n");
  }

  free(a);
  free(b);
  free(c);
  return 0;
}

	.text
	.file	"Task1CPUdp.hip"
	.globl	_Z14cpu_matrixmultPdS_PS_iii    # -- Begin function _Z14cpu_matrixmultPdS_PS_iii
	.type	_Z14cpu_matrixmultPdS_PS_iii,@function
_Z14cpu_matrixmultPdS_PS_iii:           # @_Z14cpu_matrixmultPdS_PS_iii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, -8(%rsp)                  # 8-byte Spill
	testl	%r9d, %r9d
	jle	.LBB0_9
# %bb.1:                                # %.preheader.lr.ph
	movl	%r9d, %eax
	movl	%ecx, %r9d
	movl	%r8d, %r10d
	xorl	%esi, %esi
	xorl	%ebx, %ebx
.LBB0_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
                                        #       Child Loop BB0_6 Depth 3
	testl	%ecx, %ecx
	jle	.LBB0_8
# %bb.3:                                # %.lr.ph27
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	%esi, %r11d
	movq	-8(%rsp), %r14                  # 8-byte Reload
	leaq	(%r14,%r11,8), %r14
	leaq	(%rdi,%rbx,8), %r15
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB0_4:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_6 Depth 3
	testl	%r8d, %r8d
	jle	.LBB0_7
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB0_4 Depth=2
	movl	%r12d, %ebp
	shlq	$3, %rbp
	movq	%r13, %r11
	imulq	%rax, %r11
	movsd	(%r15,%r11,8), %xmm0            # xmm0 = mem[0],zero
	addq	(%rdx), %rbp
	xorl	%r11d, %r11d
.LBB0_6:                                #   Parent Loop BB0_2 Depth=1
                                        #     Parent Loop BB0_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%r14,%r11,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	%xmm0, %xmm1
	addsd	(%rbp,%r11,8), %xmm1
	movsd	%xmm1, (%rbp,%r11,8)
	incq	%r11
	cmpq	%r11, %r10
	jne	.LBB0_6
.LBB0_7:                                # %._crit_edge
                                        #   in Loop: Header=BB0_4 Depth=2
	incq	%r13
	addl	%r8d, %r12d
	cmpq	%r9, %r13
	jne	.LBB0_4
.LBB0_8:                                # %._crit_edge28
                                        #   in Loop: Header=BB0_2 Depth=1
	incq	%rbx
	addl	%r8d, %esi
	cmpq	%rax, %rbx
	jne	.LBB0_2
.LBB0_9:                                # %._crit_edge30
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z14cpu_matrixmultPdS_PS_iii, .Lfunc_end0-_Z14cpu_matrixmultPdS_PS_iii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI1_0:
	.quad	0x41dfffffffc00000              # double 2147483647
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$3, %edi
	jle	.LBB1_20
# %bb.1:
	movq	%rsi, %r14
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r12d
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, %r15d
	movq	24(%r14), %rdi
	callq	atoi
	movl	%eax, %r14d
	leal	(,%r12,8), %ebx
	movl	%ebx, %eax
	imull	%r14d, %eax
	movl	%r15d, %ebp
	imull	%r14d, %ebp
	shll	$3, %ebp
	movl	%r15d, 4(%rsp)                  # 4-byte Spill
	imull	%r15d, %ebx
	movslq	%eax, %rdi
	callq	malloc
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movslq	%ebp, %rdi
	callq	malloc
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movslq	%ebx, %rdi
	movl	%r14d, %ebx
	callq	malloc
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movq	%rax, 56(%rsp)
	movl	$12345, %edi                    # imm = 0x3039
	callq	srand
	movl	%r12d, %eax
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	movl	%r14d, %r15d
	movq	%r12, 48(%rsp)                  # 8-byte Spill
	testl	%r12d, %r12d
	jle	.LBB1_7
# %bb.2:                                # %.preheader58.lr.ph
	xorl	%r14d, %r14d
	xorl	%r12d, %r12d
.LBB1_3:                                # %.preheader58
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_5 Depth 2
	testl	%ebx, %ebx
	jle	.LBB1_6
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB1_3 Depth=1
	movl	%r14d, %eax
	movq	16(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,8), %r13
	xorl	%ebp, %ebp
.LBB1_5:                                #   Parent Loop BB1_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movsd	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm1, %xmm0
	movsd	%xmm0, (%r13,%rbp,8)
	incq	%rbp
	cmpq	%rbp, %r15
	jne	.LBB1_5
.LBB1_6:                                # %._crit_edge
                                        #   in Loop: Header=BB1_3 Depth=1
	incq	%r12
	addl	%ebx, %r14d
	cmpq	40(%rsp), %r12                  # 8-byte Folded Reload
	jne	.LBB1_3
.LBB1_7:                                # %.preheader57
	movl	%ebx, %eax
	movl	4(%rsp), %ebx                   # 4-byte Reload
	movl	%ebx, %r14d
	movl	%eax, 28(%rsp)                  # 4-byte Spill
	testl	%eax, %eax
	jle	.LBB1_13
# %bb.8:                                # %.preheader56.lr.ph
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB1_9:                                # %.preheader56
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_11 Depth 2
	testl	%ebx, %ebx
	jle	.LBB1_12
# %bb.10:                               # %.lr.ph62
                                        #   in Loop: Header=BB1_9 Depth=1
	movl	%r12d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,8), %rbp
	xorl	%ebx, %ebx
.LBB1_11:                               #   Parent Loop BB1_9 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movsd	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm1, %xmm0
	movsd	%xmm0, (%rbp,%rbx,8)
	incq	%rbx
	cmpq	%rbx, %r14
	jne	.LBB1_11
.LBB1_12:                               # %._crit_edge63
                                        #   in Loop: Header=BB1_9 Depth=1
	incq	%r13
	movl	4(%rsp), %ebx                   # 4-byte Reload
	addl	%ebx, %r12d
	cmpq	%r15, %r13
	jne	.LBB1_9
.LBB1_13:                               # %._crit_edge65
	leaq	80(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	leaq	72(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%r15d, %r15d
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	56(%rsp), %rdx
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movq	48(%rsp), %r12                  # 8-byte Reload
	movl	%r12d, %ecx
	movl	%ebx, %r8d
	movl	28(%rsp), %r9d                  # 4-byte Reload
	callq	_Z14cpu_matrixmultPdS_PS_iii
	movq	(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbp), %rdi
	callq	hipEventSynchronize
	movq	(%r13), %rsi
	movq	(%rbp), %rdx
	leaq	68(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbp), %xmm0
	movl	4(%rsp), %ebp                   # 4-byte Reload
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	testl	%r12d, %r12d
	jle	.LBB1_19
# %bb.14:                               # %.preheader.lr.ph
	xorl	%r12d, %r12d
.LBB1_15:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_17 Depth 2
	testl	%ebp, %ebp
	jle	.LBB1_18
# %bb.16:                               # %.lr.ph67
                                        #   in Loop: Header=BB1_15 Depth=1
	movl	%r15d, %eax
	movq	32(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,8), %r13
	xorl	%ebx, %ebx
.LBB1_17:                               #   Parent Loop BB1_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r13,%rbx,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	incq	%rbx
	cmpq	%rbx, %r14
	jne	.LBB1_17
.LBB1_18:                               # %._crit_edge68
                                        #   in Loop: Header=BB1_15 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r12
	addl	%ebp, %r15d
	cmpq	40(%rsp), %r12                  # 8-byte Folded Reload
	jne	.LBB1_15
.LBB1_19:                               # %._crit_edge70
	movq	16(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	8(%rsp), %rdi                   # 8-byte Reload
	callq	free
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	free
	xorl	%eax, %eax
	addq	$88, %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_20:
	.cfi_def_cfa_offset 144
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$-1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"Time to calculate results on CPU: %f ms.\n"
	.size	.L.str.1, 42

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

	.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	"Usage: Task1GPUsp <n> <m> <p>"
	.size	.Lstr, 30

	.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_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
