// File: Bartor[P]kompilator/middle/ast_optimizer/ASTOptimizer.cpp
// Function: ASTOptimizer::iteratorReplacer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, long long)::$_0::operator()(Node*) const
Callback ASTOptimizer::iteratorReplacer(std::string &variableToReplace, long long value) {
    return [this, variableToReplace, value](Node *node) -> Node * {
        if (auto idVal = dynamic_cast<IdentifierValue *>(node)) {
            try {
                VariableIdentifier &varId = dynamic_cast<VariableIdentifier &>(idVal->identifier);

                if (varId.name == variableToReplace) {
                    return new NumberValue(value);
                }
            } catch (std::bad_cast _) {
                try {
                    VariableAccessIdentifier &varAccId = dynamic_cast<VariableAccessIdentifier &>(idVal->identifier);

                    if (varAccId.accessName == variableToReplace) {
                        return new IdentifierValue(*new AccessIdentifier(varAccId.name, value));
                    }
                } catch (std::bad_cast _) {}
            }
        } else if (auto varArrId = dynamic_cast<VariableAccessIdentifier *>(node)) {
            if (varArrId->accessName == variableToReplace) return new AccessIdentifier(varArrId->name, value);
        }
        return node;
    };
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x27e7a
movq -0x68(%rbp), %rdi
leaq 0x180fc(%rip), %rsi     # 0x3ff60
leaq 0x183bd(%rip), %rdx     # 0x40228
xorl %eax, %eax
movl %eax, %ecx
callq 0x62f0
movq %rax, -0x78(%rbp)
jmp 0x27e82
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x27e82
movq -0x78(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x2813f
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1821c(%rip), %rsi     # 0x400c0
leaq 0x1825d(%rip), %rdx     # 0x40108
xorl %eax, %eax
movl %eax, %ecx
callq 0x62f0
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
jne 0x27ec5
callq 0x6530
jmp 0x27ec5
movq -0x70(%rbp), %rsi
movq -0x80(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x8, %rsi
callq 0x24890
testb $0x1, %al
jne 0x27eeb
jmp 0x28053
movl $0x10, %edi
callq 0x6260
movq %rax, -0x88(%rbp)
jmp 0x27efe
movq -0x88(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x87e0
jmp 0x27f14
movq -0x88(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x28215
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x27f4f
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x10, %esi
callq 0x6270
movl -0x34(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x28222
movq -0x30(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x6360
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x203d0
movq -0x98(%rbp), %rdi
callq 0x60f0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1812a(%rip), %rsi     # 0x400c0
leaq 0x181fb(%rip), %rdx     # 0x40198
xorl %eax, %eax
movl %eax, %ecx
callq 0x62f0
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
jne 0x27fba
callq 0x6530
jmp 0x27fba
movq -0x70(%rbp), %rsi
movq -0x90(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdi
addq $0x8, %rsi
callq 0x24890
testb $0x1, %al
jne 0x27fe3
jmp 0x2811c
movl $0x10, %edi
callq 0x6260
movq %rax, -0xa0(%rbp)
jmp 0x27ff6
movl $0x18, %edi
callq 0x6260
movq %rax, -0xa8(%rbp)
jmp 0x28009
movq -0xa8(%rbp), %rdi
movq -0x70(%rbp), %rax
movq -0x48(%rbp), %rcx
movq 0x8(%rcx), %rsi
movq 0x28(%rax), %rdx
callq 0x88f0
jmp 0x28027
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdi
callq 0x8820
jmp 0x2803c
movq -0xa0(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x280f9
jmp 0x28117
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x280a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x28091
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x18, %esi
callq 0x6270
movq -0xa0(%rbp), %rdi
movl $0x10, %esi
callq 0x6270
movl -0x34(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2812a
movq -0x30(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x6360
movq %rax, %rsi
leaq -0x58(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x203d0
movq -0xb8(%rbp), %rdi
callq 0x60f0
movq -0xb0(%rbp), %rdi
callq 0x6500
callq 0x6450
jmp 0x280f0
jmp 0x280f2
movl $0x0, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x6500
callq 0x6450
movl -0x4c(%rbp), %eax
testl %eax, %eax
je 0x28115
jmp 0x28110
jmp 0x28215
jmp 0x28117
jmp 0x2820d
jmp 0x280f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x6500
callq 0x6450
jmp 0x2813a
jmp 0x28222
movq -0x18(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x28177
movq -0xc0(%rbp), %rdi
leaq 0x17e02(%rip), %rsi     # 0x3ff60
leaq 0x18033(%rip), %rdx     # 0x40198
xorl %eax, %eax
movl %eax, %ecx
callq 0x62f0
movq %rax, -0xc8(%rbp)
jmp 0x28182
xorl %eax, %eax
movq %rax, -0xc8(%rbp)
jmp 0x28182
movq -0xc8(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x2820b
movq -0x70(%rbp), %rsi
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rdi
addq $0x8, %rsi
callq 0x24890
testb $0x1, %al
jne 0x281af
jmp 0x28209
movl $0x18, %edi
callq 0x6260
movq %rax, %rdi
movq -0x70(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0xd0(%rbp)
movq -0x60(%rbp), %rcx
movq 0x8(%rcx), %rsi
movq 0x28(%rax), %rdx
callq 0x88f0
jmp 0x281dd
movq -0xd0(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x28215
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x18, %esi
callq 0x6270
jmp 0x28222
jmp 0x2820b
jmp 0x2820d
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x64d0
movq %rax, %rdi
callq 0x9470
nopw %cs:(%rax,%rax)