// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movl %edx, -0x34(%rbp)
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %r13
movq 0x8(%rsi), %r15
cmpq %r15, %r13
movq %rdi, -0x30(%rbp)
je 0x6a02c
movq %r15, %rbx
subq %r13, %rbx
movq %rbx, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r13, %rdi
movq %r15, %rsi
callq 0x6e400
cmpq $0x101, %rbx            # imm = 0x101
jl 0x6a01d
leaq 0x100(%r13), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x6e7e6
cmpq %r15, %r12
movq -0x30(%rbp), %rbx
je 0x6a02c
movq %r12, %rdi
callq 0x6e88b
addq $0x10, %r12
cmpq %r15, %r12
jne 0x6a00a
jmp 0x6a02c
movq %r13, %rdi
movq %r15, %rsi
callq 0x6e7e6
movq -0x30(%rbp), %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq (%r14), %r15
movq 0x8(%r14), %rax
movq %rax, -0x58(%rbp)
cmpq %rax, %r15
je 0x6a14b
cmpl $0x21, 0x8(%r15)
jge 0x6a15d
movq (%r15), %rax
movl 0x3c(%rax), %eax
cmpb $0x0, -0x34(%rbp)
je 0x6a071
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
je 0x6a07d
jmp 0x6a13d
orl $0x2, %eax
cmpl $0x3, %eax
jne 0x6a13d
leaq 0x8(%r15), %r13
movq (%rbx), %r12
movq 0x8(%rbx), %r14
cmpq %r14, %r12
je 0x6a0ee
addq $0x20, %r12
xorl %eax, %eax
movl -0x8(%r12), %ebx
addl (%r13), %ebx
cmpl $0x20, %ebx
jg 0x6a0d4
movq -0x18(%r12), %rsi
cmpq -0x10(%r12), %rsi
je 0x6a0bc
movups (%r15), %xmm0
movups %xmm0, (%rsi)
addq $0x10, -0x18(%r12)
jmp 0x6a0c9
leaq -0x20(%r12), %rdi
movq %r15, %rdx
callq 0x6e9ae
movl (%r13), %eax
addl %eax, -0x8(%r12)
movb $0x1, %al
cmpl $0x21, %ebx
jl 0x6a0e6
leaq 0x20(%r12), %rcx
cmpq %r14, %r12
movq %rcx, %r12
jne 0x6a093
testb $0x1, %al
movq -0x30(%rbp), %rbx
jne 0x6a13d
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x48(%rbp), %rsi
testq %rsi, %rsi
je 0x6a114
movups (%r15), %xmm0
movups %xmm0, (%rsi)
addq $0x10, -0x48(%rbp)
jmp 0x6a120
leaq -0x50(%rbp), %rdi
movq %r15, %rdx
callq 0x6e9ae
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
movq %r13, %rdx
callq 0x6e964
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x6a13d
callq 0x2e360
addq $0x10, %r15
cmpq -0x58(%rbp), %r15
jne 0x6a04e
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xfd5b(%rip), %rdi      # 0x79ebf
leaq 0xf824(%rip), %rsi      # 0x7998f
leaq 0xfd67(%rip), %rcx      # 0x79ed9
movl $0x354, %edx            # imm = 0x354
callq 0x2e2a0
movq %rax, %r14
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x6a192
callq 0x2e360
jmp 0x6a192
movq %rax, %r14
movq -0x30(%rbp), %rdi
callq 0x3f9d0
movq %r14, %rdi
callq 0x2e730