// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x28, %rsp
movq %rcx, %r12
movq %rdi, %rbx
movl 0x20(%rdx), %ecx
cmpl $0x1, %ecx
je 0x2f325
movq %r8, %r15
testl %ecx, %ecx
jne 0x2f32f
movq %r15, (%rbx)
testq %r15, %r15
je 0x2f34f
movq (%r15), %rax
movq -0x20(%rax), %rax
incl 0x8(%r15,%rax)
jmp 0x2f34f
movq %r12, (%rbx)
testq %r12, %r12
jne 0x2f342
jmp 0x2f34f
movq %rdx, %r14
movl 0x20(%r12), %edx
movl 0x20(%r15), %eax
cmpl %eax, %edx
jne 0x2f361
movq %r12, (%rbx)
movq (%r12), %rax
movq -0x20(%rax), %rax
incl 0x8(%r12,%rax)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
orl %edx, %edi
cmpl $0x1, %edi
ja 0x2f383
testl %edx, %edx
je 0x2f3f4
movq %r14, (%rbx)
movq (%r14), %rax
movq -0x20(%rax), %rax
incl 0x8(%r14,%rax)
jmp 0x2f34f
testl %edx, %edx
setne %dil
movl %edx, %r8d
xorl %ecx, %r8d
cmpl $0x1, %r8d
setne %r8b
testb %r8b, %dil
jne 0x2f3e5
leaq -0x40(%rbp), %r12
movq %r12, %rdi
movq %r14, %rdx
callq 0x2f59b
movq (%r12), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
movq %r15, %rcx
callq 0x2f632
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x2f34f
movq (%rax), %rcx
movq -0x20(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x8(%rax,%rcx), %eax
cmpl $0x1, %eax
ja 0x2f42e
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x2f34f
cmpl %ecx, %edx
jne 0x2f404
cmpl $0x1, %eax
je 0x2f410
testl %eax, %eax
je 0x2f372
jmp 0x2f438
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2f59b
jmp 0x2f34f
cmpl $0x1, %edx
jne 0x2f44b
xorl %ecx, %eax
cmpl $0x1, %eax
jne 0x2f438
leaq -0x40(%rbp), %rsi
movl $0x1, (%rsi)
movq $0x0, (%rbx)
movq %rbx, %rdi
callq 0x2e50c
jmp 0x2f34f
decl %eax
movl %eax, 0x8(%rdi)
jmp 0x2f34f
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
callq 0x2f72f
jmp 0x2f34f
testl %eax, %eax
setne %dil
cmpl %ecx, %eax
setne %r8b
testb %r8b, %dil
jne 0x2f46f
movq %rbx, %rdi
movq %r14, %rdx
movq %r12, %rcx
callq 0x2f632
jmp 0x2f34f
cmpl $0x1, %eax
setne %dil
xorl %eax, %ecx
cmpl $0x1, %ecx
setne %cl
testb %cl, %dil
jne 0x2f4a8
leaq -0x40(%rbp), %r15
movq %r15, %rdi
movq %r14, %rdx
callq 0x2f59b
movq (%r15), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
movq %r12, %rcx
callq 0x2f72f
jmp 0x2f3bd
xorl %edx, %eax
cmpl $0x1, %eax
jne 0x2f4e2
leaq -0x40(%rbp), %rdx
movq %r14, (%rdx)
movq %r12, 0x8(%rdx)
leaq -0x48(%rbp), %r14
movl $0x2, %ecx
movq %r14, %rdi
callq 0x2ef78
movq (%r14), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x2f59b
movq -0x48(%rbp), %rax
jmp 0x2f3c1
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0x2f53d
cmpq 0x18(%r12), %rdi
jne 0x2f53d
cmpq 0x18(%r15), %rdi
jne 0x2f53d
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 0xecbe
movl $0x40, %edi
callq 0xb2c0
movq %rax, %r15
movq 0x18(%r14), %rsi
movq %rax, %rdi
movl %r13d, %edx
callq 0x2e6e4
movq %r15, (%rbx)
jmp 0x2f317
leaq 0x1a00a(%rip), %rdi     # 0x4954e
leaq 0x188cc(%rip), %rsi     # 0x47e17
leaq 0x1a04a(%rip), %rcx     # 0x4959c
movl $0x16e, %edx            # imm = 0x16E
callq 0xb180
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x2f593
callq 0xb977
jmp 0x2f593
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x2f593
callq 0xb99f
jmp 0x2f593
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x2f593
callq 0xb9c7
movq %rbx, %rdi
callq 0xb4e0