// File: /workspace/github_cpp_makefile_star2_O3/bothaynahazem[P]AsuMathLabG13/Matrix2017.cpp
// Function: LUPDecompose(std::complex<double>**, int, double, int*)
int LUPDecompose(complex<double> **A, int N, double Tol, int *P) {

    int i, j, k, imax;
    complex<double> *ptr;
		double maxA,absA;
    for (i = 0; i <= N; i++)
        P[i] = i; //Unit permutation matrix, P[N] initialized with N

    for (i = 0; i < N; i++) {
        maxA = 0.0;
        imax = i;

        for (k = i; k < N; k++)
            if ((absA = std::abs(A[k][i])) > maxA) {
                maxA = absA;
                imax = k;
            }

        if (maxA < Tol) return 0; //failure, matrix is degenerate

        if (imax != i) {
            //pivoting P
            j = P[i];
            P[i] = P[imax];
            P[imax] = j;

            //pivoting rows of A
            ptr = A[i];
            A[i] = A[imax];
            A[imax] = ptr;

            //counting pivots starting from N (for determinant)
            P[N]++;
        }

        for (j = i + 1; j < N; j++) {
            A[j][i] /= A[i][i];

            for (k = i + 1; k < N; k++)
                A[j][k] -= A[j][i] * A[i][k];
        }
    }

    return 1;  //decomposition done
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsd %xmm0, -0x70(%rbp)
movl $0x1, %eax
testl %esi, %esi
js 0xe052
movq %rdi, %r14
leal 0x1(%rsi), %edi
xorl %ecx, %ecx
movl %ecx, (%rdx,%rcx,4)
incq %rcx
cmpq %rcx, %rdi
jne 0xdead
testl %esi, %esi
je 0xe052
movq %rdx, -0x68(%rbp)
movl %esi, %r13d
movl $0x1, %eax
movl $0x10, %ecx
movq %rcx, -0x48(%rbp)
xorl %r15d, %r15d
movq %r13, -0x78(%rbp)
movq %rax, -0x38(%rbp)
xorpd %xmm0, %xmm0
movq %r15, %rdi
shlq $0x4, %rdi
movq %r15, %r12
movl %r15d, %ebx
movq %rdi, -0x40(%rbp)
movsd %xmm0, -0x30(%rbp)
movq (%r14,%r12,8), %rax
movsd (%rax,%rdi), %xmm0
movsd 0x8(%rax,%rdi), %xmm1
callq 0x3570
movq -0x40(%rbp), %rdi
movsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
cmoval %r12d, %ebx
maxsd %xmm1, %xmm0
incq %r12
cmpq %r12, %r13
jne 0xdef5
movsd -0x70(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0xe050
movl %ebx, %eax
cmpq %rax, %r15
je 0xdf6a
movq -0x68(%rbp), %rsi
movl (%rsi,%r15,4), %eax
movslq %ebx, %rcx
movl (%rsi,%rcx,4), %edx
movl %edx, (%rsi,%r15,4)
movl %eax, (%rsi,%rcx,4)
movq (%r14,%r15,8), %rax
movq (%r14,%rcx,8), %rdx
movq %rdx, (%r14,%r15,8)
movq %rax, (%r14,%rcx,8)
incl (%rsi,%r13,4)
leaq 0x1(%r15), %rax
movq %rax, -0x30(%rbp)
cmpq %r13, %rax
jae 0xe030
movq -0x38(%rbp), %rbx
movq %r15, -0x50(%rbp)
movq (%r14,%r15,8), %rax
movq (%r14,%rbx,8), %r12
movsd (%rax,%rdi), %xmm2
movsd 0x8(%rax,%rdi), %xmm3
movsd (%r12,%rdi), %xmm0
movsd 0x8(%r12,%rdi), %xmm1
callq 0x31f0
movq -0x40(%rbp), %rdi
movsd %xmm0, (%r12,%rdi)
movsd %xmm1, 0x8(%r12,%rdi)
movq %r13, %r12
movq -0x48(%rbp), %r13
leaq -0x60(%rbp), %r15
movq (%r14,%rbx,8), %rax
movq -0x50(%rbp), %rcx
movq (%r14,%rcx,8), %rsi
addq %r13, %rsi
movups (%rax,%rdi), %xmm0
movaps %xmm0, -0x60(%rbp)
movq %r15, %rdi
callq 0x10952
movq -0x40(%rbp), %rdi
movq (%r14,%rbx,8), %rax
movsd (%rax,%r13), %xmm0
subsd -0x60(%rbp), %xmm0
movsd 0x8(%rax,%r13), %xmm1
subsd -0x58(%rbp), %xmm1
movsd %xmm0, (%rax,%r13)
movsd %xmm1, 0x8(%rax,%r13)
addq $0x10, %r13
decq %r12
cmpq %r12, -0x38(%rbp)
jne 0xdfc4
incq %rbx
movq -0x78(%rbp), %r13
cmpq %r13, %rbx
movq -0x50(%rbp), %r15
jne 0xdf83
movq -0x38(%rbp), %rax
incq %rax
addq $0x10, -0x48(%rbp)
movq -0x30(%rbp), %r15
cmpq %r13, %r15
jne 0xdedc
movl $0x1, %eax
jmp 0xe052
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq