// File: /workspace/github_cpp_makefile_star2_O1/Bartor[P]kompilator/middle/ast_optimizer/ASTOptimizer.cpp
// Function: ASTOptimizer::constantLoopUnroller(Node*)
Node *ASTOptimizer::constantLoopUnroller(Node *node) {
    if (auto forNode = dynamic_cast<For *>(node)) {
        try {
            auto startConstant = dynamic_cast<NumberValue &>(forNode->startValue);
            try {
                auto endConstant = dynamic_cast<NumberValue &>(forNode->endValue);

                CommandList *cmdList = new CommandList();

                if (forNode->reversed) {
                    for (long long i = startConstant.value; i >= endConstant.value; i--) {
                        Callback replacer = iteratorReplacer(forNode->variableName, i);
                        originalProgram->constants.constants.push_back(i);
                        cmdList->append(*static_cast<CommandList *>(forNode->commands.copy(replacer)));
                    }
                } else {
                    for (long long i = startConstant.value; i <= endConstant.value; i++) {
                        Callback replacer = iteratorReplacer(forNode->variableName, i);
                        originalProgram->constants.constants.push_back(i);
                        cmdList->append(*static_cast<CommandList *>(forNode->commands.copy(replacer)));
                    }
                }

                return cmdList;
            } catch (std::bad_cast _) {}
        } catch (std::bad_cast _) {}
    }
    return node;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r12
movq %rdi, %r14
testq %rsi, %rsi
je 0x1950a
leaq 0xdb34(%rip), %rsi      # 0x27028
leaq 0xdf5d(%rip), %rdx      # 0x27458
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x5240
movq %rax, %rbx
jmp 0x1950c
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x1976f
movq 0x28(%rbx), %rdi
leaq 0xe0b8(%rip), %rsi      # 0x275d8
leaq 0xdc61(%rip), %rdx      # 0x27188
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
movq %r12, -0x50(%rbp)
je 0x19784
movq 0x8(%rax), %r13
movq 0x30(%rbx), %rdi
leaq 0xe08e(%rip), %rsi      # 0x275d8
leaq 0xdc37(%rip), %rdx      # 0x27188
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x19789
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x20, %edi
callq 0x51f0
movq %rax, %r12
leaq 0xdd43(%rip), %rax      # 0x272c0
addq $0x10, %rax
movq %rax, (%r12)
movq %r12, %rax
addq $0x8, %rax
movq %rax, -0x58(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r12)
movq $0x0, 0x18(%r12)
movq %rbx, -0x38(%rbp)
cmpb $0x1, 0x40(%rbx)
jne 0x19692
movq %r13, -0x30(%rbp)
cmpq -0x40(%rbp), %r13
jl 0x1976f
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
leaq -0x78(%rbp), %rbx
leaq -0xb8(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq -0x48(%rbp), %rdx
movq %r13, %rcx
callq 0x198ce
movq (%r14), %rax
movq 0x10(%rax), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x19609
movq -0x30(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x19612
leaq -0x30(%rbp), %rdx
callq 0x6732
movq -0x38(%rbp), %rax
movq 0x38(%rax), %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0xebc4
movq (%r13), %rax
movq %r13, %rdi
movq %r15, %rsi
callq *0x8(%rax)
movq 0x10(%r12), %rsi
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rcx
movq -0x58(%rbp), %rdi
callq 0x1a33e
movq -0xa8(%rbp), %rax
testq %rax, %rax
je 0x19661
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x19677
movq %rbx, %rdi
movq %rbx, %rsi
movl $0x3, %edx
callq *%rax
movq -0x30(%rbp), %rax
leaq -0x1(%rax), %r13
movq %r13, -0x30(%rbp)
cmpq -0x40(%rbp), %rax
jg 0x195d5
jmp 0x1976f
movq %r13, -0x30(%rbp)
cmpq -0x40(%rbp), %r13
jg 0x1976f
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x48(%rbp)
leaq -0x78(%rbp), %rbx
leaq -0x98(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq -0x48(%rbp), %rdx
movq %r13, %rcx
callq 0x198ce
movq (%r14), %rax
movq 0x10(%rax), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x196eb
movq -0x30(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x196f4
leaq -0x30(%rbp), %rdx
callq 0x6732
movq -0x38(%rbp), %rax
movq 0x38(%rax), %r13
movq %r15, %rdi
movq %rbx, %rsi
callq 0xebc4
movq (%r13), %rax
movq %r13, %rdi
movq %r15, %rsi
callq *0x8(%rax)
movq 0x10(%r12), %rsi
movq 0x8(%rax), %rdx
movq 0x10(%rax), %rcx
movq -0x58(%rbp), %rdi
callq 0x1a33e
movq -0x88(%rbp), %rax
testq %rax, %rax
je 0x19743
movq %r15, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq *%rax
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x19759
movq %rbx, %rdi
movq %rbx, %rsi
movl $0x3, %edx
callq *%rax
movq -0x30(%rbp), %rax
leaq 0x1(%rax), %r13
movq %r13, -0x30(%rbp)
cmpq -0x40(%rbp), %rax
jl 0x196b7
movq %r12, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5410
callq 0x5410
jmp 0x197ad
jmp 0x197ad
movq %rdx, %r15
movq %rax, %r14
jmp 0x19879
jmp 0x197a3
jmp 0x197a3
jmp 0x197a3
movq %rax, %rdi
callq 0xec29
jmp 0x197ad
movq %rdx, %r15
movq %rax, %r14
jmp 0x19842
movq %rdx, %r15
movq %rax, %r14
jmp 0x197eb
movq %rdx, %r15
movq %rax, %r14
jmp 0x1982b
movq %rdx, %r15
movq %rax, %r14
movq -0x88(%rbp), %rax
testq %rax, %rax
je 0x197eb
leaq -0x98(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x19842
leaq -0x78(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x19842
jmp 0x197a3
jmp 0x197a3
movq %rdx, %r15
movq %rax, %r14
movq -0xa8(%rbp), %rax
testq %rax, %rax
je 0x1982b
leaq -0xb8(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x19842
leaq -0x78(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
cmpl $0x1, %r15d
jne 0x19879
movq %r14, %rdi
callq 0x52b0
movq 0xe751(%rip), %rax      # 0x27fa8
addq $0x10, %rax
leaq -0x78(%rbp), %rbx
movq %rax, (%rbx)
movq %r14, %rdi
callq 0x50f0
movq %rbx, %rdi
callq 0x53f0
callq 0x5350
jmp 0x198ae
cmpl $0x1, %r15d
jne 0x198b7
movq %r14, %rdi
callq 0x52b0
movq 0xe71a(%rip), %rax      # 0x27fa8
addq $0x10, %rax
leaq -0x78(%rbp), %rbx
movq %rax, (%rbx)
movq %r14, %rdi
callq 0x50f0
movq %rbx, %rdi
callq 0x53f0
callq 0x5350
movq -0x50(%rbp), %r12
jmp 0x1976f
movq %r14, %rdi
callq 0x53d0
jmp 0x197a3
jmp 0x197a3
jmp 0x19792