// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %rdi, -0x30(%rbp)
movq (%rsi), %r13
movq 0x8(%rsi), %r15
cmpq %r15, %r13
je 0x6e012
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 0x70bf1
cmpq $0x101, %r14            # imm = 0x101
jl 0x6e007
leaq 0x100(%r13), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x70f9a
cmpq %r15, %r12
je 0x6e012
movq %r12, %rdi
callq 0x71011
addq $0x10, %r12
jmp 0x6dff4
movq %r13, %rdi
movq %r15, %rsi
callq 0x70f9a
xorps %xmm0, %xmm0
movq -0x30(%rbp), %rax
andq $0x0, 0x10(%rax)
movups %xmm0, (%rax)
movq (%rbx), %r15
movq 0x8(%rbx), %r14
leaq -0x50(%rbp), %rbx
cmpq %r14, %r15
je 0x6e0d3
movl 0x8(%r15), %eax
cmpl $0x21, %eax
jge 0x6e0e6
movq (%r15), %rcx
movl 0x3c(%rcx), %ecx
cmpb $0x0, -0x34(%rbp)
je 0x6e058
testl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
je 0x6e060
jmp 0x6e0ca
orl $0x2, %ecx
cmpl $0x3, %ecx
jne 0x6e0ca
leaq 0x8(%r15), %r13
movq -0x30(%rbp), %rcx
movq (%rcx), %r12
movq 0x8(%rcx), %rcx
cmpq %rcx, %r12
je 0x6e086
movl 0x18(%r12), %edx
addl %eax, %edx
cmpl $0x20, %edx
jle 0x6e0b6
addq $0x20, %r12
jmp 0x6e06f
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x711a6
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x711ca
movq %rbx, %rdi
callq 0x4f7e4
jmp 0x6e0ca
movq %r12, %rdi
movq %r15, %rsi
callq 0x711a6
movl (%r13), %eax
addl %eax, 0x18(%r12)
addq $0x10, %r15
jmp 0x6e02c
movq -0x30(%rbp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xee62(%rip), %rdi      # 0x7cf4f
leaq 0xe92b(%rip), %rsi      # 0x7ca1f
leaq 0xee6e(%rip), %rcx      # 0x7cf69
movl $0x354, %edx            # imm = 0x354
callq 0x412f0
movq %rax, %r14
jmp 0x6e116
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0x4f7e4
movq -0x30(%rbp), %rdi
callq 0x4ec7c
movq %r14, %rdi
callq 0x41790