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

    // Rename ingress
    ingressNode->name1_->word_ = new string(kOrigIngControlName);

    // Generate new ingress function that wraps original
    ostringstream oss;
    oss << "control ingress {\n"
            // Separate ing and egr for cases when queueing > PCIe latency (large packet buffer+congested link)
            << "  " << kSetmblIngControlName << "();\n"
            << "  " << kOrigIngControlName << "();\n" 
            << "  " << kSetargsIngControlName << "();\n"
            << "  " << kRegArgGateIngControlName << "();\n"            
        << "}\n\n";
    StrNode* newIngressNode = new StrNode(new string(oss.str()));

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

    firstInput->expression_ = newIngressNode;
    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 0x6f454
testq %rax, %rax
je 0x6408d
movq %rax, %r14
movl $0x20, %edi
callq 0x2e3a0
movq %rax, %r15
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x15b77(%rip), %rsi     # 0x799b9
leaq 0x15b7f(%rip), %rdx     # 0x799c8
movq %r15, %rdi
callq 0x33112
movq 0x48(%r14), %rax
movq %r15, 0x40(%rax)
leaq -0x1a0(%rbp), %r15
movq %r15, %rdi
callq 0x2e550
leaq 0x15b5a(%rip), %rsi     # 0x799c9
movl $0x12, %edx
movq %r15, %rdi
callq 0x2e440
leaq 0x141ed(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15b41(%rip), %rsi     # 0x799dc
leaq -0x1a0(%rbp), %rdi
movl $0xb, %edx
callq 0x2e440
leaq 0x15b35(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x141a5(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15ad6(%rip), %rsi     # 0x799b9
leaq -0x1a0(%rbp), %rdi
movl $0xf, %edx
callq 0x2e440
leaq 0x15aed(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x1415d(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15ac2(%rip), %rsi     # 0x799ed
leaq -0x1a0(%rbp), %rdi
movl $0xb, %edx
callq 0x2e440
leaq 0x15aa5(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x14115(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x15a86(%rip), %rsi     # 0x799f9
leaq -0x1a0(%rbp), %rdi
movl $0xe, %edx
callq 0x2e440
leaq 0x15a5d(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x160ea(%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 0x6400b
leaq 0x28638(%rip), %rsi     # 0x8c630
leaq 0x28969(%rip), %rdx     # 0x8c968
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r14
jmp 0x6400e
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 0x64050
movq %r12, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x6405c
leaq -0x28(%rbp), %rdx
movq %rbx, %rdi
callq 0x333de
movq 0x29f45(%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 0x2f020
jmp 0x640c7
movq %rax, %rbx
movq %r12, %rdi
jmp 0x640c0
jmp 0x640c7
movq %rax, %rbx
movq %r12, %rdi
callq 0x2e360
jmp 0x640bd
jmp 0x640c7
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e360
jmp 0x640e9
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e360
jmp 0x640ca
movq %rax, %rbx
movq 0x29ed7(%rip), %rsi     # 0x8dfa8
leaq -0x1a0(%rbp), %rdi
callq 0x2e230
leaq -0x130(%rbp), %rdi
callq 0x2e150
movq %rbx, %rdi
callq 0x2e730