// File: /workspace/github_cpp_makefile_star2_O2/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 -0xe8(%rbp), %r14
movq %r14, %rdi
movq %rsi, -0x38(%rbp)
callq 0x7272a
movq (%r14), %rbx
movq 0x8(%r14), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x2c(%rbp)
leaq -0x120(%rbp), %r15
cmpq -0x48(%rbp), %rbx
je 0x6954f
movq (%rbx), %r13
movl 0x3c(%r13), %eax
cmpb $0x0, -0x3c(%rbp)
je 0x694fa
cmpl $0x4, %eax
jne 0x694f1
movq %r15, %rdi
movq -0x38(%rbp), %rsi
callq 0x4486c
movq %r13, %rdi
movq %r15, %r12
movq %r15, %rsi
callq 0x72d72
movl %eax, %r14d
movq %r12, %rdi
callq 0x44be0
movzbl %r14b, %eax
addl %eax, -0x2c(%rbp)
movl 0x3c(%r13), %eax
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
je 0x69543
jmp 0x69546
cmpl $0x4, %eax
jne 0x6953b
leaq -0xd0(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4486c
movq %r13, %rdi
leaq -0xd0(%rbp), %r12
movq %r12, %rsi
callq 0x72d72
movl %eax, %r14d
movq %r12, %rdi
callq 0x44be0
xorb $0x1, %r14b
movzbl %r14b, %eax
addl %eax, -0x2c(%rbp)
movl 0x3c(%r13), %eax
orl $0x2, %eax
cmpl $0x3, %eax
jne 0x69546
incl -0x2c(%rbp)
addq $0x8, %rbx
jmp 0x694a5
leaq -0xb8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4486c
leaq -0xb8(%rbp), %rdi
callq 0x72600
movq %rax, %r14
leaq -0xb8(%rbp), %rdi
callq 0x44be0
leaq 0x1133a(%rip), %rsi     # 0x7a8bb
leaq -0xa0(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x411c0
testq %r14, %r14
je 0x695be
movq 0x50(%r14), %rsi
movq (%rsi), %rax
leaq -0x70(%rbp), %rdi
callq *(%rax)
leaq -0xa0(%rbp), %rdi
leaq -0x70(%rbp), %r14
movq %r14, %rsi
callq 0x41500
movq %r14, %rdi
callq 0x418c8
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x50(%rbp)
leaq -0x180(%rbp), %r12
leaq -0x160(%rbp), %r15
leaq -0x140(%rbp), %rbx
cmpq -0x80(%rbp), %rcx
je 0x697a6
movq %rcx, -0x48(%rbp)
movq (%rcx), %r13
movq %r13, %rdi
leaq 0x115c0(%rip), %rsi     # 0x7abc5
callq 0x71cf8
testb %al, %al
je 0x6973f
movq %r13, %rdi
leaq 0x2b074(%rip), %rsi     # 0x94690
leaq 0x2be0d(%rip), %rdx     # 0x95430
xorl %ecx, %ecx
callq 0x41480
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rsi
leaq -0x70(%rbp), %rdi
callq 0x415b0
cmpb $0x0, -0x3c(%rbp)
je 0x6967a
movq %r12, %r13
movq %r12, %rdi
leaq -0x70(%rbp), %rsi
callq 0x415b0
movq %r13, %rdi
movq -0x38(%rbp), %rsi
callq 0x72c6e
movl %eax, %r14d
movq %r13, %rdi
callq 0x418c8
testb %r14b, %r14b
jne 0x696ad
xorl %r14d, %r14d
pushq $0x5
jmp 0x69722
leaq -0x108(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x415b0
leaq -0x108(%rbp), %r13
movq %r13, %rdi
movq -0x38(%rbp), %rsi
callq 0x72c6e
movl %eax, %r14d
movq %r13, %rdi
callq 0x418c8
testb %r14b, %r14b
jne 0x69670
movq %r15, %r14
movq %r15, %rdi
leaq -0x70(%rbp), %rsi
leaq 0x132ea(%rip), %rdx     # 0x7c9a8
callq 0x4df81
leaq -0xa0(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x41890
cmpq $-0x1, %rax
jne 0x6970f
movq %rbx, %r13
movq %rbx, %rdi
leaq -0x70(%rbp), %rsi
leaq 0x132c2(%rip), %rdx     # 0x7c9ad
callq 0x4df81
leaq -0xa0(%rbp), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x41890
cmpq $-0x1, %rax
je 0x6974c
movq %r13, %rdi
callq 0x418c8
movq %r14, %rdi
callq 0x418c8
movb $0x1, %al
movq %rax, -0x50(%rbp)
xorl %r14d, %r14d
pushq $0x4
popq %rax
movl %eax, %r13d
leaq -0x70(%rbp), %rdi
callq 0x418c8
testb %r14b, %r14b
jne 0x6973f
cmpl $0x5, %r13d
je 0x6973f
testl %r13d, %r13d
jne 0x697a6
movq -0x48(%rbp), %rcx
addq $0x8, %rcx
jmp 0x695ea
leaq -0x1a0(%rbp), %r14
movq %r14, %rdi
leaq -0x70(%rbp), %rsi
leaq 0x13251(%rip), %rdx     # 0x7c9b2
callq 0x4df81
xorl %r13d, %r13d
leaq -0xa0(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x41890
movq %rax, -0x78(%rbp)
movq %r14, %rdi
callq 0x418c8
movq %rbx, %rdi
callq 0x418c8
movq %r15, %rdi
callq 0x418c8
cmpq $-0x1, -0x78(%rbp)
jne 0x69717
movb $0x1, %r14b
jmp 0x69726
movl -0x2c(%rbp), %esi
cmpl $0x2, %esi
setl %al
movq -0x50(%rbp), %rdx
movl %edx, %ecx
notb %cl
orb %al, %cl
testb $0x1, %cl
je 0x697d9
cmpl $0x2, %esi
setl %al
orb %dl, %al
testb $0x1, %al
je 0x697dd
cmpl $0x2, %esi
setl %al
andb %dl, %al
movzbl %al, %ebx
addl %ebx, %ebx
jmp 0x697e0
pushq $0x3
jmp 0x697df
pushq $0x1
popq %rbx
leaq -0xa0(%rbp), %rdi
callq 0x418c8
leaq -0xe8(%rbp), %rdi
callq 0x4f87c
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6988c
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x418c8
jmp 0x69832
jmp 0x69887
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
jmp 0x69870
jmp 0x69887
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
jmp 0x69853
jmp 0x69879
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
jmp 0x69853
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x418c8
jmp 0x6987c
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
jmp 0x69870
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x44be0
jmp 0x6989b
jmp 0x6988c
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x418c8
jmp 0x6988f
movq %rax, %rbx
jmp 0x6989b
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x418c8
leaq -0xe8(%rbp), %rdi
callq 0x4f87c
movq %rbx, %rdi
callq 0x41790