// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdx, %r12
movsd %xmm0, -0x68(%rbp)
movq %rdi, %r15
movl %esi, -0x2c(%rbp)
movslq %esi, %r13
movl %r13d, %eax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
cmpq %r13, %rax
jg 0xc089
movl %eax, (%r12,%rax,4)
incq %rax
jmp 0xc07b
xorl %esi, %esi
movl -0x2c(%rbp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, -0x70(%rbp)
pushq $0x1
popq %rax
movq %rax, -0x40(%rbp)
pushq $0x10
popq %rax
movq %rax, -0x48(%rbp)
movq %r12, -0x60(%rbp)
movq %r13, -0x58(%rbp)
cmpq -0x70(%rbp), %rsi
je 0xc1dc
xorpd %xmm1, %xmm1
movq %rsi, %r14
movq %rsi, -0x38(%rbp)
movl %esi, %ebx
cmpq %r14, -0x50(%rbp)
je 0xc0ff
movq -0x38(%rbp), %rdi
shlq $0x4, %rdi
addq (%r15,%r14,8), %rdi
movsd %xmm1, -0x78(%rbp)
callq 0xe565
movsd -0x78(%rbp), %xmm1
ucomisd %xmm1, %xmm0
cmoval %r14d, %ebx
maxsd %xmm1, %xmm0
incq %r14
movapd %xmm0, %xmm1
jmp 0xc0c9
movsd -0x68(%rbp), %xmm0
ucomisd %xmm1, %xmm0
movq -0x38(%rbp), %rsi
ja 0xc1e1
movl %ebx, %eax
cmpq %rax, %rsi
je 0xc140
movl (%r12,%rsi,4), %eax
movslq %ebx, %rcx
movl (%r12,%rcx,4), %edx
movl %edx, (%r12,%rsi,4)
movl %eax, (%r12,%rcx,4)
movq (%r15,%rsi,8), %rax
movq (%r15,%rcx,8), %rdx
movq %rdx, (%r15,%rsi,8)
movq %rax, (%r15,%rcx,8)
incl (%r12,%r13,4)
movq %rsi, %r13
shlq $0x4, %r13
movq -0x40(%rbp), %rbx
cmpl -0x2c(%rbp), %ebx
jge 0xc1c3
movq (%r15,%rsi,8), %rsi
addq %r13, %rsi
movq (%r15,%rbx,8), %rdi
addq %r13, %rdi
callq 0xe578
movq -0x40(%rbp), %rax
movl %eax, %r12d
movq -0x48(%rbp), %r14
cmpl -0x50(%rbp), %r12d
jge 0xc1ba
movq (%r15,%rbx,8), %rdi
addq %r13, %rdi
movq -0x38(%rbp), %rax
movq (%r15,%rax,8), %rsi
addq %r14, %rsi
callq 0xe4c8
movq (%r15,%rbx,8), %rax
movsd (%rax,%r14), %xmm2
movsd 0x8(%rax,%r14), %xmm3
subsd %xmm0, %xmm2
subsd %xmm1, %xmm3
movsd %xmm2, (%rax,%r14)
movsd %xmm3, 0x8(%rax,%r14)
addq $0x10, %r14
incl %r12d
jmp 0xc16e
incq %rbx
movq -0x38(%rbp), %rsi
jmp 0xc14b
incq %rsi
incq -0x40(%rbp)
addq $0x10, -0x48(%rbp)
movq -0x60(%rbp), %r12
movq -0x58(%rbp), %r13
jmp 0xc0b2
pushq $0x1
popq %rax
jmp 0xc1e3
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq