// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %rdx, 0x38(%rsp)
movl %esi, %r12d
movq %rdi, (%rsp)
leal 0x1(%r12), %eax
movl %eax, 0xc(%rsp)
cltq
movq %rax, 0x20(%rsp)
leaq (,%rax,8), %rax
cmpl $-0x1, %esi
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x3030
movq %rax, 0x28(%rsp)
movl %r12d, %eax
movq %rax, 0x10(%rsp)
cmpl $0x2, %r12d
setl %r10b
jl 0x13872
leal -0x2(%r12), %eax
leal 0x2(%r12), %ecx
movl %ecx, 0x8(%rsp)
movq 0x20(%rsp), %rcx
movl %ecx, %edx
leal -0x1(%r12), %esi
movq %rsi, 0x30(%rsp)
cltq
movq %rax, 0x68(%rsp)
movq 0x28(%rsp), %r14
addq $0x8, %r14
leaq (,%rdx,8), %rbp
leaq 0x8(,%rdx,8), %rax
movq %rax, 0x60(%rsp)
leaq 0x8(,%rcx,8), %rax
movq %rax, 0x58(%rsp)
movq (%rsp), %rax
leaq (%rax,%rdx,8), %rsi
addq $0x8, %rsi
movl $0x1, %edi
xorl %r15d, %r15d
movapd 0xab4f(%rip), %xmm2     # 0x1e1c0
movapd 0xaa27(%rip), %xmm3     # 0x1e0a0
movq %r14, 0x50(%rsp)
movq %rdx, 0x80(%rsp)
movq %rax, %rbx
movq %rax, %r8
movq %rax, %r9
movb %r10b, 0x18(%rsp)
movb $0x1, %al
movq 0x10(%rsp), %r11
cmpq %r11, %r15
jae 0x136e2
xorpd %xmm0, %xmm0
movq %r9, %rax
movq %r15, %rcx
movq (%rsp), %r10
movapd %xmm0, %xmm1
movsd (%rax), %xmm0
andpd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
cmoval %ecx, %r13d
maxsd %xmm1, %xmm0
incq %rcx
addq %rbp, %rax
cmpq %rcx, %r11
jne 0x136ae
movsd 0xaa77(%rip), %xmm1     # 0x1e150
ucomisd %xmm0, %xmm1
seta %al
jmp 0x136e6
movq (%rsp), %r10
testb %al, %al
jne 0x1384f
movq %r9, 0x70(%rsp)
movl %r13d, %eax
cmpq %rax, %r15
sete %al
cmpq %r11, %r15
seta %cl
orb %al, %cl
jne 0x13732
movl %r13d, %eax
imull 0xc(%rsp), %eax
cltq
leaq (%r8,%rax,8), %rax
xorl %ecx, %ecx
movsd (%rbx,%rcx,8), %xmm0
movsd (%rax,%rcx,8), %xmm1
movsd %xmm1, (%rbx,%rcx,8)
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rdx
jne 0x13716
movq %r8, 0x78(%rsp)
movq %rdx, 0x18(%rsp)
cmpq %r11, %r15
movq %rsi, 0x48(%rsp)
movq %rdi, 0x40(%rsp)
jae 0x1379a
movq 0x50(%rsp), %rax
leaq (%rax,%r15,8), %rdi
movl 0x8(%rsp), %eax
imull %r15d, %eax
incl %eax
leaq (%r10,%rax,8), %rsi
movq 0x30(%rsp), %rax
subl %r15d, %eax
leaq 0x8(,%rax,8), %rdx
callq 0x31c0
movapd 0xa921(%rip), %xmm3     # 0x1e0a0
movapd 0xaa39(%rip), %xmm2     # 0x1e1c0
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x10(%rsp), %r11
movq (%rsp), %r10
leaq 0x1(%r15), %rax
movl 0x8(%rsp), %ecx
imull %r15d, %ecx
movslq %ecx, %rcx
leaq (%r10,%r15,8), %rdx
movq %rdi, %r8
imulq 0x80(%rsp), %r8
movsd (%rdx,%r8,8), %xmm0
divsd (%r10,%rcx,8), %xmm0
movsd %xmm0, (%rdx,%r8,8)
xorpd %xmm3, %xmm0
xorl %r8d, %r8d
movsd (%r14,%r8,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%rsi,%r8,8), %xmm1
movsd %xmm1, (%rsi,%r8,8)
incq %r8
leal (%r8,%r15), %r9d
cmpl %r12d, %r9d
jl 0x137d2
incq %rdi
addq %rbp, %rsi
cmpq %r11, %rdi
jne 0x137ad
cmpq 0x68(%rsp), %r15
setge %r10b
movq 0x40(%rsp), %rdi
incq %rdi
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %r9
addq %rcx, %r9
movq 0x78(%rsp), %r8
addq $0x8, %r8
addq 0x58(%rsp), %rbx
movq 0x18(%rsp), %rdx
decq %rdx
movq 0x48(%rsp), %rsi
addq %rcx, %rsi
addq $0x8, %r14
movq %rax, %r15
cmpq 0x30(%rsp), %rax
jne 0x1368f
jmp 0x13872
movq 0x11772(%rip), %rdi     # 0x24fc8
leaq 0xb0a9(%rip), %rsi      # 0x1e906
movl $0x14, %edx
callq 0x3250
testb $0x1, 0x18(%rsp)
je 0x1392c
testl %r12d, %r12d
jle 0x1392c
decl %r12d
movslq %r12d, %rax
movq (%rsp), %rsi
movq 0x10(%rsp), %r9
leaq (%rsi,%r9,8), %rcx
leaq -0x1(%r9), %rdx
movq 0x20(%rsp), %rdi
imulq %rdi, %rdx
leaq (%rsi,%rdx,8), %rdx
movq %rdi, %rsi
notq %rsi
shlq $0x3, %rsi
leaq 0x1(%rax), %rdi
movq 0x38(%rsp), %r8
movq 0x38(%rsp), %r14
leaq -0x1(%r9), %r10
movq %r10, %r11
imulq 0x20(%rsp), %r11
movsd (%rcx,%r11,8), %xmm0
movsd %xmm0, -0x8(%r14,%r9,8)
cmpq %rax, %r9
jg 0x138f9
movq 0x10(%rsp), %r11
movsd (%rdx,%r11,8), %xmm1
mulsd (%r8,%r11,8), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, (%r14,%r10,8)
incq %r11
cmpq %r11, %rdi
jne 0x138db
movl 0xc(%rsp), %r11d
imull %r10d, %r11d
movslq %r11d, %r11
movq (%rsp), %rbx
leaq (%rbx,%r10,8), %rbx
divsd (%rbx,%r11,8), %xmm0
movsd %xmm0, (%r14,%r10,8)
addq %rsi, %rdx
incq %rdi
addq $-0x8, %r8
cmpq $0x1, %r9
movq %r10, %r9
jg 0x138b7
movq 0x28(%rsp), %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3280