// File: /workspace/github_cpp_makefile_star2_O2/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 0x71d9c
testq %rax, %rax
je 0x69a8a
movq %rax, %r14
pushq $0x20
popq %rdi
callq 0x413f0
movq %rax, %r15
leaq 0x13162(%rip), %rsi     # 0x7ca49
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 0x13145(%rip), %rsi     # 0x7ca59
movq %r15, %rdi
callq 0x413d0
leaq 0x1172d(%rip), %rsi     # 0x7b050
movq %rax, %rdi
callq 0x413d0
leaq 0x1313a(%rip), %rsi     # 0x7ca6c
movq %rax, %rdi
callq 0x413d0
leaq 0x13137(%rip), %rsi     # 0x7ca78
movq %rax, %rdi
callq 0x413d0
leaq 0x11700(%rip), %rsi     # 0x7b050
movq %rax, %rdi
callq 0x413d0
leaq 0x130ea(%rip), %rsi     # 0x7ca49
movq %rax, %rdi
callq 0x413d0
leaq 0x1310a(%rip), %rsi     # 0x7ca78
movq %rax, %rdi
callq 0x413d0
leaq 0x116d3(%rip), %rsi     # 0x7b050
movq %rax, %rdi
callq 0x413d0
leaq 0x130f1(%rip), %rsi     # 0x7ca7d
movq %rax, %rdi
callq 0x413d0
leaq 0x130dd(%rip), %rsi     # 0x7ca78
movq %rax, %rdi
callq 0x413d0
leaq 0x116a6(%rip), %rsi     # 0x7b050
movq %rax, %rdi
callq 0x413d0
leaq 0x130d0(%rip), %rsi     # 0x7ca89
movq %rax, %rdi
callq 0x413d0
leaq 0x130b0(%rip), %rsi     # 0x7ca78
movq %rax, %rdi
callq 0x413d0
leaq 0x13746(%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 0x69a32
leaq 0x2ac71(%rip), %rsi     # 0x94690
leaq 0x2afa2(%rip), %rdx     # 0x949c8
xorl %ecx, %ecx
callq 0x41480
movq %rax, %r14
jmp 0x69a35
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 0x2c51f(%rip), %rax     # 0x95fb0
movq (%rax), %rdi
leaq 0x12f1c(%rip), %rsi     # 0x7c9b7
leaq 0x12f7d(%rip), %rdx     # 0x7ca1f
leaq 0x12f91(%rip), %r8      # 0x7ca3a
movl $0x8d, %ecx
xorl %eax, %eax
callq 0x41600
pushq $0x1
popq %rdi
callq 0x414f0
jmp 0x69af2
movq %rax, %rbx
movq %r12, %rdi
jmp 0x69aeb
jmp 0x69af2
movq %rax, %rbx
movq %r12, %rdi
callq 0x413a0
jmp 0x69ae8
jmp 0x69af2
movq %rax, %rbx
movq %r15, %rdi
callq 0x413a0
jmp 0x69b01
movq %rax, %rbx
movq %r15, %rdi
callq 0x413a0
jmp 0x69af5
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
callq 0x410e0
movq %rbx, %rdi
callq 0x41790