// File: /workspace/github_cpp_makefile_star2_O3/fanyazhi[P]Spline-Fitting/src/CRSmatrix.cpp
// Function: Jacobi(CRSmatrix, std::vector<double, std::allocator<double>>)
std::vector<double> Jacobi(CRSmatrix A, std::vector<double> b) {
    //first find the inverse of the diagonal matrix
    CRSmatrix Di = A;
    for (int i = 0; i < Di.getRowSize(); i++) {
        for (int j = 0; j < Di.getColSize(); j++) {
            //remove all elements other than the diagonal
            if (i != j) {
                Di.deleteValue(i, j);
            } else {
                //take the inverse of the diagonal
                for (int n = Di.rowPtr[i]; n < Di.rowPtr[i] + (Di.rowPtr[i + 1] - Di.rowPtr[i]); n++) {
                    if (Di.colInd[n] == j) {
                        Di.value[n] = 1 / Di.value[n];
                    }
                }
            }
        }
    }

    //find L+U
    CRSmatrix LU = A;
    for (int i = 0; i < LU.getRowSize(); i++) {
        for (int j = 0; j < LU.getColSize(); j++) {
            if (i == j) {
                LU.deleteValue(i, j);
            } else {
                //take the inverse of the diagonal
                for (int n = LU.rowPtr[i]; n < LU.rowPtr[i] + (LU.rowPtr[i + 1] - LU.rowPtr[i]); n++) {
                    if (LU.colInd[n] == j) {
                        LU.value[n] = -1.0 * LU.value[n];
                    }
                }
            }
        }
    }

    //take D^-1 * (L+U), store in DLU
    CRSmatrix DLU = LU;
    for (int i = 0; i < DLU.getRowSize(); i++) {
        for (int j = 0; j < DLU.getColSize(); j++) {
            for (int n = DLU.rowPtr[i]; n < DLU.rowPtr[i] + (DLU.rowPtr[i + 1] - DLU.rowPtr[i]); n++) {
                if (DLU.colInd[n] == j) {
                    DLU.value[n] = Di.value[i] * LU.retrieveElement(i, j);
                }
            }
        }
    }

    //find intercept D^-1 * b
    std::vector<double> cep(b.size());
    cep = Di.productAx(b);

    //initial guess is the same as the intercept
    std::vector<double> x = cep;

    //find vetor norm ||b-Ax|| of initial guess
    std::vector<double> normTemp(x.size());
    normTemp = A.productAx(x);
    for (unsigned int i = 0; i < b.size(); i++) {
        normTemp[i] = -1 * normTemp[i];
        normTemp[i] = b[i] + normTemp[i];
    }
    int count = 0;

    //start Jacobi iteration
    std::vector<double> xTemp(b.size());
    std::vector<double> prod(b.size());
    double threshold = 10E-7;
    while (vectorNorm(normTemp) > threshold) {
        count++;

        //x(k-1)
        for (unsigned int i = 0; i < b.size(); i++) {
            xTemp[i] = x[i];
        }

        //find product of D^-1(L+U)*x
        prod = DLU.productAx(xTemp);

        //add D^-1(L+U)*x to D^-1 * b, store in x
        for (unsigned int i = 0; i < x.size(); i++) {
            x[i] = prod[i] + cep[i];
        }

        //find new vetor norm ||x(k-1)-x||
        for (unsigned int i = 0; i < b.size(); i++) {
            normTemp[i] = -1.0 * x[i];
            normTemp[i] = xTemp[i] + normTemp[i];
        }
    }
    return x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq (%rsi), %rax
leaq 0x110(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x8(%rsi), %r12
movq %r12, %rsi
callq 0x3e1e
leaq 0x128(%rsp), %rdi
leaq 0x20(%r15), %r13
movq %r13, %rsi
callq 0x3ee4
movq %r13, 0x20(%rsp)
movq %r14, 0x48(%rsp)
leaq 0x140(%rsp), %rdi
leaq 0x38(%r15), %rsi
movq %rsi, %r14
callq 0x3ee4
movq %r15, 0x88(%rsp)
movl 0x108(%rsp), %ecx
testl %ecx, %ecx
jle 0x3163
leaq 0x108(%rsp), %r15
movl 0x4(%r15), %eax
xorl %r13d, %r13d
movsd 0x2f2c(%rip), %xmm1     # 0x6008
testl %eax, %eax
jle 0x3154
xorl %ebp, %ebp
movl %ebp, %ecx
cmpq %rcx, %r13
jne 0x312b
movq 0x128(%rsp), %rdx
movslq (%rdx,%r13,4), %rcx
movslq 0x4(%rdx,%r13,4), %rdx
cmpl %edx, %ecx
jge 0x3147
movq 0x110(%rsp), %rsi
movq 0x140(%rsp), %rdi
cmpl %ebp, (%rdi,%rcx,4)
jne 0x3121
movapd %xmm1, %xmm0
divsd (%rsi,%rcx,8), %xmm0
movsd %xmm0, (%rsi,%rcx,8)
incq %rcx
cmpq %rcx, %rdx
jne 0x310e
jmp 0x3147
movq %r15, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x2e46
movsd 0x2ec8(%rip), %xmm1     # 0x6008
movl 0x10c(%rsp), %eax
incl %ebp
cmpl %eax, %ebp
jl 0x30e2
movl 0x108(%rsp), %ecx
incq %r13
movslq %ecx, %rdx
cmpq %rdx, %r13
jl 0x30dc
movq 0x88(%rsp), %rax
movq (%rax), %rax
leaq 0xa8(%rsp), %rdi
movq %rax, -0x8(%rdi)
movq %r12, %rsi
callq 0x3e1e
leaq 0xc0(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x3ee4
leaq 0xd8(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x3ee4
movl 0xa0(%rsp), %ecx
testl %ecx, %ecx
jle 0x3255
leaq 0xa0(%rsp), %r12
movl 0x4(%r12), %eax
xorl %r15d, %r15d
movapd 0x2e52(%rip), %xmm1     # 0x6020
testl %eax, %eax
jle 0x3246
xorl %ebp, %ebp
movl %ebp, %ecx
cmpq %rcx, %r15
jne 0x31f9
movq %r12, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x2e46
movapd 0x2e30(%rip), %xmm1     # 0x6020
movl 0xa4(%rsp), %eax
jmp 0x3239
movq 0xc0(%rsp), %rdx
movslq (%rdx,%r15,4), %rcx
movslq 0x4(%rdx,%r15,4), %rdx
cmpl %edx, %ecx
jge 0x3239
movq 0xa8(%rsp), %rsi
movq 0xd8(%rsp), %rdi
cmpl %ebp, (%rdi,%rcx,4)
jne 0x3231
movsd (%rsi,%rcx,8), %xmm0
xorpd %xmm1, %xmm0
movlpd %xmm0, (%rsi,%rcx,8)
incq %rcx
cmpq %rcx, %rdx
jne 0x321e
incl %ebp
cmpl %eax, %ebp
jl 0x31d4
movl 0xa0(%rsp), %ecx
incq %r15
movslq %ecx, %rdx
cmpq %rdx, %r15
jl 0x31ce
movq 0xa0(%rsp), %rax
leaq 0x1b0(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0xa8(%rsp), %rsi
callq 0x3e1e
leaq 0x1c8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x3ee4
leaq 0x1e0(%rsp), %rdi
movq %r13, %rsi
callq 0x3ee4
movslq 0x1a8(%rsp), %rax
movq %rax, 0x160(%rsp)
testq %rax, %rax
movq %rbx, 0x90(%rsp)
movq 0x48(%rsp), %r14
jle 0x3412
movl 0x1ac(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x158(%rsp)
xorl %esi, %esi
cmpl $0x0, 0x2c(%rsp)
jle 0x33fe
movq 0x158(%rsp), %rax
movslq (%rax,%rsi,4), %rcx
movq %rcx, 0x98(%rsp)
leaq 0x1(%rsi), %rcx
movq %rcx, 0x168(%rsp)
movslq 0x4(%rax,%rsi,4), %r9
movq 0x1e0(%rsp), %r10
xorl %r11d, %r11d
cmpl %r9d, 0x98(%rsp)
jge 0x33d6
movq 0x110(%rsp), %r15
movq 0xa8(%rsp), %rax
movq %rax, 0x170(%rsp)
movq 0xc0(%rsp), %r13
movq 0xd8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x1b0(%rsp), %rbx
movq 0x98(%rsp), %r8
cmpl %r11d, (%r10,%r8,4)
jne 0x33ce
movl (%r13,%rsi,4), %eax
movslq 0x4(%r13,%rsi,4), %rdx
xorpd %xmm0, %xmm0
cmpl %edx, %eax
jge 0x33c2
movslq %eax, %rcx
subq %rcx, %rdx
movq 0x20(%rsp), %rdi
leaq (%rdi,%rcx,4), %rdi
xorl %ecx, %ecx
movl %eax, %r14d
xorl %r12d, %r12d
leal (%r14,%rcx), %ebp
cmpl %r11d, (%rdi,%rcx,4)
cmovel %ebp, %eax
sete %bpl
orb %bpl, %r12b
incq %rcx
cmpq %rcx, %rdx
jne 0x3393
testb $0x1, %r12b
je 0x33c2
cltq
movq 0x170(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
mulsd (%r15,%rsi,8), %xmm0
movsd %xmm0, (%rbx,%r8,8)
incq %r8
cmpq %r9, %r8
jne 0x3364
incl %r11d
cmpl 0x2c(%rsp), %r11d
jne 0x3319
movq 0x168(%rsp), %rax
movq %rax, %rsi
movq 0x90(%rsp), %rbx
movq 0x48(%rsp), %r14
jmp 0x3404
incq %rsi
movq %rsi, %rax
cmpq 0x160(%rsp), %rax
jne 0x32de
movq 0x8(%r14), %rsi
subq (%r14), %rsi
sarq $0x3, %rsi
leaq 0x70(%rsp), %rdi
movq %rsp, %rdx
callq 0x3d90
leaq 0x190(%rsp), %rdi
movq %r14, %rsi
callq 0x3e1e
movq %rsp, %rdi
leaq 0x108(%rsp), %rsi
leaq 0x190(%rsp), %rdx
callq 0x2d0e
movq 0x70(%rsp), %rdi
movq 0x80(%rsp), %rsi
movapd (%rsp), %xmm0
movapd %xmm0, 0x70(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x80(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0x34ac
subq %rdi, %rsi
callq 0x2190
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x34ac
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x190(%rsp), %rdi
testq %rdi, %rdi
je 0x34c9
movq 0x1a0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x3e1e
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x3, %rsi
movq %rsp, %rdi
leaq 0x30(%rsp), %rdx
callq 0x3d90
leaq 0x178(%rsp), %rdi
movq %rbx, %rsi
callq 0x3e1e
leaq 0x30(%rsp), %rdi
leaq 0x178(%rsp), %rdx
movq 0x88(%rsp), %rsi
callq 0x2d0e
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movapd 0x30(%rsp), %xmm0
movapd %xmm0, (%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
testq %rdi, %rdi
je 0x356d
subq %rdi, %rsi
callq 0x2190
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x356d
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x178(%rsp), %rdi
testq %rdi, %rdi
je 0x358a
movq 0x188(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x3, %rsi
cmpq %rax, %rcx
je 0x35d8
movq (%rsp), %rcx
xorl %edx, %edx
movapd 0x2a72(%rip), %xmm0     # 0x6020
movsd (%rcx,%rdx,8), %xmm1
movapd %xmm1, %xmm2
xorpd %xmm0, %xmm2
movlpd %xmm2, (%rcx,%rdx,8)
movsd (%rax,%rdx,8), %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, (%rcx,%rdx,8)
incq %rdx
movl %edx, %edi
cmpq %rdi, %rsi
ja 0x35ae
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x3d90
movq 0x8(%r14), %rsi
subq (%r14), %rsi
sarq $0x3, %rsi
leaq 0x50(%rsp), %rdi
leaq 0xf0(%rsp), %rdx
callq 0x3d90
leaq 0x210(%rsp), %r15
movq %rsp, %r12
leaq 0x1f8(%rsp), %r13
leaq 0x30(%rsp), %r14
leaq 0x1a8(%rsp), %rbp
movq %r15, %rdi
movq %r12, %rsi
callq 0x3e1e
movq 0x210(%rsp), %rax
movq 0x218(%rsp), %rcx
subq %rax, %rcx
je 0x3667
sarq $0x3, %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movsd (%rax,%rdx,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rdx
movl %edx, %esi
cmpq %rsi, %rcx
ja 0x364e
jmp 0x366b
xorpd %xmm0, %xmm0
ucomisd 0x29a5(%rip), %xmm0     # 0x6018
jb 0x367b
sqrtsd %xmm0, %xmm0
jmp 0x3680
callq 0x2120
movq 0x210(%rsp), %rdi
testq %rdi, %rdi
je 0x36a9
movq 0x220(%rsp), %rsi
subq %rdi, %rsi
movsd %xmm0, 0x20(%rsp)
callq 0x2190
movsd 0x20(%rsp), %xmm0
ucomisd 0x295f(%rip), %xmm0     # 0x6010
jbe 0x3820
movq 0x48(%rsp), %rcx
movq 0x8(%rcx), %rax
movq (%rcx), %rcx
subq %rcx, %rax
je 0x36ea
sarq $0x3, %rax
movq (%rbx), %rcx
movq 0x30(%rsp), %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0x36d6
movq %r13, %rdi
movq %r14, %rsi
callq 0x3e1e
leaq 0xf0(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2d0e
movq 0x50(%rsp), %rdi
movq 0x60(%rsp), %rsi
movapd 0xf0(%rsp), %xmm0
movapd %xmm0, 0x50(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x60(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xf0(%rsp)
movq $0x0, 0x100(%rsp)
testq %rdi, %rdi
je 0x3771
subq %rdi, %rsi
callq 0x2190
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x3771
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x1f8(%rsp), %rdi
testq %rdi, %rdi
je 0x378e
movq 0x208(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
je 0x37c4
sarq $0x3, %rcx
movq 0x50(%rsp), %rdx
movq 0x70(%rsp), %rsi
xorl %edi, %edi
movsd (%rdx,%rdi,8), %xmm0
addsd (%rsi,%rdi,8), %xmm0
movsd %xmm0, (%rax,%rdi,8)
incq %rdi
movl %edi, %r8d
cmpq %r8, %rcx
ja 0x37aa
movq 0x48(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq (%rdx), %rdx
subq %rdx, %rcx
movapd 0x2845(%rip), %xmm2     # 0x6020
je 0x3624
sarq $0x3, %rcx
movq (%rsp), %rdx
movq 0x30(%rsp), %rsi
xorl %edi, %edi
movsd (%rax,%rdi,8), %xmm0
movapd %xmm0, %xmm1
xorpd %xmm2, %xmm1
movlpd %xmm1, (%rdx,%rdi,8)
movsd (%rsi,%rdi,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rdi,8)
incq %rdi
movl %edi, %r8d
cmpq %r8, %rcx
ja 0x37f0
jmp 0x3624
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3837
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x384e
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3864
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x387e
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x1e0(%rsp), %rdi
testq %rdi, %rdi
je 0x389b
movq 0x1f0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x1c8(%rsp), %rdi
testq %rdi, %rdi
je 0x38b8
movq 0x1d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x1b0(%rsp), %rdi
testq %rdi, %rdi
je 0x38d5
movq 0x1c0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xd8(%rsp), %rdi
testq %rdi, %rdi
je 0x38f2
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x390f
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x392c
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x3949
movq 0x150(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x128(%rsp), %rdi
testq %rdi, %rdi
je 0x3966
movq 0x138(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x3983
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x3b35
jmp 0x39c3
movq %rax, %r14
movq 0x178(%rsp), %rdi
testq %rdi, %rdi
je 0x3b4c
movq 0x188(%rsp), %rsi
jmp 0x3b44
movq %rax, %r14
jmp 0x3b4c
movq %rax, %r14
jmp 0x3b62
jmp 0x39f6
movq %rax, %r14
movq 0x190(%rsp), %rdi
testq %rdi, %rdi
je 0x3b7e
movq 0x1a0(%rsp), %rsi
jmp 0x3b76
movq %rax, %r14
jmp 0x3b7e
movq %rax, %r14
jmp 0x3b98
movq %rax, %r14
movq 0x1c8(%rsp), %rdi
testq %rdi, %rdi
je 0x3a2b
movq 0x1d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3a2b
movq %rax, %r14
movq 0x1b0(%rsp), %rdi
testq %rdi, %rdi
je 0x3ba5
movq 0x1c0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3ba5
movq %rax, %r14
jmp 0x3ba5
movq %rax, %r14
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x3a7e
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3a7e
movq %rax, %r14
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x3bb2
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3bb2
movq %rax, %r14
jmp 0x3bb2
movq %rax, %r14
movq 0x128(%rsp), %rdi
testq %rdi, %rdi
je 0x3ad1
movq 0x138(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3ad1
movq %rax, %r14
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x3bbf
movq 0x120(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3bbf
movq %rax, %r14
movq 0x1f8(%rsp), %rdi
testq %rdi, %rdi
je 0x3b1e
movq 0x208(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3b1e
jmp 0x3b1b
movq %rax, %r14
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3b35
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3b4c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3b62
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x90(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3b7e
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x3b98
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x1a8(%rsp), %rdi
callq 0x3e9e
leaq 0xa0(%rsp), %rdi
callq 0x3e9e
leaq 0x108(%rsp), %rdi
callq 0x3e9e
movq %r14, %rdi
callq 0x2270
nop