// File: /workspace/github_cpp_makefile_star2_O2/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 0x71ecf
testq %rax, %rax
je 0x69ce4
movq %rax, %r14
pushq $0x20
popq %rdi
callq 0x413f0
movq %rax, %r15
leaq 0x12fcc(%rip), %rsi     # 0x7cb0d
leaq -0x1a0(%rbp), %rdx
movq %rax, %rdi
callq 0x411c0
movq 0x48(%r14), %rax
movq %r15, 0x40(%rax)
leaq -0x1a0(%rbp), %r15
movq %r15, %rdi
callq 0x415a0
leaq 0x12fae(%rip), %rsi     # 0x7cb1c
movq %r15, %rdi
callq 0x413d0
leaq 0x114d3(%rip), %rsi     # 0x7b050
movq %rax, %rdi
callq 0x413d0
leaq 0x12fa2(%rip), %rsi     # 0x7cb2e
movq %rax, %rdi
callq 0x413d0
leaq 0x12edd(%rip), %rsi     # 0x7ca78
movq %rax, %rdi
callq 0x413d0
leaq 0x114a6(%rip), %rsi     # 0x7b050
movq %rax, %rdi
callq 0x413d0
leaq 0x12f54(%rip), %rsi     # 0x7cb0d
movq %rax, %rdi
callq 0x413d0
leaq 0x12eb0(%rip), %rsi     # 0x7ca78
movq %rax, %rdi
callq 0x413d0
leaq 0x11479(%rip), %rsi     # 0x7b050
movq %rax, %rdi
callq 0x413d0
leaq 0x12f54(%rip), %rsi     # 0x7cb3a
movq %rax, %rdi
callq 0x413d0
leaq 0x12e83(%rip), %rsi     # 0x7ca78
movq %rax, %rdi
callq 0x413d0
leaq 0x1144c(%rip), %rsi     # 0x7b050
movq %rax, %rdi
callq 0x413d0
leaq 0x12f33(%rip), %rsi     # 0x7cb46
movq %rax, %rdi
callq 0x413d0
leaq 0x12e56(%rip), %rsi     # 0x7ca78
movq %rax, %rdi
callq 0x413d0
leaq 0x134ec(%rip), %rsi     # 0x7d11d
movq %rax, %rdi
callq 0x413d0
pushq $0x48
popq %rdi
callq 0x413f0
movq %rax, %r15
pushq $0x20
popq %rdi
callq 0x413f0
movq %rax, %r12
leaq -0x198(%rbp), %rsi
movq %rax, %rdi
callq 0x416b0
movq %r15, %rdi
movq %r12, %rsi
callq 0x44730
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x69c8c
leaq 0x2aa17(%rip), %rsi     # 0x94690
leaq 0x2ad48(%rip), %rdx     # 0x949c8
xorl %ecx, %ecx
callq 0x41480
movq %rax, %r14
jmp 0x69c8f
xorl %r14d, %r14d
pushq $0x50
popq %rdi
callq 0x413f0
movq %rax, %r12
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
movq %rax, %rdi
callq 0x44434
movq %r12, 0x40(%r14)
movq %r14, 0x30(%r12)
movq %r15, 0x48(%r14)
leaq -0x28(%rbp), %rsi
movq %r12, (%rsi)
movq %rbx, %rdi
callq 0x44d46
leaq -0x1a0(%rbp), %rdi
callq 0x410e0
movb $0x1, %al
addq $0x180, %rsp            # imm = 0x180
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x2c2c5(%rip), %rax     # 0x95fb0
movq (%rax), %rdi
leaq 0x12da3(%rip), %rsi     # 0x7ca98
leaq 0x12d23(%rip), %rdx     # 0x7ca1f
leaq 0x12dfc(%rip), %r8      # 0x7caff
movl $0xb1, %ecx
xorl %eax, %eax
callq 0x41600
pushq $0x1
popq %rdi
callq 0x414f0
jmp 0x69d4c
movq %rax, %rbx
movq %r12, %rdi
jmp 0x69d45
jmp 0x69d4c
movq %rax, %rbx
movq %r12, %rdi
callq 0x413a0
jmp 0x69d42
jmp 0x69d4c
movq %rax, %rbx
movq %r15, %rdi
callq 0x413a0
jmp 0x69d5b
movq %rax, %rbx
movq %r15, %rdi
callq 0x413a0
jmp 0x69d4f
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
callq 0x410e0
movq %rbx, %rdi
callq 0x41790