// File: eniac[P]Mantis/src/compile/compile_c.cpp
// Function: generateHdlPool(std::vector<AstNode*, std::allocator<AstNode*>>, std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>&, int, int)
void generateHdlPool(std::vector<AstNode*> nodeArray, ostringstream& oss_mbl_init, int ing_iso_opt, int egr_iso_opt) {
    // Max number of alts
    for (auto n : nodeArray) {
        if (typeContains(n, "P4RMalleableFieldNode")) {
            auto v = dynamic_cast<P4RMalleableFieldNode*>(n);

            string var_name = *v->name_->word_;

            int num_alt = 0;

            for (FieldNode* tmp_alt : *v->varAlts_->fields_->list_) {
                num_alt += 1;
            }
            PRINT_VERBOSE("Number of alts for %s: %d \n", var_name.c_str(), num_alt);
            if(num_alt > num_max_alts) {
                num_max_alts = num_alt;
            }            
       }
    }

    if(((unsigned int)ing_iso_opt) & 0b10 || ((unsigned int)egr_iso_opt) & 0b10) {
        oss_mbl_init << "  bool __mantis__indicator_hdls"
                     << "[" << std::to_string(kNumUserHdls) << "];\n";
    }    
    // Malloc handler array over linked list for random access, memoization cache omitted
    // oss_mbl_init << "  hdls = (uint32_t *)calloc("
    //              << kNumUserHdls << "*2*" << std::to_string(num_max_alts)
    //              << ", sizeof(uint32_t)"
    //              << ");\n\n";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %rdi, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb2ae0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb2b10
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb2b40
testb $0x1, %al
jne 0xe121d
jmp 0xe1345
leaq -0x28(%rbp), %rdi
callq 0xb2b80
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
leaq 0x5afb8(%rip), %rsi     # 0x13c1f0
callq 0x12c730
testb $0x1, %al
jne 0xe1246
jmp 0xe1335
movq -0x38(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0xe127e
movq -0xc0(%rbp), %rdi
leaq 0x9137b(%rip), %rsi     # 0x1725e0
leaq 0x920fc(%rip), %rdx     # 0x173368
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0xc8(%rbp)
jmp 0xe1289
xorl %eax, %eax
movq %rax, -0xc8(%rbp)
jmp 0xe1289
movq -0xc8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0xaa290
movl $0x0, -0x64(%rbp)
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0xb7b80
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
callq 0xb7a10
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xcb0f0
testb $0x1, %al
jne 0xe12f1
jmp 0xe1318
leaq -0x78(%rbp), %rdi
callq 0xcb130
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xcb150
jmp 0xe12de
movl -0x64(%rbp), %eax
cmpl 0x9330f(%rip), %eax     # 0x174630
jle 0xe132c
movl -0x64(%rbp), %eax
movl %eax, 0x93304(%rip)     # 0x174630
leaq -0x60(%rbp), %rdi
callq 0xaabe8
jmp 0xe1337
leaq -0x28(%rbp), %rdi
callq 0xb2ba0
jmp 0xe1207
movl -0x14(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0xe135f
movl -0x18(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xe13fd
movq -0x10(%rbp), %rdi
leaq 0x5af65(%rip), %rsi     # 0x13c2cf
callq 0xaa540
movq %rax, %rdi
leaq 0x5ab07(%rip), %rsi     # 0x13be80
callq 0xaa540
movq %rax, -0xe0(%rbp)
movl 0x932ad(%rip), %esi     # 0x174638
leaq -0xa8(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0xc0780
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
callq 0xaa4c0
movq %rax, -0xd0(%rbp)
jmp 0xe13ba
movq -0xd0(%rbp), %rdi
leaq 0x5aae1(%rip), %rsi     # 0x13bea9
callq 0xaa540
jmp 0xe13cf
leaq -0xa8(%rbp), %rdi
callq 0xaabe8
jmp 0xe13fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xaabe8
jmp 0xe1406
addq $0xe0, %rsp
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0xaaa60
nopw %cs:(%rax,%rax)