// File: /workspace/github_cpp_makefile_star2_O3/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 0x42502
leaq 0x120(%rbx), %r12
leaq 0x38(%rsp), %rsi
movq %r12, %rdi
callq 0x41168
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x80(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4256a
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 0x42278
movq (%rbx), %rax
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq *0x40(%rax)
movq 0x38(%rsp), %rbp
movq 0x40(%rsp), %r15
cmpq %r15, %rbp
je 0x4225a
movq (%rbp), %rsi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
testq %rax, %rax
je 0x4216e
movq %rbx, %rdi
movq %rax, %rsi
callq 0x42604
jmp 0x42225
movsd 0x118(%rbx), %xmm0
movq (%rbp), %r14
ucomisd 0x60(%r14), %xmm0
jbe 0x4222e
movq 0x50(%r14), %r13
movq 0x58(%r14), %r14
cmpq %r14, 0x128(%rbx)
je 0x421c0
testq %r14, %r14
js 0x424a5
movl $0x1, %ecx
movq %r12, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0xff4c
cmpq %r14, 0x128(%rbx)
jne 0x424c4
movq (%r12), %rax
movq %r14, %rcx
shrq $0x3f, %rcx
addq %r14, %rcx
andq $-0x2, %rcx
cmpq $0x2, %r14
jl 0x421ef
xorl %edx, %edx
movapd (%r13,%rdx,8), %xmm0
movapd %xmm0, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jl 0x421da
cmpq %r14, %rcx
jge 0x42208
movsd (%r13,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r14
jne 0x421f4
movq (%rbp), %rax
movsd 0x60(%rax), %xmm0
movsd %xmm0, 0x118(%rbx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x88(%rax)
movq (%rbp), %r14
testq %r14, %r14
je 0x42238
movq %r14, %rdi
callq 0x41eb2
jmp 0x4223b
xorl %r14d, %r14d
movl $0x68, %esi
movq %r14, %rdi
callq 0x9350
addq $0x8, %rbp
cmpq %r15, %rbp
jne 0x4214c
movq 0x38(%rsp), %rbp
testq %rbp, %rbp
je 0x4211a
movq 0x48(%rsp), %rsi
subq %rbp, %rsi
movq %rbp, %rdi
callq 0x9350
jmp 0x4211a
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x90(%rax)
testb %al, %al
je 0x42493
leaq 0xc0(%rbx), %r12
movq 0x120(%rbx), %r15
movq 0x128(%rbx), %r14
cmpq %r14, 0xc8(%rbx)
je 0x422d3
testq %r14, %r14
js 0x424a5
movl $0x1, %ecx
movq %r12, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0xff4c
cmpq %r14, 0xc8(%rbx)
jne 0x424c4
movq (%r12), %rax
movq %r14, %rcx
shrq $0x3f, %rcx
addq %r14, %rcx
andq $-0x2, %rcx
cmpq $0x2, %r14
jl 0x42301
xorl %edx, %edx
movapd (%r15,%rdx,8), %xmm0
movapd %xmm0, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jl 0x422ed
cmpq %r14, %rcx
jge 0x42319
movsd (%r15,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r14
jne 0x42306
movq 0xc8(%rbx), %r14
testq %r14, %r14
je 0x4235b
movq (%r12), %r15
xorl %r12d, %r12d
testq %r14, %r14
movl $0x0, %r13d
cmovgq %r14, %r13
cmpq %r12, %r13
je 0x424e3
movsd (%r15,%r12,8), %xmm0
callq 0x9140
movsd %xmm0, (%r15,%r12,8)
incq %r12
cmpq %r12, %r14
jne 0x42339
leaq 0x2bb04(%rip), %rsi     # 0x6de66
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x90e0
testl %eax, %eax
je 0x423b6
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0xda46
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x18(%rax)
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x423b6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x9350
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movl $0x10, %edx
callq 0x9710
movsd 0x20(%rbx), %xmm0
movq %r14, %rdi
callq 0x9570
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x9330
movsbl %al, %esi
movq %r14, %rdi
callq 0x9040
movq %rax, %rdi
callq 0x9230
movq 0x43bb5(%rip), %rdi     # 0x85fc0
leaq 0x2cab6(%rip), %rsi     # 0x6eec8
movl $0xa, %edx
callq 0x93b0
movsd 0x20(%rbx), %xmm0
movq 0x43b98(%rip), %rdi     # 0x85fc0
callq 0x9570
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x9330
movsbl %al, %esi
movq %rbx, %rdi
callq 0x9040
movq %rax, %rdi
callq 0x9230
leaq 0x38(%rsp), %rdi
callq 0x94b0
movq 0x43b38(%rip), %rax     # 0x85fa0
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 0x92d0
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 0x1a9cc(%rip), %rdi     # 0x5ce78
leaq 0x1a824(%rip), %rsi     # 0x5ccd7
leaq 0x1ab4d(%rip), %rcx     # 0x5d007
movl $0x11d, %edx            # imm = 0x11D
callq 0x9200
leaq 0x1abb5(%rip), %rdi     # 0x5d080
leaq 0x1a067(%rip), %rsi     # 0x5c539
leaq 0x1ae33(%rip), %rcx     # 0x5d30c
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x9200
leaq 0x1ad5b(%rip), %rdi     # 0x5d245
leaq 0x1ad71(%rip), %rsi     # 0x5d262
leaq 0x1ad8d(%rip), %rcx     # 0x5d285
movl $0x1a9, %edx            # imm = 0x1A9
callq 0x9200
leaq 0x1a053(%rip), %rdi     # 0x5c55c
leaq 0x1a0e1(%rip), %rsi     # 0x5c5f1
leaq 0x1aed5(%rip), %rcx     # 0x5d3ec
movl $0x4a, %edx
callq 0x9200
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x42561
movq 0x28(%rsp), %rsi
incq %rsi
jmp 0x4255c
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x9510
jmp 0x42561
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x42561
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x9350
movq %rbx, %rdi
callq 0x9680
nop