// File: /workspace/github_cpp_makefile_star2_O3/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 0x6eba6
testq %rax, %rax
je 0x63dc8
movq %rax, %r14
movl $0x20, %edi
callq 0x2e3a0
movq %rax, %r15
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x15f00(%rip), %rsi     # 0x79a7d
leaq 0x15f07(%rip), %rdx     # 0x79a8b
movq %r15, %rdi
callq 0x32e40
movq 0x48(%r14), %rax
movq %r15, 0x40(%rax)
leaq -0x1a0(%rbp), %r15
movq %r15, %rdi
callq 0x2e550
leaq 0x15ee2(%rip), %rsi     # 0x79a8c
movl $0x11, %edx
movq %r15, %rdi
callq 0x2e440
leaq 0x144b2(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15ec8(%rip), %rsi     # 0x79a9e
leaq -0x1a0(%rbp), %rdi
movl $0xb, %edx
callq 0x2e440
leaq 0x15dfa(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x1446a(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15e5f(%rip), %rsi     # 0x79a7d
leaq -0x1a0(%rbp), %rdi
movl $0xe, %edx
callq 0x2e440
leaq 0x15db2(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x14422(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15e44(%rip), %rsi     # 0x79aaa
leaq -0x1a0(%rbp), %rdi
movl $0xb, %edx
callq 0x2e440
leaq 0x15d6a(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x143da(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15e08(%rip), %rsi     # 0x79ab6
leaq -0x1a0(%rbp), %rdi
movl $0xe, %edx
callq 0x2e440
leaq 0x15d22(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x163af(%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 0x32870
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x63d46
leaq 0x2897d(%rip), %rsi     # 0x8c6b0
leaq 0x28cae(%rip), %rdx     # 0x8c9e8
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r14
jmp 0x63d49
xorl %r14d, %r14d
movl $0x50, %edi
callq 0x2e3a0
movq %rax, %r12
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
movq %rax, %rdi
callq 0x323d8
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 0x63d8b
movq %r12, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x63d97
leaq -0x28(%rbp), %rdx
movq %rbx, %rdi
callq 0x3311a
movq 0x2a20a(%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 0x2ef59
jmp 0x63e02
movq %rax, %rbx
movq %r12, %rdi
jmp 0x63dfb
jmp 0x63e02
movq %rax, %rbx
movq %r12, %rdi
callq 0x2e360
jmp 0x63df8
jmp 0x63e02
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e360
jmp 0x63e24
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e360
jmp 0x63e05
movq %rax, %rbx
movq 0x2a19c(%rip), %rsi     # 0x8dfa8
leaq -0x1a0(%rbp), %rdi
callq 0x2e230
leaq -0x130(%rbp), %rdi
callq 0x2e150
movq %rbx, %rdi
callq 0x2e730