// File: /workspace/github_cpp_makefile_star2_O2/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 0xc579(%rip), %rsi      # 0x1f640
leaq 0xc0fa(%rip), %rdx      # 0x1f1c8
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x1319a
movq %rax, %rbx
movq 0x10(%r14), %rdi
leaq 0xc554(%rip), %rsi      # 0x1f640
leaq 0xc0d5(%rip), %rdx      # 0x1f1c8
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x1319f
movl 0x18(%r14), %ecx
cmpq $0x5, %rcx
ja 0x132b0
leaq 0x55f0(%rip), %rdx      # 0x18708
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
sete %r15b
jmp 0x13185
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
setle %r15b
jmp 0x13185
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
setl %r15b
jmp 0x13185
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
setg %r15b
jmp 0x13185
movq 0x8(%rbx), %rcx
xorl %r15d, %r15d
cmpq 0x8(%rax), %rcx
setne %r15b
jmp 0x13185
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 0x53d0
callq 0x53d0
jmp 0x131a6
movq %rdx, -0x38(%rbp)
movq %rax, %r12
cmpl $0x1, -0x38(%rbp)
jne 0x13542
movq %r12, %rdi
callq 0x5250
movq 0xcdea(%rip), %rbx      # 0x1ffb0
addq $0x10, %rbx
movq %rbx, -0x50(%rbp)
movq %r12, %rdi
callq 0x50d0
movq 0x8(%r14), %rdi
leaq 0xc45f(%rip), %rsi      # 0x1f640
leaq 0xc028(%rip), %rdx      # 0x1f210
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x132be
movq %rax, %r15
movq 0x10(%r14), %rdi
leaq 0xc43a(%rip), %rsi      # 0x1f640
leaq 0xc003(%rip), %rdx      # 0x1f210
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x132c3
movq %rax, %r13
movq 0x8(%r15), %rdi
leaq 0xc3fd(%rip), %rsi      # 0x1f628
leaq 0xbebe(%rip), %rdx      # 0x1f0f0
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x132c8
movq %rax, %r12
movq 0x8(%r13), %rdi
leaq 0xc3d8(%rip), %rsi      # 0x1f628
leaq 0xbe99(%rip), %rdx      # 0x1f0f0
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x132cd
movq 0x8(%r12), %rdi
movq 0x8(%rax), %rsi
callq 0x12c38
testb %al, %al
je 0x1328e
movl 0x18(%r14), %eax
cmpl $0x5, %eax
ja 0x132b9
pushq $0xe
popq %rcx
btl %eax, %ecx
jae 0x13292
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x13299
pushq $0x1
jmp 0x13294
pushq $0x2
popq %r15
xorl %r14d, %r14d
leaq -0x50(%rbp), %rdi
callq 0x53b0
callq 0x5320
testb %r14b, %r14b
je 0x13188
pushq $0x1
popq %r15
jmp 0x13188
movb $0x1, %r14b
jmp 0x13299
callq 0x53d0
callq 0x53d0
callq 0x53d0
callq 0x53d0
jmp 0x132d4
movq %rdx, -0x30(%rbp)
movq %rax, %r12
movq -0x30(%rbp), %rax
cmpl -0x38(%rbp), %eax
jne 0x134fc
movq %r12, %rdi
callq 0x5250
movq %rbx, -0x40(%rbp)
movq %r12, %rdi
callq 0x50d0
movq 0x8(%r15), %rdi
leaq 0xc321(%rip), %rsi      # 0x1f628
leaq 0xbe2a(%rip), %rdx      # 0x1f138
xorl %ecx, %ecx
callq 0x51f0
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x133a4
movq 0x8(%r13), %rdi
leaq 0xc2fb(%rip), %rsi      # 0x1f628
leaq 0xbe04(%rip), %rdx      # 0x1f138
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x133a9
movq %rax, %r12
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x8(%r12), %rsi
callq 0x12c38
pushq $0x1
popq %r15
testb %al, %al
je 0x13389
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpq 0x10(%r12), %rax
jne 0x13389
movl 0x18(%r14), %eax
cmpl $0x5, %eax
ja 0x1339f
pushq $0xe
popq %rcx
btl %eax, %ecx
jae 0x13385
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x1338c
pushq $0x2
popq %r15
xorl %r14d, %r14d
leaq -0x40(%rbp), %rdi
callq 0x53b0
callq 0x5320
jmp 0x13299
movb $0x1, %r14b
jmp 0x1338c
callq 0x53d0
callq 0x53d0
jmp 0x133b0
movq %rdx, -0x30(%rbp)
movq %rax, %r12
movq -0x30(%rbp), %rax
cmpl -0x38(%rbp), %eax
jne 0x1345b
movq %r12, %rdi
callq 0x5250
movq %rbx, -0x48(%rbp)
movq %r12, %rdi
callq 0x50d0
movq 0x8(%r15), %rdi
leaq 0xc245(%rip), %rsi      # 0x1f628
leaq 0xbd96(%rip), %rdx      # 0x1f180
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x1345d
movq %rax, %r12
movq 0x8(%r13), %rdi
leaq 0xc224(%rip), %rsi      # 0x1f628
leaq 0xbd75(%rip), %rdx      # 0x1f180
xorl %ecx, %ecx
callq 0x51f0
testq %rax, %rax
je 0x13462
movq %rax, %r13
movq 0x8(%r12), %rdi
movq 0x8(%rax), %rsi
callq 0x12c38
pushq $0x1
popq %r15
testb %al, %al
je 0x1346b
movq 0x10(%r12), %rdi
movq 0x10(%r13), %rsi
callq 0x12c38
testb %al, %al
je 0x1346b
movl 0x18(%r14), %eax
cmpl $0x5, %eax
ja 0x134a6
pushq $0xe
popq %rcx
btl %eax, %ecx
jae 0x13467
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x134a9
jmp 0x134da
callq 0x53d0
callq 0x53d0
pushq $0x2
popq %r15
xorl %r14d, %r14d
jmp 0x134a9
jmp 0x13472
movq %rdx, -0x30(%rbp)
movq %rax, %r12
movq -0x30(%rbp), %rax
cmpl -0x38(%rbp), %eax
jne 0x134cc
movq %r12, %rdi
callq 0x5250
leaq -0x58(%rbp), %r14
movq %rbx, (%r14)
movq %r12, %rdi
callq 0x50d0
movq %r14, %rdi
callq 0x53b0
callq 0x5320
movb $0x1, %r14b
leaq -0x48(%rbp), %rdi
callq 0x53b0
callq 0x5320
jmp 0x1338c
movq %rdx, -0x30(%rbp)
movq %rax, %r12
jmp 0x134da
movq %rdx, -0x30(%rbp)
movq %rax, %r12
leaq -0x48(%rbp), %rdi
callq 0x53b0
callq 0x5320
leaq -0x40(%rbp), %rdi
callq 0x53b0
callq 0x5320
jmp 0x134fc
movq %rdx, -0x30(%rbp)
movq %rax, %r12
jmp 0x134fc
jmp 0x134f5
movq %rdx, -0x30(%rbp)
movq %rax, %r12
movq -0x30(%rbp), %rax
cmpl -0x38(%rbp), %eax
jne 0x13534
movq %r12, %rdi
callq 0x5250
leaq -0x40(%rbp), %r14
movq %rbx, (%r14)
movq %r12, %rdi
callq 0x50d0
movq %r14, %rdi
callq 0x53b0
callq 0x5320
movb $0x1, %r14b
jmp 0x13299
movq %rax, %r12
leaq -0x50(%rbp), %rdi
callq 0x53b0
callq 0x5320
movq %r12, %rdi
callq 0x5390
movq %rax, %rdi
callq 0xa8e7