// File: /workspace/github_cpp_makefile_star2_O3/Bartor[P]kompilator/middle/ast_optimizer/ASTOptimizer.cpp
// Function: ASTOptimizer::constantConditionRemover(Node*)
Node *ASTOptimizer::constantConditionRemover(Node *node) {
    if (auto whileNode = dynamic_cast<While *>(node)) {
        if (checkTautology(whileNode->condition) == ALWAYS) {
            std::cout << "  |[w] Infinite loop detected" << std::endl;
            return node;
        } else if (checkTautology(whileNode->condition) == NEVER) {
            return new CommandList();
        }
    } else if (auto ifNode = dynamic_cast<If *>(node)) {
        if (checkTautology(ifNode->condition) == ALWAYS) {
            return ifNode->commands.copy(identity);
        } else if (checkTautology(ifNode->condition) == NEVER) {
            return new CommandList();
        }
    } else if (auto ifElseNode = dynamic_cast<IfElse *>(node)) {
        if (checkTautology(ifElseNode->condition) == ALWAYS) {
            return ifElseNode->commands.copy(identity);
        } else if (checkTautology(ifElseNode->condition) == NEVER) {
            return ifElseNode->elseCommands.copy(identity);
        }
    }
    return node;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x60, %rsp
testq %rsi, %rsi
je 0x19782
movq %rsi, %rbx
leaq 0xcf00(%rip), %rsi      # 0x26610
leaq 0xcd31(%rip), %rdx      # 0x26448
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x19789
movq %rax, %r14
movq 0x8(%rax), %rdi
callq 0x185d4
cmpl $0x2, %eax
jne 0x19801
movq 0xd886(%rip), %r14      # 0x26fc8
leaq 0x60b2(%rip), %rsi      # 0x1f7fb
movl $0x1d, %edx
movq %r14, %rdi
callq 0x5250
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x51d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5140
jmp 0x198fc
xorl %ebx, %ebx
jmp 0x198fc
leaq 0xce80(%rip), %rsi      # 0x26610
leaq 0xcc21(%rip), %rdx      # 0x263b8
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x19841
movq %rax, %r14
movq 0x8(%rax), %rdi
callq 0x185d4
cmpl $0x2, %eax
jne 0x19801
movq 0x10(%r14), %rbx
leaq 0xdbca(%rip), %rsi      # 0x27390
leaq -0x70(%rbp), %r14
movq %r14, %rdi
callq 0xeab4
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rax)
movq %rax, %rbx
movq -0x60(%rbp), %rax
testq %rax, %rax
je 0x198fc
leaq -0x70(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x198fc
movq 0x8(%r14), %rdi
callq 0x185d4
testl %eax, %eax
jne 0x198fc
movl $0x20, %edi
callq 0x51f0
movq %rax, %rbx
leaq 0xcad2(%rip), %rax      # 0x262f8
addq $0x10, %rax
movq %rax, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
movq $0x0, 0x18(%rbx)
jmp 0x198fc
leaq 0xcdc8(%rip), %rsi      # 0x26610
leaq 0xcbb1(%rip), %rdx      # 0x26400
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x198fc
movq %rax, %r14
movq 0x8(%rax), %rdi
callq 0x185d4
cmpl $0x2, %eax
jne 0x198b2
movq 0x10(%r14), %rbx
leaq 0xdb12(%rip), %rsi      # 0x27390
leaq -0x50(%rbp), %r14
movq %r14, %rdi
callq 0xeab4
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rax)
movq %rax, %rbx
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x198fc
leaq -0x50(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x198fc
movq 0x8(%r14), %rdi
callq 0x185d4
testl %eax, %eax
jne 0x198fc
movq 0x18(%r14), %rbx
leaq 0xdac6(%rip), %rsi      # 0x27390
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0xeab4
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rax)
movq %rax, %rbx
movq -0x20(%rbp), %rax
testq %rax, %rax
je 0x198fc
leaq -0x30(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rbx, %rax
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x1996c
movq %rax, %rbx
movq -0x20(%rbp), %rax
testq %rax, %rax
je 0x19964
leaq -0x30(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x19964
jmp 0x1996c
jmp 0x1996c
movq %rax, %rbx
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x19964
leaq -0x50(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x19964
jmp 0x1996c
jmp 0x1996c
movq %rax, %rbx
movq -0x60(%rbp), %rax
testq %rax, %rax
je 0x19964
leaq -0x70(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rbx, %rdi
callq 0x53d0
movq %rax, %rdi
callq 0xeb19