// File: /workspace/github_cpp_makefile_star2_O3/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 $0x168, %rsp            # imm = 0x168
movl %esi, -0x3c(%rbp)
movq %rdi, %rsi
leaq -0x188(%rbp), %r15
movq %r15, %rdi
movq %rsi, -0x38(%rbp)
callq 0x6f575
movq (%r15), %r12
movq 0x8(%r15), %r14
cmpq %r14, %r12
je 0x6335f
xorl %ebx, %ebx
movq (%r12), %r13
movl 0x3c(%r13), %eax
cmpb $0x0, -0x3c(%rbp)
je 0x632fa
cmpl $0x4, %eax
jne 0x632f1
leaq -0x170(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x32ac0
movq %r13, %rdi
leaq -0x170(%rbp), %rsi
callq 0x6fdc6
movl %eax, %r15d
movq -0x170(%rbp), %rdi
testq %rdi, %rdi
je 0x632e7
callq 0x2e360
movzbl %r15b, %eax
addl %eax, %ebx
movl 0x3c(%r13), %eax
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
je 0x63348
jmp 0x6334a
cmpl $0x4, %eax
jne 0x63340
leaq -0x158(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x32ac0
movq %r13, %rdi
leaq -0x158(%rbp), %rsi
callq 0x6fdc6
movl %eax, %r15d
movq -0x158(%rbp), %rdi
testq %rdi, %rdi
je 0x63332
callq 0x2e360
xorb $0x1, %r15b
movzbl %r15b, %eax
addl %eax, %ebx
movl 0x3c(%r13), %eax
orl $0x2, %eax
cmpl $0x3, %eax
jne 0x6334a
incl %ebx
addq $0x8, %r12
cmpq %r14, %r12
jne 0x632a1
cmpl $0x2, %ebx
setl %bl
jmp 0x63361
movb $0x1, %bl
leaq -0x140(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x32ac0
leaq -0x140(%rbp), %rdi
callq 0x6f412
movq %rax, %r15
movq -0x140(%rbp), %rdi
testq %rdi, %rdi
je 0x63391
callq 0x2e360
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x14538(%rip), %rdx     # 0x778db
leaq -0xc8(%rbp), %rdi
movq %rdx, %rsi
callq 0x32e40
testq %r15, %r15
je 0x633e8
movq 0x50(%r15), %rsi
movq (%rsi), %rax
leaq -0x60(%rbp), %rdi
callq *(%rax)
leaq -0xc8(%rbp), %rdi
leaq -0x60(%rbp), %r15
movq %r15, %rsi
callq 0x2e4c0
movq (%r15), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x633e8
callq 0x2e360
movb %bl, -0x29(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %r15
movq 0x8(%rax), %r13
cmpq %r13, %r15
je 0x636ec
movq $0x0, -0x68(%rbp)
leaq 0x147d7(%rip), %rbx     # 0x77be5
leaq -0x88(%rbp), %r14
movq (%r15), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x6e968
testb %al, %al
je 0x636c7
movq %r12, %rdi
leaq 0x2927b(%rip), %rsi     # 0x8c6b0
leaq 0x2a014(%rip), %rdx     # 0x8d450
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 0x32cbc
cmpb $0x0, -0x3c(%rbp)
je 0x634d2
leaq -0x118(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x128(%rbp), %rdi
callq 0x32cbc
leaq -0x128(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x6fcf1
movl %eax, %r12d
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x634c0
callq 0x2e360
testb %r12b, %r12b
jne 0x63527
movl $0x5, %r14d
xorl %ebx, %ebx
jmp 0x63688
leaq -0xf8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x108(%rbp), %rdi
callq 0x32cbc
leaq -0x108(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x6fcf1
movl %eax, %r12d
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x63522
callq 0x2e360
testb %r12b, %r12b
jne 0x634c5
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x32cbc
movq %r14, %rdi
leaq 0x163c9(%rip), %rsi     # 0x79918
callq 0x2e7e0
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rcx
leaq -0xc8(%rbp), %rdi
xorl %edx, %edx
callq 0x2e710
movb $0x1, %bl
cmpq $-0x1, %rax
jne 0x6365e
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 0x32cbc
movq %rbx, %rdi
leaq 0x16372(%rip), %rsi     # 0x7991d
callq 0x2e7e0
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rcx
leaq -0xc8(%rbp), %rdi
xorl %edx, %edx
callq 0x2e710
movb $0x1, %bl
cmpq $-0x1, %rax
jne 0x63646
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 0x32cbc
movq %rbx, %rdi
leaq 0x1631c(%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
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x63646
callq 0x2e360
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x6365e
callq 0x2e360
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x63673
callq 0x2e360
movq -0x68(%rbp), %rax
orb %bl, %al
movq %rax, -0x68(%rbp)
movzbl %bl, %r14d
xorb $0x1, %bl
shll $0x2, %r14d
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x6369a
callq 0x2e360
testb %bl, %bl
jne 0x636b9
cmpl $0x5, %r14d
je 0x636b9
testl %r14d, %r14d
leaq 0x14537(%rip), %rbx     # 0x77be5
leaq -0x88(%rbp), %r14
je 0x636c7
jmp 0x636d4
leaq 0x14525(%rip), %rbx     # 0x77be5
leaq -0x88(%rbp), %r14
addq $0x8, %r15
cmpq %r13, %r15
jne 0x63415
movq -0x68(%rbp), %rdx
movl %edx, %eax
notb %al
movb -0x29(%rbp), %cl
orb %cl, %al
movl $0x3, %ebx
testb $0x1, %al
jne 0x636f1
jmp 0x63705
xorl %edx, %edx
movb -0x29(%rbp), %cl
movl %ecx, %eax
orb %dl, %al
movl $0x1, %ebx
testb $0x1, %al
je 0x63705
andb %dl, %cl
movzbl %cl, %ebx
addl %ebx, %ebx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x6371d
callq 0x2e360
movq -0x188(%rbp), %rdi
testq %rdi, %rdi
je 0x6372e
callq 0x2e360
movl %ebx, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x63818
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x6377f
callq 0x2e360
jmp 0x6377f
jmp 0x6377c
jmp 0x63813
movq %rax, %rbx
movq -0x140(%rbp), %rdi
jmp 0x637f3
jmp 0x63813
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x6379e
callq 0x2e360
jmp 0x6379e
jmp 0x6379b
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
jmp 0x637d1
jmp 0x637fa
movq %rax, %rbx
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
jmp 0x637d1
movq %rax, %rbx
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x637fd
callq 0x2e360
jmp 0x637fd
movq %rax, %rbx
movq -0x170(%rbp), %rdi
jmp 0x637f3
movq %rax, %rbx
movq -0x158(%rbp), %rdi
testq %rdi, %rdi
jne 0x6382e
jmp 0x63833
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x6381b
callq 0x2e360
jmp 0x6381b
jmp 0x63818
movq %rax, %rbx
jmp 0x63833
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x63833
callq 0x2e360
movq -0x188(%rbp), %rdi
testq %rdi, %rdi
je 0x63844
callq 0x2e360
movq %rbx, %rdi
callq 0x2e730