// File: /workspace/github_cpp_makefile_star2_O2/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 0x13f1f
movq %rsi, %rbx
leaq 0xb744(%rip), %rsi      # 0x1f618
leaq 0xb575(%rip), %rdx      # 0x1f450
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x13f26
movq %rax, %r14
movq 0x8(%rax), %rdi
callq 0x130a8
cmpl $0x2, %eax
jne 0x13f83
movq 0xc0c2(%rip), %rdi      # 0x1ffc8
leaq 0x48fe(%rip), %rsi      # 0x1880b
callq 0x51b0
movq %rax, %rdi
callq 0x5100
jmp 0x14054
xorl %ebx, %ebx
jmp 0x14054
leaq 0xb6eb(%rip), %rsi      # 0x1f618
leaq 0xb48c(%rip), %rdx      # 0x1f3c0
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x13fbe
movq %rax, %r14
movq 0x8(%rax), %rdi
callq 0x130a8
cmpl $0x2, %eax
jne 0x13f83
movq 0x10(%r14), %rbx
leaq 0xc421(%rip), %rsi      # 0x20380
leaq -0x70(%rbp), %r14
movq %r14, %rdi
callq 0xa87a
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rax)
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0x1404f
movq 0x8(%r14), %rdi
callq 0x130a8
testl %eax, %eax
jne 0x14054
pushq $0x20
popq %rdi
callq 0x51c0
movq %rax, %rbx
leaq 0xb35a(%rip), %rax      # 0x1f300
addq $0x10, %rax
movq %rax, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
andq $0x0, 0x18(%rbx)
jmp 0x14054
leaq 0xb653(%rip), %rsi      # 0x1f618
leaq 0xb43c(%rip), %rdx      # 0x1f408
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x14054
movq %rax, %r14
movq 0x8(%rax), %rdi
callq 0x130a8
cmpl $0x2, %eax
jne 0x14018
movq 0x10(%r14), %rbx
leaq 0xc389(%rip), %rsi      # 0x20380
leaq -0x50(%rbp), %r14
movq %r14, %rdi
callq 0xa87a
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rax)
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0x1404f
movq 0x8(%r14), %rdi
callq 0x130a8
testl %eax, %eax
jne 0x14054
movq 0x18(%r14), %rbx
leaq 0xc350(%rip), %rsi      # 0x20380
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0xa87a
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rax)
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0xa8c8
movq %rbx, %rax
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x14064
jmp 0x14064
movq %rax, %rbx
movq %r14, %rdi
callq 0xa8c8
movq %rbx, %rdi
callq 0x5390
nop