// File: 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
subq $0x260, %rsp            # imm = 0x260
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movl $0xffffffff, -0x10(%rbp) # imm = 0xFFFFFFFF
movb $0x1, -0x11(%rbp)
movb $0x1, -0x12(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x12dc10
movl $0x0, -0x34(%rbp)
movb $0x0, -0x35(%rbp)
movb $0x0, -0x36(%rbp)
leaq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0xb73b0
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0xb7240
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xcb210
testb $0x1, %al
jne 0x1179aa
jmp 0x117b48
leaq -0x48(%rbp), %rdi
callq 0xcb250
movq (%rax), %rax
movq %rax, -0x58(%rbp)
testb $0x1, -0x9(%rbp)
je 0x117a7b
movq -0x58(%rbp), %rax
cmpl $0x4, 0x3c(%rax)
jne 0x117a55
movq -0x58(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0xb2bc0
jmp 0x1179ec
movq -0x210(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x12e7f0
movb %al, -0x211(%rbp)
jmp 0x117a04
leaq -0x70(%rbp), %rdi
callq 0xb22f0
movb -0x211(%rbp), %al
testb $0x1, %al
jne 0x117a19
jmp 0x117a53
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movb $0x1, -0x35(%rbp)
jmp 0x117a53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x11810f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xb22f0
jmp 0x11810f
jmp 0x117a55
movq -0x58(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x117a69
movq -0x58(%rbp), %rax
cmpl $0x2, 0x3c(%rax)
jne 0x117a76
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movb $0x1, -0x36(%rbp)
jmp 0x117b38
movq -0x58(%rbp), %rax
cmpl $0x4, 0x3c(%rax)
jne 0x117b15
movq -0x58(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0xb2bc0
jmp 0x117aa6
movq -0x220(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x12e7f0
movb %al, -0x221(%rbp)
jmp 0x117ac1
movb -0x221(%rbp), %al
xorb $-0x1, %al
movb %al, -0x222(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xb22f0
movb -0x222(%rbp), %al
testb $0x1, %al
jne 0x117ae7
jmp 0x117b13
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movb $0x1, -0x35(%rbp)
jmp 0x117b13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xb22f0
jmp 0x11810f
jmp 0x117b15
movq -0x58(%rbp), %rax
cmpl $0x1, 0x3c(%rax)
je 0x117b29
movq -0x58(%rbp), %rax
cmpl $0x3, 0x3c(%rax)
jne 0x117b36
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movb $0x1, -0x36(%rbp)
jmp 0x117b38
jmp 0x117b3a
leaq -0x48(%rbp), %rdi
callq 0xcb270
jmp 0x117994
cmpl $0x1, -0x34(%rbp)
jg 0x117b54
movb $0x0, -0x11(%rbp)
jmp 0x117b56
jmp 0x117b56
movq -0x8(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0xb2bc0
jmp 0x117b68
leaq -0xb8(%rbp), %rdi
callq 0x12d980
movq %rax, -0x230(%rbp)
jmp 0x117b7d
leaq -0xb8(%rbp), %rdi
callq 0xb22f0
movq -0x230(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0xaaa70
movq -0x238(%rbp), %rdx
leaq 0x23feb(%rip), %rsi     # 0x13bba3
leaq -0xd8(%rbp), %rdi
callq 0xaa7d0
jmp 0x117bc6
leaq -0xd9(%rbp), %rdi
callq 0xaa5f0
cmpq $0x0, -0xa0(%rbp)
je 0x117c68
movq -0xa0(%rbp), %rax
movq 0x50(%rax), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x100(%rbp), %rdi
callq *%rax
jmp 0x117bfc
leaq -0xd8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xaa6d0
leaq -0x100(%rbp), %rdi
callq 0xaabe8
jmp 0x117c68
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0xb22f0
jmp 0x11810f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xd9(%rbp), %rdi
callq 0xaa5f0
jmp 0x11810f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x118103
movb $0x0, -0x101(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rdi
callq 0xb2ae0
movq %rax, -0x118(%rbp)
movq -0x110(%rbp), %rdi
callq 0xb2b10
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0xb2b40
testb $0x1, %al
jne 0x117cbc
jmp 0x11806b
leaq -0x118(%rbp), %rdi
callq 0xb2b80
movq (%rax), %rax
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rdi
leaq 0x241cd(%rip), %rsi     # 0x13bead
callq 0x12c730
movb %al, -0x239(%rbp)
jmp 0x117ced
movb -0x239(%rbp), %al
testb $0x1, %al
jne 0x117cfc
jmp 0x118058
movq -0x128(%rbp), %rax
movq %rax, -0x248(%rbp)
cmpq $0x0, %rax
je 0x117d37
movq -0x248(%rbp), %rdi
leaq 0x5a8c2(%rip), %rsi     # 0x1725e0
leaq 0x5b65b(%rip), %rdx     # 0x173380
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0x250(%rbp)
jmp 0x117d42
xorl %eax, %eax
movq %rax, -0x250(%rbp)
jmp 0x117d42
movq -0x250(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rsi
leaq -0x150(%rbp), %rdi
callq 0xaa290
jmp 0x117d71
testb $0x1, -0x9(%rbp)
je 0x117e0d
leaq -0x170(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xaa290
jmp 0x117d90
movq -0x8(%rbp), %rsi
leaq -0x170(%rbp), %rdi
callq 0x12e680
movb %al, -0x251(%rbp)
jmp 0x117da8
movb -0x251(%rbp), %al
xorb $-0x1, %al
movb %al, -0x252(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xaabe8
movb -0x252(%rbp), %al
testb $0x1, %al
jne 0x117dce
jmp 0x117e0b
movl $0x5, -0x174(%rbp)
jmp 0x118018
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x118047
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xaabe8
jmp 0x118047
jmp 0x117e80
leaq -0x198(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xaa290
jmp 0x117e22
movq -0x8(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0x12e680
movb %al, -0x253(%rbp)
jmp 0x117e3a
leaq -0x198(%rbp), %rdi
callq 0xaabe8
movb -0x253(%rbp), %al
testb $0x1, %al
jne 0x117e52
jmp 0x117e7e
movl $0x5, -0x174(%rbp)
jmp 0x118018
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x198(%rbp), %rdi
callq 0xaabe8
jmp 0x118047
jmp 0x117e80
movb $0x0, -0x1d9(%rbp)
movb $0x0, -0x201(%rbp)
leaq 0x25e4b(%rip), %rdx     # 0x13dce0
leaq -0x1b8(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xcb380
jmp 0x117eaa
leaq -0xd8(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xaabb0
movq %rax, %rcx
movb $0x1, %al
cmpq $-0x1, %rcx
movb %al, -0x254(%rbp)
jne 0x117f68
leaq 0x25e08(%rip), %rdx     # 0x13dce5
leaq -0x1d8(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xcb380
jmp 0x117ef2
movb $0x1, -0x1d9(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xaabb0
movq %rax, %rcx
movb $0x1, %al
cmpq $-0x1, %rcx
movb %al, -0x254(%rbp)
jne 0x117f68
leaq 0x25dc2(%rip), %rdx     # 0x13dcea
leaq -0x200(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xcb380
jmp 0x117f3d
movb $0x1, -0x201(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0x200(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xaabb0
cmpq $-0x1, %rax
setne %al
movb %al, -0x254(%rbp)
movb -0x254(%rbp), %al
movb %al, -0x255(%rbp)
testb $0x1, -0x201(%rbp)
jne 0x117f7f
jmp 0x117f8b
leaq -0x200(%rbp), %rdi
callq 0xaabe8
testb $0x1, -0x1d9(%rbp)
jne 0x117f96
jmp 0x117fa2
leaq -0x1d8(%rbp), %rdi
callq 0xaabe8
leaq -0x1b8(%rbp), %rdi
callq 0xaabe8
movb -0x255(%rbp), %al
testb $0x1, %al
jne 0x117fba
jmp 0x11800e
movb $0x1, -0x101(%rbp)
movl $0x4, -0x174(%rbp)
jmp 0x118018
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x118000
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
testb $0x1, -0x1d9(%rbp)
jne 0x117ff2
jmp 0x117ffe
leaq -0x1d8(%rbp), %rdi
callq 0xaabe8
jmp 0x118000
leaq -0x1b8(%rbp), %rdi
callq 0xaabe8
jmp 0x118047
movl $0x0, -0x174(%rbp)
leaq -0x150(%rbp), %rdi
callq 0xaabe8
movl -0x174(%rbp), %eax
movl %eax, -0x25c(%rbp)
testl %eax, %eax
je 0x118045
jmp 0x118036
movl -0x25c(%rbp), %eax
subl $0x4, %eax
je 0x11806b
jmp 0x118043
jmp 0x11805a
jmp 0x118058
leaq -0x150(%rbp), %rdi
callq 0xaabe8
jmp 0x118103
jmp 0x11805a
leaq -0x118(%rbp), %rdi
callq 0xb2ba0
jmp 0x117ca0
testb $0x1, -0x101(%rbp)
jne 0x118078
movb $0x0, -0x12(%rbp)
testb $0x1, -0x11(%rbp)
je 0x11808d
testb $0x1, -0x12(%rbp)
je 0x11808d
movl $0x3, -0x10(%rbp)
jmp 0x1180c2
testb $0x1, -0x11(%rbp)
je 0x1180a2
testb $0x1, -0x12(%rbp)
jne 0x1180a2
movl $0x1, -0x10(%rbp)
jmp 0x1180c0
testb $0x1, -0x11(%rbp)
jne 0x1180b7
testb $0x1, -0x12(%rbp)
je 0x1180b7
movl $0x2, -0x10(%rbp)
jmp 0x1180be
movl $0x0, -0x10(%rbp)
jmp 0x1180c0
jmp 0x1180c2
testb $0x1, -0x9(%rbp)
je 0x1180ca
jmp 0x1180cc
jmp 0x1180cc
movl -0x10(%rbp), %eax
movl %eax, -0x260(%rbp)
movl $0x1, -0x174(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xaabe8
leaq -0x30(%rbp), %rdi
callq 0xccb90
movl -0x260(%rbp), %eax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
leaq -0xd8(%rbp), %rdi
callq 0xaabe8
leaq -0x30(%rbp), %rdi
callq 0xccb90
movq -0x78(%rbp), %rdi
callq 0xaaa60
nopw %cs:(%rax,%rax)