// File: /workspace/github_cpp_makefile_star2_O3/canzarlab[P]Trajan/src/BnG.cpp
// Function: HybridBnBSolver::EvalOpen()
vector<BnBNode*> HybridBnBSolver::EvalOpen()
{
    if (!GetObjective())
    {
        BnBNode* lt = Open.back(); Open.pop_back();

        if (Open.size() > 1)
        {
            BnBNode* rt = Open.back(); 
            if (lt->obj == 1 && !SolveNode(lt, PGTOL, NUMTOL)) lt->obj = 2;
            if (lt->warm == rt->warm) // TODO this is horrible.
            {
                Open.pop_back();
                if (rt->obj == 1 && !SolveNode(rt, PGTOL, NUMTOL)) rt->obj = 2;
                if (lt->obj < rt->obj) swap(lt, rt); // if (lt->obj > rt->obj) swap(lt, rt);
                if (rt->obj < 1) Open.push_back(rt);         
            }        
        }

        vector<BnBNode*> v;
        if (!(lt->obj == 2 || (lt->obj == 1 && !SolveNode(lt, PGTOL, NUMTOL))))
            v.push_back(lt);
        return v;
        //return (lt->obj == 2 || (lt->obj == 1 && !SolveNode(lt, PGTOL, NUMTOL))) ? nullptr : lt;
    }
    else
    {
        thread thr_obj[thr_no];    
        vector<BnBNode*> thr_vec[thr_no];
        size_t k = 0;    

        for (auto& it : Open)
            if (it->obj == 1) 
                thr_vec[k % thr_no].push_back(it), ++k;
        k = min(k, thr_no);

        for (size_t i = 0; i < k; ++i)
            thr_obj[i] = thread(&HybridBnBSolver::ThreadCallback, this, &thr_vec[i]); 

        for (size_t i = 0; i < k; ++i)
            thr_obj[i].join();

        sort(Open.begin(), Open.end(), [](BnBNode*& l, BnBNode*& r)
        { 
            return l->obj < r->obj; 
        });

        while (Open.size() && Open.back()->obj > 0)
            Open.pop_back();

        vector<BnBNode*> v; 
        for (size_t i = 0; Open.size() && i < thr_no; ++i)
            v.push_back(Open.back()), Open.pop_back();

        return v;
        //return (node->obj < 1) ? node : nullptr;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %r13
movsd 0x118(%rsi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x43ea5
jnp 0x43fba
movq %rsp, -0x70(%rbp)
movq 0x150(%r14), %r15
movq %rsp, %rbx
leaq 0xf(,%r15,8), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
testq %r15, %r15
je 0x43edc
leaq (,%r15,8), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x91c0
movq %rbx, -0x40(%rbp)
movq 0x150(%r14), %rdx
movq %rsp, %rbx
leaq (%rdx,%rdx,2), %rax
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rbx
movq %rbx, %rsp
movq %rdx, -0x30(%rbp)
testq %rdx, %rdx
je 0x43f38
leaq -0x18(,%rax,8), %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x91c0
movq %rbx, -0x38(%rbp)
movq %r13, -0x50(%rbp)
movq 0x160(%r14), %rbx
movq 0x168(%r14), %r12
xorl %r13d, %r13d
cmpq %r12, %rbx
je 0x44044
movq (%rbx), %rcx
movsd 0x60(%rcx), %xmm0
ucomisd 0x1848e(%rip), %xmm0    # 0x5c3f8
jne 0x43fa5
jp 0x43fa5
movq %r13, %rax
xorl %edx, %edx
divq 0x150(%r14)
leaq (%rdx,%rdx,2), %rax
movq -0x38(%rbp), %rdx
leaq (%rdx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x43f9a
movq %rcx, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x43fa2
movq %rbx, %rdx
callq 0x45a56
incq %r13
addq $0x8, %rbx
cmpq %r12, %rbx
jne 0x43f5a
movq 0x150(%r14), %rax
jmp 0x44048
movq 0x168(%r14), %rax
leaq -0x8(%rax), %rcx
movq -0x8(%rax), %r15
movq %r15, -0x60(%rbp)
movq %rcx, 0x168(%r14)
subq 0x160(%r14), %rcx
cmpq $0x9, %rcx
jb 0x4434c
movq -0x10(%rax), %r12
movq %r12, -0x48(%rbp)
movsd 0x60(%r15), %xmm0
ucomisd 0x183fd(%rip), %xmm0    # 0x5c3f8
jne 0x4402d
jp 0x4402d
movq (%r14), %rax
movsd 0x19826(%rip), %xmm0    # 0x5d830
movsd 0x2aea6(%rip), %xmm1    # 0x6eeb8
movq %r14, %rdi
movq %r15, %rsi
callq *0x28(%rax)
testb %al, %al
jne 0x4402d
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0x60(%r15)
movq 0x48(%r15), %rax
cmpq 0x48(%r12), %rax
je 0x44290
movq %r15, %rbx
jmp 0x44349
movq -0x30(%rbp), %rax
cmpq %r13, %rax
cmovbq %rax, %r13
testq %r13, %r13
movq -0x38(%rbp), %r12
je 0x440ca
movq %r12, %rbx
xorl %r12d, %r12d
leaq -0x24d(%rip), %rax      # 0x43e18
movq %rax, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq %r14, -0x80(%rbp)
movq %rbx, -0x78(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x80(%rbp), %rdx
leaq -0x78(%rbp), %rcx
callq 0x451f2
movq -0x40(%rbp), %rcx
cmpq $0x0, (%rcx,%r12,8)
jne 0x4446e
movq -0x48(%rbp), %rax
movq %rax, (%rcx,%r12,8)
incq %r12
addq $0x18, %rbx
cmpq %r12, %r13
jne 0x4405e
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %r12
movq %rbx, %rdi
callq 0x9630
addq $0x8, %rbx
decq %r13
jne 0x440b9
movq 0x160(%r14), %rdi
movq 0x168(%r14), %r13
cmpq %r13, %rdi
je 0x44170
movq %r13, %rbx
subq %rdi, %rbx
movq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rdi, -0x68(%rbp)
movq %r13, %rsi
callq 0x44db6
cmpq $0x81, %rbx
jl 0x44164
movq -0x68(%rbp), %rdi
leaq 0x80(%rdi), %rbx
movq %rbx, %rsi
callq 0x45007
cmpq %r13, %rbx
je 0x44170
movq -0x8(%rbx), %rcx
movq (%rbx), %rax
movsd 0x60(%rax), %xmm0
movsd 0x60(%rcx), %xmm1
ucomisd %xmm0, %xmm1
movq %rbx, %rdx
jbe 0x4415b
movq %rbx, %rdx
movq %rcx, (%rdx)
movq -0x10(%rdx), %rcx
movsd 0x60(%rcx), %xmm1
addq $-0x8, %rdx
ucomisd %xmm0, %xmm1
ja 0x44145
movq %rax, (%rdx)
addq $0x8, %rbx
jmp 0x44123
movq -0x68(%rbp), %rdi
movq %r13, %rsi
callq 0x45007
movq 0x160(%r14), %rax
movq 0x168(%r14), %rdx
cmpq %rax, %rdx
je 0x441b9
addq $-0x8, %rdx
xorpd %xmm0, %xmm0
movq -0x50(%rbp), %r13
movq (%rdx), %rcx
movsd 0x60(%rcx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x441bf
movq %rdx, 0x168(%r14)
leaq -0x8(%rdx), %rcx
cmpq %rax, %rdx
movq %rcx, %rdx
jne 0x4418f
addq $0x8, %rcx
movq %rcx, %rdx
jmp 0x441c3
movq -0x50(%rbp), %r13
jmp 0x441c3
addq $0x8, %rdx
xorpd %xmm0, %xmm0
movupd %xmm0, (%r13)
movq $0x0, 0x10(%r13)
cmpq %rax, %rdx
je 0x4423a
cmpq $0x0, 0x150(%r14)
je 0x4423a
movl $0x1, %ebx
addq $-0x8, %rdx
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x44204
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r13)
jmp 0x4420c
movq %r13, %rdi
callq 0x45a56
movq 0x150(%r14), %rax
movq 0x168(%r14), %rdx
addq $-0x8, %rdx
movq %rdx, 0x168(%r14)
cmpq 0x160(%r14), %rdx
je 0x4423a
leaq 0x1(%rbx), %rcx
cmpq %rax, %rbx
movq %rcx, %rbx
jb 0x441e9
movq -0x30(%rbp), %rax
testq %rax, %rax
je 0x44268
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbx
movq -0x18(%r12,%rbx), %rdi
testq %rdi, %rdi
je 0x44262
movq -0x8(%r12,%rbx), %rsi
subq %rdi, %rsi
callq 0x9350
addq $-0x18, %rbx
jne 0x4424b
testq %r15, %r15
movq -0x40(%rbp), %rax
je 0x44287
shlq $0x3, %r15
cmpq $0x0, -0x8(%rax,%r15)
jne 0x4446e
addq $-0x8, %r15
jne 0x44275
movq -0x70(%rbp), %rsp
jmp 0x443c2
addq $-0x8, 0x168(%r14)
movsd 0x60(%r12), %xmm0
ucomisd 0x18151(%rip), %xmm0    # 0x5c3f8
jne 0x442eb
jp 0x442eb
movq (%r14), %rax
movsd 0x1957a(%rip), %xmm0    # 0x5d830
movsd 0x2abfa(%rip), %xmm1    # 0x6eeb8
movq %r14, %rdi
movq %r12, %rsi
callq *0x28(%rax)
testb %al, %al
je 0x442d4
movsd 0x60(%r12), %xmm0
jmp 0x442eb
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0x60(%r12)
movsd 0x2abd5(%rip), %xmm0    # 0x6eec0
movsd 0x60(%r15), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x44304
movq %r12, -0x60(%rbp)
movq %r15, -0x48(%rbp)
movq %r12, %rbx
jmp 0x4430e
movq %r15, %rbx
movapd %xmm0, %xmm1
movq %r12, %r15
movsd 0x180e2(%rip), %xmm0    # 0x5c3f8
ucomisd %xmm1, %xmm0
jbe 0x44349
movq 0x168(%r14), %rsi
cmpq 0x170(%r14), %rsi
je 0x44339
movq %r15, (%rsi)
addq $0x8, 0x168(%r14)
jmp 0x44349
leaq 0x160(%r14), %rdi
leaq -0x48(%rbp), %rdx
callq 0x45a56
movq %rbx, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%r13)
movq $0x0, 0x10(%r13)
movsd 0x60(%r15), %xmm0
ucomisd 0x2ab54(%rip), %xmm0    # 0x6eec0
jne 0x44370
jnp 0x443c2
ucomisd 0x18080(%rip), %xmm0    # 0x5c3f8
jne 0x443b4
jp 0x443b4
movq (%r14), %rax
movsd 0x194a9(%rip), %xmm0    # 0x5d830
movsd 0x2ab29(%rip), %xmm1    # 0x6eeb8
movq %r14, %rdi
movq %r15, %rsi
callq *0x28(%rax)
testb %al, %al
je 0x443c2
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x443b6
movq -0x60(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r13)
jmp 0x443c2
xorl %esi, %esi
leaq -0x60(%rbp), %rdx
movq %r13, %rdi
callq 0x45a56
movq %r13, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%r13), %rdi
testq %rdi, %rdi
je 0x44466
movq 0x10(%r13), %rsi
subq %rdi, %rsi
callq 0x9350
jmp 0x44466
jmp 0x44414
movq %rax, %r14
movq (%r13), %rdi
testq %rdi, %rdi
je 0x44417
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x9350
jmp 0x44417
jmp 0x44414
movq %rax, %r14
cmpq $0x0, -0x30(%rbp)
movq -0x38(%rbp), %r12
je 0x4444b
movq -0x30(%rbp), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbx
movq -0x18(%r12,%rbx), %rdi
testq %rdi, %rdi
je 0x44445
movq -0x8(%r12,%rbx), %rsi
subq %rdi, %rsi
callq 0x9350
addq $-0x18, %rbx
jne 0x4442e
testq %r15, %r15
je 0x44466
shlq $0x3, %r15
movq -0x40(%rbp), %rax
cmpq $0x0, -0x8(%rax,%r15)
jne 0x4446e
addq $-0x8, %r15
jne 0x44458
movq %r14, %rdi
callq 0x9680
callq 0x90d0