// File: /workspace/github_cpp_makefile_star2_O1/canzarlab[P]Trajan/src/BnG.cpp
// Function: GenericBnBSolver::Solve(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void GenericBnBSolver::Solve(string filename, string outScoreFile)
{
    this->filename = filename;
    
#if DEBUG == 1    
    if (debug_file == "")
        debug_log = ofstream(filename + ".log");
    else
        debug_log = ofstream(debug_file + ".log");
    debug_nodecnt  = 0;
    debug_genocnt  = 0;
    debug_genotime = 0;
    debug_genomin  = 1e20;
    debug_genomax  = 0;
#endif

#if DEBUG == 1    
    Timer T; T.start();
#endif

    sys_sol.conservativeResizeLike(Vector::Zero(nr_cols));
    OnSolverInit();

    PushNode(InitNodeFrom(nullptr));
    while (!OpenEmpty())
    {
        for (auto& it : EvalOpen())
        {
            vector<BnBNode*>* V = EvalBranch(it);
#if DEBUG == 1
            if (V != nullptr)
                debug_log << "fixed: " << V->front()->debug_varid << " (" << V->front()->debug_varval << " <- " << it->sol(V->front()->debug_varid) << ") in node " << it->debug_nodeid << endl << endl;
#endif

            if (V != nullptr)
                PushAll(V);
            else if (sys_ub > it->obj)
            {
                sys_sol = it->sol;
                sys_ub  = it->obj;         
#if DEBUG == 1    
                debug_log << "BOUND " << sys_ub << " (" << it->debug_nodeid << ")" << endl << endl;
#endif            
                OnSolverUpdate();
            }
            delete it;
            
        }         
    }
#if DEBUG == 1    
    T.stop();
#endif

    if (OnSolverFinish())
    {
        x = sys_sol;
        for (size_t i = 0; i < x.size(); ++i)
            x(i) = round(x(i));    
        if (filename != "") 
            WriteSolution(filename);     
        // write the objective function 
        ofstream score(outScoreFile);
        score << moptVal << endl;
        cout << "my score: "  << moptVal << endl;
        score.close();
    }

#if DEBUG == 1    
    debug_log << "total time: " << T.secs() << endl;
    debug_log << "total nodes: " << debug_nodecnt << endl;
    debug_log << "total geno calls: " << debug_genocnt << endl;
    debug_log << "total geno time: " << debug_genotime << " (" << debug_genomin << ", " << debug_genotime / debug_genocnt << "," << debug_genomax << ")" << endl;
    debug_log << "best: " << -sys_ub << endl << endl;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rdx, 0x8(%rsp)
movq %rdi, %rbx
addq $0x130, %rdi            # imm = 0x130
movq %rsi, 0x10(%rsp)
callq 0x91b0
movslq 0x10c(%rbx), %rax
movq %rax, 0x38(%rsp)
movq $0x0, 0x48(%rsp)
testq %rax, %rax
js 0x42c5f
leaq 0x120(%rbx), %r12
leaq 0x38(%rsp), %rsi
movq %r12, %rdi
callq 0x41a26
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x80(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x42cc6
movq (%rbx), %rcx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x30(%rcx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
testb %al, %al
jne 0x429d2
movq (%rbx), %rax
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq *0x40(%rax)
movq 0x38(%rsp), %r14
movq 0x40(%rsp), %r15
cmpq %r15, %r14
je 0x429b2
movq (%r14), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
testq %rax, %rax
je 0x428d5
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42d60
jmp 0x4298c
movsd 0x118(%rbx), %xmm0
movq (%r14), %rax
ucomisd 0x60(%rax), %xmm0
jbe 0x4298c
movq 0x50(%rax), %r13
movq 0x58(%rax), %rbp
cmpq %rbp, 0x128(%rbx)
je 0x42918
testq %rbp, %rbp
js 0x42c21
movl $0x1, %ecx
movq %r12, %rdi
movq %rbp, %rsi
movq %rbp, %rdx
callq 0x10056
movq 0x128(%rbx), %rax
cmpq %rbp, %rax
jne 0x42c02
movq (%r12), %rcx
movq %rax, %rdx
shrq $0x3f, %rdx
addq %rax, %rdx
andq $-0x2, %rdx
cmpq $0x2, %rax
jl 0x42957
xorl %esi, %esi
movapd (%r13,%rsi,8), %xmm0
movapd %xmm0, (%rcx,%rsi,8)
addq $0x2, %rsi
cmpq %rdx, %rsi
jl 0x42942
cmpq %rax, %rdx
jge 0x42970
movsd (%r13,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x4295c
movq (%r14), %rax
movsd 0x60(%rax), %xmm0
movsd %xmm0, 0x118(%rbx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x88(%rax)
movq (%r14), %rbp
testq %rbp, %rbp
je 0x429a9
movq %rbp, %rdi
callq 0x4261a
movl $0x68, %esi
movq %rbp, %rdi
callq 0x9340
addq $0x8, %r14
jmp 0x428ab
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x42882
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x9340
jmp 0x42882
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x90(%rax)
testb %al, %al
je 0x42bf0
leaq 0xc0(%rbx), %r12
movq 0x120(%rbx), %r14
movq 0x128(%rbx), %r13
cmpq %r13, 0xc8(%rbx)
je 0x42a20
testq %r13, %r13
js 0x42c21
movl $0x1, %ecx
movq %r12, %rdi
movq %r13, %rsi
movq %r13, %rdx
callq 0x10056
movq 0xc8(%rbx), %rax
cmpq %r13, %rax
jne 0x42c02
movq (%r12), %rcx
movq %rax, %rdx
shrq $0x3f, %rdx
addq %rax, %rdx
andq $-0x2, %rdx
cmpq $0x2, %rax
jl 0x42a5e
xorl %esi, %esi
movapd (%r14,%rsi,8), %xmm0
movapd %xmm0, (%rcx,%rsi,8)
addq $0x2, %rsi
cmpq %rdx, %rsi
jl 0x42a4a
cmpq %rax, %rdx
jge 0x42a76
movsd (%r14,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x42a63
movq 0xc8(%rbx), %r14
testq %r14, %r14
je 0x42ab8
movq (%r12), %r15
xorl %r12d, %r12d
testq %r14, %r14
movl $0x0, %r13d
cmovgq %r14, %r13
cmpq %r12, %r13
je 0x42c40
movsd (%r15,%r12,8), %xmm0
callq 0x9140
movsd %xmm0, (%r15,%r12,8)
incq %r12
cmpq %r12, %r14
jne 0x42a96
leaq 0x2c7f7(%rip), %rsi     # 0x6f2b6
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x90e0
testl %eax, %eax
je 0x42b13
leaq 0x28(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0xda94
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x18(%rax)
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0x42b13
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x9340
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movl $0x10, %edx
callq 0x9700
movsd 0x20(%rbx), %xmm0
movq %r15, %rdi
callq 0x9560
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x9320
movsbl %al, %esi
movq %r14, %rdi
callq 0x9040
movq %rax, %rdi
callq 0x9220
movq 0x45458(%rip), %rdi     # 0x87fc0
leaq 0x2d6a9(%rip), %rsi     # 0x70218
movl $0xa, %edx
callq 0x93a0
movsd 0x20(%rbx), %xmm0
movq 0x4543b(%rip), %rdi     # 0x87fc0
callq 0x9560
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x9320
movsbl %al, %esi
movq %rbx, %rdi
callq 0x9040
movq %rax, %rdi
callq 0x9220
leaq 0x38(%rsp), %rdi
callq 0x94a0
movq 0x453db(%rip), %rax     # 0x87fa0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x40(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x38(%rsp,%rcx)
callq 0x92c0
leaq 0x130(%rsp), %rdi
callq 0x9110
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a457(%rip), %rdi     # 0x5d060
leaq 0x19909(%rip), %rsi     # 0x5c519
leaq 0x1a6d5(%rip), %rcx     # 0x5d2ec
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x9200
leaq 0x1a230(%rip), %rdi     # 0x5ce58
leaq 0x1a088(%rip), %rsi     # 0x5ccb7
leaq 0x1a3b1(%rip), %rcx     # 0x5cfe7
movl $0x11d, %edx            # imm = 0x11D
callq 0x9200
leaq 0x1a5de(%rip), %rdi     # 0x5d225
leaq 0x1a5f4(%rip), %rsi     # 0x5d242
leaq 0x1a610(%rip), %rcx     # 0x5d265
movl $0x1a9, %edx            # imm = 0x1A9
callq 0x9200
leaq 0x198d6(%rip), %rdi     # 0x5c53c
leaq 0x19964(%rip), %rsi     # 0x5c5d1
leaq 0x1a758(%rip), %rcx     # 0x5d3cc
movl $0x4a, %edx
callq 0x9200
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0x42cbe
movq 0x28(%rsp), %rsi
incq %rsi
jmp 0x42cb9
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x9500
jmp 0x42cbe
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x42cbe
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x9340
movq %rbx, %rdi
callq 0x9670