// File: eniac[P]Mantis/src/compile/find_nodes.cpp
// Function: findAndRemoveMalleables(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*>>>*, 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*>>>*, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, P4RMalleableTableNode*, 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, P4RMalleableTableNode*>>>*, std::vector<AstNode*, std::allocator<AstNode*>> const&)
void findAndRemoveMalleables(
            unordered_map<string, P4RMalleableValueNode*>* mblValues,
            unordered_map<string, P4RMalleableFieldNode*>* mblFields,
            unordered_map<string, P4RMalleableTableNode*>* mblTables,
            const vector<AstNode*>& astNodes) {
    // Find all the Malleables
    for (auto n : astNodes) {
        if (typeContains(n, "P4RMalleableValueNode")) {
            auto v = dynamic_cast<P4RMalleableValueNode*>(n);
            mblValues->emplace(*v->name_->word_, v);
            n->removed_ = true;
        } else if (typeContains(n, "P4RMalleableFieldNode")) {
            auto v = dynamic_cast<P4RMalleableFieldNode*>(n);
            mblFields->emplace(*v->name_->word_, v);
            n->removed_ = true;
        } else if (typeContains(n, "P4RMalleableTableNode")) {
            auto v = dynamic_cast<P4RMalleableTableNode*>(n);
            mblTables->emplace(*v->table_->name_->word_, v);
            // for a Malleable table, the parser will give both MalleableTableNode and TableNode, 
            // we need to tag the latter as Malleable
            v->table_->isMalleable_ = true;
            n->removed_ = true;
        } else if (typeContains(n, "P4RInitBlockNode")) {
            n->removed_ = true;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0xb8280
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0xb82b0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x12f810
testb $0x1, %al
jne 0x12cf93
jmp 0x12d1a0
leaq -0x30(%rbp), %rdi
callq 0x12f850
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq 0xf123(%rip), %rsi      # 0x13c0d1
callq 0x12c730
testb $0x1, %al
jne 0x12cfb9
jmp 0x12d034
movq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x12cff1
movq -0x90(%rbp), %rdi
leaq 0x45608(%rip), %rsi     # 0x1725e0
leaq 0x46359(%rip), %rdx     # 0x173338
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0x98(%rbp)
jmp 0x12cffc
xorl %eax, %eax
movq %rax, -0x98(%rbp)
jmp 0x12cffc
movq -0x98(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rsi
leaq -0x48(%rbp), %rdx
callq 0x12f920
movq %rax, -0x58(%rbp)
movb %dl, -0x50(%rbp)
movq -0x40(%rbp), %rax
movb $0x1, 0x38(%rax)
jmp 0x12d190
movq -0x40(%rbp), %rdi
leaq 0xf1b1(%rip), %rsi      # 0x13c1f0
callq 0x12c730
testb $0x1, %al
jne 0x12d04a
jmp 0x12d0c5
movq -0x40(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, %rax
je 0x12d082
movq -0xa0(%rbp), %rdi
leaq 0x45577(%rip), %rsi     # 0x1725e0
leaq 0x462f8(%rip), %rdx     # 0x173368
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0xa8(%rbp)
jmp 0x12d08d
xorl %eax, %eax
movq %rax, -0xa8(%rbp)
jmp 0x12d08d
movq -0xa8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rsi
leaq -0x60(%rbp), %rdx
callq 0x12f970
movq %rax, -0x70(%rbp)
movb %dl, -0x68(%rbp)
movq -0x40(%rbp), %rax
movb $0x1, 0x38(%rax)
jmp 0x12d18e
movq -0x40(%rbp), %rdi
leaq 0xeddd(%rip), %rsi      # 0x13bead
callq 0x12c730
testb $0x1, %al
jne 0x12d0de
jmp 0x12d16c
movq -0x40(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
je 0x12d116
movq -0xb0(%rbp), %rdi
leaq 0x454e3(%rip), %rsi     # 0x1725e0
leaq 0x4627c(%rip), %rdx     # 0x173380
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0xb8(%rbp)
jmp 0x12d121
xorl %eax, %eax
movq %rax, -0xb8(%rbp)
jmp 0x12d121
movq -0xb8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
movq -0x78(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rsi
leaq -0x78(%rbp), %rdx
callq 0x12f9c0
movq %rax, -0x88(%rbp)
movb %dl, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq 0x40(%rax), %rax
movb $0x1, 0x91(%rax)
movq -0x40(%rbp), %rax
movb $0x1, 0x38(%rax)
jmp 0x12d18c
movq -0x40(%rbp), %rdi
leaq 0x1150c(%rip), %rsi     # 0x13e683
callq 0x12c730
testb $0x1, %al
jne 0x12d182
jmp 0x12d18a
movq -0x40(%rbp), %rax
movb $0x1, 0x38(%rax)
jmp 0x12d18c
jmp 0x12d18e
jmp 0x12d190
jmp 0x12d192
leaq -0x30(%rbp), %rdi
callq 0x12f870
jmp 0x12cf7d
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)