// File: /workspace/github_cpp_makefile_star2_O1/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 $0x218, %rsp            # imm = 0x218
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r13
movq (%rsi), %rax
leaq 0x100(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x8(%rsi), %r15
movq %r15, %rsi
callq 0x3dea
leaq 0x118(%rsp), %rdi
leaq 0x20(%r12), %rbx
movq %rbx, %rsi
callq 0x3eb0
movq %r13, 0x78(%rsp)
movq %r14, 0x38(%rsp)
leaq 0x130(%rsp), %rdi
movq %r12, 0x80(%rsp)
leaq 0x38(%r12), %r14
movq %r14, %rsi
callq 0x3eb0
cmpl $0x0, 0xf8(%rsp)
jle 0x315c
xorl %r12d, %r12d
movsd 0x2f3d(%rip), %xmm1     # 0x6008
leaq 0xf8(%rsp), %r13
cmpl $0x0, 0xfc(%rsp)
jle 0x3148
xorl %ebp, %ebp
movl %ebp, %eax
cmpq %rax, %r12
jne 0x3128
movq 0x118(%rsp), %rcx
movslq (%rcx,%r12,4), %rax
movslq 0x4(%rcx,%r12,4), %rcx
cmpl %ecx, %eax
jge 0x313d
movq 0x100(%rsp), %rdx
movq 0x130(%rsp), %rsi
cmpl %ebp, (%rsi,%rax,4)
jne 0x311e
movapd %xmm1, %xmm0
divsd (%rdx,%rax,8), %xmm0
movsd %xmm0, (%rdx,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x310b
jmp 0x313d
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x2e46
movsd 0x2ecb(%rip), %xmm1     # 0x6008
incl %ebp
cmpl 0xfc(%rsp), %ebp
jl 0x30df
incq %r12
movslq 0xf8(%rsp), %rax
cmpq %rax, %r12
jl 0x30d3
movq %r14, %r13
movq 0x80(%rsp), %rax
movq (%rax), %rax
leaq 0xb0(%rsp), %r12
movq %rax, -0x8(%r12)
movq %r12, %rdi
movq %r15, %rsi
callq 0x3dea
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3eb0
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3eb0
cmpl $0x0, 0xa8(%rsp)
jle 0x3258
xorl %r15d, %r15d
leaq 0xa8(%rsp), %rbp
movapd 0x2e57(%rip), %xmm1     # 0x6020
cmpl $0x0, 0xac(%rsp)
jle 0x3244
xorl %r13d, %r13d
movl %r13d, %eax
cmpq %rax, %r15
jne 0x31f6
movq %rbp, %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x2e46
movapd 0x2e2c(%rip), %xmm1     # 0x6020
jmp 0x3237
movq 0xc8(%rsp), %rcx
movslq (%rcx,%r15,4), %rax
movslq 0x4(%rcx,%r15,4), %rcx
cmpl %ecx, %eax
jge 0x3237
movq 0xb0(%rsp), %rdx
movq 0xe0(%rsp), %rsi
cmpl %r13d, (%rsi,%rax,4)
jne 0x322f
movsd (%rdx,%rax,8), %xmm0
xorpd %xmm1, %xmm0
movlpd %xmm0, (%rdx,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x321b
incl %r13d
cmpl 0xac(%rsp), %r13d
jl 0x31d6
incq %r15
movslq 0xa8(%rsp), %rax
cmpq %rax, %r15
jl 0x31c9
movq 0xa8(%rsp), %rax
leaq 0x1a0(%rsp), %rdi
movq %rax, -0x8(%rdi)
movq %r12, %rsi
callq 0x3dea
leaq 0x1b8(%rsp), %rdi
movq %r14, %rsi
callq 0x3eb0
leaq 0x1d0(%rsp), %rdi
movq %rbx, %rsi
callq 0x3eb0
movslq 0x198(%rsp), %rax
movq %rax, 0x150(%rsp)
testq %rax, %rax
jle 0x3400
movl 0x19c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x148(%rsp)
xorl %esi, %esi
movl $0x1, %edi
cmpl $0x0, 0x1c(%rsp)
jle 0x33ef
movq 0x148(%rsp), %rax
movslq (%rax,%rsi,4), %rcx
movq %rcx, 0x88(%rsp)
movslq 0x4(%rax,%rsi,4), %r9
movq 0x1d0(%rsp), %r10
xorl %r11d, %r11d
movq %r10, 0x158(%rsp)
cmpl %r9d, 0x88(%rsp)
jge 0x33e1
movq 0x100(%rsp), %r15
movq 0xb0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xc8(%rsp), %r13
movq 0xe0(%rsp), %rax
movq %rax, 0x160(%rsp)
movq 0x1a0(%rsp), %rbx
movq 0x88(%rsp), %r8
cmpl %r11d, (%r10,%r8,4)
jne 0x33d5
movl (%r13,%rsi,4), %r14d
movslq 0x4(%r13,%rsi,4), %rdx
cmpl %edx, %r14d
jge 0x33b1
movq %rbx, %r10
movq %r15, %rbx
movslq %r14d, %rax
subq %rax, %rdx
movq 0x160(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
xorl %r12d, %r12d
movl %r14d, %ebp
xorl %ecx, %ecx
cmpl %r11d, (%rax,%r12,4)
leal (%rbp,%r12), %r15d
cmovel %r15d, %r14d
movzbl %cl, %ecx
cmovel %edi, %ecx
incq %r12
cmpq %r12, %rdx
jne 0x3386
movq %rbx, %r15
movq %r10, %rbx
movq 0x158(%rsp), %r10
jmp 0x33b3
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
testb $0x1, %cl
je 0x33c9
movslq %r14d, %rax
movq 0x40(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
mulsd (%r15,%rsi,8), %xmm0
movsd %xmm0, (%rbx,%r8,8)
incq %r8
cmpq %r9, %r8
jne 0x3351
incl %r11d
cmpl 0x1c(%rsp), %r11d
jne 0x3306
incq %rsi
cmpq 0x150(%rsp), %rsi
jne 0x32cf
movq 0x38(%rsp), %r14
movq 0x8(%r14), %rsi
subq (%r14), %rsi
sarq $0x3, %rsi
leaq 0x60(%rsp), %rdi
movq %rsp, %rdx
callq 0x3d60
leaq 0x180(%rsp), %rdi
movq %r14, %rsi
callq 0x3dea
movq 0x78(%rsp), %rbx
movq 0x80(%rsp), %r15
movq %rsp, %rdi
leaq 0xf8(%rsp), %rsi
leaq 0x180(%rsp), %rdx
callq 0x2cf4
movq 0x60(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq (%rsp), %rax
movq %rax, 0x60(%rsp)
movupd 0x8(%rsp), %xmm0
movupd %xmm0, 0x68(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0x3490
subq %rdi, %rsi
callq 0x2190
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x34a6
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x180(%rsp), %rdi
testq %rdi, %rdi
je 0x34c3
movq 0x190(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x60(%rsp), %rsi
movq %rbx, %rdi
callq 0x3dea
movq 0x8(%rbx), %rsi
subq (%rbx), %rsi
sarq $0x3, %rsi
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x3d60
leaq 0x168(%rsp), %rdi
movq %rbx, %rsi
callq 0x3dea
leaq 0x20(%rsp), %rdi
leaq 0x168(%rsp), %rdx
movq %r15, %rsi
callq 0x2cf4
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
movupd 0x28(%rsp), %xmm0
movupd %xmm0, 0x8(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
testq %rdi, %rdi
je 0x354b
subq %rdi, %rsi
callq 0x2190
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3562
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x168(%rsp), %rdi
testq %rdi, %rdi
je 0x357f
movq 0x178(%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 0x35cd
movq (%rsp), %rcx
xorl %edx, %edx
movapd 0x2a7d(%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 0x35a3
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x3d60
movq 0x8(%r14), %rsi
subq (%r14), %rsi
sarq $0x3, %rsi
leaq 0x48(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x3d60
leaq 0x200(%rsp), %r15
movq %rsp, %r12
leaq 0x1e8(%rsp), %r13
leaq 0x20(%rsp), %r14
leaq 0x198(%rsp), %rbp
movq %r15, %rdi
movq %r12, %rsi
callq 0x3dea
movq 0x200(%rsp), %rax
movq 0x208(%rsp), %rcx
subq %rax, %rcx
je 0x365c
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 0x3643
jmp 0x3660
xorpd %xmm0, %xmm0
ucomisd 0x29b0(%rip), %xmm0     # 0x6018
jb 0x3670
sqrtsd %xmm0, %xmm0
jmp 0x3675
callq 0x2120
movq 0x200(%rsp), %rdi
testq %rdi, %rdi
je 0x369e
movq 0x210(%rsp), %rsi
subq %rdi, %rsi
movsd %xmm0, 0x40(%rsp)
callq 0x2190
movsd 0x40(%rsp), %xmm0
ucomisd 0x296a(%rip), %xmm0     # 0x6010
jbe 0x3815
movq 0x38(%rsp), %rcx
movq 0x8(%rcx), %rax
movq (%rcx), %rcx
subq %rcx, %rax
je 0x36df
sarq $0x3, %rax
movq (%rbx), %rcx
movq 0x20(%rsp), %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0x36cb
movq %r13, %rdi
movq %r14, %rsi
callq 0x3dea
leaq 0x90(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2cf4
movq 0x48(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x90(%rsp), %rax
movq %rax, 0x48(%rsp)
movupd 0x98(%rsp), %xmm0
movupd %xmm0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movq $0x0, 0xa0(%rsp)
testq %rdi, %rdi
je 0x3749
subq %rdi, %rsi
callq 0x2190
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x3766
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x1e8(%rsp), %rdi
testq %rdi, %rdi
je 0x3783
movq 0x1f8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
je 0x37b9
sarq $0x3, %rcx
movq 0x48(%rsp), %rdx
movq 0x60(%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 0x379f
movq 0x38(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq (%rdx), %rdx
subq %rdx, %rcx
movapd 0x2850(%rip), %xmm2     # 0x6020
je 0x3619
sarq $0x3, %rcx
movq (%rsp), %rdx
movq 0x20(%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 0x37e5
jmp 0x3619
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x382c
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3843
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3859
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x3870
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x1d0(%rsp), %rdi
testq %rdi, %rdi
je 0x388d
movq 0x1e0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x38aa
movq 0x1c8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x1a0(%rsp), %rdi
testq %rdi, %rdi
je 0x38c7
movq 0x1b0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x38e4
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x3901
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x391e
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x393b
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0x3958
movq 0x128(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0x3975
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x3b27
jmp 0x39b5
movq %rax, %r14
movq 0x168(%rsp), %rdi
testq %rdi, %rdi
je 0x3b3e
movq 0x178(%rsp), %rsi
jmp 0x3b36
movq %rax, %r14
jmp 0x3b3e
movq %rax, %r14
jmp 0x3b54
jmp 0x39e8
movq %rax, %r14
movq 0x180(%rsp), %rdi
testq %rdi, %rdi
je 0x3b6d
movq 0x190(%rsp), %rsi
jmp 0x3b65
movq %rax, %r14
jmp 0x3b6d
movq %rax, %r14
jmp 0x3b84
movq %rax, %r14
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x3a1d
movq 0x1c8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3a1d
movq %rax, %r14
movq 0x1a0(%rsp), %rdi
testq %rdi, %rdi
je 0x3b91
movq 0x1b0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3b91
movq %rax, %r14
jmp 0x3b91
movq %rax, %r14
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x3a70
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3a70
movq %rax, %r14
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x3b9e
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3b9e
movq %rax, %r14
jmp 0x3b9e
movq %rax, %r14
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0x3ac3
movq 0x128(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3ac3
movq %rax, %r14
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0x3bab
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3bab
movq %rax, %r14
movq 0x1e8(%rsp), %rdi
testq %rdi, %rdi
je 0x3b10
movq 0x1f8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x3b10
jmp 0x3b0d
movq %rax, %r14
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3b27
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3b3e
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x3b54
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x78(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3b6d
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x3b84
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x198(%rsp), %rdi
callq 0x3e6a
leaq 0xa8(%rsp), %rdi
callq 0x3e6a
leaq 0xf8(%rsp), %rdi
callq 0x3e6a
movq %r14, %rdi
callq 0x2270
nop