// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movsd 0x118(%rsi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x44651
jnp 0x44876
movq %rsp, -0x68(%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 0x44688
leaq (,%r15,8), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x91c0
movq %rbx, -0x50(%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, -0x58(%rbp)
testq %rdx, %rdx
je 0x446e4
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, -0x48(%rbp)
movq %r12, -0x60(%rbp)
movq 0x160(%r14), %rbx
movq 0x168(%r14), %r12
xorl %r13d, %r13d
cmpq %r12, %rbx
je 0x44753
movq (%rbx), %rcx
movsd 0x60(%rcx), %xmm0
ucomisd 0x17c96(%rip), %xmm0    # 0x5c3a8
jne 0x4474d
jp 0x4474d
movq %r13, %rax
xorl %edx, %edx
divq 0x150(%r14)
leaq (%rdx,%rdx,2), %rax
movq -0x48(%rbp), %rdx
leaq (%rdx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x44742
movq %rcx, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x4474a
movq %rbx, %rdx
callq 0x462ac
incq %r13
addq $0x8, %rbx
jmp 0x446fd
movq 0x150(%r14), %rax
cmpq %r13, %rax
cmovbq %rax, %r13
testq %r13, %r13
je 0x447d5
xorl %r12d, %r12d
movq -0x48(%rbp), %rbx
leaq -0x1b0(%rip), %rax      # 0x445c4
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq %r14, -0x78(%rbp)
movq %rbx, -0x70(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x78(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x45a40
movq -0x50(%rbp), %rcx
cmpq $0x0, (%rcx,%r12,8)
jne 0x44bfe
movq -0x30(%rbp), %rax
movq %rax, (%rcx,%r12,8)
incq %r12
addq $0x18, %rbx
cmpq %r12, %r13
jne 0x4476d
movq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x9620
addq $0x8, %rbx
decq %r13
jne 0x447c4
movq 0x160(%r14), %r12
movq 0x168(%r14), %r13
cmpq %r13, %r12
je 0x449a9
movq %r13, %rbx
subq %r12, %rbx
movq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x455c2
cmpq $0x81, %rbx
jl 0x4499e
leaq 0x80(%r12), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x45846
cmpq %r13, %rbx
je 0x449a9
movq -0x8(%rbx), %rcx
movq (%rbx), %rax
movsd 0x60(%rax), %xmm0
movsd 0x60(%rcx), %xmm1
ucomisd %xmm0, %xmm1
movq %rbx, %rdx
jbe 0x4486d
movq %rbx, %rdx
movq %rcx, (%rdx)
movq -0x10(%rdx), %rcx
movsd 0x60(%rcx), %xmm1
addq $-0x8, %rdx
ucomisd %xmm0, %xmm1
ja 0x44857
movq %rax, (%rdx)
addq $0x8, %rbx
jmp 0x44831
movq 0x168(%r14), %rax
leaq -0x8(%rax), %rcx
movq -0x8(%rax), %rsi
movq %rsi, -0x40(%rbp)
movq %rcx, 0x168(%r14)
subq 0x160(%r14), %rcx
cmpq $0x9, %rcx
jb 0x44ad9
movq -0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movsd 0x60(%rsi), %xmm0
ucomisd 0x17af2(%rip), %xmm0    # 0x5c3a8
jne 0x448e9
jp 0x448e9
movq (%r14), %rax
movsd 0x19043(%rip), %xmm0    # 0x5d908
movsd 0x2b93b(%rip), %xmm1    # 0x70208
movq %r14, %rdi
callq *0x28(%rax)
testb %al, %al
jne 0x448e9
movq -0x40(%rbp), %rax
movabsq $0x4000000000000000, %rcx # imm = 0x4000000000000000
movq %rcx, 0x60(%rax)
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rsi
cmpq 0x48(%rsi), %rax
jne 0x44ad9
addq $-0x8, 0x168(%r14)
movsd 0x60(%rsi), %xmm0
ucomisd 0x17a94(%rip), %xmm0    # 0x5c3a8
jne 0x44947
jp 0x44947
movq (%r14), %rax
movsd 0x18fe5(%rip), %xmm0    # 0x5d908
movsd 0x2b8dd(%rip), %xmm1    # 0x70208
movq %r14, %rdi
callq *0x28(%rax)
testb %al, %al
jne 0x44947
movq -0x30(%rbp), %rax
movabsq $0x4000000000000000, %rcx # imm = 0x4000000000000000
movq %rcx, 0x60(%rax)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
movsd 0x60(%rcx), %xmm0
ucomisd 0x60(%rax), %xmm0
jbe 0x44963
movq %rcx, -0x40(%rbp)
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsd 0x17a39(%rip), %xmm0    # 0x5c3a8
ucomisd 0x60(%rax), %xmm0
jbe 0x44ad9
movq 0x168(%r14), %rsi
cmpq 0x170(%r14), %rsi
je 0x44ac9
movq %rax, (%rsi)
addq $0x8, 0x168(%r14)
jmp 0x44ad9
movq %r12, %rdi
movq %r13, %rsi
callq 0x45846
movq 0x160(%r14), %rax
movq 0x168(%r14), %rcx
cmpq %rax, %rcx
je 0x449e5
addq $-0x8, %rcx
xorpd %xmm0, %xmm0
movq (%rcx), %rdx
movsd 0x60(%rdx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x449e5
movq %rcx, 0x168(%r14)
leaq -0x8(%rcx), %rdx
cmpq %rax, %rcx
movq %rdx, %rcx
jne 0x449c4
xorpd %xmm0, %xmm0
movq -0x60(%rbp), %r12
movupd %xmm0, (%r12)
movq $0x0, 0x10(%r12)
movq 0x168(%r14), %rdx
cmpq 0x160(%r14), %rdx
movq -0x48(%rbp), %r13
je 0x44a73
cmpq $0x0, 0x150(%r14)
je 0x44a73
movl $0x1, %ebx
addq $-0x8, %rdx
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x44a3d
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x44a45
movq %r12, %rdi
callq 0x462ac
movq 0x150(%r14), %rax
movq 0x168(%r14), %rdx
addq $-0x8, %rdx
movq %rdx, 0x168(%r14)
cmpq 0x160(%r14), %rdx
je 0x44a73
leaq 0x1(%rbx), %rcx
cmpq %rax, %rbx
movq %rcx, %rbx
jb 0x44a1f
movq -0x58(%rbp), %rax
testq %rax, %rax
je 0x44aa1
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbx
movq -0x18(%r13,%rbx), %rdi
testq %rdi, %rdi
je 0x44a9b
movq -0x8(%r13,%rbx), %rsi
subq %rdi, %rsi
callq 0x9340
addq $-0x18, %rbx
jne 0x44a84
testq %r15, %r15
movq -0x50(%rbp), %rax
je 0x44ac0
shlq $0x3, %r15
cmpq $0x0, -0x8(%rax,%r15)
jne 0x44bfe
addq $-0x8, %r15
jne 0x44aae
movq -0x68(%rbp), %rsp
jmp 0x44b51
leaq 0x160(%r14), %rdi
leaq -0x30(%rbp), %rdx
callq 0x462ac
xorpd %xmm0, %xmm0
movupd %xmm0, (%r12)
movq $0x0, 0x10(%r12)
movq -0x40(%rbp), %rsi
movsd 0x60(%rsi), %xmm0
ucomisd 0x2b713(%rip), %xmm0    # 0x70210
jne 0x44b01
jnp 0x44b51
ucomisd 0x1789f(%rip), %xmm0    # 0x5c3a8
jne 0x44b2a
jp 0x44b2a
movq (%r14), %rax
movsd 0x18df0(%rip), %xmm0    # 0x5d908
movsd 0x2b6e8(%rip), %xmm1    # 0x70208
movq %r14, %rdi
callq *0x28(%rax)
testb %al, %al
je 0x44b51
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x44b45
movq -0x40(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x44b51
leaq -0x40(%rbp), %rdx
movq %r12, %rdi
callq 0x462ac
movq %r12, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%r12), %rdi
testq %rdi, %rdi
je 0x44bf6
movq 0x10(%r12), %rsi
subq %rdi, %rsi
callq 0x9340
jmp 0x44bf6
jmp 0x44ba4
movq %rax, %r14
movq (%r12), %rdi
testq %rdi, %rdi
je 0x44ba7
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x9340
jmp 0x44ba7
jmp 0x44ba4
movq %rax, %r14
cmpq $0x0, -0x58(%rbp)
movq -0x48(%rbp), %r12
je 0x44bdb
movq -0x58(%rbp), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbx
movq -0x18(%r12,%rbx), %rdi
testq %rdi, %rdi
je 0x44bd5
movq -0x8(%r12,%rbx), %rsi
subq %rdi, %rsi
callq 0x9340
addq $-0x18, %rbx
jne 0x44bbe
testq %r15, %r15
je 0x44bf6
shlq $0x3, %r15
movq -0x50(%rbp), %rax
cmpq $0x0, -0x8(%rax,%r15)
jne 0x44bfe
addq $-0x8, %r15
jne 0x44be8
movq %r14, %rdi
callq 0x9670
callq 0x90d0