// File: /workspace/github_cpp_makefile_star2_O2/vsklad[P]cgen/./bal/encoding/literal.hpp
// Function: bal::Ref<bal::Literal<bal::Anf>> bal::ch<bal::Anf>(bal::Literal<bal::Anf>*, bal::Literal<bal::Anf>*, bal::Literal<bal::Anf>*, bal::Literal<bal::Anf>*)
Ref<Literal<FORMULA_T>> ch(Literal<FORMULA_T>* const r,
                               Literal<FORMULA_T>* const x, Literal<FORMULA_T>* const y, Literal<FORMULA_T>* const z) {
        if (literal_t__is_constant_0(x->value)) {
            return z;
        } else if (literal_t__is_constant_1(x->value) || y->value == z->value) {
            return y;
        } else if (literal_t__is_constant(y->value) && literal_t__is_constant(z->value)) {
            if (literal_t__is_constant_0(y->value)) {
                return inv(r, x);
            } else {
                return x;
            };
        } else if (literal_t__is_constant_0(y->value) || literal_t__is_negation_of(y->value, x->value)) {
            // x ? 0b0 : z -> -x & z
            // x ? -x : z -> -x & z
            Ref<Literal<FORMULA_T>> inv_x = inv(r, x);
            return con2(inv_x.data(), inv_x.data(), z);
        } else if (y->value == x->value && literal_t__is_constant_0(z->value)) {
            return x;
        } else if (y->value == x->value && literal_t__is_constant_1(z->value)) {
            return 1;
        } else if (literal_t__is_constant_1(y->value) && literal_t__is_negation_of(z->value, x->value)) {
            return 1;
        } else if (literal_t__is_constant_1(y->value) || y->value == x->value) {
            // x ? 0b1 : z -> x | z
            // x ? x : z -> x | z
            return dis2(r, x, z);
        } else if (literal_t__is_constant_0(z->value) || z->value == x->value) {
            return con2(r, x, y);
        } else if (literal_t__is_constant_1(z->value) || literal_t__is_negation_of(z->value, x->value)) {
            // x&y ^ !x = !(x&!y) = !x V y
            Ref<Literal<FORMULA_T>> inv_x = inv(r, x);
            return dis2(inv_x.data(), inv_x.data(), y);
        } else if (literal_t__is_negation_of(z->value, y->value)) {
            // x ? y : -y -> xy | -x-y
            // !(x^y)
            Ref<Literal<FORMULA_T>> eor_xy = eor2(r, x, y);
            return inv(eor_xy.data(), eor_xy.data());
        } else {
            _assert_level_1(x->formula != nullptr && x->formula == y->formula && x->formula == z->formula);
            const literalid_t r_value = x->formula->new_variable_literal();
            ch(x->formula, r_value, x->value, y->value, z->value);
            return new Literal<FORMULA_T>(x->formula, r_value);
        };
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r12
movq %rdi, %rbx
movl 0x20(%rdx), %ecx
cmpl $0x1, %ecx
je 0x25e4f
movq %r8, %r15
testl %ecx, %ecx
jne 0x25e59
movq %r15, (%rbx)
testq %r15, %r15
je 0x25e79
movq (%r15), %rax
movq -0x20(%rax), %rax
incl 0x8(%r15,%rax)
jmp 0x25e79
movq %r12, (%rbx)
testq %r12, %r12
jne 0x25e6c
jmp 0x25e79
movq %rdx, %r14
movl 0x20(%r12), %edx
movl 0x20(%r15), %eax
cmpl %eax, %edx
jne 0x25e8b
movq %r12, (%rbx)
movq (%r12), %rax
movq -0x20(%rax), %rax
incl 0x8(%r12,%rax)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
orl %edx, %edi
cmpl $0x1, %edi
ja 0x25ea9
testl %edx, %edx
je 0x25efd
movq %r14, (%rbx)
movq (%r14), %rax
movq -0x20(%rax), %rax
incl 0x8(%r14,%rax)
jmp 0x25e79
testl %edx, %edx
setne %dil
movl %edx, %r8d
xorl %ecx, %r8d
cmpl $0x1, %r8d
setne %r8b
testb %r8b, %dil
jne 0x25eee
leaq -0x30(%rbp), %r12
movq %r12, %rdi
movq %r14, %rdx
callq 0x2605c
movq (%r12), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
movq %r15, %rcx
callq 0x260e3
leaq -0x30(%rbp), %rdi
callq 0x1f456
jmp 0x25e79
cmpl %ecx, %edx
jne 0x25f0d
cmpl $0x1, %eax
je 0x25f19
testl %eax, %eax
je 0x25e98
jmp 0x25f30
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2605c
jmp 0x25e79
cmpl $0x1, %edx
jne 0x25f43
xorl %ecx, %eax
cmpl $0x1, %eax
jne 0x25f30
leaq -0x30(%rbp), %rsi
movl $0x1, (%rsi)
movq %rbx, %rdi
callq 0x261d4
jmp 0x25e79
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
callq 0x261e2
jmp 0x25e79
testl %eax, %eax
setne %dil
cmpl %ecx, %eax
setne %r8b
testb %r8b, %dil
jne 0x25f67
movq %rbx, %rdi
movq %r14, %rdx
movq %r12, %rcx
callq 0x260e3
jmp 0x25e79
cmpl $0x1, %eax
setne %dil
xorl %eax, %ecx
cmpl $0x1, %ecx
setne %cl
testb %cl, %dil
jne 0x25fa0
leaq -0x30(%rbp), %r15
movq %r15, %rdi
movq %r14, %rdx
callq 0x2605c
movq (%r15), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
movq %r12, %rcx
callq 0x261e2
jmp 0x25ee3
xorl %edx, %eax
cmpl $0x1, %eax
jne 0x25fcc
leaq -0x30(%rbp), %r15
movq %r15, %rdi
movq %r14, %rdx
movq %r12, %rcx
callq 0x262d7
movq (%r15), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x2605c
jmp 0x25ee3
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0x26025
cmpq 0x18(%r12), %rdi
jne 0x26025
cmpq 0x18(%r15), %rdi
jne 0x26025
movq (%rdi), %rax
callq *0x8(%rax)
movl %eax, %r13d
movq 0x18(%r14), %rdi
movl 0x20(%r14), %edx
movl 0x20(%r12), %ecx
movl 0x20(%r15), %r8d
movl %eax, %esi
callq 0xe5b5
pushq $0x40
popq %rdi
callq 0xc2a0
movq %rax, %r15
movq 0x18(%r14), %rsi
movq %rax, %rdi
movl %r13d, %edx
callq 0x251ae
movq %r15, (%rbx)
jmp 0x25e41
leaq 0x156d0(%rip), %rdi     # 0x3b6fc
leaq 0x13f48(%rip), %rsi     # 0x39f7b
leaq 0x15710(%rip), %rcx     # 0x3b74a
movl $0x16e, %edx            # imm = 0x16E
callq 0xc180
jmp 0x26048
jmp 0x26048
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x1f456
movq %rbx, %rdi
callq 0xc4c0