// File: /workspace/github_cpp_makefile_star2_O1/Bartor[P]kompilator/middle/ast_optimizer/ASTOptimizer.cpp
// Function: checkTautology(Condition&)
ConditionState checkTautology(Condition &condition) {
    try {
        NumberValue &lVal = dynamic_cast<NumberValue &>(condition.lhs);
        NumberValue &rVal = dynamic_cast<NumberValue &>(condition.rhs);

        switch (condition.type) {
            case EQUAL:
                return lVal.value == rVal.value ? ALWAYS : NEVER;
            case NOT_EQUAL:
                return lVal.value != rVal.value ? ALWAYS : NEVER;
            case LESS:
                return lVal.value < rVal.value ? ALWAYS : NEVER;
            case GREATER:
                return lVal.value > rVal.value ? ALWAYS : NEVER;
            case LESS_OR_EQUAL:
                return lVal.value <= rVal.value ? ALWAYS : NEVER;
            case GREATER_OR_EQUAL:
                return lVal.value >= rVal.value ? ALWAYS : NEVER;
        }
    } catch (std::bad_cast _) {
        try {
            IdentifierValue &lVal = dynamic_cast<IdentifierValue &>(condition.lhs);
            IdentifierValue &rVal = dynamic_cast<IdentifierValue &>(condition.rhs);

            try {
                VariableIdentifier &lValId = dynamic_cast<VariableIdentifier &>(lVal.identifier);
                VariableIdentifier &rValId = dynamic_cast<VariableIdentifier &>(rVal.identifier);

                if (lValId.name == rValId.name) {
                    switch (condition.type) {
                        case EQUAL:
                        case LESS_OR_EQUAL:
                        case GREATER_OR_EQUAL:
                            return ALWAYS;
                        case NOT_EQUAL:
                        case LESS:
                        case GREATER:
                            return NEVER;
                    }
                } else return SOMETIMES;
            } catch (std::bad_cast _) {
                try {
                    AccessIdentifier &lValAcc = dynamic_cast<AccessIdentifier &>(lVal.identifier);
                    AccessIdentifier &rValAcc = dynamic_cast<AccessIdentifier &>(rVal.identifier);

                    if (lValAcc.name == rValAcc.name && lValAcc.index == rValAcc.index) {
                        switch (condition.type) {
                            case EQUAL:
                            case LESS_OR_EQUAL:
                            case GREATER_OR_EQUAL:
                                return ALWAYS;
                            case NOT_EQUAL:
                            case LESS:
                            case GREATER:
                                return NEVER;
                        }
                    } else return SOMETIMES;
                } catch (std::bad_cast) {
                    try {
                        VariableAccessIdentifier &lValVarAcc = dynamic_cast<VariableAccessIdentifier &>(lVal.identifier);
                        VariableAccessIdentifier &rValVarAcc = dynamic_cast<VariableAccessIdentifier &>(rVal.identifier);

                        if (lValVarAcc.name == rValVarAcc.name && lValVarAcc.accessName == rValVarAcc.accessName) {
                            switch (condition.type) {
                                case EQUAL:
                                case LESS_OR_EQUAL:
                                case GREATER_OR_EQUAL:
                                    return ALWAYS;
                                case NOT_EQUAL:
                                case LESS:
                                case GREATER:
                                    return NEVER;
                            }
                        } else return SOMETIMES;
                    } catch (std::bad_cast _) {}
                }
            }
        } catch (std::bad_cast _) {}
    }
    return SOMETIMES;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
leaq 0xed75(%rip), %rsi      # 0x275d8
leaq 0xe91e(%rip), %rdx      # 0x27188
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x18945
movq %rax, %r14
movq 0x10(%rbx), %rdi
leaq 0xed50(%rip), %rsi      # 0x275d8
leaq 0xe8f9(%rip), %rdx      # 0x27188
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x1894a
movl 0x18(%rbx), %ecx
cmpq $0x5, %rcx
ja 0x18941
leaq 0x7e65(%rip), %rdx      # 0x20718
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x8(%r14), %rcx
xorl %r14d, %r14d
cmpq 0x8(%rax), %rcx
sete %r14b
jmp 0x18920
movq 0x8(%r14), %rcx
xorl %r14d, %r14d
cmpq 0x8(%rax), %rcx
setle %r14b
jmp 0x18920
movq 0x8(%r14), %rcx
xorl %r14d, %r14d
cmpq 0x8(%rax), %rcx
setl %r14b
jmp 0x18920
movq 0x8(%r14), %rcx
xorl %r14d, %r14d
cmpq 0x8(%rax), %rcx
setg %r14b
jmp 0x18920
movq 0x8(%r14), %rcx
xorl %r14d, %r14d
cmpq 0x8(%rax), %rcx
setne %r14b
jmp 0x18920
movq 0x8(%r14), %rcx
xorl %r14d, %r14d
cmpq 0x8(%rax), %rcx
setge %r14b
addl %r14d, %r14d
xorl %eax, %eax
testb %al, %al
je 0x1892f
movl $0x1, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
jmp 0x18925
callq 0x5410
callq 0x5410
jmp 0x18951
movq %rax, %r15
cmpl $0x1, %edx
jne 0x18d12
movq %r15, %rdi
callq 0x52b0
movq 0xf63c(%rip), %r13      # 0x27fa8
addq $0x10, %r13
movq %r13, -0x48(%rbp)
movq %r15, %rdi
callq 0x50f0
movq 0x8(%rbx), %rdi
leaq 0xec51(%rip), %rsi      # 0x275d8
leaq 0xe842(%rip), %rdx      # 0x271d0
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x18a53
movq %rax, %r14
movq 0x10(%rbx), %rdi
leaq 0xec2c(%rip), %rsi      # 0x275d8
leaq 0xe81d(%rip), %rdx      # 0x271d0
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x18a58
movq %rax, %r12
movq 0x8(%r14), %rdi
leaq 0xe697(%rip), %rsi      # 0x27068
leaq 0xe6d8(%rip), %rdx      # 0x270b0
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x18a5d
movq %rax, %r15
movq 0x8(%r12), %rdi
leaq 0xe675(%rip), %rsi      # 0x27068
leaq 0xe6b6(%rip), %rdx      # 0x270b0
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x18a62
movq 0x8(%r15), %rdi
movq 0x8(%rax), %rsi
callq 0x1a313
testb %al, %al
je 0x18a30
movl 0x18(%rbx), %eax
cmpl $0x5, %eax
ja 0x18a4f
movl $0xe, %ecx
btl %eax, %ecx
jae 0x18a38
xorl %eax, %eax
xorl %r14d, %r14d
jmp 0x18a40
movl $0x1, %r14d
jmp 0x18a3e
movl $0x2, %r14d
xorl %eax, %eax
testb %al, %al
je 0x18c71
movb $0x1, %bl
jmp 0x18c73
movb $0x1, %al
jmp 0x18a40
callq 0x5410
callq 0x5410
callq 0x5410
callq 0x5410
jmp 0x18a69
movq %rdx, -0x30(%rbp)
movq %rax, %r15
movl $0x1, %eax
cmpl %eax, -0x30(%rbp)
jne 0x18cce
movq %r15, %rdi
callq 0x52b0
movq %r13, -0x38(%rbp)
movq %r15, %rdi
callq 0x50f0
movq 0x8(%r14), %rdi
leaq 0xe5cb(%rip), %rsi      # 0x27068
leaq 0xe654(%rip), %rdx      # 0x270f8
xorl %ecx, %ecx
callq 0x5240
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x18b33
movq 0x8(%r12), %rdi
leaq 0xe5a8(%rip), %rsi      # 0x27068
leaq 0xe631(%rip), %rdx      # 0x270f8
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x18b38
movq %rax, %r15
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x8(%r15), %rsi
callq 0x1a313
movl $0x1, %r14d
testb %al, %al
je 0x18b1e
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpq 0x10(%r15), %rax
jne 0x18b1e
movl 0x18(%rbx), %eax
cmpl $0x5, %eax
ja 0x18b2f
movl $0xe, %ecx
btl %eax, %ecx
jae 0x18b18
xorl %eax, %eax
xorl %r14d, %r14d
jmp 0x18b20
movl $0x2, %r14d
xorl %eax, %eax
testb %al, %al
je 0x18c59
movb $0x1, %bl
jmp 0x18c5b
movb $0x1, %al
jmp 0x18b20
callq 0x5410
callq 0x5410
jmp 0x18b3f
movq %rdx, -0x30(%rbp)
movq %rax, %r15
movl $0x1, %eax
cmpl %eax, -0x30(%rbp)
jne 0x18bed
movq %r15, %rdi
callq 0x52b0
movq %r13, -0x40(%rbp)
movq %r15, %rdi
callq 0x50f0
movq 0x8(%r14), %rdi
leaq 0xe4f5(%rip), %rsi      # 0x27068
leaq 0xe5c6(%rip), %rdx      # 0x27140
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x18bf2
movq %rax, %r15
movq 0x8(%r12), %rdi
leaq 0xe4d3(%rip), %rsi      # 0x27068
leaq 0xe5a4(%rip), %rdx      # 0x27140
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x18bf7
movq %rax, %r12
movq 0x8(%r15), %rdi
movq 0x8(%rax), %rsi
callq 0x1a313
movl $0x1, %r14d
testb %al, %al
je 0x18c02
movq 0x10(%r15), %rdi
movq 0x10(%r12), %rsi
callq 0x1a313
testb %al, %al
je 0x18c02
movl 0x18(%rbx), %eax
cmpl $0x5, %eax
ja 0x18c41
movl $0xe, %ecx
btl %eax, %ecx
jae 0x18bfc
xorl %ebx, %ebx
xorl %r14d, %r14d
jmp 0x18c43
jmp 0x18cb5
callq 0x5410
callq 0x5410
movl $0x2, %r14d
xorl %ebx, %ebx
jmp 0x18c43
jmp 0x18c08
movq %rdx, -0x30(%rbp)
movq %rax, %r15
movl $0x1, %eax
cmpl %eax, -0x30(%rbp)
jne 0x18ca7
movq %r15, %rdi
callq 0x52b0
leaq -0x50(%rbp), %rbx
movq %r13, (%rbx)
movq %r15, %rdi
callq 0x50f0
movq %rbx, %rdi
callq 0x53f0
callq 0x5350
movb $0x1, %bl
leaq -0x40(%rbp), %rdi
callq 0x53f0
callq 0x5350
testb %bl, %bl
jne 0x18b28
xorl %ebx, %ebx
leaq -0x38(%rbp), %rdi
callq 0x53f0
callq 0x5350
testb %bl, %bl
jne 0x18a48
xorl %ebx, %ebx
leaq -0x48(%rbp), %rdi
callq 0x53f0
callq 0x5350
testb %bl, %bl
jne 0x18929
jmp 0x1892f
movq %rdx, -0x30(%rbp)
movq %rax, %r15
jmp 0x18cce
movq %rdx, -0x30(%rbp)
movq %rax, %r15
jmp 0x18cb5
movq %rdx, -0x30(%rbp)
movq %rax, %r15
leaq -0x40(%rbp), %rdi
callq 0x53f0
callq 0x5350
leaq -0x38(%rbp), %rdi
callq 0x53f0
callq 0x5350
jmp 0x18cce
jmp 0x18cc7
movq %rdx, -0x30(%rbp)
movq %rax, %r15
movl $0x1, %eax
cmpl %eax, -0x30(%rbp)
jne 0x18d04
movq %r15, %rdi
callq 0x52b0
leaq -0x38(%rbp), %rbx
movq %r13, (%rbx)
movq %r15, %rdi
callq 0x50f0
movq %rbx, %rdi
callq 0x53f0
callq 0x5350
jmp 0x18a48
movq %rax, %r15
leaq -0x48(%rbp), %rdi
callq 0x53f0
callq 0x5350
movq %r15, %rdi
callq 0x53d0
movq %rax, %rdi
callq 0xec29