// File: /workspace/github_cpp_makefile_star2_O1/eniac[P]Mantis/src/compile/find_nodes.cpp
// Function: findRegargInIng(ReactionArgNode*, std::vector<AstNode*, std::allocator<AstNode*>>)
bool findRegargInIng(ReactionArgNode* regarg, std::vector<AstNode*> nodeArray) {

    if(regarg->argType_!=ReactionArgNode::REGISTER) {
        PRINT_VERBOSE("Miscall findRegargInIng for arg %s\n", regarg->toString().c_str());
        return false;
    }

    vector<P4ExprNode*> blackboxes = findBlackbox(nodeArray);
    
    std::string prog_name;
    for (auto blackbox : blackboxes) {
        prog_name = blackbox->name2_->toString();
        std::stringstream ss(blackbox->body_->toString());
        std::string reg_name;
        std::string item;
        while (std::getline(ss, item, ';'))
        {
            std::stringstream ss_(item);
            std::string item_;
            while (std::getline(ss_, item_, ':')) {
                boost::algorithm::trim(item_);
                if(item_.compare("reg")==0) {
                    std::getline(ss_, item_, ':');
                    boost::algorithm::trim(item_);
                    reg_name = item_;
                }
            }
        }
        if(reg_name.compare(regarg->toString())==0) {
            break;
        }
    }
    string action_name;
    bool found = false;
    for (auto tmp_node : nodeArray) {
        if(typeContains(tmp_node, "ActionNode") && !typeContains(tmp_node, "P4R")) {
            ActionNode* tmp_action_node = dynamic_cast<ActionNode*>(tmp_node);
            string tmp_action_name = tmp_action_node->name_->toString();
            ActionStmtsNode* actionstmts = tmp_action_node->stmts_;
            for (ActionStmtNode* as : *actionstmts->list_) {
                if(as->toString().find("execute_stateful_alu")!=string::npos &&
                    as->toString().find(prog_name)!=string::npos) {
                    found = true;
                    action_name = tmp_action_node->name_->toString();
                    break;
                }
            }
            if (found) {
                break;
            }
        }
    }
    if(!found) {
        PANIC("Action missing to execute the stateful alu for %s\n", regarg->toString().c_str());
    }
    string table_name;
    found = false;
    for (auto node : nodeArray) {
        if(typeContains(node, "TableNode") && !typeContains(node, "P4R")) {
            TableNode* table = dynamic_cast<TableNode*>(node);
            table_name = *(table->name_->word_);
            TableActionStmtsNode* actions = table->actions_;
            for (TableActionStmtNode* tas : *actions->list_) {
                string tmp_action_name = *tas->name_->word_;
                if(tmp_action_name.compare(action_name)==0) {
                    found = true;
                    break;
                }
            }
            if(found) {
                break;
            }        
        }
    }
    if(!found) {
        PANIC("Table missing for %s\n", regarg->toString().c_str());
    }    
    // Now locate ing/egr for the table
    P4ExprNode* ing_node = findIngress(nodeArray);
    P4ExprNode* egr_node = findEgress(nodeArray);
    if(ing_node==NULL || egr_node==NULL) {
        PANIC("Missing ing/egr node for %s\n", regarg->toString().c_str());
    }
    // A valid table will either be applied at ing or egr
    if(ing_node->body_->toString().find(table_name) != string::npos) {
        return true;
    } else if (egr_node->body_->toString().find(table_name) != string::npos) {
        return false;
    } else {
        PANIC("Failed to locate %s for %s\n", table_name.c_str(), regarg->toString().c_str());
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3f8, %rsp            # imm = 0x3F8
movq %rdi, -0x60(%rbp)
cmpl $0x4, 0x3c(%rdi)
jne 0x710b9
leaq -0x110(%rbp), %rbx
movq %rbx, %rdi
movq %rsi, -0x68(%rbp)
callq 0x6f770
leaq -0xe8(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
movq %rax, -0x70(%rbp)
cmpq %rax, %rcx
je 0x70c29
leaq -0xa8(%rbp), %r15
movl $0x80, %eax
leaq -0x298(%rbp), %r14
leaq (%r14,%rax), %rdx
movq %rdx, -0x58(%rbp)
leaq -0x420(%rbp), %r12
addq %r12, %rax
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rbx
leaq -0xa0(%rbp), %r13
movq %rcx, -0x78(%rbp)
movq (%rcx), %rax
movq %rax, -0x30(%rbp)
movq 0x50(%rax), %rsi
movq (%rsi), %rax
movq %r12, %rdi
callq *(%rax)
leaq -0xf8(%rbp), %rdi
movq %r12, %rsi
callq 0x2e4c0
movq -0x420(%rbp), %rdi
leaq -0x410(%rbp), %rax
cmpq %rax, %rdi
je 0x70977
callq 0x2e360
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rsi
movq (%rsi), %rax
movq %r14, %rdi
callq *(%rax)
leaq 0x9662(%rip), %r12      # 0x79ff0
leaq -0x420(%rbp), %rdi
movq %r14, %rsi
movl $0x18, %edx
callq 0x2e670
movq -0x298(%rbp), %rdi
leaq -0x288(%rbp), %rax
cmpq %rax, %rdi
je 0x709ba
callq 0x2e360
leaq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
xorl %ecx, %ecx
movq %rcx, -0x48(%rbp)
movb %cl, -0x40(%rbp)
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movq %rcx, -0x90(%rbp)
movb %cl, -0x88(%rbp)
leaq -0x420(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movl $0x3b, %edx
callq 0x2e790
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x70b4f
movq %r14, %rdi
leaq -0x98(%rbp), %rsi
movl $0x18, %edx
callq 0x2e670
leaq -0xc0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq $0x0, -0xc8(%rbp)
movb $0x0, -0xc0(%rbp)
movq %r14, %rdi
movq %rbx, %rsi
movl $0x3a, %edx
callq 0x2e790
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x70b1a
movq %r13, %rdi
callq 0x2e800
movw $0x2000, -0xb0(%rbp)    # imm = 0x2000
movq %r15, %rdi
movq %r13, %rsi
callq 0x2e270
movq %rbx, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x39c99
movq %r15, %rdi
callq 0x2e580
movq %r13, %rdi
callq 0x2e580
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2e0f0
testl %eax, %eax
jne 0x70a44
movq %r14, %rdi
movq %rbx, %rsi
movl $0x3a, %edx
callq 0x2e790
movq %r13, %rdi
callq 0x2e800
movw $0x2000, -0xb0(%rbp)    # imm = 0x2000
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x2e270
movq %rbx, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x39c99
movq %r12, %rdi
callq 0x2e580
movq %r13, %rdi
callq 0x2e580
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0x2e240
leaq 0x94db(%rip), %r12      # 0x79ff0
jmp 0x70a44
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x70b32
callq 0x2e360
movq %r14, %rdi
movq 0x1d41c(%rip), %rsi     # 0x8df58
callq 0x2e2f0
movq -0x58(%rbp), %rdi
callq 0x2e150
jmp 0x709e6
movq -0x60(%rbp), %rsi
movq (%rsi), %rax
movq %r14, %rdi
callq *(%rax)
movq -0x48(%rbp), %rax
movq -0x290(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, %rdx
cmovbq %rcx, %rdx
testq %rdx, %rdx
je 0x70b9b
movq -0x298(%rbp), %rsi
movq -0x50(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq %rcx, %r12
callq 0x2e3c0
movq %r12, %rcx
testl %eax, %eax
movq -0x30(%rbp), %rax
sete %r12b
jmp 0x70b9e
movb $0x1, %r12b
cmpq %rcx, %rax
sete -0x30(%rbp)
movq -0x298(%rbp), %rdi
leaq -0x288(%rbp), %rax
cmpq %rax, %rdi
je 0x70bbd
callq 0x2e360
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x70bd5
callq 0x2e360
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x70be7
callq 0x2e360
andb -0x30(%rbp), %r12b
movb %r12b, -0x30(%rbp)
leaq -0x420(%rbp), %r12
movq %r12, %rdi
movq 0x1d358(%rip), %rsi     # 0x8df58
callq 0x2e2f0
movq -0xd8(%rbp), %rdi
callq 0x2e150
movq -0x78(%rbp), %rcx
addq $0x8, %rcx
cmpq -0x70(%rbp), %rcx
sete %al
orb -0x30(%rbp), %al
je 0x70939
leaq -0x410(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq -0x68(%rbp), %rax
movq (%rax), %r14
movq 0x8(%rax), %r15
cmpq %r15, %r14
je 0x710cf
movq $0x0, -0x58(%rbp)
leaq 0x6d0d(%rip), %r12      # 0x7796f
movq %r15, -0x70(%rbp)
movq (%r14), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6f390
testb %al, %al
je 0x70c8b
movq %rbx, %rdi
leaq 0x6c48(%rip), %rsi      # 0x778ca
callq 0x6f390
testb %al, %al
je 0x70c92
xorl %eax, %eax
jmp 0x70e07
testq %rbx, %rbx
je 0x70cb4
movq %rbx, %rdi
leaq 0x1b98f(%rip), %rsi     # 0x8c630
leaq 0x1c248(%rip), %rdx     # 0x8cef0
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r12
jmp 0x70cb7
xorl %r12d, %r12d
movq 0x40(%r12), %rsi
movq (%rsi), %rax
leaq -0x298(%rbp), %rdi
callq *(%rax)
movq %r14, -0x78(%rbp)
movq 0x50(%r12), %rax
movq 0x40(%rax), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r14
cmpq %r14, %rbx
je 0x70ddc
movq %r12, -0x30(%rbp)
addq $0x8, %rbx
leaq -0x50(%rbp), %r15
movq -0x8(%rbx), %r13
movq (%r13), %rax
movq %r15, %rdi
movq %r13, %rsi
callq *(%rax)
xorl %r12d, %r12d
movl $0x14, %ecx
movq %r15, %rdi
leaq 0x905c(%rip), %rsi      # 0x79d6f
xorl %edx, %edx
callq 0x2e710
movq %rax, %r15
cmpq $-0x1, %rax
je 0x70d56
movq (%r13), %rax
leaq -0x98(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq *(%rax)
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rcx
movq %r12, %rdi
xorl %edx, %edx
callq 0x2e710
cmpq $-0x1, %rax
setne %r12b
cmpq $-0x1, %r15
leaq -0x50(%rbp), %r15
je 0x70d78
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x70d78
callq 0x2e360
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x70d8a
callq 0x2e360
testb %r12b, %r12b
je 0x70dc6
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rsi
movq (%rsi), %rax
movq %r15, %rdi
callq *(%rax)
leaq -0x420(%rbp), %rdi
movq %r15, %rsi
callq 0x2e4c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x70dc0
callq 0x2e360
movb $0x1, %al
movq %rax, -0x58(%rbp)
cmpq %r14, %rbx
sete %al
orb %al, %r12b
addq $0x8, %rbx
testb %r12b, %r12b
je 0x70cf1
movq -0x298(%rbp), %rdi
leaq -0x288(%rbp), %rax
cmpq %rax, %rdi
je 0x70df4
callq 0x2e360
movq -0x58(%rbp), %rax
movq -0x78(%rbp), %r14
movq -0x70(%rbp), %r15
leaq 0x6b68(%rip), %r12      # 0x7796f
testb $0x1, %al
jne 0x70e18
addq $0x8, %r14
cmpq %r15, %r14
jne 0x70c66
testb $0x1, -0x58(%rbp)
je 0x710cf
leaq -0x288(%rbp), %rax
movq %rax, -0x298(%rbp)
movq $0x0, -0x290(%rbp)
movb $0x0, -0x288(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %r14
movq 0x8(%rax), %r15
cmpq %r15, %r14
je 0x710f8
xorl %ebx, %ebx
movq %r15, -0x30(%rbp)
movq (%r14), %r13
movq %r13, %rdi
leaq 0x6d88(%rip), %rsi      # 0x77bf1
callq 0x6f390
testb %al, %al
je 0x70e85
movq %r13, %rdi
leaq 0x6a4e(%rip), %rsi      # 0x778ca
callq 0x6f390
testb %al, %al
je 0x70e8c
xorl %eax, %eax
jmp 0x70f86
testq %r13, %r13
je 0x70eae
movq %r13, %rdi
leaq 0x1b795(%rip), %rsi     # 0x8c630
leaq 0x1bfa6(%rip), %rdx     # 0x8ce48
xorl %ecx, %ecx
callq 0x2e430
movq %rax, %r13
jmp 0x70eb1
xorl %r13d, %r13d
movq 0x40(%r13), %rax
movq 0x40(%rax), %rsi
leaq -0x298(%rbp), %rdi
callq 0x2e240
movq %r14, -0x58(%rbp)
movq 0x50(%r13), %rax
movq 0x40(%rax), %rax
movq (%rax), %r13
movq 0x8(%rax), %r15
cmpq %r15, %r13
je 0x70f7c
addq $0x8, %r13
movq -0x8(%r13), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
leaq -0x40(%rbp), %rcx
movq %rcx, -0x50(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %rdi
callq 0x32f92
movq -0x48(%rbp), %r12
movq -0x418(%rbp), %r14
cmpq %r12, %r14
movq %r12, %rdx
cmovbq %r14, %rdx
testq %rdx, %rdx
je 0x70f3d
movq -0x420(%rbp), %rsi
movq -0x50(%rbp), %rdi
callq 0x2e3c0
testl %eax, %eax
sete %al
jmp 0x70f3f
movb $0x1, %al
cmpq %r14, %r12
sete %r14b
andb %al, %r14b
movzbl %bl, %ebx
movl $0x1, %eax
cmovnel %eax, %ebx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x70f66
callq 0x2e360
cmpq %r15, %r13
sete %al
orb %al, %r14b
addq $0x8, %r13
testb %r14b, %r14b
je 0x70ee5
movl %ebx, %eax
movq -0x58(%rbp), %r14
movq -0x30(%rbp), %r15
testb $0x1, %al
jne 0x70f97
addq $0x8, %r14
cmpq %r15, %r14
jne 0x70e5c
testb $0x1, %bl
je 0x710f8
movq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x6f454
movq %rax, %rbx
movq %r14, %rdi
callq 0x6f5e2
testq %rbx, %rbx
je 0x7111b
movq %rax, %r13
testq %rax, %rax
je 0x7111b
movq 0x60(%rbx), %rsi
movq (%rsi), %rax
leaq -0x50(%rbp), %rdi
callq *(%rax)
movq -0x298(%rbp), %rsi
movq -0x290(%rbp), %rcx
leaq -0x50(%rbp), %r12
movq %r12, %rdi
xorl %edx, %edx
callq 0x2e710
movq %rax, %r15
cmpq $-0x1, %rax
setne %bl
movq (%r12), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x71011
callq 0x2e360
cmpq $-0x1, %r15
jne 0x7105e
movq 0x60(%r13), %rsi
movq (%rsi), %rax
leaq -0x50(%rbp), %rdi
callq *(%rax)
movq -0x298(%rbp), %rsi
movq -0x290(%rbp), %rcx
leaq -0x50(%rbp), %r15
movq %r15, %rdi
xorl %edx, %edx
callq 0x2e710
movq %rax, %r12
movq (%r15), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x71054
callq 0x2e360
cmpq $-0x1, %r12
je 0x7113e
movq -0x298(%rbp), %rdi
leaq -0x288(%rbp), %rax
cmpq %rax, %rdi
je 0x71076
callq 0x2e360
movq -0x420(%rbp), %rdi
leaq -0x410(%rbp), %rax
cmpq %rax, %rdi
je 0x7108e
callq 0x2e360
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x710a6
callq 0x2e360
movq -0x110(%rbp), %rdi
testq %rdi, %rdi
je 0x710bb
callq 0x2e360
jmp 0x710bb
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1ceea(%rip), %rax     # 0x8dfc0
movq (%rax), %rbx
movq -0x60(%rbp), %rsi
movq (%rsi), %rax
leaq -0x298(%rbp), %rdi
callq *(%rax)
leaq -0x298(%rbp), %rdi
movq %rbx, %rsi
callq 0x2f34b
movq 0x1cec1(%rip), %rax     # 0x8dfc0
movq (%rax), %rbx
movq -0x60(%rbp), %rsi
movq (%rsi), %rax
leaq -0x50(%rbp), %rdi
callq *(%rax)
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0x2f308
movq 0x1ce9e(%rip), %rax     # 0x8dfc0
movq (%rax), %rbx
movq -0x60(%rbp), %rsi
movq (%rsi), %rax
leaq -0x50(%rbp), %rdi
callq *(%rax)
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0x2f2c5
movq 0x1ce7b(%rip), %rax     # 0x8dfc0
movq (%rax), %rbx
movq -0x298(%rbp), %r14
movq -0x60(%rbp), %rsi
movq (%rsi), %rax
leaq -0x50(%rbp), %rdi
callq *(%rax)
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2f27b
jmp 0x711c0
jmp 0x711c0
jmp 0x711c0
jmp 0x711c0
jmp 0x711c0
jmp 0x711c0
jmp 0x711c0
jmp 0x711a0
jmp 0x711c0
jmp 0x711a0
jmp 0x711fe
jmp 0x71183
movq %rax, %rbx
jmp 0x712a7
movq %rax, %rbx
movq -0x298(%rbp), %rdi
leaq -0x288(%rbp), %rax
jmp 0x711e9
jmp 0x711c0
movq %rax, %rbx
jmp 0x711db
jmp 0x711c0
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x711c3
callq 0x2e360
jmp 0x711c3
jmp 0x711c0
movq %rax, %rbx
movq -0x298(%rbp), %rdi
leaq -0x288(%rbp), %rax
cmpq %rax, %rdi
je 0x711db
callq 0x2e360
movq -0x420(%rbp), %rdi
leaq -0x410(%rbp), %rax
cmpq %rax, %rdi
je 0x712a7
callq 0x2e360
jmp 0x712a7
jmp 0x711fe
movq %rax, %rbx
jmp 0x7125e
movq %rax, %rbx
movq %r12, %rdi
jmp 0x71211
movq %rax, %rbx
movq %r15, %rdi
callq 0x2e580
leaq -0xa0(%rbp), %rdi
callq 0x2e580
jmp 0x71227
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x7123f
callq 0x2e360
movq 0x1cd12(%rip), %rsi     # 0x8df58
leaq -0x298(%rbp), %rdi
callq 0x2e2f0
leaq -0x218(%rbp), %rdi
callq 0x2e150
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x71276
callq 0x2e360
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x71288
callq 0x2e360
movq 0x1ccc9(%rip), %rsi     # 0x8df58
leaq -0x420(%rbp), %rdi
callq 0x2e2f0
leaq -0x3a0(%rbp), %rdi
callq 0x2e150
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x712bf
callq 0x2e360
movq -0x110(%rbp), %rdi
testq %rdi, %rdi
je 0x712d0
callq 0x2e360
movq %rbx, %rdi
callq 0x2e730