// File: /workspace/github_cpp_makefile_star2_O3/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 0x6ea2c
testq %rax, %rax
je 0x63ad8
movq %rax, %r14
movl $0x20, %edi
callq 0x2e3a0
movq %rax, %r15
addq $0x10, %rax
movq %rax, (%r15)
leaq 0x1612c(%rip), %rsi     # 0x799b9
leaq 0x16134(%rip), %rdx     # 0x799c8
movq %r15, %rdi
callq 0x32e40
movq 0x48(%r14), %rax
movq %r15, 0x40(%rax)
leaq -0x1a0(%rbp), %r15
movq %r15, %rdi
callq 0x2e550
leaq 0x1610f(%rip), %rsi     # 0x799c9
movl $0x12, %edx
movq %r15, %rdi
callq 0x2e440
leaq 0x147a2(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x160f6(%rip), %rsi     # 0x799dc
leaq -0x1a0(%rbp), %rdi
movl $0xb, %edx
callq 0x2e440
leaq 0x160ea(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x1475a(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x1608b(%rip), %rsi     # 0x799b9
leaq -0x1a0(%rbp), %rdi
movl $0xf, %edx
callq 0x2e440
leaq 0x160a2(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x14712(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x16077(%rip), %rsi     # 0x799ed
leaq -0x1a0(%rbp), %rdi
movl $0xb, %edx
callq 0x2e440
leaq 0x1605a(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x146ca(%rip), %rsi     # 0x78070
leaq -0x1a0(%rbp), %rdi
movl $0x2, %edx
callq 0x2e440
leaq 0x1603b(%rip), %rsi     # 0x799f9
leaq -0x1a0(%rbp), %rdi
movl $0xe, %edx
callq 0x2e440
leaq 0x16012(%rip), %rsi     # 0x799e8
leaq -0x1a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2e440
leaq 0x1669f(%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 0x63a56
leaq 0x28c6d(%rip), %rsi     # 0x8c6b0
leaq 0x28f9e(%rip), %rdx     # 0x8c9e8
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r14
jmp 0x63a59
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 0x63a9b
movq %r12, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x63aa7
leaq -0x28(%rbp), %rdx
movq %rbx, %rdi
callq 0x3311a
movq 0x2a4fa(%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 0x2ef22
jmp 0x63b12
movq %rax, %rbx
movq %r12, %rdi
jmp 0x63b0b
jmp 0x63b12
movq %rax, %rbx
movq %r12, %rdi
callq 0x2e360
jmp 0x63b08
jmp 0x63b12
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e360
jmp 0x63b34
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e360
jmp 0x63b15
movq %rax, %rbx
movq 0x2a48c(%rip), %rsi     # 0x8dfa8
leaq -0x1a0(%rbp), %rdi
callq 0x2e230
leaq -0x130(%rbp), %rdi
callq 0x2e150
movq %rbx, %rdi
callq 0x2e730