// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, %rbx
testq %rsi, %rsi
je 0x199dc
leaq 0xd662(%rip), %rsi      # 0x27028
leaq 0xda43(%rip), %rdx      # 0x27410
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x5240
movq %rax, %r14
jmp 0x199df
xorl %r14d, %r14d
testq %r14, %r14
je 0x19a3d
movq 0x8(%r14), %rdi
callq 0x18844
cmpl $0x2, %eax
jne 0x19abf
movq 0xe5cb(%rip), %r14      # 0x27fc8
leaq 0x6e17(%rip), %rsi      # 0x2081b
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 0x19bc4
testq %rbx, %rbx
je 0x19a5f
leaq 0xd5df(%rip), %rsi      # 0x27028
leaq 0xd930(%rip), %rdx      # 0x27380
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x5240
movq %rax, %r14
jmp 0x19a62
xorl %r14d, %r14d
testq %r14, %r14
je 0x19aff
movq 0x8(%r14), %rdi
callq 0x18844
cmpl $0x2, %eax
jne 0x19abf
movq 0x10(%r14), %rbx
leaq 0xe90c(%rip), %rsi      # 0x28390
leaq -0x70(%rbp), %r14
movq %r14, %rdi
callq 0xebc4
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rax)
movq %rax, %rbx
movq -0x60(%rbp), %rax
testq %rax, %rax
je 0x19bc4
leaq -0x70(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x19bc4
movq 0x8(%r14), %rdi
callq 0x18844
testl %eax, %eax
jne 0x19bc4
movl $0x20, %edi
callq 0x51f0
movq %rax, %rbx
leaq 0xd7dc(%rip), %rax      # 0x272c0
addq $0x10, %rax
movq %rax, (%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbx)
movq $0x0, 0x18(%rbx)
jmp 0x19bc4
testq %rbx, %rbx
je 0x19b21
leaq 0xd51d(%rip), %rsi      # 0x27028
leaq 0xd8b6(%rip), %rdx      # 0x273c8
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x5240
movq %rax, %r14
jmp 0x19b24
xorl %r14d, %r14d
testq %r14, %r14
je 0x19bc4
movq 0x8(%r14), %rdi
callq 0x18844
cmpl $0x2, %eax
jne 0x19b7a
movq 0x10(%r14), %rbx
leaq 0xe84a(%rip), %rsi      # 0x28390
leaq -0x50(%rbp), %r14
movq %r14, %rdi
callq 0xebc4
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rax)
movq %rax, %rbx
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x19bc4
leaq -0x50(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x19bc4
movq 0x8(%r14), %rdi
callq 0x18844
testl %eax, %eax
jne 0x19bc4
movq 0x18(%r14), %rbx
leaq 0xe7fe(%rip), %rsi      # 0x28390
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0xebc4
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x8(%rax)
movq %rax, %rbx
movq -0x20(%rbp), %rax
testq %rax, %rax
je 0x19bc4
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 0x19c34
movq %rax, %rbx
movq -0x20(%rbp), %rax
testq %rax, %rax
je 0x19c2c
leaq -0x30(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x19c2c
jmp 0x19c34
jmp 0x19c34
movq %rax, %rbx
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x19c2c
leaq -0x50(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x19c2c
jmp 0x19c34
jmp 0x19c34
movq %rax, %rbx
movq -0x60(%rbp), %rax
testq %rax, %rax
je 0x19c2c
leaq -0x70(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rbx, %rdi
callq 0x53d0
movq %rax, %rdi
callq 0xec29