// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, -0x30(%rbp)
movl %edx, -0x2c(%rbp)
movq %rsi, -0x38(%rbp)
movq (%rdi), %r14
movq 0x8(%rdi), %r15
cmpq %r15, %r14
je 0x4e271
leaq -0x48(%rbp), %r13
leaq 0x29d66(%rip), %r12     # 0x77f28
movq (%r14), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6e968
testb %al, %al
je 0x4e264
testq %rbx, %rbx
je 0x4e1fa
movq %rbx, %rdi
leaq 0x3e4c9(%rip), %rsi     # 0x8c6b0
leaq 0x3f24a(%rip), %rdx     # 0x8d438
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %rbx
jmp 0x4e1fc
xorl %ebx, %ebx
movq 0x40(%rbx), %rax
movq 0x40(%rax), %rax
movq %r13, -0x58(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %rdi
callq 0x32cbc
movq 0x58(%rbx), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq 0x8(%rax), %rcx
movq (%rax), %rdx
xorl %eax, %eax
subq %rdx, %rcx
je 0x4e248
movabsq $0x7fffffff8, %rax      # imm = 0x7FFFFFFF8
addq %rcx, %rax
shrq $0x3, %rax
incl %eax
cmpl 0x401f6(%rip), %eax     # 0x8e444
jle 0x4e256
movl %eax, 0x401ee(%rip)     # 0x8e444
movq -0x58(%rbp), %rdi
cmpq %r13, %rdi
je 0x4e264
callq 0x2e360
addq $0x8, %r14
cmpq %r15, %r14
jne 0x4e1c2
movl -0x30(%rbp), %eax
orl -0x2c(%rbp), %eax
testb $0x2, %al
je 0x4e30c
leaq 0x29d81(%rip), %rsi     # 0x78007
movl $0x1f, %edx
movq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0x2e440
leaq 0x2991a(%rip), %rsi     # 0x77bb8
movl $0x1, %edx
movq %r15, %rdi
callq 0x2e440
leaq -0x48(%rbp), %r14
movq %r14, -0x10(%r14)
leaq -0x58(%rbp), %rbx
movl $0x4, %esi
movq %rbx, %rdi
movl $0x2d, %edx
callq 0x2e460
movq (%rbx), %rdi
movl $0x4, %esi
movl $0x1388, %edx           # imm = 0x1388
callq 0x39847
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r15, %rdi
callq 0x2e440
leaq 0x298f0(%rip), %rsi     # 0x77be1
movl $0x3, %edx
movq %rax, %rdi
callq 0x2e440
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x4e30c
callq 0x2e360
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x4e32c
callq 0x2e360
movq %rbx, %rdi
callq 0x2e730