// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %r8, -0x60(%rbp)
movq %rcx, -0x58(%rbp)
movq %rdx, -0x68(%rbp)
movq %rdi, %r15
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rsi), %r12
movq 0x8(%rsi), %rcx
cmpq %rcx, %r12
je 0x6fb58
movq %r15, -0x50(%rbp)
movq %rcx, -0x48(%rbp)
movq (%r12), %rax
movq %rax, -0x38(%rbp)
cmpl $0x3, 0x3c(%rax)
ja 0x6fb4b
movq 0x40(%rax), %rdi
leaq 0x86a7(%rip), %rsi      # 0x77f34
callq 0x6e968
movq -0x38(%rbp), %rcx
movq 0x40(%rcx), %rdi
testb %al, %al
je 0x6f8c4
testq %rdi, %rdi
je 0x6f9b7
leaq 0x1ce02(%rip), %rsi     # 0x8c6b0
leaq 0x1db6b(%rip), %rdx     # 0x8d420
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r13
jmp 0x6f9ba
leaq 0x6545(%rip), %rsi      # 0x75e10
callq 0x6e968
testb %al, %al
je 0x6fb89
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rdi
leaq 0x1cdc9(%rip), %rsi     # 0x8c6b0
leaq 0x1dc0a(%rip), %rdx     # 0x8d4f8
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r13
movq 0x80(%rax), %rax
movq 0x40(%rax), %rsi
movq -0x58(%rbp), %rdi
callq 0x6e750
movq 0x80(%r13), %rcx
movq 0x40(%rcx), %rsi
testq %rax, %rax
je 0x6fab5
movq -0x58(%rbp), %rdi
callq 0x6e750
testq %rax, %rax
je 0x6fbe4
movq 0x28(%rax), %rax
movq 0x48(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq (%rax), %r14
callq 0x2e060
movq %rax, %r13
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r14, %rdi
leaq -0x40(%rbp), %rsi
movl $0xa, %edx
callq 0x2e570
cmpq %r14, -0x40(%rbp)
je 0x6fbd8
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x6fbcc
movl (%r13), %ecx
cmpl $0x22, %ecx
je 0x6fbcc
testl %ecx, %ecx
jne 0x6f99f
movl %ebx, (%r13)
movl %eax, -0x2c(%rbp)
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x70980
jmp 0x6fb47
xorl %r13d, %r13d
movq 0x40(%r13), %rax
movq 0x40(%rax), %rsi
movq -0x68(%rbp), %rdi
callq 0x720be
movq %r12, -0x70(%rbp)
testq %rax, %rax
je 0x6fbc0
movq 0x28(%rax), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r14
cmpq %r14, %rbx
je 0x6fb6a
movq 0x48(%r13), %rax
movq 0x40(%rax), %r15
movq 0x8(%r15), %r13
movq (%rbx), %r12
movq 0x40(%r12), %rax
movq 0x40(%rax), %rax
cmpq %r13, 0x8(%rax)
jne 0x6fa21
testq %r13, %r13
je 0x6fa2f
movq (%r15), %rsi
movq (%rax), %rdi
movq %r13, %rdx
callq 0x2e3c0
testl %eax, %eax
je 0x6fa2f
addq $0x8, %rbx
cmpq %r14, %rbx
jne 0x6f9f8
jmp 0x6fb6a
movq 0x48(%r12), %rax
movq 0x40(%rax), %rax
movq (%rax), %r14
callq 0x2e060
movq %rax, %r13
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r14, %rdi
leaq -0x40(%rbp), %rsi
movl $0xa, %edx
callq 0x2e570
cmpq %r14, -0x40(%rbp)
je 0x6fbb4
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
movq -0x50(%rbp), %r15
movq -0x70(%rbp), %r12
jb 0x6fba8
movl (%r13), %ecx
cmpl $0x22, %ecx
je 0x6fba8
testl %ecx, %ecx
jne 0x6fa9d
movl %ebx, (%r13)
movl %eax, -0x2c(%rbp)
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x70980
jmp 0x6fb47
movq -0x60(%rbp), %rdi
callq 0x6e85c
testq %rax, %rax
je 0x6fc08
movq 0x28(%rax), %rax
movq 0x48(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq (%rax), %r14
callq 0x2e060
movq %rax, %r13
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r14, %rdi
leaq -0x40(%rbp), %rsi
movl $0xa, %edx
callq 0x2e570
cmpq %r14, -0x40(%rbp)
je 0x6fbfc
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x6fbf0
movl (%r13), %ecx
cmpl $0x22, %ecx
je 0x6fbf0
testl %ecx, %ecx
jne 0x6fb34
movl %ebx, (%r13)
movl %eax, -0x2c(%rbp)
movq %r15, %rdi
leaq -0x38(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0x70980
movq -0x48(%rbp), %rcx
addq $0x8, %r12
cmpq %rcx, %r12
jne 0x6f870
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6030(%rip), %rdi      # 0x75ba1
leaq 0xa791(%rip), %rsi      # 0x7a309
leaq 0xa7a5(%rip), %rcx      # 0x7a324
movl $0x111, %edx            # imm = 0x111
callq 0x2e2a0
leaq 0xa87b(%rip), %rdi      # 0x7a40b
leaq 0xa772(%rip), %rsi      # 0x7a309
leaq 0xa786(%rip), %rcx      # 0x7a324
movl $0x11d, %edx            # imm = 0x11D
callq 0x2e2a0
leaq 0x6289(%rip), %rdi      # 0x75e38
callq 0x2e5c0
leaq 0x627d(%rip), %rdi      # 0x75e38
callq 0x2e260
leaq 0x94ed(%rip), %rdi      # 0x790b4
callq 0x2e5c0
leaq 0x6265(%rip), %rdi      # 0x75e38
callq 0x2e5c0
leaq 0x6259(%rip), %rdi      # 0x75e38
callq 0x2e260
leaq 0x94c9(%rip), %rdi      # 0x790b4
callq 0x2e5c0
leaq 0x6241(%rip), %rdi      # 0x75e38
callq 0x2e5c0
leaq 0x6235(%rip), %rdi      # 0x75e38
callq 0x2e260
leaq 0x94a5(%rip), %rdi      # 0x790b4
callq 0x2e5c0
jmp 0x6fc3c
jmp 0x6fc3c
jmp 0x6fc3c
jmp 0x6fc3c
jmp 0x6fc3c
jmp 0x6fc3c
jmp 0x6fc2c
jmp 0x6fc3c
jmp 0x6fc3c
jmp 0x6fc3c
jmp 0x6fc3c
jmp 0x6fc2c
movq %rax, %r14
cmpl $0x0, (%r13)
jne 0x6fc3f
movl %ebx, (%r13)
jmp 0x6fc3f
movq %rax, %r14
movq -0x50(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6fc50
callq 0x2e360
movq %r14, %rdi
callq 0x2e730