// File: /workspace/github_cpp_makefile_star2_O1/eniac[P]Mantis/src/compile/compile_p4.cpp
// Function: augmentEgress(std::vector<AstNode*, std::allocator<AstNode*>>*)
bool augmentEgress(vector<AstNode*>* astNodes) {
    // Fetch egress
    P4ExprNode* egressNode = findEgress(*astNodes);
    if (!egressNode) {
        PANIC("Error: could not find the egress control block. Perhaps you didn't call it 'egress'?\n");
        exit(1);
    }

    // Rename egress
    egressNode->name1_->word_ = new string(kOrigEgrControlName);

    // Generate new ingress function that wraps original
    ostringstream oss;
    oss << "control egress {\n"
            << "  " << kSetmblEgrControlName << "();\n"
            << "  " << kOrigEgrControlName << "();\n" 
            << "  " << kSetargsEgrControlName << "();\n"
            << "  " << kRegArgGateEgrControlName << "();\n"
        << "}\n\n";
    StrNode* newEgressNode = new StrNode(new string(oss.str()));

    // Inject wrapper right before original
    InputNode* firstInput = dynamic_cast<InputNode*>(egressNode->parent_);
    InputNode* secondInput = new InputNode(firstInput->next_,
                                           firstInput->expression_);
    firstInput->next_ = secondInput;
    secondInput->parent_ = firstInput;

    firstInput->expression_ = newEgressNode;
    astNodes->push_back(secondInput);

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x180, %rsp            # imm = 0x180
movq %rdi, %rbx
callq 0x6f5e2
testq %rax, %rax
je 0x6437d
movq %rax, %r14
movl $0x20, %edi
callq 0x2e3a0
movq %rax, %r15
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x1594b(%rip), %rsi     # 0x79a7d
leaq 0x15952(%rip), %rdx     # 0x79a8b
movq %r15, %rdi
callq 0x33112
movq 0x48(%r14), %rax
movq %r15, 0x40(%rax)
leaq -0x1a0(%rbp), %r15
movq %r15, %rdi
callq 0x2e550
leaq 0x1592d(%rip), %rsi     # 0x79a8c
movl $0x11, %edx
movq %r15, %rdi
callq 0x2e440
leaq 0x13efd(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15913(%rip), %rsi     # 0x79a9e
leaq -0x1a0(%rbp), %rdi
movl $0xb, %edx
callq 0x2e440
leaq 0x15845(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x13eb5(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x158aa(%rip), %rsi     # 0x79a7d
leaq -0x1a0(%rbp), %rdi
movl $0xe, %edx
callq 0x2e440
leaq 0x157fd(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x13e6d(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x1588f(%rip), %rsi     # 0x79aaa
leaq -0x1a0(%rbp), %rdi
movl $0xb, %edx
callq 0x2e440
leaq 0x157b5(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x13e25(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15853(%rip), %rsi     # 0x79ab6
leaq -0x1a0(%rbp), %rdi
movl $0xe, %edx
callq 0x2e440
leaq 0x1576d(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x15dfa(%rip), %rsi     # 0x7a08d
leaq -0x1a0(%rbp), %rdi
movl $0x3, %edx
callq 0x2e440
movl $0x48, %edi
callq 0x2e3a0
movq %rax, %r15
movl $0x20, %edi
callq 0x2e3a0
movq %rax, %r12
leaq -0x198(%rbp), %rsi
movq %rax, %rdi
callq 0x2e660
movq %r15, %rdi
movq %r12, %rsi
callq 0x32b5a
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x642fb
leaq 0x28348(%rip), %rsi     # 0x8c630
leaq 0x28679(%rip), %rdx     # 0x8c968
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r14
jmp 0x642fe
xorl %r14d, %r14d
movl $0x50, %edi
callq 0x2e3a0
movq %rax, %r12
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
movq %rax, %rdi
callq 0x326fe
movq %r12, 0x40(%r14)
movq %r14, 0x30(%r12)
movq %r15, 0x48(%r14)
movq %r12, -0x28(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x64340
movq %r12, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x6434c
leaq -0x28(%rbp), %rdx
movq %rbx, %rdi
callq 0x333de
movq 0x29c55(%rip), %rsi     # 0x8dfa8
leaq -0x1a0(%rbp), %rdi
callq 0x2e230
leaq -0x130(%rbp), %rdi
callq 0x2e150
movb $0x1, %al
addq $0x180, %rsp            # imm = 0x180
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x2f057
jmp 0x643b7
movq %rax, %rbx
movq %r12, %rdi
jmp 0x643b0
jmp 0x643b7
movq %rax, %rbx
movq %r12, %rdi
callq 0x2e360
jmp 0x643ad
jmp 0x643b7
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e360
jmp 0x643d9
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e360
jmp 0x643ba
movq %rax, %rbx
movq 0x29be7(%rip), %rsi     # 0x8dfa8
leaq -0x1a0(%rbp), %rdi
callq 0x2e230
leaq -0x130(%rbp), %rdi
callq 0x2e150
movq %rbx, %rdi
callq 0x2e730