// File: /workspace/github_cpp_makefile_star2_O2/eniac[P]Mantis/src/compile/compile_c.cpp
// Function: generatePrologueEnd(std::vector<AstNode*, std::allocator<AstNode*>>, std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char>>&, int, int)
void generatePrologueEnd(std::vector<AstNode*> nodeArray, ostringstream& oss_init_end, int ing_iso_opt, int egr_iso_opt) {

    oss_init_end << "  __mantis__add_vars_ing;\n";
    oss_init_end << "  __mantis__add_vars_egr;\n";

    // Flip __vv to point to shallow copy
    if(((unsigned int)ing_iso_opt) & 0b10) {
        oss_init_end << "\n  __mantis__flip_vv_ing;\n\n";
    }
    if(((unsigned int)egr_iso_opt) & 0b10) {
        oss_init_end << "\n  __mantis__flip_vv_egr;\n\n";
    }    

    P4RInitBlockNode * init_node = findInitBlock(nodeArray);
    string p4r_init_user_str = "";
    if (init_node != 0) {
        p4r_init_user_str = init_node->body_->toString();
    }

    for (auto node : nodeArray) {
        // For each mbl table
        if(typeContains(node, "P4RMalleableTableNode")) {
            TableNode* table = dynamic_cast<P4RMalleableTableNode*>(node)->table_;
            string table_name = *(table->name_->word_);

            // Whenever mbl table(s) present, isolation required

            TableActionStmtsNode* actions = table->actions_;

            // Mbl tables are always with With matches (at least match on __vv)
            // For each action
            for (TableActionStmtNode* tas : *actions->list_) {
                string action_name = *tas->name_->word_;

                string str_prepare_macro_func;
                string str_mirror_macro_func;

                std::smatch result;

                // Construct match regrex for add
                str_prepare_macro_func = table_name + "_add_" + action_name;
                std::regex e_add (str_prepare_macro_func+"\\s*\\("+"([^\\)]*)"+"\\)");   // matches words beginning by "sub"

                // Stop after first match
                while (std::regex_search (p4r_init_user_str, result, e_add)) {
                    
                    str_prepare_macro_func = result[0];
                    str_mirror_macro_func = "__mantis__mirror_" + str_prepare_macro_func;
                    // Call corresponding mirror macros
                    oss_init_end << "\n  "
                                        << str_mirror_macro_func
                                        << ";\n\n";

                    // Search remaining string of p4r_reaction_user_str
                    p4r_init_user_str = result.suffix().str();
                }
                // Mod
                str_prepare_macro_func = table_name + "_mod_" + action_name;
                std::regex e_mod (str_prepare_macro_func+"\\s*\\("+"([^\\)]*)"+"\\)");   // matches words beginning by "sub"
                while (std::regex_search (p4r_init_user_str, result, e_mod)) {
                    str_prepare_macro_func = result[0];
                    str_mirror_macro_func = "__mantis__mirror_" + str_prepare_macro_func;
                    oss_init_end << "\n  "
                                        << str_mirror_macro_func
                                        << ";\n\n";
                    p4r_init_user_str = result.suffix().str();
                }
                // Del
                str_prepare_macro_func = table_name + "_del_" + action_name;
                std::regex e_del (str_prepare_macro_func+"\\s*\\("+"([^\\)]*)"+"\\)");   // matches words beginning by "sub"
                while (std::regex_search (p4r_init_user_str, result, e_del)) {
                    str_prepare_macro_func = result[0];
                    str_mirror_macro_func = "__mantis__mirror_" + str_prepare_macro_func;
                    oss_init_end << "\n  "
                                << str_mirror_macro_func
                                << ";\n\n";
                    p4r_init_user_str = result.suffix().str();
                }
            }   
        }
    }

    // Point __vv back to working copy for dialogue
    if(((unsigned int)ing_iso_opt) & 0b10) {
        oss_init_end<< "\n  __mantis__flip_vv_ing;\n\n"; 
    }
    if(((unsigned int)egr_iso_opt) & 0b10) {
        oss_init_end<< "\n  __mantis__flip_vv_egr;\n\n";
    }  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movl %ecx, %r15d
movl %edx, %r12d
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x2372e(%rip), %rsi     # 0x7b007
movq %r14, %rdi
callq 0x413d0
leaq 0x2373a(%rip), %rsi     # 0x7b022
movq %r14, -0x30(%rbp)
movq %r14, %rdi
callq 0x413d0
testb $0x2, %r12b
je 0x5790a
leaq 0x22c57(%rip), %rsi     # 0x7a558
movq -0x30(%rbp), %rdi
callq 0x413d0
testb $0x2, %r15b
je 0x57920
leaq 0x22c5d(%rip), %rsi     # 0x7a574
movq -0x30(%rbp), %rdi
callq 0x413d0
leaq -0x1d0(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4486c
movq %r14, %rdi
callq 0x72576
movq %rax, %r14
leaq -0x1d0(%rbp), %rdi
callq 0x44be0
leaq 0x22f6b(%rip), %rsi     # 0x7a8bb
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rdx
callq 0x411c0
testq %r14, %r14
je 0x57996
movq 0x48(%r14), %rsi
movq (%rsi), %rax
leaq -0xd8(%rbp), %rdi
callq *(%rax)
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %r14
movq %r14, %rsi
callq 0x41500
movq %r14, %rdi
callq 0x418c8
movl %r12d, -0x58(%rbp)
movl %r15d, -0x54(%rbp)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq %rcx, -0xe0(%rbp)
leaq -0x1b8(%rbp), %r12
leaq -0x158(%rbp), %r13
leaq -0x178(%rbp), %r14
cmpq -0xe0(%rbp), %rax
je 0x58030
movq %rax, -0xe8(%rbp)
movq (%rax), %rbx
movq %rbx, %rdi
leaq 0x231e3(%rip), %rsi     # 0x7abc5
callq 0x71cf8
testb %al, %al
je 0x58020
movq %rbx, %rdi
leaq 0x3cc97(%rip), %rsi     # 0x94690
leaq 0x3da30(%rip), %rdx     # 0x95430
xorl %ecx, %ecx
callq 0x41480
movq 0x40(%rax), %rbx
movq 0x40(%rbx), %rax
movq 0x40(%rax), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x415b0
movq 0x50(%rbx), %rax
movq 0x40(%rax), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq %rax, -0xf0(%rbp)
cmpq -0xf0(%rbp), %rcx
je 0x58014
movq %rcx, -0xf8(%rbp)
movq (%rcx), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rsi
leaq -0x138(%rbp), %rdi
callq 0x415b0
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
andq $0x0, -0x90(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
andq $0x0, -0x70(%rbp)
xorl %eax, %eax
movb %al, -0x88(%rbp)
movb %al, -0x68(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movq %r12, %rdi
leaq -0xd8(%rbp), %rsi
leaq 0x22f94(%rip), %rdx     # 0x7aa3e
callq 0x4df81
leaq -0x198(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
leaq -0x138(%rbp), %rdx
callq 0x4df58
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41500
movq %r15, %rdi
callq 0x418c8
movq %r12, %rdi
callq 0x418c8
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x23546(%rip), %rdx     # 0x7b03d
callq 0x4df81
movq %r14, %rdi
movq %r13, %rsi
leaq 0x2353a(%rip), %rdx     # 0x7b043
callq 0x4ed31
movq %r12, %rdi
movq %r14, %rsi
leaq 0x23531(%rip), %rdx     # 0x7b04c
callq 0x4ed31
leaq -0x198(%rbp), %rdi
movq %r12, %rsi
pushq $0x10
popq %rdx
callq 0x58d60
movq %r12, %rdi
callq 0x418c8
movq %r14, %rdi
callq 0x418c8
movq %r13, %rdi
callq 0x418c8
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
leaq -0x198(%rbp), %rdx
xorl %ecx, %ecx
callq 0x58e56
testb %al, %al
je 0x57c4f
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
leaq -0x48(%rcx), %rdi
cmpq $0x48, %rdx
movq %rax, %rsi
cmoveq %rdi, %rsi
cmpq %rax, %rcx
cmoveq %rdi, %rsi
movq %r12, %rdi
callq 0x58f2c
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x41500
movq %r12, %rdi
callq 0x418c8
movq %r12, %rdi
leaq 0x230a9(%rip), %rsi     # 0x7ac67
movq %rbx, %rdx
callq 0x58eb6
leaq -0x78(%rbp), %rdi
movq %r12, %rsi
callq 0x41500
movq %r12, %rdi
callq 0x418c8
movq -0x30(%rbp), %rdi
leaq 0x2346a(%rip), %rsi     # 0x7b04f
callq 0x413d0
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x41380
movq %rax, %rdi
leaq 0x225b4(%rip), %rsi     # 0x7a1b4
callq 0x413d0
movq -0x48(%rbp), %rsi
movq %rsi, %rax
subq -0x50(%rbp), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq $0x4, %rax
jb 0x57c24
addq $-0x18, %rsi
jmp 0x57c28
addq $-0x48, %rsi
movq %r12, %rdi
callq 0x58f2c
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x41500
movq %r12, %rdi
callq 0x418c8
jmp 0x57b51
movq %r14, %rdi
leaq -0xd8(%rbp), %rsi
leaq 0x22ec6(%rip), %rdx     # 0x7ab26
callq 0x4df81
movq %r12, %rdi
movq %r14, %rsi
leaq -0x138(%rbp), %rdx
callq 0x4df58
leaq -0x98(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x41500
movq %r12, %rdi
callq 0x418c8
movq %r14, %rdi
callq 0x418c8
leaq -0x118(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x23390(%rip), %rdx     # 0x7b03d
callq 0x4df81
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x23384(%rip), %rdx     # 0x7b043
callq 0x4ed31
movq %r14, %rdi
movq %r13, %rsi
leaq 0x2337b(%rip), %rdx     # 0x7b04c
callq 0x4ed31
movq %r12, %rdi
movq %r14, %rsi
pushq $0x10
popq %rdx
callq 0x58d60
movq %r14, %rdi
callq 0x418c8
movq %r13, %rdi
callq 0x418c8
leaq -0x118(%rbp), %rdi
callq 0x418c8
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x58e56
testb %al, %al
je 0x57e01
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
leaq -0x48(%rcx), %rdi
cmpq $0x48, %rdx
movq %rax, %rsi
cmoveq %rdi, %rsi
cmpq %rax, %rcx
cmoveq %rdi, %rsi
movq %r14, %rdi
callq 0x58f2c
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41500
movq %r14, %rdi
callq 0x418c8
movq %r14, %rdi
leaq 0x22ef7(%rip), %rsi     # 0x7ac67
movq %rbx, %rdx
callq 0x58eb6
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x41500
movq %r14, %rdi
callq 0x418c8
movq -0x30(%rbp), %rdi
leaq 0x232b8(%rip), %rsi     # 0x7b04f
callq 0x413d0
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x41380
movq %rax, %rdi
leaq 0x22402(%rip), %rsi     # 0x7a1b4
callq 0x413d0
movq -0x48(%rbp), %rsi
movq %rsi, %rax
subq -0x50(%rbp), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq $0x4, %rax
jb 0x57dd6
addq $-0x18, %rsi
jmp 0x57dda
addq $-0x48, %rsi
movq %r14, %rdi
callq 0x58f2c
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41500
movq %r14, %rdi
callq 0x418c8
jmp 0x57d07
movq %r13, %rdi
leaq -0xd8(%rbp), %rsi
leaq 0x22c9b(%rip), %rdx     # 0x7aaad
callq 0x4df81
movq %r14, %rdi
movq %r13, %rsi
leaq -0x138(%rbp), %rdx
callq 0x4df58
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41500
movq %r14, %rdi
callq 0x418c8
movq %r13, %rdi
callq 0x418c8
leaq -0x1f0(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x231de(%rip), %rdx     # 0x7b03d
callq 0x4df81
leaq -0x118(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x231cb(%rip), %rdx     # 0x7b043
callq 0x4ed31
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x231c2(%rip), %rdx     # 0x7b04c
callq 0x4ed31
movq %r14, %rdi
movq %r13, %rsi
pushq $0x10
popq %rdx
callq 0x58d60
movq %r13, %rdi
callq 0x418c8
leaq -0x118(%rbp), %rdi
callq 0x418c8
leaq -0x1f0(%rbp), %rdi
callq 0x418c8
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x58e56
testb %al, %al
je 0x57fbe
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
leaq -0x48(%rcx), %rdi
cmpq $0x48, %rdx
movq %rax, %rsi
cmoveq %rdi, %rsi
cmpq %rax, %rcx
cmoveq %rdi, %rsi
movq %r13, %rdi
callq 0x58f2c
leaq -0x98(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x41500
movq %r13, %rdi
callq 0x418c8
movq %r13, %rdi
leaq 0x22d3a(%rip), %rsi     # 0x7ac67
movq %rbx, %rdx
callq 0x58eb6
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x41500
movq %r13, %rdi
callq 0x418c8
movq -0x30(%rbp), %rdi
leaq 0x230fb(%rip), %rsi     # 0x7b04f
callq 0x413d0
movq %rax, %rdi
leaq -0x78(%rbp), %rsi
callq 0x41380
movq %rax, %rdi
leaq 0x22245(%rip), %rsi     # 0x7a1b4
callq 0x413d0
movq -0x48(%rbp), %rsi
movq %rsi, %rax
subq -0x50(%rbp), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq $0x4, %rax
jb 0x57f93
addq $-0x18, %rsi
jmp 0x57f97
addq $-0x48, %rsi
movq %r13, %rdi
callq 0x58f2c
leaq -0xb8(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x41500
movq %r13, %rdi
callq 0x418c8
jmp 0x57ec4
movq %r14, %rdi
callq 0x58e18
movq %r12, %rdi
callq 0x58e18
leaq -0x198(%rbp), %rdi
callq 0x58e18
leaq -0x50(%rbp), %rdi
callq 0x59518
leaq -0x78(%rbp), %rdi
callq 0x418c8
leaq -0x98(%rbp), %rdi
callq 0x418c8
leaq -0x138(%rbp), %rdi
callq 0x418c8
movq -0xf8(%rbp), %rcx
addq $0x8, %rcx
jmp 0x57a35
leaq -0xd8(%rbp), %rdi
callq 0x418c8
movq -0xe8(%rbp), %rax
addq $0x8, %rax
jmp 0x579c1
testb $0x2, -0x58(%rbp)
je 0x58046
leaq 0x2251b(%rip), %rsi     # 0x7a558
movq -0x30(%rbp), %rdi
callq 0x413d0
testb $0x2, -0x54(%rbp)
je 0x5805c
leaq 0x22521(%rip), %rsi     # 0x7a574
movq -0x30(%rbp), %rdi
callq 0x413d0
leaq -0xb8(%rbp), %rdi
callq 0x418c8
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5809c
jmp 0x5809c
movq %rax, %rbx
jmp 0x5820f
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x44be0
jmp 0x5820f
jmp 0x5809c
movq %rax, %rbx
jmp 0x58203
movq %rax, %rbx
jmp 0x580ce
movq %rax, %rbx
jmp 0x580c2
jmp 0x581ad
movq %rax, %rbx
leaq -0x158(%rbp), %rdi
callq 0x418c8
leaq -0x118(%rbp), %rdi
callq 0x418c8
leaq -0x1f0(%rbp), %rdi
jmp 0x580e1
movq %rax, %rbx
leaq -0x158(%rbp), %rdi
callq 0x418c8
jmp 0x581b0
jmp 0x581ad
jmp 0x581be
movq %rax, %rbx
jmp 0x5811a
movq %rax, %rbx
jmp 0x5810e
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
callq 0x418c8
leaq -0x158(%rbp), %rdi
callq 0x418c8
leaq -0x118(%rbp), %rdi
jmp 0x58132
jmp 0x581be
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
callq 0x418c8
jmp 0x581c1
jmp 0x58174
movq %rax, %rbx
jmp 0x5816b
movq %rax, %rbx
jmp 0x5815f
movq %rax, %rbx
jmp 0x581f7
movq %rax, %rbx
leaq -0x1b8(%rbp), %rdi
callq 0x418c8
leaq -0x178(%rbp), %rdi
callq 0x418c8
leaq -0x158(%rbp), %rdi
jmp 0x58183
movq %rax, %rbx
jmp 0x581cd
movq %rax, %rbx
leaq -0x1b8(%rbp), %rdi
callq 0x418c8
jmp 0x581cd
jmp 0x5819c
jmp 0x5819c
jmp 0x5819c
jmp 0x581ad
jmp 0x581ad
jmp 0x581ad
jmp 0x581be
jmp 0x581be
jmp 0x581be
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
callq 0x58e18
jmp 0x581b0
movq %rax, %rbx
leaq -0x1b8(%rbp), %rdi
callq 0x58e18
jmp 0x581c1
movq %rax, %rbx
leaq -0x198(%rbp), %rdi
callq 0x58e18
leaq -0x50(%rbp), %rdi
callq 0x59518
leaq -0x78(%rbp), %rdi
callq 0x418c8
leaq -0x98(%rbp), %rdi
callq 0x418c8
leaq -0x138(%rbp), %rdi
callq 0x418c8
leaq -0xd8(%rbp), %rdi
callq 0x418c8
leaq -0xb8(%rbp), %rdi
callq 0x418c8
movq %rbx, %rdi
callq 0x41790