// File: /workspace/github_cpp_makefile_star2_O3/jamesliu516[P]amrdg2d/wall4amrdg2013.cpp
// Function: gem(double*, int, double*)
void gem(double *a, int M, double *u)
{	
    int i,j,k1,p,mm,flag=1;
    double eita,ui3;

    const double nrrs=1e-8;
    //double *r=(double *)malloc((M+1)*sizeof(double));
    double *r=new double[M+1];

    //-----M*(M+1)������������ԪGauss��ȥ--------/
    for(k1=0;k1<=M-2;k1++)            
    {
        ui3=0.0;

        for(mm=k1;mm<=M-1;mm++)
        {
            if(ui3<fabs(a[mm*(M+1)+k1]))
            {
                ui3=fabs(a[mm*(M+1)+k1]);
                p=mm;
            }
        }

        if(ui3 < nrrs) 
        {
            // printf("matrix singularity.\n");
            cout<<"matrix singularity.\n";
            flag=0;
            break;
        }
        if(p!=k1)
        {
            for(j=k1;j<=M;j++) 
            {
                ui3=a[k1*(M+1)+j];
                a[k1*(M+1)+j]=a[p*(M+1)+j];
                a[p*(M+1)+j]=ui3;
            }  
        }
        for(j=k1+1;j<=M;j++)
            r[j]=a[k1*(M+1)+j];
        for(i=k1+1;i<=M-1;i++)
        {
            eita=a[i*(M+1)+k1]/a[k1*(M+1)+k1];
            a[i*(M+1)+k1]=eita;
            for(j=k1+1;j<=M;j++)
                a[i*(M+1)+j]=a[i*(M+1)+j]-eita*r[j];
        }
    }
    //-----�ش��õ�������-------
    if(flag)
    {
        for(i=M-1;i>=0;i--)
        {	
            u[i]=a[i*(M+1)+M];
            for(j=i+1;j<=M-1;j++)
                u[i]=u[i]-a[i*(M+1)+j]*u[j];
            u[i]=u[i]/a[i*(M+1)+i];
        }
    }
    //free(r);
    delete [] r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r15
movl %esi, %ebx
movq %rdi, %r13
leal 0x1(%rbx), %r12d
leaq (,%r12,8), %r14
cmpl $-0x1, %esi
movq $-0x1, %rdi
cmovgeq %r14, %rdi
callq 0x3030
movl %ebx, %ebp
cmpl $0x1, %ebx
movq %r13, 0x10(%rsp)
movq %r12, 0x8(%rsp)
jg 0x12fe3
leal -0x1(%rbx), %r8d
jmp 0x13209
movq %r15, 0x50(%rsp)
leal 0x2(%rbx), %ecx
movl %ecx, 0x4(%rsp)
movq %rbx, 0x48(%rsp)
leal -0x1(%rbx), %r8d
movslq %r12d, %rcx
movq %rax, 0x18(%rsp)
movq %r12, %r11
movq %rax, %r12
addq $0x8, %r12
leaq 0x8(,%r11,8), %rax
movq %rax, 0x60(%rsp)
leaq 0x8(,%rcx,8), %rax
movq %rax, 0x58(%rsp)
leaq 0x8(,%r11,8), %r9
addq %r13, %r9
movl $0x1, %eax
movq %rax, 0x30(%rsp)
xorl %ebx, %ebx
movapd 0xa17d(%rip), %xmm2     # 0x1d1c0
movsd 0xa105(%rip), %xmm3     # 0x1d150
movapd 0xa04d(%rip), %xmm4     # 0x1d0a0
movq %r12, 0x70(%rsp)
movq %r11, 0x28(%rsp)
movq %r13, %r15
movq %r13, 0x20(%rsp)
movq %r13, 0x38(%rsp)
movq %r13, %r10
movq %r8, 0x68(%rsp)
cmpq %rbp, %rbx
jae 0x132b5
movq 0x70(%rsp), %rax
leaq (%rax,%rbx,8), %rdi
movl 0x4(%rsp), %eax
imull %ebx, %eax
incl %eax
leaq (%r10,%rax,8), %rsi
movl %r8d, %eax
subl %ebx, %eax
leaq 0x8(,%rax,8), %rdx
xorpd %xmm0, %xmm0
movq 0x38(%rsp), %rax
movq %rbx, %rcx
movapd %xmm0, %xmm1
movsd (%rax), %xmm0
andpd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
cmoval %ecx, %r13d
maxsd %xmm1, %xmm0
incq %rcx
addq %r14, %rax
cmpq %rcx, %rbp
jne 0x130aa
ucomisd %xmm0, %xmm3
ja 0x132b5
movl %r13d, %eax
cmpq %rax, %rbx
sete %al
cmpq %rbp, %rbx
seta %cl
orb %al, %cl
movq 0x28(%rsp), %r8
jne 0x13121
movl %r13d, %eax
imull %r11d, %eax
cltq
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
xorl %ecx, %ecx
movsd (%r15,%rcx,8), %xmm0
movsd (%rax,%rcx,8), %xmm1
movsd %xmm1, (%r15,%rcx,8)
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r8
jne 0x13103
cmpq %rbp, %rbx
movq %r9, 0x40(%rsp)
jae 0x13157
callq 0x31c0
movapd 0x9f68(%rip), %xmm4     # 0x1d0a0
movsd 0xa010(%rip), %xmm3     # 0x1d150
movapd 0xa078(%rip), %xmm2     # 0x1d1c0
movq 0x40(%rsp), %r9
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r10
leaq 0x1(%rbx), %rax
movl 0x4(%rsp), %ecx
imull %ebx, %ecx
movslq %ecx, %rcx
leaq (%r10,%rbx,8), %rdx
movq %r9, %rsi
movq 0x30(%rsp), %rdi
movq %rdi, %r8
imulq %r11, %r8
movsd (%rdx,%r8,8), %xmm0
divsd (%r10,%rcx,8), %xmm0
movsd %xmm0, (%rdx,%r8,8)
xorpd %xmm4, %xmm0
xorl %r8d, %r8d
movsd (%r12,%r8,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%rsi,%r8,8), %xmm1
movsd %xmm1, (%rsi,%r8,8)
incq %r8
leal (%r8,%rbx), %r9d
cmpl %ebp, %r9d
jl 0x13191
incq %rdi
addq %r14, %rsi
cmpq %rbp, %rdi
jne 0x13171
incq 0x30(%rsp)
movq 0x60(%rsp), %rcx
addq %rcx, 0x38(%rsp)
addq $0x8, 0x20(%rsp)
addq 0x58(%rsp), %r15
decq 0x28(%rsp)
movq 0x40(%rsp), %r9
addq %rcx, %r9
addq $0x8, %r12
movq %rax, %rbx
movq 0x68(%rsp), %r8
cmpq %r8, %rax
jne 0x13072
movq 0x50(%rsp), %r15
movq 0x18(%rsp), %rax
movq 0x48(%rsp), %rbx
testl %ebx, %ebx
jle 0x132d2
movslq %r8d, %r12
movslq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rdi
leaq (%rdi,%rbp,8), %rdx
leaq -0x1(%rbp), %rsi
imulq %rcx, %rsi
leaq (%rdi,%rsi,8), %rsi
movq %rcx, %rdi
notq %rdi
shlq $0x3, %rdi
leaq 0x1(%r12), %r8
movq %r15, %r9
movq %rbp, %r10
leaq -0x1(%r10), %r11
movq %r11, %rbx
imulq %rcx, %rbx
movsd (%rdx,%rbx,8), %xmm0
movsd %xmm0, -0x8(%r15,%r10,8)
cmpq %r12, %r10
jg 0x1327f
movq %rbp, %rbx
movsd (%rsi,%rbx,8), %xmm1
mulsd (%r9,%rbx,8), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, (%r15,%r11,8)
incq %rbx
cmpq %rbx, %r8
jne 0x13262
movq 0x8(%rsp), %rbx
imull %r11d, %ebx
movslq %ebx, %rbx
movq 0x10(%rsp), %r14
leaq (%r14,%r11,8), %r14
divsd (%r14,%rbx,8), %xmm0
movsd %xmm0, (%r15,%r11,8)
addq %rdi, %rsi
incq %r8
addq $-0x8, %r9
cmpq $0x1, %r10
movq %r11, %r10
jg 0x13243
jmp 0x132d2
movq 0x10d0c(%rip), %rdi     # 0x23fc8
leaq 0xa623(%rip), %rsi      # 0x1d8e6
movl $0x14, %edx
callq 0x3250
movq 0x18(%rsp), %rax
movq %rax, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3280