#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
__global__ void RowOperation1(float* matrix_cu,int* rank_cu,float* inverse_cu, int* dim)
{
	int i = threadIdx.y + blockDim.y * blockIdx.y;
	int j = threadIdx.x + blockDim.x * blockIdx.x;
	float pivot_cu = matrix_cu[i + dim[0] * rank_cu[0]];
	__syncthreads();
	if(i != rank_cu[0])
	{
		inverse_cu[i + dim[0] * j] -= pivot_cu * inverse_cu[rank_cu[0] + dim[0] * j];
		matrix_cu[i + dim[0] * j] -= pivot_cu * matrix_cu[rank_cu[0] + dim[0] * j];
	}
}
__global__ void RowOperation2(float* matrix_cu,int* rank_cu,float* inverse_cu, int* dim)
{
	int i = threadIdx.x;
	float pivot = matrix_cu[(dim[0]+1) * (rank_cu[0])];
	__syncthreads();
	matrix_cu[rank_cu[0] + dim[0] * i] /= pivot;
	inverse_cu[rank_cu[0] + dim[0] * i] /= pivot;
}


/** matrix inverse */
void inv(float* matrix, int row_dim, int col_dim,float* inverse)
{
	// check square matrix
	if(col_dim == row_dim)
	{
		int * dime = new int [1];
		int * rank =new int [1];
		dime[0]=col_dim;
		float * matrix_cu;
                float * inverse_cu;
                int * dim;
                int * rank_cu;
                int matrix_size = sizeof(float) * row_dim * col_dim;
		int int_size = sizeof(int);
		cudaError_t err;
                cudaMalloc(&matrix_cu,matrix_size);
                cudaMalloc(&inverse_cu,matrix_size);
		cudaMalloc(&rank_cu,int_size);
		err = cudaGetLastError();
		if (err != cudaSuccess) {cout<< "rank_malloc wrong";return;}
                for(int j = 0;j < col_dim; j++)
		cudaMalloc(&dim,int_size);
		cudaMemcpy(dim,dime,int_size,cudaMemcpyHostToDevice);
		err = cudaGetLastError();
                if (err != cudaSuccess) {cout<< "dim_copy wrong";return;}
		for(int j = 0;j < col_dim; j++)
		{
			rank[0]=j;
			//find max magnitude
			float tmp = 0;
			int p = -1;
			for(int i = j; i < row_dim; i++)
			{
				if(abs(matrix[i + row_dim * j]) != 0) 
				{
					tmp = abs(matrix[i + row_dim * j]);
					p = i;
					if(j != p)
					{
						for(int k=0;k < col_dim; k++)
						{
						swap(matrix[j + row_dim * k],matrix[p + row_dim * k]);
                                		swap(inverse[j + row_dim * k],inverse[p + row_dim * k]);
						}
					}
					break;
				}
			}
			
			// have zero row
			if(p == -1)
			{
				cout << "it's singular";
				return;
			}
			cudaMemcpy(rank_cu,rank,int_size,cudaMemcpyHostToDevice);
			err = cudaGetLastError();
                        if (err != cudaSuccess) {cout<< "rank_copy wrong";return;}
			cudaMemcpy(matrix_cu,matrix,matrix_size,cudaMemcpyHostToDevice);
			cudaMemcpy(inverse_cu,inverse,matrix_size,cudaMemcpyHostToDevice);
			err = cudaGetLastError();
                        if (err != cudaSuccess) {cout<< "inverse_copy wrong";return;}
			//row operation
			RowOperation2<<<1,col_dim>>>(matrix, rank_cu, inverse, dim);
			err = cudaGetLastError();
			if (err != cudaSuccess) {cout<< "2 wrong";return;}
			RowOperation1<<<row_dim,col_dim>>>(matrix, rank_cu, inverse, dim);
			err = cudaGetLastError();
                        if (err != cudaSuccess) {cout<< "1 wrong";return;}
			cudaMemcpy(matrix,matrix_cu,matrix_size,cudaMemcpyDeviceToHost);
			cudaMemcpy(inverse,inverse_cu,matrix_size,cudaMemcpyDeviceToHost);
			
		}
	}
	else
	{
		cout << "it isn't sqare matrix";
		return;
	}
}

/** matrix print */
void print(float* matrix, int row_dim, int col_dim)
{
	for(int i=0; i < row_dim; i++)
	{
		for(int j=0; j < col_dim; j++)
		{
			cout << matrix[i+ col_dim * j]<<" ";
		}
		cout<<endl;
	}
}

int main ()
{
	//random seed
	srand(0);
	
	//set dimention
	int row_dim = 6;
	int col_dim = 6;
	
	//initial array
	float* inverse = new float [row_dim * col_dim];
	float* result = new float [row_dim * col_dim];
    for(int i = 0; i < row_dim * col_dim; i++)
    {
        inverse[i] = rand()%9;
        result[i] = (i / col_dim == i % row_dim)?1.0f:0.0f;
        /*for(int j = 0;j < col_dim; j++)
        {
            inverse[i][j] = float(rand()%9);
            result[i][j] = (i == j)?1.0f:0.0f;
        }*/
    }
    
    //check input
    print(inverse, row_dim, col_dim);
    
    cout << "----------------------\n";
    
    //test inverse
    inv(inverse, row_dim, col_dim, result);
    
    //check result
    print(result, row_dim, col_dim);
    
    
	return 0;
}

	.file	"tmpxft_00200511_00000000-6_cuda_inv.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3895:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3895:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.isra.0, @function
_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.isra.0:
.LFB4557:
	.cfi_startproc
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	testq	%rsi, %rsi
	jne	.L3
	movq	(%rdi), %rax
	movl	$1, %esi
	addq	-24(%rax), %rbx
	addq	$16, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	_ZNSt9basic_iosIcSt11char_traitsIcEE8setstateESt12_Ios_Iostate@PLT
.L3:
	.cfi_restore_state
	movq	%rsi, %rdi
	movq	%rsi, 8(%rsp)
	call	strlen@PLT
	movq	8(%rsp), %rsi
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	movq	%rax, %rdx
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l@PLT
	.cfi_endproc
.LFE4557:
	.size	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.isra.0, .-_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.isra.0
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	" "
	.text
	.globl	_Z5printPfii
	.type	_Z5printPfii, @function
_Z5printPfii:
.LFB3891:
	.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
	movslq	%edx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r13, %rbp
	salq	$2, %r13
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	%esi, 12(%rsp)
.L7:
	cmpl	%ebx, 12(%rsp)
	jle	.L6
	leaq	(%r12,%rbx,4), %r14
	xorl	%r15d, %r15d
.L10:
	cmpl	%ebp, %r15d
	jge	.L12
	leaq	_ZSt4cout(%rip), %rdi
	cvtss2sd	(%r14), %xmm0
	incl	%r15d
	addq	%r13, %r14
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.isra.0
	jmp	.L10
.L12:
	leaq	_ZSt4cout(%rip), %rdi
	incq	%rbx
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	jmp	.L7
.L6:
	addq	$24, %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
.LFE3891:
	.size	_Z5printPfii, .-_Z5printPfii
	.globl	_Z40__device_stub__Z13RowOperation1PfPiS_S0_PfPiS_S0_
	.type	_Z40__device_stub__Z13RowOperation1PfPiS_S0_PfPiS_S0_, @function
_Z40__device_stub__Z13RowOperation1PfPiS_S0_PfPiS_S0_:
.LFB3917:
	.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
	movq	%rcx, (%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)
	movq	%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	.L13
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z13RowOperation1PfPiS_S0_(%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
.L13:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3917:
	.size	_Z40__device_stub__Z13RowOperation1PfPiS_S0_PfPiS_S0_, .-_Z40__device_stub__Z13RowOperation1PfPiS_S0_PfPiS_S0_
	.globl	_Z13RowOperation1PfPiS_S0_
	.type	_Z13RowOperation1PfPiS_S0_, @function
_Z13RowOperation1PfPiS_S0_:
.LFB3918:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z13RowOperation1PfPiS_S0_PfPiS_S0_
	.cfi_endproc
.LFE3918:
	.size	_Z13RowOperation1PfPiS_S0_, .-_Z13RowOperation1PfPiS_S0_
	.globl	_Z40__device_stub__Z13RowOperation2PfPiS_S0_PfPiS_S0_
	.type	_Z40__device_stub__Z13RowOperation2PfPiS_S0_PfPiS_S0_, @function
_Z40__device_stub__Z13RowOperation2PfPiS_S0_PfPiS_S0_:
.LFB3919:
	.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
	movq	%rcx, (%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)
	movq	%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	.L18
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z13RowOperation2PfPiS_S0_(%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
.L18:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3919:
	.size	_Z40__device_stub__Z13RowOperation2PfPiS_S0_PfPiS_S0_, .-_Z40__device_stub__Z13RowOperation2PfPiS_S0_PfPiS_S0_
	.globl	_Z13RowOperation2PfPiS_S0_
	.type	_Z13RowOperation2PfPiS_S0_, @function
_Z13RowOperation2PfPiS_S0_:
.LFB3920:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z13RowOperation2PfPiS_S0_PfPiS_S0_
	.cfi_endproc
.LFE3920:
	.size	_Z13RowOperation2PfPiS_S0_, .-_Z13RowOperation2PfPiS_S0_
	.section	.rodata.str1.1
.LC1:
	.string	"rank_malloc wrong"
.LC2:
	.string	"dim_copy wrong"
.LC4:
	.string	"rank_copy wrong"
.LC5:
	.string	"inverse_copy wrong"
.LC6:
	.string	"2 wrong"
.LC7:
	.string	"1 wrong"
.LC8:
	.string	"it isn't sqare matrix"
.LC9:
	.string	"it's singular"
	.text
	.globl	_Z3invPfiiS_
	.type	_Z3invPfiiS_, @function
_Z3invPfiiS_:
.LFB3889:
	.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	$104, %rsp
	.cfi_def_cfa_offset 160
	movl	%esi, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	cmpl	%esi, %edx
	jne	.L24
	movq	%rdi, %rbp
	movl	$4, %edi
	movl	%edx, %ebx
	movq	%rcx, %r12
	call	_Znam@PLT
	movl	$4, %edi
	movslq	%ebx, %r14
	xorl	%r15d, %r15d
	movq	%rax, %r13
	call	_Znam@PLT
	movl	%ebx, 0(%r13)
	leaq	32(%rsp), %rdi
	movq	%rax, 16(%rsp)
	movl	%ebx, %eax
	imull	%ebx, %eax
	sall	$2, %eax
	cltq
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	leaq	40(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	$4, %esi
	leaq	56(%rsp), %rdi
	call	cudaMalloc@PLT
	call	cudaGetLastError@PLT
	leaq	48(%rsp), %rdx
	leaq	.LC1(%rip), %rsi
	movq	%rdx, 24(%rsp)
	testl	%eax, %eax
	jne	.L53
.L25:
	cmpl	%r15d, %ebx
	jle	.L55
	movq	24(%rsp), %rdi
	movl	$4, %esi
	incl	%r15d
	call	cudaMalloc@PLT
	jmp	.L25
.L55:
	movq	48(%rsp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %r15d
	testl	%eax, %eax
	jne	.L28
	leaq	0(,%r14,4), %rax
	xorl	%r13d, %r13d
	movabsq	$4294967297, %r14
	movq	%rax, 24(%rsp)
	jmp	.L29
.L28:
	leaq	.LC2(%rip), %rsi
	jmp	.L53
.L41:
	movq	(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movq	40(%rsp), %rsi
	movq	%r12, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
.L29:
	movl	%r13d, %edx
	cmpl	%r13d, %ebx
	jle	.L23
	movq	16(%rsp), %rax
	xorps	%xmm0, %xmm0
	movl	%r13d, (%rax)
	movslq	%r15d, %rax
	leaq	0(%rbp,%rax,4), %rcx
	movq	%r13, %rax
.L30:
	cmpl	%eax, 12(%rsp)
	jle	.L56
	ucomiss	(%rcx,%rax,4), %xmm0
	leaq	1(%rax), %rsi
	jp	.L48
	je	.L47
.L48:
	cmpl	%edx, %eax
	je	.L32
	cltq
	leaq	0(,%r13,4), %rdx
	xorl	%ecx, %ecx
	salq	$2, %rax
.L33:
	movss	0(%rbp,%rdx), %xmm0
	movss	0(%rbp,%rax), %xmm1
	incl	%ecx
	movq	24(%rsp), %rsi
	movss	%xmm1, 0(%rbp,%rdx)
	movss	%xmm0, 0(%rbp,%rax)
	movss	(%r12,%rdx), %xmm0
	movss	(%r12,%rax), %xmm1
	movss	%xmm1, (%r12,%rdx)
	addq	%rsi, %rdx
	movss	%xmm0, (%r12,%rax)
	addq	%rsi, %rax
	cmpl	%ecx, %ebx
	jne	.L33
	jmp	.L32
.L47:
	movq	%rsi, %rax
	jmp	.L30
.L32:
	movq	16(%rsp), %rsi
	movq	56(%rsp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L36
	leaq	.LC4(%rip), %rsi
	jmp	.L53
.L36:
	movq	(%rsp), %rdx
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movq	40(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L37
	leaq	.LC5(%rip), %rsi
	jmp	.L53
.L37:
	movq	%r14, 68(%rsp)
	movl	72(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%ebx, 64(%rsp)
	movq	64(%rsp), %rdx
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r14, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L38
	movq	48(%rsp), %rcx
	movq	56(%rsp), %rsi
	movq	%r12, %rdx
	movq	%rbp, %rdi
	call	_Z40__device_stub__Z13RowOperation2PfPiS_S0_PfPiS_S0_
.L38:
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L39
	leaq	.LC6(%rip), %rsi
	jmp	.L53
.L39:
	movl	12(%rsp), %eax
	movq	%r14, 68(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r14, 80(%rsp)
	movl	72(%rsp), %ecx
	movl	%ebx, 64(%rsp)
	movl	84(%rsp), %esi
	movl	%eax, 76(%rsp)
	movq	64(%rsp), %rdx
	movq	76(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movq	48(%rsp), %rcx
	movq	56(%rsp), %rsi
	movq	%r12, %rdx
	movq	%rbp, %rdi
	call	_Z40__device_stub__Z13RowOperation1PfPiS_S0_PfPiS_S0_
.L40:
	call	cudaGetLastError@PLT
	movl	12(%rsp), %ecx
	incq	%r13
	addl	%ecx, %r15d
	testl	%eax, %eax
	je	.L41
	leaq	.LC7(%rip), %rsi
	jmp	.L53
.L24:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L54
	addq	$104, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	leaq	.LC8(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	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	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.isra.0
.L56:
	.cfi_restore_state
	leaq	.LC9(%rip), %rsi
.L53:
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.isra.0
.L23:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L45
.L54:
	call	__stack_chk_fail@PLT
.L45:
	addq	$104, %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
.LFE3889:
	.size	_Z3invPfiiS_, .-_Z3invPfiiS_
	.section	.rodata.str1.1
.LC11:
	.string	"----------------------\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3892:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%edi, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	call	srand@PLT
	movl	$144, %edi
	call	_Znam@PLT
	movl	$144, %edi
	movq	%rax, %r13
	call	_Znam@PLT
	movq	%rax, %r12
.L59:
	call	rand@PLT
	movl	$9, %ecx
	cltd
	idivl	%ecx
	movl	%ebx, %eax
	movl	$6, %ecx
	cvtsi2ssl	%edx, %xmm0
	cltd
	idivl	%ecx
	movss	%xmm0, 0(%r13,%rbx,4)
	xorps	%xmm0, %xmm0
	cmpl	%edx, %eax
	jne	.L58
	movss	.LC10(%rip), %xmm0
.L58:
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	cmpq	$36, %rbx
	jne	.L59
	movl	$6, %edx
	movq	%r13, %rdi
	movl	$6, %esi
	call	_Z5printPfii
	leaq	.LC11(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.isra.0
	movq	%r12, %rcx
	movq	%r13, %rdi
	movl	$6, %edx
	movl	$6, %esi
	call	_Z3invPfiiS_
	movl	$6, %edx
	movq	%r12, %rdi
	movl	$6, %esi
	call	_Z5printPfii
	popq	%rdx
	.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
.LFE3892:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z13RowOperation2PfPiS_S0_"
.LC13:
	.string	"_Z13RowOperation1PfPiS_S0_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3922:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z13RowOperation2PfPiS_S0_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC13(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z13RowOperation1PfPiS_S0_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3922:
	.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.cst4,"aM",@progbits,4
	.align 4
.LC10:
	.long	1065353216
	.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 <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
__global__ void RowOperation1(float* matrix_cu,int* rank_cu,float* inverse_cu, int* dim)
{
	int i = threadIdx.y + blockDim.y * blockIdx.y;
	int j = threadIdx.x + blockDim.x * blockIdx.x;
	float pivot_cu = matrix_cu[i + dim[0] * rank_cu[0]];
	__syncthreads();
	if(i != rank_cu[0])
	{
		inverse_cu[i + dim[0] * j] -= pivot_cu * inverse_cu[rank_cu[0] + dim[0] * j];
		matrix_cu[i + dim[0] * j] -= pivot_cu * matrix_cu[rank_cu[0] + dim[0] * j];
	}
}
__global__ void RowOperation2(float* matrix_cu,int* rank_cu,float* inverse_cu, int* dim)
{
	int i = threadIdx.x;
	float pivot = matrix_cu[(dim[0]+1) * (rank_cu[0])];
	__syncthreads();
	matrix_cu[rank_cu[0] + dim[0] * i] /= pivot;
	inverse_cu[rank_cu[0] + dim[0] * i] /= pivot;
}


/** matrix inverse */
void inv(float* matrix, int row_dim, int col_dim,float* inverse)
{
	// check square matrix
	if(col_dim == row_dim)
	{
		int * dime = new int [1];
		int * rank =new int [1];
		dime[0]=col_dim;
		float * matrix_cu;
                float * inverse_cu;
                int * dim;
                int * rank_cu;
                int matrix_size = sizeof(float) * row_dim * col_dim;
		int int_size = sizeof(int);
		hipError_t err;
                hipMalloc(&matrix_cu,matrix_size);
                hipMalloc(&inverse_cu,matrix_size);
		hipMalloc(&rank_cu,int_size);
		err = hipGetLastError();
		if (err != hipSuccess) {cout<< "rank_malloc wrong";return;}
                for(int j = 0;j < col_dim; j++)
		hipMalloc(&dim,int_size);
		hipMemcpy(dim,dime,int_size,hipMemcpyHostToDevice);
		err = hipGetLastError();
                if (err != hipSuccess) {cout<< "dim_copy wrong";return;}
		for(int j = 0;j < col_dim; j++)
		{
			rank[0]=j;
			//find max magnitude
			float tmp = 0;
			int p = -1;
			for(int i = j; i < row_dim; i++)
			{
				if(abs(matrix[i + row_dim * j]) != 0) 
				{
					tmp = abs(matrix[i + row_dim * j]);
					p = i;
					if(j != p)
					{
						for(int k=0;k < col_dim; k++)
						{
						swap(matrix[j + row_dim * k],matrix[p + row_dim * k]);
                                		swap(inverse[j + row_dim * k],inverse[p + row_dim * k]);
						}
					}
					break;
				}
			}
			
			// have zero row
			if(p == -1)
			{
				cout << "it's singular";
				return;
			}
			hipMemcpy(rank_cu,rank,int_size,hipMemcpyHostToDevice);
			err = hipGetLastError();
                        if (err != hipSuccess) {cout<< "rank_copy wrong";return;}
			hipMemcpy(matrix_cu,matrix,matrix_size,hipMemcpyHostToDevice);
			hipMemcpy(inverse_cu,inverse,matrix_size,hipMemcpyHostToDevice);
			err = hipGetLastError();
                        if (err != hipSuccess) {cout<< "inverse_copy wrong";return;}
			//row operation
			RowOperation2<<<1,col_dim>>>(matrix, rank_cu, inverse, dim);
			err = hipGetLastError();
			if (err != hipSuccess) {cout<< "2 wrong";return;}
			RowOperation1<<<row_dim,col_dim>>>(matrix, rank_cu, inverse, dim);
			err = hipGetLastError();
                        if (err != hipSuccess) {cout<< "1 wrong";return;}
			hipMemcpy(matrix,matrix_cu,matrix_size,hipMemcpyDeviceToHost);
			hipMemcpy(inverse,inverse_cu,matrix_size,hipMemcpyDeviceToHost);
			
		}
	}
	else
	{
		cout << "it isn't sqare matrix";
		return;
	}
}

/** matrix print */
void print(float* matrix, int row_dim, int col_dim)
{
	for(int i=0; i < row_dim; i++)
	{
		for(int j=0; j < col_dim; j++)
		{
			cout << matrix[i+ col_dim * j]<<" ";
		}
		cout<<endl;
	}
}

int main ()
{
	//random seed
	srand(0);
	
	//set dimention
	int row_dim = 6;
	int col_dim = 6;
	
	//initial array
	float* inverse = new float [row_dim * col_dim];
	float* result = new float [row_dim * col_dim];
    for(int i = 0; i < row_dim * col_dim; i++)
    {
        inverse[i] = rand()%9;
        result[i] = (i / col_dim == i % row_dim)?1.0f:0.0f;
        /*for(int j = 0;j < col_dim; j++)
        {
            inverse[i][j] = float(rand()%9);
            result[i][j] = (i == j)?1.0f:0.0f;
        }*/
    }
    
    //check input
    print(inverse, row_dim, col_dim);
    
    cout << "----------------------\n";
    
    //test inverse
    inv(inverse, row_dim, col_dim, result);
    
    //check result
    print(result, row_dim, col_dim);
    
    
	return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z28__device_stub__RowOperation1PfPiS_S0_ # -- Begin function _Z28__device_stub__RowOperation1PfPiS_S0_
	.type	_Z28__device_stub__RowOperation1PfPiS_S0_,@function
_Z28__device_stub__RowOperation1PfPiS_S0_: # @_Z28__device_stub__RowOperation1PfPiS_S0_
	.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	16(%rsp), %rdx
	movq	%rcx, (%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	8(%rsp), %r12
	movq	%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	$_Z13RowOperation1PfPiS_S0_, %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	_Z28__device_stub__RowOperation1PfPiS_S0_, .Lfunc_end0-_Z28__device_stub__RowOperation1PfPiS_S0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z28__device_stub__RowOperation2PfPiS_S0_ # -- Begin function _Z28__device_stub__RowOperation2PfPiS_S0_
	.type	_Z28__device_stub__RowOperation2PfPiS_S0_,@function
_Z28__device_stub__RowOperation2PfPiS_S0_: # @_Z28__device_stub__RowOperation2PfPiS_S0_
	.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	16(%rsp), %rdx
	movq	%rcx, (%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	8(%rsp), %r12
	movq	%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	$_Z13RowOperation2PfPiS_S0_, %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_end1:
	.size	_Z28__device_stub__RowOperation2PfPiS_S0_, .Lfunc_end1-_Z28__device_stub__RowOperation2PfPiS_S0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z3invPfiiS_                    # -- Begin function _Z3invPfiiS_
	.type	_Z3invPfiiS_,@function
_Z3invPfiiS_:                           # @_Z3invPfiiS_
	.cfi_startproc
# %bb.0:
	cmpl	%esi, %edx
	jne	.LBB2_3
# %bb.1:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rcx, %r14
	movl	%edx, %ebp
	movq	%rdi, %rbx
	movl	$4, %edi
	callq	_Znam
	movq	%rax, %r13
	movl	$4, %edi
	callq	_Znam
	movq	%rax, %r15
	movl	%ebp, (%r13)
	movl	%ebp, %eax
	imull	%ebp, %eax
	shll	$2, %eax
	movslq	%eax, %r12
	leaq	64(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	56(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB2_4
# %bb.2:
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$17, %edx
	jmp	.LBB2_28
.LBB2_3:
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %rbp
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$21, %edx
	jmp	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l # TAILCALL
.LBB2_4:                                # %.preheader114
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -56
	.cfi_offset %rbp, -16
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%r15, 48(%rsp)                  # 8-byte Spill
	movq	%rbx, 16(%rsp)                  # 8-byte Spill
	testl	%ebp, %ebp
	jle	.LBB2_7
# %bb.5:
	leaq	32(%rsp), %r15
	movl	%ebp, %ebx
.LBB2_6:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$4, %esi
	movq	%r15, %rdi
	callq	hipMalloc
	decl	%ebx
	jne	.LBB2_6
.LBB2_7:                                # %._crit_edge
	movq	32(%rsp), %rdi
	movl	$4, %edx
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB2_9
# %bb.8:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$14, %edx
	jmp	.LBB2_28
.LBB2_9:                                # %.preheader113
	movq	%r14, 8(%rsp)                   # 8-byte Spill
	testl	%ebp, %ebp
	jle	.LBB2_29
# %bb.10:                               # %.lr.ph126
	movabsq	$4294967296, %rax               # imm = 0x100000000
	movl	%ebp, %edi
	movq	%rdi, %rcx
	btsq	$32, %rcx
	movq	%rcx, 40(%rsp)                  # 8-byte Spill
	leaq	(,%rdi,4), %rbp
	leaq	4(,%rdi,4), %rsi
	xorl	%r8d, %r8d
	xorps	%xmm1, %xmm1
	incq	%rax
	movq	%rax, 112(%rsp)                 # 8-byte Spill
	movq	8(%rsp), %rbx                   # 8-byte Reload
	movq	16(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %r14
	xorl	%r13d, %r13d
	xorl	%r10d, %r10d
.LBB2_11:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_13 Depth 2
                                        #     Child Loop BB2_17 Depth 2
	movq	48(%rsp), %rax                  # 8-byte Reload
	movl	%r10d, (%rax)
	cmpq	%rdi, %r10
	je	.LBB2_27
# %bb.12:                               # %.lr.ph120
                                        #   in Loop: Header=BB2_11 Depth=1
	leaq	(%rdi,%r8), %rdx
	movl	%r10d, %eax
	xorl	%ecx, %ecx
.LBB2_13:                               #   Parent Loop BB2_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r15,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	%xmm1, %xmm0
	jne	.LBB2_15
	jp	.LBB2_15
# %bb.14:                               #   in Loop: Header=BB2_13 Depth=2
	incq	%rcx
	incl	%eax
	cmpq	%rcx, %rdx
	jne	.LBB2_13
	jmp	.LBB2_27
.LBB2_15:                               #   in Loop: Header=BB2_11 Depth=1
	movq	%r13, 104(%rsp)                 # 8-byte Spill
	movq	%rsi, 88(%rsp)                  # 8-byte Spill
	movq	%r8, 80(%rsp)                   # 8-byte Spill
	subl	%r8d, %ecx
	movq	%r10, 72(%rsp)                  # 8-byte Spill
	cmpq	%rcx, %r10
	je	.LBB2_18
# %bb.16:                               # %.lr.ph123.preheader
                                        #   in Loop: Header=BB2_11 Depth=1
	movslq	%eax, %rcx
	movq	16(%rsp), %rax                  # 8-byte Reload
	leaq	(%rax,%rcx,4), %rax
	movq	8(%rsp), %rdx                   # 8-byte Reload
	leaq	(%rdx,%rcx,4), %rcx
	movq	%rdi, %rdx
	xorl	%esi, %esi
.LBB2_17:                               # %.lr.ph123
                                        #   Parent Loop BB2_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r14,%rsi), %xmm0              # xmm0 = mem[0],zero,zero,zero
	movss	(%rax,%rsi), %xmm1              # xmm1 = mem[0],zero,zero,zero
	movss	%xmm1, (%r14,%rsi)
	movss	%xmm0, (%rax,%rsi)
	movss	(%rbx,%rsi), %xmm0              # xmm0 = mem[0],zero,zero,zero
	movss	(%rcx,%rsi), %xmm1              # xmm1 = mem[0],zero,zero,zero
	movss	%xmm1, (%rbx,%rsi)
	movss	%xmm0, (%rcx,%rsi)
	addq	%rbp, %rsi
	decq	%rdx
	jne	.LBB2_17
.LBB2_18:                               # %.loopexit
                                        #   in Loop: Header=BB2_11 Depth=1
	movq	%rdi, 96(%rsp)                  # 8-byte Spill
	movq	24(%rsp), %rdi
	movl	$4, %edx
	movq	48(%rsp), %rsi                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_30
# %bb.19:                               #   in Loop: Header=BB2_11 Depth=1
	movq	64(%rsp), %rdi
	movq	16(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	56(%rsp), %rdi
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_31
# %bb.20:                               #   in Loop: Header=BB2_11 Depth=1
	movq	112(%rsp), %rdi                 # 8-byte Reload
	movl	$1, %esi
	movq	40(%rsp), %rdx                  # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_22
# %bb.21:                               #   in Loop: Header=BB2_11 Depth=1
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rcx
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	8(%rsp), %rdx                   # 8-byte Reload
	callq	_Z28__device_stub__RowOperation2PfPiS_S0_
.LBB2_22:                               #   in Loop: Header=BB2_11 Depth=1
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_32
# %bb.23:                               #   in Loop: Header=BB2_11 Depth=1
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_25
# %bb.24:                               #   in Loop: Header=BB2_11 Depth=1
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rcx
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	8(%rsp), %rdx                   # 8-byte Reload
	callq	_Z28__device_stub__RowOperation1PfPiS_S0_
.LBB2_25:                               #   in Loop: Header=BB2_11 Depth=1
	callq	hipGetLastError
	testl	%eax, %eax
	movq	104(%rsp), %r13                 # 8-byte Reload
	jne	.LBB2_33
# %bb.26:                               #   in Loop: Header=BB2_11 Depth=1
	movq	64(%rsp), %rsi
	movq	16(%rsp), %rdi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	56(%rsp), %rsi
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	72(%rsp), %r10                  # 8-byte Reload
	incq	%r10
	movabsq	$4294967296, %rax               # imm = 0x100000000
	addq	%rax, %r13
	movq	80(%rsp), %r8                   # 8-byte Reload
	decq	%r8
	movq	88(%rsp), %rsi                  # 8-byte Reload
	addq	%rsi, %r15
	addq	$4, %r14
	addq	$4, %rbx
	movq	96(%rsp), %rdi                  # 8-byte Reload
	cmpq	%rdi, %r10
	xorps	%xmm1, %xmm1
	jne	.LBB2_11
	jmp	.LBB2_29
.LBB2_27:                               # %.critedge
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$13, %edx
.LBB2_28:                               # %.critedge103
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.LBB2_29:                               # %.critedge103
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB2_30:
	.cfi_def_cfa_offset 176
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$15, %edx
	jmp	.LBB2_28
.LBB2_31:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$18, %edx
	jmp	.LBB2_28
.LBB2_32:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	jmp	.LBB2_34
.LBB2_33:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
.LBB2_34:                               # %.critedge103
	movl	$7, %edx
	jmp	.LBB2_28
.Lfunc_end2:
	.size	_Z3invPfiiS_, .Lfunc_end2-_Z3invPfiiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z5printPfii                    # -- Begin function _Z5printPfii
	.type	_Z5printPfii,@function
_Z5printPfii:                           # @_Z5printPfii
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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, 12(%rsp)                  # 4-byte Spill
	testl	%esi, %esi
	jle	.LBB3_4
# %bb.1:                                # %.preheader.lr.ph
	movq	%rdi, %r12
	movslq	12(%rsp), %r15                  # 4-byte Folded Reload
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%r15d, %ebx
	shlq	$2, %r15
	xorl	%ebp, %ebp
.LBB3_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_5 Depth 2
	movq	%rbx, %r13
	movq	%r12, %r14
	cmpl	$0, 12(%rsp)                    # 4-byte Folded Reload
	jle	.LBB3_3
.LBB3_5:                                # %.lr.ph
                                        #   Parent Loop BB3_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.8, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	addq	%r15, %r14
	decq	%r13
	jne	.LBB3_5
.LBB3_3:                                # %._crit_edge
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	movl	$_ZSt4cout, %eax
	addq	%rax, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	incq	%rbp
	addq	$4, %r12
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB3_2
.LBB3_4:                                # %._crit_edge13
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z5printPfii, .Lfunc_end3-_Z5printPfii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x3f800000                      # float 1
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%r15d, %r15d
	xorl	%edi, %edi
	callq	srand
	movl	$144, %edi
	callq	_Znam
	movq	%rax, %r14
	movl	$144, %edi
	callq	_Znam
	movq	%rax, %rbx
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	movzbl	%r15b, %eax
	imull	$171, %eax, %ebp
	shrl	$10, %ebp
	movl	%ebp, %eax
	addl	%eax, %eax
	leal	(%rax,%rax,2), %r12d
	callq	rand
	cltq
	imulq	$954437177, %rax, %rcx          # imm = 0x38E38E39
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$33, %rcx
	addl	%edx, %ecx
	leal	(%rcx,%rcx,8), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	movl	%r15d, %eax
	subl	%r12d, %eax
	movss	.LCPI4_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	cmpb	%bpl, %al
	je	.LBB4_3
# %bb.2:                                #   in Loop: Header=BB4_1 Depth=1
	xorps	%xmm0, %xmm0
.LBB4_3:                                #   in Loop: Header=BB4_1 Depth=1
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	$36, %r15
	jne	.LBB4_1
# %bb.4:
	movq	%r14, %rdi
	movl	$6, %esi
	movl	$6, %edx
	callq	_Z5printPfii
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$23, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r14, %rdi
	movl	$6, %esi
	movl	$6, %edx
	movq	%rbx, %rcx
	callq	_Z3invPfiiS_
	movq	%rbx, %rdi
	movl	$6, %esi
	movl	$6, %edx
	callq	_Z5printPfii
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	main, .Lfunc_end4-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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13RowOperation1PfPiS_S0_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13RowOperation2PfPiS_S0_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z13RowOperation1PfPiS_S0_,@object # @_Z13RowOperation1PfPiS_S0_
	.section	.rodata,"a",@progbits
	.globl	_Z13RowOperation1PfPiS_S0_
	.p2align	3, 0x0
_Z13RowOperation1PfPiS_S0_:
	.quad	_Z28__device_stub__RowOperation1PfPiS_S0_
	.size	_Z13RowOperation1PfPiS_S0_, 8

	.type	_Z13RowOperation2PfPiS_S0_,@object # @_Z13RowOperation2PfPiS_S0_
	.globl	_Z13RowOperation2PfPiS_S0_
	.p2align	3, 0x0
_Z13RowOperation2PfPiS_S0_:
	.quad	_Z28__device_stub__RowOperation2PfPiS_S0_
	.size	_Z13RowOperation2PfPiS_S0_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"rank_malloc wrong"
	.size	.L.str, 18

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"dim_copy wrong"
	.size	.L.str.1, 15

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"it's singular"
	.size	.L.str.2, 14

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"rank_copy wrong"
	.size	.L.str.3, 16

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"inverse_copy wrong"
	.size	.L.str.4, 19

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"2 wrong"
	.size	.L.str.5, 8

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"1 wrong"
	.size	.L.str.6, 8

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"it isn't sqare matrix"
	.size	.L.str.7, 22

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"----------------------\n"
	.size	.L.str.9, 24

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z13RowOperation1PfPiS_S0_"
	.size	.L__unnamed_1, 27

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z13RowOperation2PfPiS_S0_"
	.size	.L__unnamed_2, 27

	.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 _Z28__device_stub__RowOperation1PfPiS_S0_
	.addrsig_sym _Z28__device_stub__RowOperation2PfPiS_S0_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z13RowOperation1PfPiS_S0_
	.addrsig_sym _Z13RowOperation2PfPiS_S0_
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z13RowOperation1PfPiS_S0_ ; -- Begin function _Z13RowOperation1PfPiS_S0_
	.globl	_Z13RowOperation1PfPiS_S0_
	.p2align	8
	.type	_Z13RowOperation1PfPiS_S0_,@function
_Z13RowOperation1PfPiS_S0_:             ; @_Z13RowOperation1PfPiS_S0_
; %bb.0:
	s_clause 0x1
	s_load_b256 s[4:11], s[0:1], 0x0
	s_load_b32 s0, s[0:1], 0x2c
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_load_b32 s1, s[10:11], 0x0
	s_load_b32 s2, s[6:7], 0x0
	s_lshr_b32 s3, s0, 16
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s3, v[3:4]
	s_waitcnt lgkmcnt(0)
	v_mad_u64_u32 v[2:3], null, s2, s1, v[1:2]
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_load_b32 s1, s[6:7], 0x0
	s_waitcnt lgkmcnt(0)
	v_cmpx_ne_u32_e64 s1, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b32 s2, s[10:11], 0x0
	v_and_b32_e32 v0, 0x3ff, v0
	s_and_b32 s0, s0, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[3:4], null, s14, s0, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, s2, v3
	v_add_nc_u32_e32 v0, s1, v3
	v_add_nc_u32_e32 v3, v3, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v1, 31, v0
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v5, vcc_lo, s8, v0
	v_add_co_ci_u32_e32 v6, vcc_lo, s9, v1, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v7, vcc_lo, s8, v3
	v_add_co_ci_u32_e32 v8, vcc_lo, s9, v4, vcc_lo
	v_add_co_u32 v0, vcc_lo, s4, v0
	s_clause 0x1
	global_load_b32 v5, v[5:6], off
	global_load_b32 v6, v[7:8], off
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	v_add_co_u32 v3, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	s_waitcnt vmcnt(0)
	v_fma_f32 v5, -v2, v5, v6
	global_store_b32 v[7:8], v5, off
	s_clause 0x1
	global_load_b32 v0, v[0:1], off
	global_load_b32 v1, v[3:4], off
	s_waitcnt vmcnt(0)
	v_fma_f32 v0, -v2, v0, v1
	global_store_b32 v[3:4], v0, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13RowOperation1PfPiS_S0_
		.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 9
		.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	_Z13RowOperation1PfPiS_S0_, .Lfunc_end0-_Z13RowOperation1PfPiS_S0_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 400
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 1
; 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
	.protected	_Z13RowOperation2PfPiS_S0_ ; -- Begin function _Z13RowOperation2PfPiS_S0_
	.globl	_Z13RowOperation2PfPiS_S0_
	.p2align	8
	.type	_Z13RowOperation2PfPiS_S0_,@function
_Z13RowOperation2PfPiS_S0_:             ; @_Z13RowOperation2PfPiS_S0_
; %bb.0:
	s_load_b256 s[0:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_load_b32 s8, s[6:7], 0x0
	s_load_b32 s9, s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	s_add_i32 s8, s8, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s8, s8, s9
	s_ashr_i32 s9, s8, 31
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[8:9], s[8:9], 2
	s_add_u32 s8, s0, s8
	s_addc_u32 s9, s1, s9
	s_load_b32 s8, s[8:9], 0x0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_load_b32 s2, s[2:3], 0x0
	s_load_b32 s3, s[6:7], 0x0
	s_waitcnt lgkmcnt(0)
	v_mad_u64_u32 v[1:2], null, s3, v0, s[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v1, vcc_lo
	global_load_b32 v4, v[2:3], off
	s_waitcnt vmcnt(0)
	v_div_scale_f32 v5, null, s8, s8, v4
	v_div_scale_f32 v8, vcc_lo, v4, s8, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v6, v5
	s_waitcnt_depctr 0xfff
	v_fma_f32 v7, -v5, v6, 1.0
	v_fmac_f32_e32 v6, v7, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v7, v8, v6
	v_fma_f32 v9, -v5, v7, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v7, v9, v6
	v_fma_f32 v5, -v5, v7, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v5, v5, v6, v7
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	v_div_fixup_f32 v4, v5, s8, v4
	global_store_b32 v[2:3], v4, off
	global_load_b32 v2, v[0:1], off
	s_waitcnt vmcnt(0)
	v_div_scale_f32 v3, null, s8, s8, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v4, v3
	s_waitcnt_depctr 0xfff
	v_fma_f32 v5, -v3, v4, 1.0
	v_fmac_f32_e32 v4, v5, v4
	v_div_scale_f32 v5, vcc_lo, v2, s8, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v6, v5, v4
	v_fma_f32 v7, -v3, v6, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v6, v7, v4
	v_fma_f32 v3, -v3, v6, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f32 v3, v3, v4, v6
	v_div_fixup_f32 v2, v3, s8, v2
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13RowOperation2PfPiS_S0_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.amdhsa_user_sgpr_count 15
		.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 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 10
		.amdhsa_next_free_sgpr 10
		.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_end1:
	.size	_Z13RowOperation2PfPiS_S0_, .Lfunc_end1-_Z13RowOperation2PfPiS_S0_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 396
; NumSgprs: 12
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 12
; NumVGPRsForWavesPerEU: 10
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.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
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .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:           _Z13RowOperation1PfPiS_S0_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z13RowOperation1PfPiS_S0_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .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
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13RowOperation2PfPiS_S0_
    .private_segment_fixed_size: 0
    .sgpr_count:     12
    .sgpr_spill_count: 0
    .symbol:         _Z13RowOperation2PfPiS_S0_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
