// File: 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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movq %rdx, 0x40(%rsp)
movl $0x1, 0x28(%rsp)
movsd 0x14376(%rip), %xmm0    # 0x3f148
movsd %xmm0, 0x10(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, 0x8(%rsp)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
movl 0x4c(%rsp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jg 0x2b14a
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x34(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movl 0x4c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x2aec6
movsd 0x18(%rsp), %xmm1
movq 0x50(%rsp), %rax
movl 0x2c(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x34(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movaps 0x1438e(%rip), %xmm2    # 0x3f200
pand %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2aeb4
movq 0x50(%rsp), %rax
movl 0x2c(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x34(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movaps 0x1435e(%rip), %xmm1    # 0x3f200
pand %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x30(%rsp)
jmp 0x2aeb6
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x2ae33
movsd 0x1427a(%rip), %xmm0    # 0x3f148
ucomisd 0x18(%rsp), %xmm0
jbe 0x2aef6
movq 0x200f3(%rip), %rdi     # 0x4afd0
leaq 0x14992(%rip), %rsi     # 0x3f876
callq 0x3240
movl $0x0, 0x28(%rsp)
jmp 0x2b14a
movl 0x30(%rsp), %eax
cmpl 0x34(%rsp), %eax
je 0x2afb4
movl 0x34(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jg 0x2afb2
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x38(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x50(%rsp), %rax
movl 0x30(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x38(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x38(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x18(%rsp), %xmm0
movq 0x50(%rsp), %rax
movl 0x30(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x38(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x2af0c
jmp 0x2afb4
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jg 0x2b004
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x38(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x8(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x2afbf
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movl 0x4c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x2b138
movq 0x50(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x34(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x50(%rsp), %rax
movl 0x34(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x34(%rsp), %ecx
movslq %ecx, %rcx
divsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
movq 0x50(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x34(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jg 0x2b126
movq 0x50(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x38(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x20(%rsp), %xmm0
movq 0x8(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x50(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x38(%rsp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x2b096
jmp 0x2b128
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x2b00f
jmp 0x2b13a
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x2ae0f
cmpl $0x0, 0x28(%rsp)
je 0x2b27d
movl 0x4c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jl 0x2b27b
movq 0x50(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x4c(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x40(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
movl 0x4c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x2b22e
movq 0x40(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq 0x50(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x38(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x40(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq 0x40(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x2b1a4
movq 0x40(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x50(%rsp), %rax
movl 0x3c(%rsp), %ecx
movl 0x4c(%rsp), %edx
addl $0x1, %edx
imull %edx, %ecx
addl 0x3c(%rsp), %ecx
movslq %ecx, %rcx
divsd (%rax,%rcx,8), %xmm0
movq 0x40(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x3c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x2b160
jmp 0x2b27d
movq 0x8(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x2b295
movq (%rsp), %rdi
callq 0x3340
addq $0x58, %rsp
retq
nopw (%rax,%rax)