// File: /workspace/github_cpp_makefile_star2_O1/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 0x4e810
leaq -0x48(%rbp), %r13
leaq 0x297c7(%rip), %r12     # 0x77f28
movq (%r14), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6f390
testb %al, %al
je 0x4e803
testq %rbx, %rbx
je 0x4e799
movq %rbx, %rdi
leaq 0x3deaa(%rip), %rsi     # 0x8c630
leaq 0x3ec2b(%rip), %rdx     # 0x8d3b8
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %rbx
jmp 0x4e79b
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 0x32f92
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 0x4e7e7
movabsq $0x7fffffff8, %rax      # imm = 0x7FFFFFFF8
addq %rcx, %rax
shrq $0x3, %rax
incl %eax
cmpl 0x3fc57(%rip), %eax     # 0x8e444
jle 0x4e7f5
movl %eax, 0x3fc4f(%rip)     # 0x8e444
movq -0x58(%rbp), %rdi
cmpq %r13, %rdi
je 0x4e803
callq 0x2e360
addq $0x8, %r14
cmpq %r15, %r14
jne 0x4e761
movl -0x30(%rbp), %eax
orl -0x2c(%rbp), %eax
testb $0x2, %al
je 0x4e8ab
leaq 0x297e2(%rip), %rsi     # 0x78007
movl $0x1f, %edx
movq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0x2e440
leaq 0x2937b(%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 0x39c27
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r15, %rdi
callq 0x2e440
leaq 0x29351(%rip), %rsi     # 0x77be1
movl $0x3, %edx
movq %rax, %rdi
callq 0x2e440
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x4e8ab
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 0x4e8cb
callq 0x2e360
movq %rbx, %rdi
callq 0x2e730