// File: eniac[P]Mantis/src/compile/find_nodes.cpp
// Function: findAndTransformMblRefsInAction(ActionNode*, std::vector<MblRefNode*, std::allocator<MblRefNode*>>*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void findAndTransformMblRefsInAction(ActionNode* action,
                                     vector<MblRefNode*>* varRefs,
                                     const string& varName,
                                     const string& altHeader,
                                     const string& altField) {

    for (ActionStmtNode* as : *action->stmts_->list_) {
        for (BodyWordNode* bw : *as->args_->list_) {
            if (bw->wordType_ != BodyWordNode::VARREF) {
                continue;
            }

            auto varRef = dynamic_cast<MblRefNode*>(bw->contents_);
            if (*varRef->name_->word_ == varName) {
                varRef->transform(altHeader, altField);
            } else if (varRefs && !varRef->transformed_) {
                varRefs->push_back(dynamic_cast<MblRefNode*>(bw->contents_));
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0xb6410
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0xb62a0
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0xc0ca0
testb $0x1, %al
jne 0x12d63f
jmp 0x12d7ce
leaq -0x38(%rbp), %rdi
callq 0xc0ce0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x40(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0xb6be0
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
callq 0xb6a70
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xc0a60
testb $0x1, %al
jne 0x12d68f
jmp 0x12d7be
leaq -0x58(%rbp), %rdi
callq 0xc0aa0
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0x12d6ae
jmp 0x12d7b0
movq -0x68(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x12d6e4
movq -0x80(%rbp), %rdi
leaq 0x44f15(%rip), %rsi     # 0x1725e0
leaq 0x45d56(%rip), %rdx     # 0x173428
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0x88(%rbp)
jmp 0x12d6ef
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x12d6ef
movq -0x88(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x80(%rax), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0xfef60
testb $0x1, %al
jne 0x12d718
jmp 0x12d72e
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xcac20
jmp 0x12d7ae
cmpq $0x0, -0x10(%rbp)
je 0x12d7ac
movq -0x70(%rbp), %rax
testb $0x1, 0x39(%rax)
jne 0x12d7ac
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x68(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x12d786
movq -0x90(%rbp), %rdi
leaq 0x44e73(%rip), %rsi     # 0x1725e0
leaq 0x45cb4(%rip), %rdx     # 0x173428
xorl %eax, %eax
movl %eax, %ecx
callq 0xaa660
movq %rax, -0xa0(%rbp)
jmp 0x12d791
xorl %eax, %eax
movq %rax, -0xa0(%rbp)
jmp 0x12d791
movq -0x98(%rbp), %rdi
movq -0xa0(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rsi
callq 0x129e80
jmp 0x12d7ae
jmp 0x12d7b0
leaq -0x58(%rbp), %rdi
callq 0xc0ac0
jmp 0x12d679
jmp 0x12d7c0
leaq -0x38(%rbp), %rdi
callq 0xc0d00
jmp 0x12d629
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)