// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %r8, -0x50(%rbp)
movq %rcx, -0x48(%rbp)
movq %rdx, -0x60(%rbp)
movq %rdi, %rbx
andq $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq (%rsi), %r14
movq 0x8(%rsi), %r15
leaq 0x8554(%rip), %r12      # 0x7af14
movq %rdi, -0x40(%rbp)
movq %r15, -0x58(%rbp)
cmpq %r15, %r14
je 0x72b73
movq (%r14), %rax
movq %rax, -0x38(%rbp)
cmpl $0x3, 0x3c(%rax)
ja 0x72b6a
movq 0x40(%rax), %rdi
movq %r12, %rsi
callq 0x71cf8
movq -0x38(%rbp), %rcx
movq 0x40(%rcx), %rdi
testb %al, %al
je 0x72a20
testq %rdi, %rdi
je 0x72ab6
leaq 0x21c86(%rip), %rsi     # 0x94690
leaq 0x229ef(%rip), %rdx     # 0x95400
xorl %ecx, %ecx
callq 0x41480
movq %rax, %r13
jmp 0x72ab9
leaq 0x63c9(%rip), %rsi      # 0x78df0
callq 0x71cf8
testb %al, %al
je 0x72ba4
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
leaq 0x21c4d(%rip), %rsi     # 0x94690
leaq 0x22a8e(%rip), %rdx     # 0x954d8
xorl %ecx, %ecx
callq 0x41480
movq %rax, %r13
movq 0x80(%rax), %rax
movq 0x40(%rax), %rsi
movq -0x48(%rbp), %rdi
callq 0x71b12
movq 0x80(%r13), %rcx
movq 0x40(%rcx), %rsi
testq %rax, %rax
je 0x72b35
movq -0x48(%rbp), %rdi
callq 0x7503c
movq (%rax), %rax
movq 0x48(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x49b15
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x736f4
jmp 0x72b6a
xorl %r13d, %r13d
movq 0x40(%r13), %rax
movq 0x40(%rax), %rsi
movq -0x60(%rbp), %rdi
callq 0x74f22
movq (%rax), %rax
movq (%rax), %r15
movq 0x8(%rax), %rbx
cmpq %rbx, %r15
je 0x72b85
movq (%r15), %r12
movq 0x40(%r12), %rax
movq 0x40(%rax), %rdi
movq 0x48(%r13), %rax
movq 0x40(%rax), %rsi
callq 0x619cc
addq $0x8, %r15
testb %al, %al
je 0x72ad4
movq 0x48(%r12), %rax
movq 0x40(%rax), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
movq -0x40(%rbp), %rbx
callq 0x49b15
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x736f4
movq -0x58(%rbp), %r15
leaq 0x83e1(%rip), %r12      # 0x7af14
jmp 0x72b6a
movq -0x50(%rbp), %rdi
callq 0x7505c
movq (%rax), %rax
movq 0x48(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x49b15
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x736f4
addq $0x8, %r14
jmp 0x729c8
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5ff5(%rip), %rdi      # 0x78b81
leaq 0xa806(%rip), %rsi      # 0x7d399
leaq 0xa81a(%rip), %rcx      # 0x7d3b4
movl $0x111, %edx            # imm = 0x111
callq 0x412f0
leaq 0xa8f0(%rip), %rdi      # 0x7d49b
leaq 0xa7e7(%rip), %rsi      # 0x7d399
leaq 0xa7fb(%rip), %rcx      # 0x7d3b4
movl $0x11d, %edx            # imm = 0x11D
callq 0x412f0
jmp 0x72bd8
jmp 0x72bd8
jmp 0x72bd8
jmp 0x72bd8
movq %rax, %r14
movq -0x40(%rbp), %rbx
jmp 0x72bdb
jmp 0x72bd8
jmp 0x72bd8
movq %rax, %r14
movq %rbx, %rdi
callq 0x4f7e4
movq %r14, %rdi
callq 0x41790