// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rsi, %r14
movq %rdi, %r13
movsd 0x118(%rsi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movq %rsi, -0x30(%rbp)
jne 0x3e50b
jnp 0x3e6ff
movq %rsp, -0x78(%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 0x3e542
leaq (,%r15,8), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x91d0
movq %r15, -0x48(%rbp)
movq %rbx, -0x38(%rbp)
movq 0x150(%r14), %rcx
movq %rsp, %rbx
imulq $0x18, %rcx, %r15
leaq 0xf(%r15), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movq %rcx, -0x58(%rbp)
testq %rcx, %rcx
je 0x3e592
leaq -0x18(%r15), %rcx
pushq $0x18
popq %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
subq %rdx, %rcx
addq $0x18, %rcx
movq %rbx, %rdi
xorl %esi, %esi
movq %rcx, %rdx
callq 0x91d0
movq %r15, -0x70(%rbp)
movq %rbx, -0x40(%rbp)
movq 0x160(%r14), %rbx
movq 0x168(%r14), %r15
xorl %r14d, %r14d
cmpq %r15, %rbx
je 0x3e5ed
movq (%rbx), %rax
movsd 0x60(%rax), %xmm0
ucomisd 0x15260(%rip), %xmm0    # 0x53820
jne 0x3e5e7
jp 0x3e5e7
movq %r14, %rax
xorl %edx, %edx
movq -0x30(%rbp), %rcx
divq 0x150(%rcx)
imulq $0x18, %rdx, %rdi
addq -0x40(%rbp), %rdi
movq %rbx, %rsi
callq 0x3f4f8
incq %r14
addq $0x8, %rbx
jmp 0x3e5ab
movq %r13, -0x80(%rbp)
movq -0x30(%rbp), %rax
movq 0x150(%rax), %rax
cmpq %r14, %rax
cmovbq %rax, %r14
movq -0x38(%rbp), %r15
movq -0x40(%rbp), %rbx
movq %r14, %r13
subq $0x1, %r13
jb 0x3e671
leaq -0x19d(%rip), %rax      # 0x3e47e
movq %rax, -0x68(%rbp)
andq $0x0, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x90(%rbp)
movq %rbx, -0x88(%rbp)
leaq -0x50(%rbp), %r12
movq %r12, %rdi
leaq -0x68(%rbp), %rsi
leaq -0x90(%rbp), %rdx
leaq -0x88(%rbp), %rcx
callq 0x3f5b6
movq %r15, %rdi
movq %r12, %rsi
callq 0x3f59c
movq %r12, %rdi
callq 0x36ca4
addq $0x18, %rbx
addq $0x8, %r15
jmp 0x3e60e
movq -0x38(%rbp), %rbx
movq -0x30(%rbp), %r15
subq $0x1, %r14
jb 0x3e68d
movq %rbx, %rdi
callq 0x95f0
addq $0x8, %rbx
jmp 0x3e679
movq 0x160(%r15), %rbx
movq 0x168(%r15), %r13
cmpq %r13, %rbx
je 0x3e795
movq %r13, %r14
subq %rbx, %r14
movq %r14, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3f1f5
cmpq $0x81, %r14
jl 0x3e78a
leaq 0x80(%rbx), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3f40a
cmpq %r13, %r15
je 0x3e795
movq %r15, %rdi
callq 0x3f474
addq $0x8, %r15
jmp 0x3e6e8
movq 0x168(%r14), %rax
leaq -0x8(%rax), %rcx
movq -0x8(%rax), %r15
movq %r15, -0x68(%rbp)
movq %rcx, 0x168(%r14)
subq 0x160(%r14), %rcx
cmpq $0x9, %rcx
jb 0x3e909
movq -0x10(%rax), %r12
movq %r12, -0x50(%rbp)
movsd 0x60(%r15), %xmm0
ucomisd 0x150e0(%rip), %xmm0    # 0x53820
movabsq $0x4000000000000000, %rbx # imm = 0x4000000000000000
jne 0x3e773
jp 0x3e773
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
movsd 0x150d3(%rip), %xmm0    # 0x53830
movsd 0x2fc7b(%rip), %xmm1    # 0x6e3e0
movq %r15, %rsi
callq *0x28(%rax)
testb %al, %al
jne 0x3e773
movq %rbx, 0x60(%r15)
movq 0x48(%r15), %rax
cmpq 0x48(%r12), %rax
je 0x3e871
movq %r15, %r12
jmp 0x3e906
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3f40a
movq -0x30(%rbp), %r14
movq 0x160(%r14), %rax
movq 0x168(%r14), %rcx
addq $-0x8, %rcx
xorpd %xmm0, %xmm0
movq -0x80(%rbp), %r13
movq -0x38(%rbp), %r15
leaq 0x8(%rcx), %rsi
cmpq %rax, %rsi
je 0x3e7db
movq (%rcx), %rdx
movsd 0x60(%rdx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x3e7db
movq %rcx, 0x168(%r14)
addq $-0x8, %rcx
jmp 0x3e7b7
xorpd %xmm0, %xmm0
movupd %xmm0, (%r13)
andq $0x0, 0x10(%r13)
xorl %ebx, %ebx
cmpq %rax, %rsi
je 0x3e824
cmpq 0x150(%r14), %rbx
jae 0x3e824
addq $-0x8, %rsi
movq %r13, %rdi
callq 0x3f4f8
movq 0x160(%r14), %rax
movq 0x168(%r14), %rsi
addq $-0x8, %rsi
movq %rsi, 0x168(%r14)
incq %rbx
jmp 0x3e7ec
movq -0x58(%rbp), %rax
testq %rax, %rax
movq -0x40(%rbp), %r14
je 0x3e848
addq $-0x18, %r14
imulq $0x18, %rax, %rbx
leaq (%r14,%rbx), %rdi
callq 0x3f7d6
addq $-0x18, %rbx
jne 0x3e839
movq -0x48(%rbp), %rbx
testq %rbx, %rbx
je 0x3e868
addq $-0x8, %r15
shlq $0x3, %rbx
leaq (%r15,%rbx), %rdi
callq 0x36ca4
addq $-0x8, %rbx
jne 0x3e859
movq -0x78(%rbp), %rsp
jmp 0x3e963
movq -0x30(%rbp), %rax
addq $-0x8, 0x168(%rax)
movsd 0x60(%r12), %xmm0
ucomisd 0x14f94(%rip), %xmm0    # 0x53820
jne 0x3e8c7
jp 0x3e8c7
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
movsd 0x14f91(%rip), %xmm0    # 0x53830
movsd 0x2fb39(%rip), %xmm1    # 0x6e3e0
movq %r12, %rsi
callq *0x28(%rax)
testb %al, %al
je 0x3e8ba
movsd 0x60(%r12), %xmm0
jmp 0x3e8c7
movq %rbx, 0x60(%r12)
movsd 0x2fb21(%rip), %xmm0    # 0x6e3e8
movsd 0x60(%r15), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x3e8dd
movq %r12, -0x68(%rbp)
movq %r15, -0x50(%rbp)
jmp 0x3e8e4
movq %r15, %r12
movapd %xmm0, %xmm1
movsd 0x14f34(%rip), %xmm0    # 0x53820
ucomisd %xmm1, %xmm0
jbe 0x3e906
movq -0x30(%rbp), %rax
leaq 0x160(%rax), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3f4f8
movq %r12, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%r13)
andq $0x0, 0x10(%r13)
movsd 0x60(%r15), %xmm0
ucomisd 0x2fac2(%rip), %xmm0    # 0x6e3e8
jne 0x3e92a
jnp 0x3e963
ucomisd 0x14eee(%rip), %xmm0    # 0x53820
jne 0x3e957
jp 0x3e957
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
movsd 0x14eeb(%rip), %xmm0    # 0x53830
movsd 0x2fa93(%rip), %xmm1    # 0x6e3e0
movq %r15, %rsi
callq *0x28(%rax)
testb %al, %al
je 0x3e963
leaq -0x68(%rbp), %rsi
movq %r13, %rdi
callq 0x3f4f8
movq %r13, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r13, %rdi
callq 0x3f7d6
jmp 0x3e9de
jmp 0x3e993
movq %rax, %rbx
movq %r13, %rdi
callq 0x3f7d6
jmp 0x3e996
jmp 0x3e993
movq %rax, %rbx
cmpq $0x0, -0x58(%rbp)
movq -0x40(%rbp), %r14
movq -0x70(%rbp), %r15
je 0x3e9b8
addq $-0x18, %r14
leaq (%r14,%r15), %rdi
callq 0x3f7d6
addq $-0x18, %r15
jne 0x3e9a9
cmpq $0x0, -0x48(%rbp)
je 0x3e9de
movq -0x38(%rbp), %r14
addq $-0x8, %r14
movq -0x48(%rbp), %r15
shlq $0x3, %r15
leaq (%r14,%r15), %rdi
callq 0x36ca4
addq $-0x8, %r15
jne 0x3e9cf
movq %rbx, %rdi
callq 0x9640