// File: /workspace/github_cpp_makefile_star2_O3/eniac[P]Mantis/src/compile/compile_p4.cpp
// Function: runBinPackForIng(std::vector<std::pair<ReactionArgNode*, int>, std::allocator<std::pair<ReactionArgNode*, int>>>*, std::vector<AstNode*, std::allocator<AstNode*>>, bool)
static vector<ReactionArgBin> runBinPackForIng(
            vector<pair<ReactionArgNode*, int> >* argSizes, vector<AstNode*> nodeArray, bool forIng) {

    sort(argSizes->begin(), argSizes->end(),
            [](const pair<ReactionArgNode*, int>& l,
               const pair<ReactionArgNode*, int>& r) {
                if (l.second != r.second) {
                    return l.second > r.second;
                }
                return l.first > r.first;
            });

    vector<ReactionArgBin> bins;
    for (const pair<ReactionArgNode*, int>& p : *argSizes) {
        assert(p.second <= REGISTER_SIZE);

        // Packing
        if(forIng) {
            if(p.first->argType_!=ReactionArgNode::INGRESS_FIELD && p.first->argType_!=ReactionArgNode::INGRESS_MBL_FIELD) {
                continue;
            }
        } else {
            if(p.first->argType_!=ReactionArgNode::EGRESS_FIELD && p.first->argType_!=ReactionArgNode::EGRESS_MBL_FIELD) {
                continue;
            }
        }

        bool added = false;
        for (ReactionArgBin& bin : bins) {
            if (p.second + bin.second <= REGISTER_SIZE) {
                bin.first.push_back(p);
                bin.second += p.second;
                added = true;
                break;
            }
        }

        if (!added) {
            vector<ReactionArgSize> newBin;
            newBin.push_back(p);
            bins.emplace_back(move(newBin), p.second);
        }
    }

    return bins;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, -0x34(%rbp)
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %r13
movq 0x8(%rsi), %r15
cmpq %r15, %r13
je 0x697d3
movq %r14, -0x30(%rbp)
movq %r15, %r14
subq %r13, %r14
movq %r14, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x6d9d6
cmpq $0x101, %r14            # imm = 0x101
jl 0x697c4
leaq 0x100(%r13), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x6ddbf
cmpq %r15, %r12
movq -0x30(%rbp), %r14
je 0x697d3
movq %r12, %rdi
callq 0x6de64
addq $0x10, %r12
cmpq %r15, %r12
jne 0x697b1
jmp 0x697d3
movq %r13, %rdi
movq %r15, %rsi
callq 0x6ddbf
movq -0x30(%rbp), %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq (%r14), %r15
movq 0x8(%r14), %rax
movq %rax, -0x30(%rbp)
cmpq %rax, %r15
je 0x698c4
leaq -0x50(%rbp), %r14
movl 0x8(%r15), %eax
cmpl $0x21, %eax
jge 0x698d3
movq (%r15), %rcx
movl 0x3c(%rcx), %ecx
cmpb $0x0, -0x34(%rbp)
je 0x6981f
testl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
je 0x6982b
jmp 0x698b6
orl $0x2, %ecx
cmpl $0x3, %ecx
jne 0x698b6
leaq 0x8(%r15), %r13
movq (%rbx), %r12
movq 0x8(%rbx), %rcx
cmpq %rcx, %r12
je 0x6984d
movl 0x18(%r12), %edx
addl %eax, %edx
cmpl $0x20, %edx
jle 0x69887
addq $0x20, %r12
jmp 0x69836
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x6df88
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x6df3e
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x698b6
callq 0x2e360
jmp 0x698b6
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x698a2
movups (%r15), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r12)
jmp 0x698ad
movq %r12, %rdi
movq %r15, %rdx
callq 0x6df88
movl (%r13), %eax
addl %eax, 0x18(%r12)
addq $0x10, %r15
cmpq -0x30(%rbp), %r15
jne 0x697f9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x105e5(%rip), %rdi     # 0x79ebf
leaq 0x100ae(%rip), %rsi     # 0x7998f
leaq 0x105f1(%rip), %rcx     # 0x79ed9
movl $0x354, %edx            # imm = 0x354
callq 0x2e2a0
movq %rax, %r14
jmp 0x69908
movq %rax, %r14
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x69908
callq 0x2e360
movq %rbx, %rdi
callq 0x3f588
movq %r14, %rdi
callq 0x2e730