// File: /workspace/github_cpp_makefile_star2_O3/canzarlab[P]Trajan/src/Solver.cpp
// Function: Solver::Solver(Graph&, Graph&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, bool)
Solver::Solver(Graph& t1, Graph& t2, string d, double k, bool dag) : t1(t1), t2(t2), d(d), k(k), dag(dag)
{
    if (d == "e"){
        std::string fileName = costMatrixFileName;  // use file name from main function. 
        std::ifstream f(fileName.c_str());
        if (f.good())
        {
            CSVReader reader(costMatrixFileName);
            cost_matrix = reader.getDoubleData();
        }
        else
        {
            std::cout << "PLEASE INPUT WEIGHT(COST) MATRIX DIRECTORY:"; 
            std::cin >> fileName;
            CSVReader reader(fileName);
            cost_matrix = reader.getDoubleData();
        }
        // scale distance matrix 
        // std::cout << "Rescale distance matrix\n"; TODO: 
        int n = (int) cost_matrix.size();
        int m = (int) cost_matrix[0].size();
        scaleCoef = 1.0;
        for (int i=0; i < n; ++i)
            scaleCoef = max(scaleCoef, cost_matrix[i][0]);
        scaleCoef = min(scaleCoef, 100.0);
        for (int i=0; i < n; ++i){
            for (int j=0; j < m;++j)
            {
                cost_matrix[i][j] = cost_matrix[i][j]/scaleCoef;
            }
        }
        // std::cout << "scale coef: " << scaleCoef << m << n << endl;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
movl %r8d, %ebp
movsd %xmm0, 0x28(%rsp)
movq %rcx, %r15
movq %rdi, %rbx
leaq 0x50cfd(%rip), %rax     # 0x844a8
movq %rax, (%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rdi)
movq $0x0, 0x18(%rdi)
movabsq $0x3ff0000000000000, %r12 # imm = 0x3FF0000000000000
movq %r12, 0x28(%rdi)
movq %rsi, 0x30(%rdi)
movq %rdx, 0x38(%rdi)
leaq 0x40(%rdi), %r14
leaq 0x50(%rdi), %r13
movq %r13, 0x40(%rdi)
movq (%rcx), %rsi
movq 0x8(%rcx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xda46
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x60(%rbx)
movb %bpl, 0x68(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x70(%rbx)
movq $0x0, 0x80(%rbx)
leaq 0x3b41e(%rip), %rsi     # 0x6ec3b
movq %r15, %rdi
callq 0x90e0
testl %eax, %eax
jne 0x33b84
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x52b8b(%rip), %rbp     # 0x863c8
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0xda46
movq 0x8(%rsp), %rsi
leaq 0x130(%rsp), %rdi
movl $0x8, %edx
callq 0x96d0
movq 0x130(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x150(%rsp,%rax)
je 0x33953
movq 0x52736(%rip), %rdi     # 0x85fc0
leaq 0x3a531(%rip), %rsi     # 0x6ddc2
movl $0x2b, %edx
callq 0x93b0
movq 0x52736(%rip), %rdi     # 0x85fd8
leaq 0x8(%rsp), %rsi
callq 0x9410
leaq 0x60(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0xda46
leaq 0x40(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x3a4e4(%rip), %rsi     # 0x6ddc0
leaq 0x3a4de(%rip), %rdx     # 0x6ddc1
leaq 0x30(%rsp), %rdi
callq 0xdadc
leaq 0xb0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0xd61a
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3391b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x9350
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x33932
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x9350
leaq 0xf0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
callq 0x58d30
jmp 0x33a08
leaq 0xa0(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %rdi
callq 0xda46
leaq 0x80(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x3a436(%rip), %rsi     # 0x6ddc0
leaq 0x3a430(%rip), %rdx     # 0x6ddc1
leaq 0x70(%rsp), %rdi
callq 0xdadc
leaq 0xb0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0xd61a
movq 0x70(%rsp), %rdi
cmpq %rbp, %rdi
je 0x339cf
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x9350
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x339ec
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x9350
leaq 0xf0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
callq 0x58d30
movq 0x80(%rbx), %rax
leaq 0xf0(%rsp), %r14
movapd (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x80(%rbx)
movupd 0x70(%rbx), %xmm1
movupd %xmm0, 0x70(%rbx)
leaq 0x110(%rsp), %rdi
movapd %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x2f65a
movq %r14, %rdi
callq 0x2f65a
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x33a80
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x9350
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x33aa1
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x9350
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
movq 0x8(%rax), %rdx
subq (%rax), %rdx
movq %r12, 0x28(%rbx)
testl %ecx, %ecx
jle 0x33b5b
shrq $0x3, %rdx
movl %ecx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movsd 0x28913(%rip), %xmm0    # 0x5c3f8
movq %rax, %rdi
movapd %xmm0, %xmm1
movq (%rdi), %r8
movsd (%r8), %xmm0
maxsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rbx)
addq $0x18, %rdi
decq %rsi
jne 0x33ae8
movsd 0x3a28a(%rip), %xmm1    # 0x6dd98
minsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rbx)
testl %ecx, %ecx
jle 0x33b5b
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andq %rdi, %rcx
movq %rdx, %rsi
andq %rdi, %rsi
xorl %edi, %edi
testl %edx, %edx
jle 0x33b53
leaq (%rdi,%rdi,2), %r8
movq (%rax,%r8,8), %r8
xorl %r9d, %r9d
movsd (%r8,%r9,8), %xmm0
divsd 0x28(%rbx), %xmm0
movsd %xmm0, (%r8,%r9,8)
incq %r9
cmpq %r9, %rsi
jne 0x33b3a
incq %rdi
cmpq %rcx, %rdi
jne 0x33b2b
leaq 0x130(%rsp), %rdi
callq 0x90b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x33b84
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x9350
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x33bd3
movq %rax, %r12
movq 0x70(%rsp), %rdi
cmpq %rbp, %rdi
je 0x33bba
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x9350
jmp 0x33bba
movq %rax, %r12
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x33c2c
movq 0xa0(%rsp), %rsi
jmp 0x33c13
jmp 0x33c29
movq %rax, %r12
leaq 0xb0(%rsp), %rdi
callq 0xd742
jmp 0x33c2c
movq %rax, %r12
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x33c04
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x9350
jmp 0x33c04
movq %rax, %r12
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x33c2c
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x9350
jmp 0x33c2c
jmp 0x33c29
movq %rax, %r12
jmp 0x33c39
movq %rax, %r12
jmp 0x33c55
movq %rax, %r12
leaq 0x130(%rsp), %rdi
callq 0x90b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x33c55
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x9350
leaq 0x70(%rbx), %rdi
callq 0x2f65a
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x33c77
movq (%r13), %rsi
incq %rsi
callq 0x9350
jmp 0x33c77
movq %rax, %r12
leaq 0x8(%rbx), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x33c8f
movq 0x18(%rbx), %rsi
subq %rdi, %rsi
callq 0x9350
movq %r12, %rdi
callq 0x9680
nop