// File: eniac[P]Mantis/src/compile/compile_p4.cpp
// Function: transformMalleableFieldRef(MblRefNode*, std::vector<MblRefNode*, std::allocator<MblRefNode*>>*, std::vector<AstNode*, std::allocator<AstNode*>>*, P4RMalleableFieldNode const&)
static void transformMalleableFieldRef(MblRefNode* ref, vector<MblRefNode*>* mblRefs,
                               vector<AstNode*>* nodeArray,
                               const P4RMalleableFieldNode& variable) {
    // malleable field references can be in (1) actions, (2) table match fields,
    // and (3) reaction arguments
    AstNode* parent = ref->parent_;
    while (parent != NULL) {
        if (typeContains(parent, "ActionNode")) {
            ActionNode* action = dynamic_cast<ActionNode*>(parent);
            duplicateActions(ref, action, mblRefs, nodeArray, variable);
            return;
        } else if (typeContains(parent, "TableNode")) {
            TableNode* table = dynamic_cast<TableNode*>(parent);
            transformTableWithRefRead(ref, table, variable);
            return;
        } else if (typeContains(parent, "P4RReactionNode")) {
            return;
        }
        parent = parent->parent_;
    }

    PANIC("Syntax Error: Could not find parent of variable reference\n");
    exit(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x119527
movq -0x28(%rbp), %rdi
leaq 0x2280d(%rip), %rsi     # 0x13bc37
callq 0x12c730
testb $0x1, %al
jne 0x119435
jmp 0x119492
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x119464
movq -0x40(%rbp), %rdi
leaq 0x59192(%rip), %rsi     # 0x1725e0
leaq 0x59a4b(%rip), %rdx     # 0x172ea0
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0x48(%rbp)
jmp 0x11946c
xorl %eax, %eax
movq %rax, -0x48(%rbp)
jmp 0x11946c
movq -0x48(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
callq 0x125600
jmp 0x11955c
movq -0x28(%rbp), %rdi
leaq 0x22a1c(%rip), %rsi     # 0x13beb9
callq 0x12c730
testb $0x1, %al
jne 0x1194a8
jmp 0x1194fa
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x1194d7
movq -0x50(%rbp), %rdi
leaq 0x5911f(%rip), %rsi     # 0x1725e0
leaq 0x59930(%rip), %rdx     # 0x172df8
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0x58(%rbp)
jmp 0x1194df
xorl %eax, %eax
movq %rax, -0x58(%rbp)
jmp 0x1194df
movq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x1260c0
jmp 0x11955c
movq -0x28(%rbp), %rdi
leaq 0x249d5(%rip), %rsi     # 0x13deda
callq 0x12c730
testb $0x1, %al
jne 0x119510
jmp 0x119512
jmp 0x11955c
jmp 0x119514
jmp 0x119516
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x119414
movq 0x5aa82(%rip), %rax     # 0x173fb0
movq (%rax), %rdi
leaq 0x24ce8(%rip), %rsi     # 0x13e220
leaq 0x24818(%rip), %rdx     # 0x13dd57
movl $0x165, %ecx            # imm = 0x165
leaq 0x24d21(%rip), %r8      # 0x13e26c
movb $0x0, %al
callq 0xaa850
movl $0x1, %edi
callq 0xaa6c0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)