// File: /workspace/github_cpp_makefile_star2_O1/eniac[P]Mantis/src/compile/find_nodes.cpp
// Function: findAllReactionArgSizes(std::vector<ReactionArgNode*, std::allocator<ReactionArgNode*>> const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<FieldDecNode*, std::allocator<FieldDecNode*>>*, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::vector<FieldDecNode*, std::allocator<FieldDecNode*>>*>>> const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, P4RMalleableValueNode*, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, P4RMalleableValueNode*>>> const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, P4RMalleableFieldNode*, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, P4RMalleableFieldNode*>>> const&)
vector<pair<ReactionArgNode*, int> > findAllReactionArgSizes(
            const vector<ReactionArgNode*>& reactionArgs,
            const HeaderDecsMap& headerDecsMap,
            const unordered_map<string, P4RMalleableValueNode*>& mblValues,
            const unordered_map<string, P4RMalleableFieldNode*>& mblFields) {
    vector<pair<ReactionArgNode*, int> > argSizes;

    for (auto ra : reactionArgs) {
        switch (ra->argType_) {
        case ReactionArgNode::INGRESS_FIELD:
        case ReactionArgNode::EGRESS_FIELD:
        case ReactionArgNode::INGRESS_MBL_FIELD:
        case ReactionArgNode::EGRESS_MBL_FIELD:
            if (typeContains(ra->arg_, "FieldNode")) {
                // If it's a field node, grab from headerDecsMap
                auto fieldArg = dynamic_cast<FieldNode*>(ra->arg_);
                auto fieldDecs = headerDecsMap.at(*fieldArg->headerName_->word_);
                bool found = false;

                for (FieldDecNode* fd : *fieldDecs) {
                    if (*fd->name_->word_ == *fieldArg->fieldName_->word_) {
                        argSizes.emplace_back(ra, stoi(*fd->size_->word_));
                        found = true;
                        break;
                    }
                }
                assert(found);
            } else if (typeContains(ra->arg_, "MblRefNode")) {
                // If it's a var ref, find it
                auto varRefArg = dynamic_cast<MblRefNode*>(ra->arg_);
                if (mblValues.find(*varRefArg->name_->word_) != mblValues.end()) {
                    auto size = mblValues.at(*varRefArg->name_->word_)->varWidth_->val_->word_;
                    argSizes.emplace_back(ra, stoi(*size));
                } else {
                    auto size = mblFields.at(*varRefArg->name_->word_)->varWidth_->val_->word_;
                    argSizes.emplace_back(ra, stoi(*size));
                }
            } else {
                assert(false && "Should never happen.");
            }
            break;
        case ReactionArgNode::REGISTER:
            // Not taken into account when bin-packing
            break;
        }
    }

    return argSizes;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, -0x60(%rbp)
movq %rcx, -0x58(%rbp)
movq %rdx, -0x68(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, -0x38(%rbp)
movq $0x0, 0x10(%rdi)
movq (%rsi), %r12
movq 0x8(%rsi), %rcx
cmpq %rcx, %r12
je 0x70627
movq %rcx, -0x50(%rbp)
movq (%r12), %rax
movq %rax, -0x40(%rbp)
cmpl $0x3, 0x3c(%rax)
ja 0x7061a
movq 0x40(%rax), %rdi
leaq 0x7c13(%rip), %rsi      # 0x77f34
callq 0x6f390
movq -0x40(%rbp), %rcx
movq 0x40(%rcx), %rdi
testb %al, %al
je 0x70358
testq %rdi, %rdi
je 0x7044a
leaq 0x1c2ee(%rip), %rsi     # 0x8c630
leaq 0x1d057(%rip), %rdx     # 0x8d3a0
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r13
jmp 0x7044d
leaq 0x5ab1(%rip), %rsi      # 0x75e10
callq 0x6f390
testb %al, %al
je 0x70671
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rdi
leaq 0x1c2b5(%rip), %rsi     # 0x8c630
leaq 0x1d0f6(%rip), %rdx     # 0x8d478
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r14
movq 0x80(%rax), %rax
movq 0x40(%rax), %rsi
movq -0x58(%rbp), %rdi
callq 0x6f176
movq 0x80(%r14), %rcx
movq 0x40(%rcx), %rsi
testq %rax, %rax
je 0x70585
movq -0x58(%rbp), %rdi
callq 0x6f176
testq %rax, %rax
je 0x706b4
movq 0x28(%rax), %rax
movq 0x48(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq (%rax), %r15
callq 0x2e060
movq %rax, %r14
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r15, %rdi
leaq -0x48(%rbp), %rsi
movl $0xa, %edx
callq 0x2e570
cmpq %r15, -0x48(%rbp)
je 0x706a8
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x7069c
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x7069c
testl %ecx, %ecx
jne 0x70431
movl %ebx, (%r14)
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x714b8
jmp 0x70616
xorl %r13d, %r13d
movq 0x40(%r13), %rax
movq 0x40(%rax), %rsi
movq -0x68(%rbp), %rdi
callq 0x72c4e
testq %rax, %rax
je 0x70690
movq 0x28(%rax), %rax
movq (%rax), %rbx
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
cmpq %rax, %rbx
je 0x70652
movq %r12, -0x70(%rbp)
addq $0x8, %rbx
xorl %r14d, %r14d
movq %r13, -0x78(%rbp)
movq -0x8(%rbx), %r12
movq 0x40(%r12), %rax
movq 0x40(%rax), %rax
movq 0x48(%r13), %rcx
movq 0x40(%rcx), %rcx
movq 0x8(%rax), %rdx
cmpq 0x8(%rcx), %rdx
jne 0x704c5
testq %rdx, %rdx
je 0x704ca
movq (%rcx), %rsi
movq (%rax), %rdi
callq 0x2e3c0
testl %eax, %eax
sete %r15b
jmp 0x704cd
xorl %r15d, %r15d
jmp 0x704cd
movb $0x1, %r15b
testb %r15b, %r15b
je 0x70556
movq 0x48(%r12), %rax
movq 0x40(%rax), %rax
movq (%rax), %r13
callq 0x2e060
movq %rax, %r14
movl (%rax), %r12d
movl $0x0, (%rax)
movq %r13, %rdi
leaq -0x48(%rbp), %rsi
movl $0xa, %edx
callq 0x2e570
cmpq %r13, -0x48(%rbp)
je 0x7063a
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x70646
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x70646
testl %ecx, %ecx
movq -0x78(%rbp), %r13
jne 0x7053f
movl %r12d, (%r14)
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x714b8
movb $0x1, %r14b
cmpq -0x80(%rbp), %rbx
sete %al
orb %al, %r15b
addq $0x8, %rbx
cmpb $0x1, %r15b
jne 0x7048e
testb $0x1, %r14b
movq -0x70(%rbp), %r12
movq -0x50(%rbp), %rcx
jne 0x7061a
jmp 0x70652
movq -0x60(%rbp), %rdi
callq 0x6f282
testq %rax, %rax
je 0x706d8
movq 0x28(%rax), %rax
movq 0x48(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq (%rax), %r15
callq 0x2e060
movq %rax, %r14
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r15, %rdi
leaq -0x48(%rbp), %rsi
movl $0xa, %edx
callq 0x2e570
cmpq %r15, -0x48(%rbp)
je 0x706cc
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x706c0
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x706c0
testl %ecx, %ecx
jne 0x70602
movl %ebx, (%r14)
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x714b8
movq -0x50(%rbp), %rcx
addq $0x8, %r12
cmpq %rcx, %r12
jne 0x70304
movq -0x38(%rbp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x57f7(%rip), %rdi      # 0x75e38
callq 0x2e260
leaq 0x57eb(%rip), %rdi      # 0x75e38
callq 0x2e5c0
leaq 0x5548(%rip), %rdi      # 0x75ba1
leaq 0x9ca9(%rip), %rsi      # 0x7a309
leaq 0x9cbd(%rip), %rcx      # 0x7a324
movl $0x111, %edx            # imm = 0x111
callq 0x2e2a0
leaq 0x9d93(%rip), %rdi      # 0x7a40b
leaq 0x9c8a(%rip), %rsi      # 0x7a309
leaq 0x9c9e(%rip), %rcx      # 0x7a324
movl $0x11d, %edx            # imm = 0x11D
callq 0x2e2a0
leaq 0x8a1d(%rip), %rdi      # 0x790b4
callq 0x2e5c0
leaq 0x5795(%rip), %rdi      # 0x75e38
callq 0x2e5c0
leaq 0x5789(%rip), %rdi      # 0x75e38
callq 0x2e260
leaq 0x89f9(%rip), %rdi      # 0x790b4
callq 0x2e5c0
leaq 0x5771(%rip), %rdi      # 0x75e38
callq 0x2e5c0
leaq 0x5765(%rip), %rdi      # 0x75e38
callq 0x2e260
leaq 0x89d5(%rip), %rdi      # 0x790b4
callq 0x2e5c0
jmp 0x70708
jmp 0x70708
jmp 0x70708
jmp 0x70708
jmp 0x70708
jmp 0x70708
jmp 0x706f8
jmp 0x70708
jmp 0x70708
jmp 0x70708
movq %rax, %r15
cmpl $0x0, (%r14)
jne 0x70719
movl %ebx, (%r14)
jmp 0x70719
jmp 0x70708
movq %rax, %r15
jmp 0x70719
movq %rax, %r15
cmpl $0x0, (%r14)
jne 0x70719
movl %r12d, (%r14)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x7072a
callq 0x2e360
movq %r15, %rdi
callq 0x2e730