// File: /workspace/github_cpp_makefile_star2_O1/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)
movq %rdi, %rbx
testl %esi, %esi
js 0xdd95
leal 0x1(%rsi), %eax
xorl %ecx, %ecx
movl %ecx, (%rdx,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0xdd8a
movl $0x1, %eax
testl %esi, %esi
jle 0xdf35
movq %rdx, -0x68(%rbp)
movl %esi, %r13d
movl $0x1, %eax
movl $0x10, %ecx
movq %rcx, -0x48(%rbp)
xorl %r14d, %r14d
movq %r13, -0x78(%rbp)
movq %rax, -0x38(%rbp)
xorpd %xmm0, %xmm0
movq %r14, %rdi
shlq $0x4, %rdi
movq %r14, %r12
movl %r14d, %r15d
movq %rdi, -0x40(%rbp)
movsd %xmm0, -0x30(%rbp)
movq (%rbx,%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, %r15d
maxsd %xmm1, %xmm0
incq %r12
cmpq %r12, %r13
jne 0xddd7
movsd -0x70(%rbp), %xmm1
ucomisd %xmm0, %xmm1
ja 0xdf33
movl %r15d, %eax
cmpq %rax, %r14
je 0xde4d
movq -0x68(%rbp), %rsi
movl (%rsi,%r14,4), %eax
movslq %r15d, %rcx
movl (%rsi,%rcx,4), %edx
movl %edx, (%rsi,%r14,4)
movl %eax, (%rsi,%rcx,4)
movq (%rbx,%r14,8), %rax
movq (%rbx,%rcx,8), %rdx
movq %rdx, (%rbx,%r14,8)
movq %rax, (%rbx,%rcx,8)
incl (%rsi,%r13,4)
leaq 0x1(%r14), %rax
movq %rax, -0x30(%rbp)
cmpq %r13, %rax
jae 0xdf13
movq -0x38(%rbp), %r15
movq %r14, -0x50(%rbp)
movq (%rbx,%r14,8), %rax
movq (%rbx,%r15,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), %r14
movq (%rbx,%r15,8), %rax
movq -0x50(%rbp), %rcx
movq (%rbx,%rcx,8), %rsi
addq %r13, %rsi
movups (%rax,%rdi), %xmm0
movaps %xmm0, -0x60(%rbp)
movq %r14, %rdi
callq 0x10788
movq -0x40(%rbp), %rdi
movq (%rbx,%r15,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 0xdea7
incq %r15
movq -0x78(%rbp), %r13
cmpq %r13, %r15
movq -0x50(%rbp), %r14
jne 0xde66
movq -0x38(%rbp), %rax
incq %rax
addq $0x10, -0x48(%rbp)
movq -0x30(%rbp), %r14
cmpq %r13, %r14
jne 0xddbe
movl $0x1, %eax
jmp 0xdf35
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq