// File: /workspace/github_cpp_makefile_star2_O1/eniac[P]Mantis/src/compile/compile_p4.cpp
// Function: inferIsoOptForIng(std::vector<AstNode*, std::allocator<AstNode*>>*, bool)
int inferIsoOptForIng(vector<AstNode*>* nodeArray, bool forIng) {

    int inferred_iso = -1;
    bool require_meas_iso = true;
    bool require_react_iso = true;
    vector<ReactionArgNode*> reaction_args = findReactionArgs(*nodeArray);
    int num_args = 0;
    bool has_regarg = false;
    bool has_fieldarg = false;

    for (auto ra : reaction_args) {   
        if(forIng) {
            if (ra->argType_==ReactionArgNode::REGISTER) {
                if(findRegargInIng(ra, *nodeArray)) {
                    num_args += 1;
                    has_regarg = true;
                }
            }
            if (ra->argType_==ReactionArgNode::INGRESS_FIELD || ra->argType_==ReactionArgNode::INGRESS_MBL_FIELD) {
                num_args += 1;
                has_fieldarg = true;
            }
        } else {
            if (ra->argType_==ReactionArgNode::REGISTER) {
                if(!findRegargInIng(ra, *nodeArray)) {
                    num_args += 1;
                    has_regarg = true;
                }
            }
            if (ra->argType_==ReactionArgNode::EGRESS_FIELD || ra->argType_==ReactionArgNode::EGRESS_MBL_FIELD) {
                num_args += 1;
                has_fieldarg = true;
            }
        }
    }

    if (num_args <= 1) {
        require_meas_iso = false;
    } else {
        // Potentially being false after bin-packing (single packed register, 2 single element reg)
        // Also single element 32b reg could be packed with field arg into a single 64b reg
    }

    // Simple static analysis to differentiate the case requiring no update isolation
    P4RReactionNode * react_node = findReaction(*nodeArray);
    string user_dialogue = "";
    if (react_node != 0) {
        user_dialogue = react_node->body_->toString();
    }
    bool foundMblOperation = false;
    // If malleable table operations specified, break if any
    for (auto node : *nodeArray) {
        if(typeContains(node, "P4RMalleableTableNode")) {
            P4RMalleableTableNode* table = dynamic_cast<P4RMalleableTableNode*>(node);
            string table_name = *(table->table_->name_->word_);

            if(forIng) {
                if(!findTblInIng(table_name, *nodeArray)) {
                    continue;
                }
            } else {
                if(findTblInIng(table_name, *nodeArray)) {
                    continue;
                }
            }
            
            if(user_dialogue.find(table_name+"_mod")!=std::string::npos || user_dialogue.find(table_name+"_add")!=std::string::npos || user_dialogue.find(table_name+"_del")!=std::string::npos) {
                foundMblOperation = true;
                break;
            }
        }
    } 

    if (!foundMblOperation) {
        require_react_iso = false;
    }

    if (require_meas_iso && require_react_iso) {
        inferred_iso = 3;
    } else if (require_meas_iso && !require_react_iso) {
        inferred_iso = 1;
    } else if (!require_meas_iso && require_react_iso) {
        inferred_iso = 2;
    } else {
        inferred_iso = 0;
    }

    if(forIng) {
        PRINT_VERBOSE("Inferred ing isolation option: %d\n", inferred_iso);
    } else {
        PRINT_VERBOSE("Inferred egr isolation option: %d\n", inferred_iso);
    }

    return inferred_iso;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl %esi, -0x3c(%rbp)
movq %rdi, %rsi
leaq -0x198(%rbp), %r14
movq %r14, %rdi
movq %rsi, -0x38(%rbp)
callq 0x70010
movq (%r14), %r15
movq 0x8(%r14), %r12
cmpq %r12, %r15
je 0x638ed
xorl %ebx, %ebx
movq (%r15), %r13
movl 0x3c(%r13), %eax
cmpb $0x0, -0x3c(%rbp)
je 0x63888
cmpl $0x4, %eax
jne 0x6387c
leaq -0x180(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x32d96
movq %r13, %rdi
leaq -0x180(%rbp), %rsi
callq 0x708a0
movl %eax, %r14d
movq -0x180(%rbp), %rdi
testq %rdi, %rdi
je 0x63876
callq 0x2e360
movzbl %r14b, %eax
addl %eax, %ebx
testl $0xfffffffd, 0x3c(%r13) # imm = 0xFFFFFFFD
je 0x638d6
jmp 0x638d8
cmpl $0x4, %eax
jne 0x638ca
leaq -0x168(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x32d96
movq %r13, %rdi
leaq -0x168(%rbp), %rsi
callq 0x708a0
movl %eax, %r14d
movq -0x168(%rbp), %rdi
testq %rdi, %rdi
je 0x638c0
callq 0x2e360
xorb $0x1, %r14b
movzbl %r14b, %eax
addl %eax, %ebx
movl 0x3c(%r13), %eax
orl $0x2, %eax
cmpl $0x3, %eax
jne 0x638d8
incl %ebx
addq $0x8, %r15
cmpq %r12, %r15
jne 0x63831
cmpl $0x2, %ebx
setl %bl
jmp 0x638ef
movb $0x1, %bl
leaq -0x150(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x32d96
leaq -0x150(%rbp), %rdi
callq 0x6fe8f
movq %rax, %r15
movq -0x150(%rbp), %rdi
testq %rdi, %rdi
je 0x6391f
callq 0x2e360
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x13faa(%rip), %rdx     # 0x778db
leaq -0xc8(%rbp), %rdi
movq %rdx, %rsi
callq 0x33112
testq %r15, %r15
je 0x63976
movq 0x50(%r15), %rsi
movq (%rsi), %rax
leaq -0x60(%rbp), %rdi
callq *(%rax)
leaq -0xc8(%rbp), %rdi
leaq -0x60(%rbp), %r14
movq %r14, %rsi
callq 0x2e4c0
movq (%r14), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x63976
callq 0x2e360
movq -0x38(%rbp), %rax
movq (%rax), %r15
movq 0x8(%rax), %rax
movq %rax, -0xf8(%rbp)
cmpq %rax, %r15
je 0x63c80
movb %bl, -0x29(%rbp)
leaq -0x78(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq $0x0, -0x68(%rbp)
leaq -0x88(%rbp), %r13
movq (%r15), %r12
movq %r12, %rdi
leaq 0x1422a(%rip), %rsi     # 0x77be5
callq 0x6f390
xorl %ebx, %ebx
testb %al, %al
je 0x63c5d
movq %r12, %rdi
leaq 0x28c5c(%rip), %rsi     # 0x8c630
leaq 0x299f5(%rip), %rdx     # 0x8d3d0
xorl %ecx, %ecx
callq 0x2e430
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
leaq -0x50(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %rdi
callq 0x32f92
cmpb $0x0, -0x3c(%rbp)
je 0x63a6e
leaq -0x128(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x138(%rbp), %rdi
callq 0x32f92
leaq -0x138(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x707cb
movl %eax, %r14d
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x63a5f
callq 0x2e360
movl $0x5, %ebx
testb %r14b, %r14b
jne 0x63acc
jmp 0x63c4b
leaq -0x108(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x118(%rbp), %rdi
callq 0x32f92
leaq -0x118(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x707cb
movl %eax, %r14d
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x63abe
callq 0x2e360
movl $0x5, %ebx
testb %r14b, %r14b
jne 0x63c4b
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x32f92
movq %rbx, %rdi
leaq 0x15e1a(%rip), %rsi     # 0x79918
callq 0x2e7e0
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rcx
xorl %r14d, %r14d
leaq -0xc8(%rbp), %rdi
xorl %edx, %edx
callq 0x2e710
movq %rax, %r12
movb $0x1, %bl
cmpq $-0x1, %rax
jne 0x63be0
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %r14
movq %r13, %rdi
callq 0x32f92
movq %r14, %rdi
leaq 0x15dc1(%rip), %rsi     # 0x7991d
callq 0x2e7e0
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rcx
xorl %r14d, %r14d
leaq -0xc8(%rbp), %rdi
xorl %edx, %edx
callq 0x2e710
cmpq $-0x1, %rax
jne 0x63be0
leaq -0xd8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %rbx
movq %rbx, %rdi
callq 0x32f92
movq %rbx, %rdi
leaq 0x15d6d(%rip), %rsi     # 0x79922
callq 0x2e7e0
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rcx
leaq -0xc8(%rbp), %rdi
xorl %edx, %edx
callq 0x2e710
cmpq $-0x1, %rax
setne %bl
movb $0x1, %r14b
testb %r14b, %r14b
je 0x63bfd
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x63bfd
callq 0x2e360
cmpq $-0x1, %r12
jne 0x63c18
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x63c18
callq 0x2e360
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x63c30
callq 0x2e360
movq -0x68(%rbp), %rax
movzbl %al, %eax
testb %bl, %bl
movl $0x1, %ecx
cmovnel %ecx, %eax
movq %rax, -0x68(%rbp)
movzbl %bl, %ebx
shll $0x2, %ebx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x63c5d
callq 0x2e360
cmpl $0x5, %ebx
je 0x63c66
testl %ebx, %ebx
jne 0x63c77
addq $0x8, %r15
cmpq -0xf8(%rbp), %r15
jne 0x639ae
movb -0x29(%rbp), %bl
movq -0x68(%rbp), %rdx
jmp 0x63c82
xorl %edx, %edx
movl %edx, %eax
notb %al
orb %bl, %al
movl %ebx, %ecx
movl $0x3, %ebx
testb $0x1, %al
je 0x63ca7
movl %ecx, %eax
orb %dl, %al
movl $0x1, %ebx
testb $0x1, %al
je 0x63ca7
andb %dl, %cl
movzbl %cl, %ebx
addl %ebx, %ebx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x63cbf
callq 0x2e360
movq -0x198(%rbp), %rdi
testq %rdi, %rdi
je 0x63cd0
callq 0x2e360
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x63d04
callq 0x2e360
jmp 0x63d04
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq -0xf0(%rbp), %rdi
jne 0x63d44
jmp 0x63d63
jmp 0x63dcd
jmp 0x63dc8
movq %rax, %rbx
movq -0x150(%rbp), %rdi
jmp 0x63da8
jmp 0x63dc8
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x63d63
callq 0x2e360
jmp 0x63d63
jmp 0x63d60
movq %rax, %rbx
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
jmp 0x63d86
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
jmp 0x63d86
jmp 0x63daf
movq %rax, %rbx
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x63db2
callq 0x2e360
jmp 0x63db2
movq %rax, %rbx
movq -0x180(%rbp), %rdi
jmp 0x63da8
movq %rax, %rbx
movq -0x168(%rbp), %rdi
testq %rdi, %rdi
jne 0x63de3
jmp 0x63de8
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x63dd0
callq 0x2e360
jmp 0x63dd0
jmp 0x63dcd
movq %rax, %rbx
jmp 0x63de8
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x63de8
callq 0x2e360
movq -0x198(%rbp), %rdi
testq %rdi, %rdi
je 0x63df9
callq 0x2e360
movq %rbx, %rdi
callq 0x2e730