/*
Fast matrix exponentiation using CUDA.
The exectuable takes two arguments: the matrix in a file and the power.
The file should have a integer N in the first line that is the size of the matrix and
N lines with N integers each representing the matrix.
Example of file:
3
1 2 3
4 5 6
7 8 9

Example of usage:
./mExp input.txt 4
*/
#include<fstream>

typedef long long ll;

using namespace std;

void read_matrix(ifstream& file, ll* matrix, int n){
  int i=0;
  while(file >> matrix[i++]){}
}

int get_size_warp(){
  int deviceId;
  cudaGetDevice(&deviceId);
  cudaDeviceProp props;
  cudaGetDeviceProperties(&props, deviceId);
  return props.multiProcessorCount;
}

__global__ void multi_matrix(ll *a, ll *b, ll *c, int n){

  int tidx = threadIdx.x+blockDim.x*blockIdx.x, slidex = blockDim.x*gridDim.x;
  int tidy = threadIdx.y+blockDim.y*blockIdx.y, slidey = blockDim.y*gridDim.y;
  for(int i=tidx;i<n;i+=slidex){
    for(int j=tidy;j<n;j+=slidey){
      ll tmp=0;
      for(int k=0;k<n;k++){
        tmp+=a[i*n+k]*b[k*n+j];
      }
      c[i*n+j]=tmp;
    }
  }
}


void exp_matrix(ll *a, int n, int exp){

  ll *idt;
  ll *m1_device, *m2_device, *m3_device, *a_device;
  ll *tmp;
  int size = n*n*sizeof(ll);
  int size_warp = get_size_warp();
  dim3 grid(16, 16), block(size_warp, size_warp);

  idt = (ll*)malloc(size);

  cudaMalloc(&m1_device, size);
  cudaMalloc(&m2_device, size);
  cudaMalloc(&m3_device, size);
  cudaMalloc(&a_device, size);

  for(int i=0;i<n*n;i++)idt[i]=0;
  for(int i=0;i*(n+1)<n*n;i++)idt[i*(n+1)]=1;

  cudaMemcpy(a_device, a, size, cudaMemcpyHostToDevice);
  cudaMemcpy(m1_device, idt, size, cudaMemcpyHostToDevice);
  cudaMemcpy(m3_device, idt, size, cudaMemcpyHostToDevice);

  while(exp!=0){
    int b = exp%2;
    multi_matrix<<<grid, block>>>(a_device, m1_device, m2_device, n);
    cudaDeviceSynchronize();
    if(b){
      multi_matrix<<<grid, block>>>(m3_device, m2_device, m1_device, n); 
      cudaDeviceSynchronize();
      tmp = m1_device;
      m1_device = m2_device;
      m3_device = tmp;
    }
    else m1_device = m2_device;

    exp>>=1;
  }

  cudaMemcpy(a, m3_device, size, cudaMemcpyDeviceToHost);
}

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

  if(argc<3)return 0;

  ifstream inFile(argv[1]);
  ofstream outFile(string(argv[1])+".output");

  int exp = stoi(argv[2]);
  int n;
  ll *matrix;

  inFile >> n;

  matrix = (ll*)malloc((n*n)*sizeof(ll));

  read_matrix(inFile, matrix, n);

  exp_matrix(matrix, n, exp);

  cudaDeviceSynchronize();

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      outFile << matrix[i*n+j] << " ";
    }
    outFile << endl;
  }
  return 0;
}

	.file	"tmpxft_002dfebc_00000000-6_matrix-exp.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3772:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3772:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi
	.type	_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi, @function
_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi:
.LFB3766:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rsi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 32
.L3:
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	addq	$8, %rbx
	call	_ZNSi10_M_extractIxEERSiRT_@PLT
	movq	(%rax), %rdx
	movq	-24(%rdx), %rdx
	testb	$5, 32(%rax,%rdx)
	je	.L3
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3766:
	.size	_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi, .-_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi
	.globl	_Z13get_size_warpv
	.type	_Z13get_size_warpv, @function
_Z13get_size_warpv:
.LFB3767:
	.cfi_startproc
	endbr64
	subq	$1064, %rsp
	.cfi_def_cfa_offset 1072
	movq	%fs:40, %rax
	movq	%rax, 1048(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdi
	call	cudaGetDevice@PLT
	movl	12(%rsp), %esi
	leaq	16(%rsp), %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	404(%rsp), %eax
	movq	1048(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$1064, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3767:
	.size	_Z13get_size_warpv, .-_Z13get_size_warpv
	.globl	_Z37__device_stub__Z12multi_matrixPxS_S_iPxS_S_i
	.type	_Z37__device_stub__Z12multi_matrixPxS_S_iPxS_S_i, @function
_Z37__device_stub__Z12multi_matrixPxS_S_iPxS_S_i:
.LFB3794:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z12multi_matrixPxS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L11:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3794:
	.size	_Z37__device_stub__Z12multi_matrixPxS_S_iPxS_S_i, .-_Z37__device_stub__Z12multi_matrixPxS_S_iPxS_S_i
	.globl	_Z12multi_matrixPxS_S_i
	.type	_Z12multi_matrixPxS_S_i, @function
_Z12multi_matrixPxS_S_i:
.LFB3795:
	.cfi_startproc
	endbr64
	jmp	_Z37__device_stub__Z12multi_matrixPxS_S_iPxS_S_i
	.cfi_endproc
.LFE3795:
	.size	_Z12multi_matrixPxS_S_i, .-_Z12multi_matrixPxS_S_i
	.globl	_Z10exp_matrixPxii
	.type	_Z10exp_matrixPxii, @function
_Z10exp_matrixPxii:
.LFB3768:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%esi, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	imull	%esi, %r15d
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movabsq	$68719476752, %rbx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	_Z13get_size_warpv
	movq	%rbx, 32(%rsp)
	leal	0(,%r15,8), %ebx
	movslq	%ebx, %rbx
	movl	$1, 40(%rsp)
	movq	%rbx, %rdi
	movl	%eax, 44(%rsp)
	movl	%eax, 48(%rsp)
	movl	$1, 52(%rsp)
	call	malloc@PLT
	movq	%rsp, %rdi
	movq	%rbx, %rsi
	movq	%rax, %r13
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	xorl	%eax, %eax
.L17:
	cmpl	%eax, %r15d
	jle	.L29
	xorl	%edx, %edx
	movq	%rdx, 0(%r13,%rax,8)
	incq	%rax
	jmp	.L17
.L29:
	movslq	%ebp, %rax
	leal	1(%rbp), %ecx
	movq	%r13, %rdx
	leaq	8(,%rax,8), %rsi
	xorl	%eax, %eax
.L19:
	cmpl	%eax, %r15d
	jle	.L30
	movq	$1, (%rdx)
	addl	%ecx, %eax
	addq	%rsi, %rdx
	jmp	.L19
.L30:
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
.L21:
	testl	%r12d, %r12d
	je	.L31
	movl	52(%rsp), %ecx
	movq	44(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	32(%rsp), %rdi
	movl	40(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L22
	movq	8(%rsp), %rdx
	movq	(%rsp), %rsi
	movl	%ebp, %ecx
	movq	24(%rsp), %rdi
	call	_Z37__device_stub__Z12multi_matrixPxS_S_iPxS_S_i
.L22:
	call	cudaDeviceSynchronize@PLT
	testl	$1, %r12d
	je	.L23
	movl	52(%rsp), %ecx
	movq	44(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	32(%rsp), %rdi
	movl	40(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	movq	(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	%ebp, %ecx
	movq	16(%rsp), %rdi
	call	_Z37__device_stub__Z12multi_matrixPxS_S_iPxS_S_i
.L24:
	call	cudaDeviceSynchronize@PLT
	movq	(%rsp), %rax
	movq	8(%rsp), %rdx
	movq	%rax, 16(%rsp)
	movq	%rdx, (%rsp)
	jmp	.L25
.L23:
	movq	8(%rsp), %rax
	movq	%rax, (%rsp)
.L25:
	sarl	%r12d
	jmp	.L21
.L31:
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%r14, %rdi
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$72, %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
.LFE3768:
	.size	_Z10exp_matrixPxii, .-_Z10exp_matrixPxii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z12multi_matrixPxS_S_i"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3797:
	.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	.LC0(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12multi_matrixPxS_S_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3797:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev,"axG",@progbits,_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD5Ev,comdat
	.align 2
	.weak	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.type	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev, @function
_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev:
.LFB3876:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	__errno_location@PLT
	cmpl	$0, (%rax)
	jne	.L34
	movl	(%rbx), %edx
	movl	%edx, (%rax)
.L34:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3876:
	.size	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev, .-_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.weak	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	.set	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev,_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.section	.rodata._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_.str1.1,"aMS",@progbits,1
.LC1:
	.string	"basic_string: construction from null is not valid"
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC5IS3_EEPKcRKS3_,comdat
	.align 2
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, @function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_:
.LFB4124:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	16(%rdi), %rax
	movq	%rax, (%rdi)
	testq	%rsi, %rsi
	jne	.L38
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L43
	leaq	.LC1(%rip), %rdi
	call	_ZSt19__throw_logic_errorPKc@PLT
.L38:
	movq	%rdi, %rbx
	movq	%rsi, %rdi
	movq	%rsi, %rbp
	call	strlen@PLT
	movq	%rax, (%rsp)
	leaq	0(%rbp,%rax), %r12
	cmpq	$15, %rax
	jbe	.L40
	movq	%rsp, %rsi
	xorl	%edx, %edx
	movq	%rbx, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm@PLT
	movq	%rax, (%rbx)
	movq	(%rsp), %rax
	movq	%rax, 16(%rbx)
.L40:
	movq	(%rbx), %rdi
	movq	%r12, %rdx
	movq	%rbp, %rsi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE13_S_copy_charsEPcPKcS7_@PLT
	movq	(%rsp), %rax
	movq	(%rbx), %rdx
	movq	%rax, 8(%rbx)
	movb	$0, (%rdx,%rax)
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L41
.L43:
	call	__stack_chk_fail@PLT
.L41:
	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
.LFE4124:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
	.set	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.section	.rodata.str1.1
.LC2:
	.string	".output"
.LC3:
	.string	"stoi"
.LC4:
	.string	" "
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3769:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3769
	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	$1128, %rsp
	.cfi_def_cfa_offset 1184
	movq	%fs:40, %rax
	movq	%rax, 1112(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	jle	.L45
	movq	%rsi, %r15
	movq	8(%rsi), %rsi
	movl	$8, %edx
	leaq	592(%rsp), %rbp
	movq	%rbp, %rdi
	leaq	8(%rsp), %rbx
	leaq	16(%rsp), %r13
.LEHB0:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT
.LEHE0:
	movq	8(%r15), %rsi
	movq	%rbx, %rdx
	movq	%r13, %rdi
.LEHB1:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE1:
	leaq	.LC2(%rip), %rsi
	movq	%r13, %rdi
.LEHB2:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc@PLT
.LEHE2:
	leaq	48(%rsp), %r14
	movq	%rax, %rsi
	leaq	80(%rsp), %r12
	movq	%r14, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EOS4_@PLT
	movl	$16, %edx
	movq	%r14, %rsi
	movq	%r12, %rdi
.LEHB3:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1ERKNSt7__cxx1112basic_stringIcS1_SaIcEEESt13_Ios_Openmode@PLT
.LEHE3:
	movq	%r14, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	%r13, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	16(%r15), %rsi
	leaq	3(%rsp), %rdx
	movq	%r14, %rdi
.LEHB4:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE4:
	call	__errno_location@PLT
	movq	48(%rsp), %r13
	movl	$10, %edx
	movq	%rbx, %rsi
	movq	%rax, %r15
	movl	(%rax), %eax
	movq	%r13, %rdi
	movl	%eax, 4(%rsp)
	xorl	%eax, %eax
	movl	%eax, (%r15)
	call	__isoc23_strtol@PLT
	cmpq	8(%rsp), %r13
	leaq	4(%rsp), %r13
	jne	.L46
	movq	1112(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L71
	leaq	.LC3(%rip), %rdi
.LEHB5:
	call	_ZSt24__throw_invalid_argumentPKc@PLT
.L46:
	cmpl	$34, (%r15)
	je	.L48
	movl	$2147483648, %edx
	movl	$4294967295, %ecx
	addq	%rax, %rdx
	cmpq	%rdx, %rcx
	jnb	.L49
.L48:
	movq	1112(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L71
	leaq	.LC3(%rip), %rdi
	call	_ZSt20__throw_out_of_rangePKc@PLT
.LEHE5:
.L49:
	movq	%r13, %rdi
	movl	%eax, %r15d
	call	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	movq	%r14, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	%rbx, %rsi
	movq	%rbp, %rdi
.LEHB6:
	call	_ZNSirsERi@PLT
	jmp	.L74
.L68:
	endbr64
	movq	%rax, %rbx
.L52:
	movq	%r13, %rdi
	call	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	movq	%r14, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L53
.L74:
	movl	8(%rsp), %r13d
	movl	%r13d, %edi
	imull	%r13d, %edi
	movslq	%edi, %rdi
	salq	$3, %rdi
	call	malloc@PLT
	movl	%r13d, %edx
	movq	%rbp, %rdi
	movq	%rax, %rsi
	movq	%rax, %rbx
	call	_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi
	movl	8(%rsp), %esi
	movl	%r15d, %edx
	movq	%rbx, %rdi
	call	_Z10exp_matrixPxii
	call	cudaDeviceSynchronize@PLT
	xorl	%r13d, %r13d
	leaq	.LC4(%rip), %r15
.L54:
	cmpl	%r13d, 8(%rsp)
	jle	.L75
	xorl	%r14d, %r14d
.L56:
	movl	8(%rsp), %eax
	cmpl	%r14d, %eax
	jle	.L76
	imull	%r13d, %eax
	movq	%r12, %rdi
	addl	%r14d, %eax
	cltq
	movq	(%rbx,%rax,8), %rsi
	call	_ZNSo9_M_insertIxEERSoT_@PLT
	movq	%rax, %rdi
	movl	$1, %edx
	movq	%r15, %rsi
	call	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	incl	%r14d
	jmp	.L56
.L76:
	movq	%r12, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.LEHE6:
	incl	%r13d
	jmp	.L54
.L75:
	movq	%r12, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	%rbp, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
.L45:
	movq	1112(%rsp), %rax
	subq	%fs:40, %rax
	je	.L61
	jmp	.L71
.L65:
	endbr64
	movq	%rax, %rbx
.L57:
	movq	%r14, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L58
.L64:
	endbr64
	movq	%rax, %rbx
.L58:
	movq	%r13, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L59
.L67:
	endbr64
	movq	%rax, %rbx
.L53:
	movq	%r12, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	jmp	.L59
.L66:
	endbr64
	movq	%rax, %rbx
.L59:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	1112(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L71
	movq	%rbx, %rdi
.LEHB7:
	call	_Unwind_Resume@PLT
.LEHE7:
.L71:
	call	__stack_chk_fail@PLT
.L61:
	addq	$1128, %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
.LFE3769:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3769:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3769-.LLSDACSB3769
.LLSDACSB3769:
	.uleb128 .LEHB0-.LFB3769
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3769
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L66-.LFB3769
	.uleb128 0
	.uleb128 .LEHB2-.LFB3769
	.uleb128 .LEHE2-.LEHB2
	.uleb128 .L64-.LFB3769
	.uleb128 0
	.uleb128 .LEHB3-.LFB3769
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L65-.LFB3769
	.uleb128 0
	.uleb128 .LEHB4-.LFB3769
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L67-.LFB3769
	.uleb128 0
	.uleb128 .LEHB5-.LFB3769
	.uleb128 .LEHE5-.LEHB5
	.uleb128 .L68-.LFB3769
	.uleb128 0
	.uleb128 .LEHB6-.LFB3769
	.uleb128 .LEHE6-.LEHB6
	.uleb128 .L67-.LFB3769
	.uleb128 0
	.uleb128 .LEHB7-.LFB3769
	.uleb128 .LEHE7-.LEHB7
	.uleb128 0
	.uleb128 0
.LLSDACSE3769:
	.section	.text.startup
	.size	main, .-main
	.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
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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:

/*
Fast matrix exponentiation using CUDA.
The exectuable takes two arguments: the matrix in a file and the power.
The file should have a integer N in the first line that is the size of the matrix and
N lines with N integers each representing the matrix.
Example of file:
3
1 2 3
4 5 6
7 8 9

Example of usage:
./mExp input.txt 4
*/

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

typedef long long ll;

using namespace std;

void read_matrix(ifstream& file, ll* matrix, int n){
  int i=0;
  while(file >> matrix[i++]){}
}

int get_size_warp(){
  int deviceId;
  hipGetDevice(&deviceId);
  hipDeviceProp_t props;
  hipGetDeviceProperties(&props, deviceId);
  return props.multiProcessorCount;
}

__global__ void multi_matrix(ll *a, ll *b, ll *c, int n){

  int tidx = threadIdx.x+blockDim.x*blockIdx.x, slidex = blockDim.x*gridDim.x;
  int tidy = threadIdx.y+blockDim.y*blockIdx.y, slidey = blockDim.y*gridDim.y;
  for(int i=tidx;i<n;i+=slidex){
    for(int j=tidy;j<n;j+=slidey){
      ll tmp=0;
      for(int k=0;k<n;k++){
        tmp+=a[i*n+k]*b[k*n+j];
      }
      c[i*n+j]=tmp;
    }
  }
}


void exp_matrix(ll *a, int n, int exp){

  ll *idt;
  ll *m1_device, *m2_device, *m3_device, *a_device;
  ll *tmp;
  int size = n*n*sizeof(ll);
  int size_warp = get_size_warp();
  dim3 grid(16, 16), block(size_warp, size_warp);

  idt = (ll*)malloc(size);

  hipMalloc(&m1_device, size);
  hipMalloc(&m2_device, size);
  hipMalloc(&m3_device, size);
  hipMalloc(&a_device, size);

  for(int i=0;i<n*n;i++)idt[i]=0;
  for(int i=0;i*(n+1)<n*n;i++)idt[i*(n+1)]=1;

  hipMemcpy(a_device, a, size, hipMemcpyHostToDevice);
  hipMemcpy(m1_device, idt, size, hipMemcpyHostToDevice);
  hipMemcpy(m3_device, idt, size, hipMemcpyHostToDevice);

  while(exp!=0){
    int b = exp%2;
    multi_matrix<<<grid, block>>>(a_device, m1_device, m2_device, n);
    hipDeviceSynchronize();
    if(b){
      multi_matrix<<<grid, block>>>(m3_device, m2_device, m1_device, n); 
      hipDeviceSynchronize();
      tmp = m1_device;
      m1_device = m2_device;
      m3_device = tmp;
    }
    else m1_device = m2_device;

    exp>>=1;
  }

  hipMemcpy(a, m3_device, size, hipMemcpyDeviceToHost);
}

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

  if(argc<3)return 0;

  ifstream inFile(argv[1]);
  ofstream outFile(string(argv[1])+".output");

  int exp = stoi(argv[2]);
  int n;
  ll *matrix;

  inFile >> n;

  matrix = (ll*)malloc((n*n)*sizeof(ll));

  read_matrix(inFile, matrix, n);

  exp_matrix(matrix, n, exp);

  hipDeviceSynchronize();

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      outFile << matrix[i*n+j] << " ";
    }
    outFile << endl;
  }
  return 0;
}

	.text
	.file	"matrix-exp.hip"
	.globl	_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi # -- Begin function _Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi
	.type	_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi,@function
_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi: # @_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movq	%rbx, %rsi
	callq	_ZNSi10_M_extractIxEERSiRT_
	movq	(%rax), %rcx
	movq	-24(%rcx), %rcx
	addq	$8, %rbx
	testb	$5, 32(%rax,%rcx)
	je	.LBB0_1
# %bb.2:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi, .Lfunc_end0-_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi
	.cfi_endproc
                                        # -- End function
	.globl	_Z13get_size_warpv              # -- Begin function _Z13get_size_warpv
	.type	_Z13get_size_warpv,@function
_Z13get_size_warpv:                     # @_Z13get_size_warpv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$1488, %rsp                     # imm = 0x5D0
	.cfi_def_cfa_offset 1504
	.cfi_offset %rbx, -16
	leaq	12(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDevice
	movl	(%rbx), %esi
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDevicePropertiesR0600
	movl	388(%rbx), %eax
	addq	$1488, %rsp                     # imm = 0x5D0
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z13get_size_warpv, .Lfunc_end1-_Z13get_size_warpv
	.cfi_endproc
                                        # -- End function
	.globl	_Z27__device_stub__multi_matrixPxS_S_i # -- Begin function _Z27__device_stub__multi_matrixPxS_S_i
	.type	_Z27__device_stub__multi_matrixPxS_S_i,@function
_Z27__device_stub__multi_matrixPxS_S_i: # @_Z27__device_stub__multi_matrixPxS_S_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z12multi_matrixPxS_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z27__device_stub__multi_matrixPxS_S_i, .Lfunc_end2-_Z27__device_stub__multi_matrixPxS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z10exp_matrixPxii              # -- Begin function _Z10exp_matrixPxii
	.type	_Z10exp_matrixPxii,@function
_Z10exp_matrixPxii:                     # @_Z10exp_matrixPxii
	.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	$1512, %rsp                     # imm = 0x5E8
	.cfi_def_cfa_offset 1568
	.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	%edx, %r14d
	movl	%esi, %ebp
	movq	%rdi, 32(%rsp)                  # 8-byte Spill
	movl	%esi, %ebx
	imull	%ebx, %ebx
	leal	(,%rbx,8), %r12d
	movq	%rsp, %r15
	movq	%r15, %rdi
	callq	hipGetDevice
	movl	(%r15), %esi
	leaq	40(%rsp), %r15
	movq	%r15, %rdi
	callq	hipGetDevicePropertiesR0600
	movl	388(%r15), %eax
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movslq	%r12d, %r15
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %r12
	leaq	40(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	%rsp, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%ebp, %ebp
	je	.LBB3_3
# %bb.1:                                # %.lr.ph66.preheader
	cmpl	$1, %ebx
	movl	%ebx, %edx
	adcl	$0, %edx
	shlq	$3, %rdx
	xorl	%r13d, %r13d
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movslq	%ebp, %rax
	incq	%rax
	movslq	%ebx, %rcx
	movq	%rax, %rdx
	shlq	$32, %rdx
	xorl	%esi, %esi
.LBB3_2:                                # %.lr.ph66
                                        # =>This Inner Loop Header: Depth=1
	movq	%rsi, %rdi
	sarq	$29, %rdi
	movq	$1, (%r12,%rdi)
	addq	%rdx, %rsi
	addq	%rax, %r13
	cmpq	%rcx, %r13
	jl	.LBB3_2
.LBB3_3:                                # %._crit_edge
	movq	16(%rsp), %rdi
	movq	32(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rdi
	movq	%r12, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rdi
	movq	%r12, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%r14d, %r14d
	je	.LBB3_13
# %bb.4:                                # %.lr.ph70.preheader
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	%rax, %r12
	shlq	$32, %r12
	orq	%rax, %r12
	movabsq	$68719476752, %r13              # imm = 0x1000000010
.LBB3_5:                                # %.lr.ph70
                                        # =>This Inner Loop Header: Depth=1
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.6:                                #   in Loop: Header=BB3_5 Depth=1
	movq	16(%rsp), %rdi
	movq	40(%rsp), %rsi
	movq	(%rsp), %rdx
	movl	%ebp, %ecx
	callq	_Z27__device_stub__multi_matrixPxS_S_i
.LBB3_7:                                #   in Loop: Header=BB3_5 Depth=1
	callq	hipDeviceSynchronize
	testb	$1, %r14b
	jne	.LBB3_8
# %bb.11:                               #   in Loop: Header=BB3_5 Depth=1
	movq	(%rsp), %rax
	movq	%rax, 40(%rsp)
	jmp	.LBB3_12
.LBB3_8:                                #   in Loop: Header=BB3_5 Depth=1
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.9:                                #   in Loop: Header=BB3_5 Depth=1
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movq	40(%rsp), %rdx
	movl	%ebp, %ecx
	callq	_Z27__device_stub__multi_matrixPxS_S_i
.LBB3_10:                               #   in Loop: Header=BB3_5 Depth=1
	callq	hipDeviceSynchronize
	movq	40(%rsp), %rax
	movq	(%rsp), %rcx
	movq	%rcx, 40(%rsp)
	movq	%rax, 8(%rsp)
.LBB3_12:                               #   in Loop: Header=BB3_5 Depth=1
	movl	%r14d, %eax
	sarl	%eax
	cmpl	$1, %r14d
	movl	%eax, %r14d
	ja	.LBB3_5
.LBB3_13:                               # %._crit_edge71
	movq	8(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	addq	$1512, %rsp                     # imm = 0x5E8
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z10exp_matrixPxii, .Lfunc_end3-_Z10exp_matrixPxii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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	$1112, %rsp                     # imm = 0x458
	.cfi_def_cfa_offset 1168
	.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
	jl	.LBB4_45
# %bb.1:
	movq	%rsi, %r15
	movq	8(%rsi), %rsi
	leaq	592(%rsp), %rdi
	movl	$8, %edx
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode
	movq	8(%r15), %rsi
.Ltmp0:
	leaq	48(%rsp), %rdi
	leaq	15(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp1:
# %bb.2:
.Ltmp3:
	leaq	48(%rsp), %rdi
	movl	$.L.str, %esi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6appendEPKc
.Ltmp4:
# %bb.3:                                # %.noexc
	movq	%rax, %rbx
	leaq	32(%rsp), %r13
	movq	%r13, -16(%r13)
	movq	(%rax), %rsi
	movq	%rax, %r14
	addq	$16, %r14
	cmpq	%r14, %rsi
	je	.LBB4_4
# %bb.5:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	movq	%rsi, 16(%rsp)
	movq	16(%rbx), %rax
	movq	%rax, 32(%rsp)
	movq	8(%rbx), %r12
	jmp	.LBB4_6
.LBB4_4:
	movq	8(%rbx), %r12
	leaq	1(%r12), %rdx
	movq	%r13, %rdi
	callq	memcpy@PLT
.LBB4_6:
	leaq	16(%rsp), %rsi
	movq	%r12, 8(%rsi)
	movq	%r14, (%rbx)
	movq	$0, 8(%rbx)
	movb	$0, 16(%rbx)
.Ltmp6:
	leaq	80(%rsp), %rbx
	movq	%rbx, %rdi
	movl	$16, %edx
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1ERKNSt7__cxx1112basic_stringIcS1_SaIcEEESt13_Ios_Openmode
.Ltmp7:
# %bb.7:
	movq	16(%rsp), %rdi
	cmpq	%r13, %rdi
	je	.LBB4_9
# %bb.8:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i36
	callq	_ZdlPv
.LBB4_9:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
	leaq	64(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB4_11
# %bb.10:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i37
	callq	_ZdlPv
.LBB4_11:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit39
	movq	16(%r15), %rsi
.Ltmp9:
	leaq	16(%rsp), %rdi
	leaq	15(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp10:
# %bb.12:
	movq	16(%rsp), %r13
	callq	__errno_location
	movq	%rax, %r12
	movl	(%rax), %r14d
	movl	$0, (%rax)
	leaq	48(%rsp), %rbp
	movq	%r13, %rdi
	movq	%rbp, %rsi
	movl	$10, %edx
	callq	__isoc23_strtol
	cmpq	%r13, (%rbp)
	je	.LBB4_13
# %bb.19:
	movq	%rax, %r15
	movslq	%r15d, %rax
	cmpq	%r15, %rax
	leaq	32(%rsp), %rcx
	jne	.LBB4_21
# %bb.20:
	movl	(%r12), %eax
	cmpl	$34, %eax
	je	.LBB4_21
# %bb.23:
	testl	%eax, %eax
	jne	.LBB4_25
# %bb.24:
	movl	%r14d, (%r12)
.LBB4_25:
	movq	16(%rsp), %rdi
	cmpq	%rcx, %rdi
	je	.LBB4_27
# %bb.26:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i40
	callq	_ZdlPv
.LBB4_27:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit42
.Ltmp12:
	leaq	592(%rsp), %rdi
	leaq	16(%rsp), %rsi
	callq	_ZNSirsERi
.Ltmp13:
# %bb.28:
	movl	16(%rsp), %edi
	imull	%edi, %edi
	shlq	$3, %rdi
	callq	malloc
	movq	%rax, %r14
	leaq	592(%rsp), %r12
	movq	%rax, %r13
.LBB4_29:                               # =>This Inner Loop Header: Depth=1
.Ltmp14:
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	_ZNSi10_M_extractIxEERSiRT_
.Ltmp15:
# %bb.30:                               # %.noexc43
                                        #   in Loop: Header=BB4_29 Depth=1
	movq	(%rax), %rcx
	movq	-24(%rcx), %rcx
	addq	$8, %r13
	testb	$5, 32(%rax,%rcx)
	je	.LBB4_29
# %bb.31:                               # %_Z11read_matrixRSt14basic_ifstreamIcSt11char_traitsIcEEPxi.exit
	movl	16(%rsp), %esi
.Ltmp17:
	movq	%r14, %rdi
	movl	%r15d, %edx
	callq	_Z10exp_matrixPxii
.Ltmp18:
# %bb.32:
.Ltmp19:
	callq	hipDeviceSynchronize
.Ltmp20:
# %bb.33:                               # %.preheader59
	movl	16(%rsp), %eax
	testl	%eax, %eax
	jle	.LBB4_44
# %bb.34:                               # %.preheader.preheader
	xorl	%r15d, %r15d
.LBB4_35:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_37 Depth 2
	testl	%eax, %eax
	jle	.LBB4_40
# %bb.36:                               # %.lr.ph.preheader
                                        #   in Loop: Header=BB4_35 Depth=1
	xorl	%r12d, %r12d
.LBB4_37:                               # %.lr.ph
                                        #   Parent Loop BB4_35 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	imull	%r15d, %eax
	cltq
	addq	%r12, %rax
	movq	(%r14,%rax,8), %rsi
.Ltmp22:
	movq	%rbx, %rdi
	callq	_ZNSo9_M_insertIxEERSoT_
.Ltmp23:
# %bb.38:                               # %_ZNSolsEx.exit
                                        #   in Loop: Header=BB4_37 Depth=2
.Ltmp24:
	movl	$.L.str.1, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp25:
# %bb.39:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
                                        #   in Loop: Header=BB4_37 Depth=2
	movl	16(%rsp), %eax
	incq	%r12
	cmpl	%eax, %r12d
	jl	.LBB4_37
.LBB4_40:                               # %._crit_edge
                                        #   in Loop: Header=BB4_35 Depth=1
	movq	80(%rsp), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
.Ltmp27:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp28:
# %bb.41:                               # %.noexc56
                                        #   in Loop: Header=BB4_35 Depth=1
.Ltmp29:
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
.Ltmp30:
# %bb.42:                               # %.noexc57
                                        #   in Loop: Header=BB4_35 Depth=1
.Ltmp31:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp32:
# %bb.43:                               # %_ZNSolsEPFRSoS_E.exit
                                        #   in Loop: Header=BB4_35 Depth=1
	incl	%r15d
	movl	16(%rsp), %eax
	cmpl	%eax, %r15d
	jl	.LBB4_35
.LBB4_44:                               # %._crit_edge62
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE(%rip), %rax
	leaq	88(%rsp), %rdi
	movq	%rax, -8(%rdi)
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE+24(%rip), %rcx
	movq	-24(%rax), %rax
	movq	%rcx, 80(%rsp,%rax)
	callq	_ZNSt13basic_filebufIcSt11char_traitsIcEED2Ev
	leaq	328(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	leaq	592(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
.LBB4_45:
	xorl	%eax, %eax
	addq	$1112, %rsp                     # imm = 0x458
	.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
.LBB4_13:
	.cfi_def_cfa_offset 1168
.Ltmp36:
	movl	$.L.str.2, %edi
	callq	_ZSt24__throw_invalid_argumentPKc
.Ltmp37:
# %bb.14:
.LBB4_21:                               # %.critedge.i.i
.Ltmp34:
	movl	$.L.str.2, %edi
	callq	_ZSt20__throw_out_of_rangePKc
.Ltmp35:
# %bb.22:
.LBB4_52:
.Ltmp11:
	jmp	.LBB4_56
.LBB4_48:
.Ltmp8:
	movq	%rax, %rbx
	movq	16(%rsp), %rdi
	cmpq	%r13, %rdi
	je	.LBB4_50
# %bb.49:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i44
	callq	_ZdlPv
	jmp	.LBB4_50
.LBB4_47:
.Ltmp5:
	movq	%rax, %rbx
.LBB4_50:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit46
	leaq	64(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB4_58
# %bb.51:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i47
	callq	_ZdlPv
	jmp	.LBB4_58
.LBB4_46:
.Ltmp2:
	movq	%rax, %rbx
	jmp	.LBB4_58
.LBB4_15:
.Ltmp38:
	movq	%rax, %rbx
	cmpl	$0, (%r12)
	jne	.LBB4_17
# %bb.16:
	movl	%r14d, (%r12)
.LBB4_17:                               # %_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev.exit.i.i
	movq	16(%rsp), %rdi
	leaq	32(%rsp), %rax
	cmpq	%rax, %rdi
	je	.LBB4_57
# %bb.18:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i50
	callq	_ZdlPv
	jmp	.LBB4_57
.LBB4_54:                               # %.loopexit.split-lp
.Ltmp21:
	jmp	.LBB4_56
.LBB4_53:                               # %.loopexit
.Ltmp16:
	jmp	.LBB4_56
.LBB4_55:
.Ltmp33:
	jmp	.LBB4_56
.LBB4_59:
.Ltmp26:
.LBB4_56:
	movq	%rax, %rbx
.LBB4_57:
	leaq	80(%rsp), %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev
.LBB4_58:
	leaq	592(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table4:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp4-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp4
	.uleb128 .Ltmp5-.Lfunc_begin0           #     jumps to .Ltmp5
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp4-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp6-.Ltmp4                  #   Call between .Ltmp4 and .Ltmp6
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin0           # >> Call Site 5 <<
	.uleb128 .Ltmp7-.Ltmp6                  #   Call between .Ltmp6 and .Ltmp7
	.uleb128 .Ltmp8-.Lfunc_begin0           #     jumps to .Ltmp8
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp9-.Lfunc_begin0           # >> Call Site 6 <<
	.uleb128 .Ltmp10-.Ltmp9                 #   Call between .Ltmp9 and .Ltmp10
	.uleb128 .Ltmp11-.Lfunc_begin0          #     jumps to .Ltmp11
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp12-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp13-.Ltmp12                #   Call between .Ltmp12 and .Ltmp13
	.uleb128 .Ltmp21-.Lfunc_begin0          #     jumps to .Ltmp21
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp14-.Lfunc_begin0          # >> Call Site 8 <<
	.uleb128 .Ltmp15-.Ltmp14                #   Call between .Ltmp14 and .Ltmp15
	.uleb128 .Ltmp16-.Lfunc_begin0          #     jumps to .Ltmp16
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp17-.Lfunc_begin0          # >> Call Site 9 <<
	.uleb128 .Ltmp20-.Ltmp17                #   Call between .Ltmp17 and .Ltmp20
	.uleb128 .Ltmp21-.Lfunc_begin0          #     jumps to .Ltmp21
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp22-.Lfunc_begin0          # >> Call Site 10 <<
	.uleb128 .Ltmp25-.Ltmp22                #   Call between .Ltmp22 and .Ltmp25
	.uleb128 .Ltmp26-.Lfunc_begin0          #     jumps to .Ltmp26
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp27-.Lfunc_begin0          # >> Call Site 11 <<
	.uleb128 .Ltmp32-.Ltmp27                #   Call between .Ltmp27 and .Ltmp32
	.uleb128 .Ltmp33-.Lfunc_begin0          #     jumps to .Ltmp33
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp36-.Lfunc_begin0          # >> Call Site 12 <<
	.uleb128 .Ltmp35-.Ltmp36                #   Call between .Ltmp36 and .Ltmp35
	.uleb128 .Ltmp38-.Lfunc_begin0          #     jumps to .Ltmp38
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp35-.Lfunc_begin0          # >> Call Site 13 <<
	.uleb128 .Lfunc_end4-.Ltmp35            #   Call between .Ltmp35 and .Lfunc_end4
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_ # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	leaq	16(%rdi), %rax
	movq	%rax, (%rdi)
	testq	%rsi, %rsi
	je	.LBB5_1
# %bb.2:
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	%rsi, %rdi
	callq	strlen
	leaq	(%rax,%rbx), %rdx
	movq	%r14, %rdi
	movq	%rbx, %rsi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # TAILCALL
.LBB5_1:
	.cfi_def_cfa_offset 32
	movl	$.L.str.3, %edi
	callq	_ZSt19__throw_logic_errorPKc
.Lfunc_end5:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .Lfunc_end5-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.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
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %rbx
	subq	%rsi, %r14
	movq	%r14, (%rsp)
	cmpq	$15, %r14
	jbe	.LBB6_1
# %bb.2:
	movq	%rsp, %r12
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm
	movq	%rax, (%rbx)
	movq	(%r12), %rcx
	movq	%rcx, 16(%rbx)
	jmp	.LBB6_3
.LBB6_1:                                # %._crit_edge
	movq	(%rbx), %rax
.LBB6_3:
	testq	%r14, %r14
	je	.LBB6_7
# %bb.4:
	cmpq	$1, %r14
	jne	.LBB6_6
# %bb.5:
	movb	(%r15), %cl
	movb	%cl, (%rax)
	jmp	.LBB6_7
.LBB6_6:
	movq	%rax, %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	callq	memcpy@PLT
.LBB6_7:                                # %_ZZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tagEN6_GuardD2Ev.exit
	movq	(%rsp), %rax
	movq	%rax, 8(%rbx)
	movq	(%rbx), %rcx
	movb	$0, (%rcx,%rax)
	addq	$8, %rsp
	.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_end6:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag, .Lfunc_end6-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.cfi_endproc
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12multi_matrixPxS_S_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z12multi_matrixPxS_S_i,@object # @_Z12multi_matrixPxS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z12multi_matrixPxS_S_i
	.p2align	3, 0x0
_Z12multi_matrixPxS_S_i:
	.quad	_Z27__device_stub__multi_matrixPxS_S_i
	.size	_Z12multi_matrixPxS_S_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	".output"
	.size	.L.str, 8

	.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	"stoi"
	.size	.L.str.2, 5

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"basic_string: construction from null is not valid"
	.size	.L.str.3, 50

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12multi_matrixPxS_S_i"
	.size	.L__unnamed_1, 24

	.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 _Z27__device_stub__multi_matrixPxS_S_i
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z12multi_matrixPxS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12multi_matrixPxS_S_i ; -- Begin function _Z12multi_matrixPxS_S_i
	.globl	_Z12multi_matrixPxS_S_i
	.p2align	8
	.type	_Z12multi_matrixPxS_S_i,@function
_Z12multi_matrixPxS_S_i:                ; @_Z12multi_matrixPxS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x2c
	s_load_b32 s2, s[0:1], 0x18
	v_and_b32_e32 v3, 0x3ff, v0
	s_add_u32 s4, s0, 32
	s_addc_u32 s5, s1, 0
	s_mov_b32 s6, exec_lo
	s_waitcnt lgkmcnt(0)
	s_and_b32 s11, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s14, s11, v[3:4]
	v_cmpx_gt_i32_e64 s2, v1
	s_cbranch_execz .LBB0_10
; %bb.1:                                ; %.preheader38.lr.ph
	v_bfe_u32 v0, v0, 10, 10
	s_lshr_b32 s10, s3, 16
	s_load_b64 s[12:13], s[4:5], 0x0
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[8:9], s[0:1], 0x10
	v_mad_u64_u32 v[2:3], null, s15, s10, v[0:1]
	v_mul_lo_u32 v4, s2, v1
	s_cmp_gt_i32 s2, 0
	s_mov_b32 s14, 0
	s_cselect_b32 s15, -1, 0
	s_ashr_i32 s3, s2, 31
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v3, 31, v2
	v_cmp_gt_i32_e64 s0, s2, v2
	v_lshlrev_b64 v[6:7], 3, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s10, s13, s10
	s_mul_i32 s16, s12, s11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s6, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v7, vcc_lo
	s_ashr_i32 s11, s10, 31
	s_lshl_b64 s[12:13], s[2:3], 3
	s_lshl_b64 s[6:7], s[10:11], 3
	s_mul_i32 s3, s16, s2
.LBB0_2:                                ; %.preheader38
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
                                        ;       Child Loop BB0_6 Depth 3
	s_and_saveexec_b32 s11, s0
	s_cbranch_execz .LBB0_9
; %bb.3:                                ; %.preheader.lr.ph
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_ashrrev_i32_e32 v5, 31, v4
	v_mul_lo_u32 v0, v1, s2
	v_dual_mov_b32 v9, v7 :: v_dual_mov_b32 v8, v6
	v_mov_b32_e32 v3, v2
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[10:11], 3, v[4:5]
	s_mov_b32 s17, 0
	v_add_co_u32 v10, vcc_lo, s4, v10
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v11, vcc_lo, s5, v11, vcc_lo
.LBB0_4:                                ; %.preheader
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_6 Depth 3
	s_and_not1_b32 vcc_lo, exec_lo, s15
	s_cbranch_vccnz .LBB0_7
; %bb.5:                                ; %.lr.ph.preheader
                                        ;   in Loop: Header=BB0_4 Depth=2
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v18, 0 :: v_dual_mov_b32 v15, v11
	v_dual_mov_b32 v19, 0 :: v_dual_mov_b32 v14, v10
	v_dual_mov_b32 v17, v9 :: v_dual_mov_b32 v16, v8
	s_mov_b32 s1, s2
.LBB0_6:                                ; %.lr.ph
                                        ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_4 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	global_load_b64 v[20:21], v[14:15], off
	global_load_b64 v[22:23], v[16:17], off
	v_add_co_u32 v16, vcc_lo, v16, s12
	v_add_co_ci_u32_e32 v17, vcc_lo, s13, v17, vcc_lo
	v_add_co_u32 v14, vcc_lo, v14, 8
	v_add_co_ci_u32_e32 v15, vcc_lo, 0, v15, vcc_lo
	s_add_i32 s1, s1, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s1, 0
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[12:13], null, v22, v20, v[18:19]
	v_mul_lo_u32 v5, v22, v21
	v_mul_lo_u32 v18, v23, v20
	v_add3_u32 v13, v18, v13, v5
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v19, v13 :: v_dual_mov_b32 v18, v12
	s_cbranch_scc0 .LBB0_6
	s_branch .LBB0_8
.LBB0_7:                                ;   in Loop: Header=BB0_4 Depth=2
	v_mov_b32_e32 v12, 0
	v_mov_b32_e32 v13, 0
.LBB0_8:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_4 Depth=2
	v_add_nc_u32_e32 v14, v3, v0
	v_add_nc_u32_e32 v3, s10, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v15, 31, v14
	v_cmp_le_i32_e32 vcc_lo, s2, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[14:15], 3, v[14:15]
	s_or_b32 s17, vcc_lo, s17
	v_add_co_u32 v14, s1, s8, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v15, s1, s9, v15, s1
	v_add_co_u32 v8, s1, v8, s6
	v_add_co_ci_u32_e64 v9, s1, s7, v9, s1
	global_store_b64 v[14:15], v[12:13], off
	s_and_not1_b32 exec_lo, exec_lo, s17
	s_cbranch_execnz .LBB0_4
.LBB0_9:                                ; %Flow68
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s11
	v_add_nc_u32_e32 v1, s16, v1
	v_add_nc_u32_e32 v4, s3, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_le_i32_e32 vcc_lo, s2, v1
	s_or_b32 s14, vcc_lo, s14
	s_and_not1_b32 exec_lo, exec_lo, s14
	s_cbranch_execnz .LBB0_2
.LBB0_10:                               ; %._crit_edge44
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12multi_matrixPxS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 24
		.amdhsa_next_free_sgpr 18
		.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	_Z12multi_matrixPxS_S_i, .Lfunc_end0-_Z12multi_matrixPxS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 568
; NumSgprs: 20
; NumVgprs: 24
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 24
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z12multi_matrixPxS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z12multi_matrixPxS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     24
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
