// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rdi, %r14
movq 0x8(%rdi), %rdi
leaq 0xe045(%rip), %rsi      # 0x26638
leaq 0xdbc6(%rip), %rdx      # 0x261c0
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x186c6
movq %rax, %rbx
movq 0x10(%r14), %rdi
leaq 0xe020(%rip), %rsi      # 0x26638
leaq 0xdba1(%rip), %rdx      # 0x261c0
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x186cb
movl 0x18(%r14), %ecx
cmpq $0x5, %rcx
ja 0x187e4
leaq 0x70c4(%rip), %rdx      # 0x1f708
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
sete %r15b
jmp 0x186b1
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
setle %r15b
jmp 0x186b1
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
setl %r15b
jmp 0x186b1
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
setg %r15b
jmp 0x186b1
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
setne %r15b
jmp 0x186b1
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
setge %r15b
addl %r15d, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5410
callq 0x5410
jmp 0x186d2
movq %rdx, -0x38(%rbp)
movq %rax, %r12
cmpl $0x1, -0x38(%rbp)
jne 0x18a84
movq %r12, %rdi
callq 0x52b0
movq 0xe8b6(%rip), %rbx      # 0x26fa8
addq $0x10, %rbx
movq %rbx, -0x50(%rbp)
movq %r12, %rdi
callq 0x50f0
movq 0x8(%r14), %rdi
leaq 0xdf2b(%rip), %rsi      # 0x26638
leaq 0xdaf4(%rip), %rdx      # 0x26208
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x187f4
movq %rax, %r15
movq 0x10(%r14), %rdi
leaq 0xdf06(%rip), %rsi      # 0x26638
leaq 0xdacf(%rip), %rdx      # 0x26208
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x187f9
movq %rax, %r13
movq 0x8(%r15), %rdi
leaq 0xdec9(%rip), %rsi      # 0x26620
leaq 0xd98a(%rip), %rdx      # 0x260e8
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x187fe
movq %rax, %r12
movq 0x8(%r13), %rdi
leaq 0xdea4(%rip), %rsi      # 0x26620
leaq 0xd965(%rip), %rdx      # 0x260e8
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x18803
movq 0x8(%r12), %rdi
movq 0x8(%rax), %rsi
callq 0x1a001
testb %al, %al
je 0x187bc
movl 0x18(%r14), %eax
cmpl $0x5, %eax
ja 0x187ef
movl $0xe, %ecx
btl %eax, %ecx
jae 0x187c4
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x187cd
movl $0x1, %r15d
jmp 0x187ca
movl $0x2, %r15d
xorl %r14d, %r14d
leaq -0x50(%rbp), %rdi
callq 0x53f0
callq 0x5350
testb %r14b, %r14b
je 0x186b4
movl $0x1, %r15d
jmp 0x186b4
movb $0x1, %r14b
jmp 0x187cd
callq 0x5410
callq 0x5410
callq 0x5410
callq 0x5410
jmp 0x1880a
movq %rdx, -0x30(%rbp)
movq %rax, %r12
movq -0x30(%rbp), %rax
cmpl -0x38(%rbp), %eax
jne 0x18a3e
movq %r12, %rdi
callq 0x52b0
movq %rbx, -0x40(%rbp)
movq %r12, %rdi
callq 0x50f0
movq 0x8(%r15), %rdi
leaq 0xdde3(%rip), %rsi      # 0x26620
leaq 0xd8ec(%rip), %rdx      # 0x26130
xorl %ecx, %ecx
callq 0x5240
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x188e0
movq 0x8(%r13), %rdi
leaq 0xddbd(%rip), %rsi      # 0x26620
leaq 0xd8c6(%rip), %rdx      # 0x26130
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x188e5
movq %rax, %r12
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x8(%r12), %rsi
callq 0x1a001
movl $0x1, %r15d
testb %al, %al
je 0x188c5
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpq 0x10(%r12), %rax
jne 0x188c5
movl 0x18(%r14), %eax
cmpl $0x5, %eax
ja 0x188db
movl $0xe, %ecx
btl %eax, %ecx
jae 0x188bf
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x188c8
movl $0x2, %r15d
xorl %r14d, %r14d
leaq -0x40(%rbp), %rdi
callq 0x53f0
callq 0x5350
jmp 0x187cd
movb $0x1, %r14b
jmp 0x188c8
callq 0x5410
callq 0x5410
jmp 0x188ec
movq %rdx, -0x30(%rbp)
movq %rax, %r12
movq -0x30(%rbp), %rax
cmpl -0x38(%rbp), %eax
jne 0x1899b
movq %r12, %rdi
callq 0x52b0
movq %rbx, -0x48(%rbp)
movq %r12, %rdi
callq 0x50f0
movq 0x8(%r15), %rdi
leaq 0xdd01(%rip), %rsi      # 0x26620
leaq 0xd852(%rip), %rdx      # 0x26178
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x1899d
movq %rax, %r12
movq 0x8(%r13), %rdi
leaq 0xdce0(%rip), %rsi      # 0x26620
leaq 0xd831(%rip), %rdx      # 0x26178
xorl %ecx, %ecx
callq 0x5240
testq %rax, %rax
je 0x189a2
movq %rax, %r13
movq 0x8(%r12), %rdi
movq 0x8(%rax), %rsi
callq 0x1a001
movl $0x1, %r15d
testb %al, %al
je 0x189ad
movq 0x10(%r12), %rdi
movq 0x10(%r13), %rsi
callq 0x1a001
testb %al, %al
je 0x189ad
movl 0x18(%r14), %eax
cmpl $0x5, %eax
ja 0x189e8
movl $0xe, %ecx
btl %eax, %ecx
jae 0x189a7
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x189eb
jmp 0x18a1c
callq 0x5410
callq 0x5410
movl $0x2, %r15d
xorl %r14d, %r14d
jmp 0x189eb
jmp 0x189b4
movq %rdx, -0x30(%rbp)
movq %rax, %r12
movq -0x30(%rbp), %rax
cmpl -0x38(%rbp), %eax
jne 0x18a0e
movq %r12, %rdi
callq 0x52b0
leaq -0x58(%rbp), %r14
movq %rbx, (%r14)
movq %r12, %rdi
callq 0x50f0
movq %r14, %rdi
callq 0x53f0
callq 0x5350
movb $0x1, %r14b
leaq -0x48(%rbp), %rdi
callq 0x53f0
callq 0x5350
jmp 0x188c8
movq %rdx, -0x30(%rbp)
movq %rax, %r12
jmp 0x18a1c
movq %rdx, -0x30(%rbp)
movq %rax, %r12
leaq -0x48(%rbp), %rdi
callq 0x53f0
callq 0x5350
leaq -0x40(%rbp), %rdi
callq 0x53f0
callq 0x5350
jmp 0x18a3e
movq %rdx, -0x30(%rbp)
movq %rax, %r12
jmp 0x18a3e
jmp 0x18a37
movq %rdx, -0x30(%rbp)
movq %rax, %r12
movq -0x30(%rbp), %rax
cmpl -0x38(%rbp), %eax
jne 0x18a76
movq %r12, %rdi
callq 0x52b0
leaq -0x40(%rbp), %r14
movq %rbx, (%r14)
movq %r12, %rdi
callq 0x50f0
movq %r14, %rdi
callq 0x53f0
callq 0x5350
movb $0x1, %r14b
jmp 0x187cd
movq %rax, %r12
leaq -0x50(%rbp), %rdi
callq 0x53f0
callq 0x5350
movq %r12, %rdi
callq 0x53d0
movq %rax, %rdi
callq 0xeb19