// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rdx, %r14
movq %rdi, %rbx
movl 0x20(%rdx), %edx
cmpl $0x1, %edx
je 0x30e4c
movq %r8, %r12
testl %edx, %edx
jne 0x30e3f
movq %r12, (%rbx)
testq %r12, %r12
je 0x30e60
movq (%r12), %rax
movq -0x20(%rax), %rax
incl 0x8(%r12,%rax)
jmp 0x30e60
movl 0x20(%r15), %eax
movl 0x20(%r12), %ecx
cmpl %ecx, %eax
jne 0x30e72
movq %r15, (%rbx)
testq %r15, %r15
je 0x30e60
movq (%r15), %rax
movq -0x20(%rax), %rax
incl 0x8(%r15,%rax)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, %edi
orl %eax, %edi
cmpl $0x1, %edi
ja 0x30e8c
testl %eax, %eax
jne 0x30eef
movq %rbx, %rdi
movq %r14, %rdx
callq 0x31110
jmp 0x30e60
testl %eax, %eax
setne %r8b
movl %eax, %edi
xorl %edx, %edi
cmpl $0x1, %edi
setne %r9b
testb %r9b, %r8b
jne 0x30ee7
leaq -0x40(%rbp), %r15
movq %r15, %rdi
movq %r14, %rdx
callq 0x31110
movq (%r15), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
movq %r12, %rcx
callq 0x311cc
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x30e60
movq (%rax), %rcx
movq -0x20(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x8(%rax,%rcx), %eax
cmpl $0x1, %eax
ja 0x30f4d
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x30f52
movl %edi, %r8d
orl %ecx, %r8d
jne 0x30f0c
movq %r14, (%rbx)
testq %r14, %r14
je 0x30e60
movq (%r14), %rax
movq -0x20(%rax), %rax
incl 0x8(%r14,%rax)
jmp 0x30e60
movl %ecx, %r8d
xorl $0x1, %r8d
orl %r8d, %edi
je 0x30f2f
movl %eax, %r8d
xorl $0x1, %r8d
movl %ecx, %edi
xorl %edx, %edi
movl %edi, %r9d
xorl $0x1, %r9d
orl %r8d, %r9d
jne 0x30f5f
leaq -0x40(%rbp), %rsi
movl $0x1, (%rsi)
movq $0x0, (%rbx)
movq %rbx, %rdi
callq 0x2ffda
jmp 0x30e60
decl %eax
movl %eax, 0x8(%rdi)
movq $0x0, -0x40(%rbp)
jmp 0x30e60
cmpl $0x1, %eax
setne %r8b
cmpl %edx, %eax
setne %r9b
testb %r9b, %r8b
jne 0x30f84
movq %rbx, %rdi
movq %r14, %rdx
movq %r12, %rcx
callq 0x312d8
jmp 0x30e60
testl %ecx, %ecx
setne %r8b
cmpl %edx, %ecx
setne %dl
testb %dl, %r8b
jne 0x30fa7
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
callq 0x311cc
jmp 0x30e60
cmpl $0x1, %ecx
setne %dl
cmpl $0x1, %edi
setne %dil
testb %dil, %dl
jne 0x30fdf
leaq -0x40(%rbp), %r12
movq %r12, %rdi
movq %r14, %rdx
callq 0x31110
movq (%r12), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
movq %r15, %rcx
callq 0x312d8
jmp 0x30ec2
xorl %eax, %ecx
cmpl $0x1, %ecx
jne 0x31039
leaq -0x40(%rbp), %rdx
movq %r14, (%rdx)
movq %r15, 0x8(%rdx)
leaq -0x48(%rbp), %r14
movl $0x2, %ecx
movq %r14, %rdi
callq 0x30a92
movq (%r14), %rdx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x31110
movq -0x48(%rbp), %rax
testq %rax, %rax
je 0x30e60
movq (%rax), %rcx
movq -0x20(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x8(%rax,%rcx), %eax
cmpl $0x1, %eax
ja 0x31094
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x31099
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0x310a6
cmpq 0x18(%r15), %rdi
jne 0x310a6
cmpq 0x18(%r12), %rdi
jne 0x310a6
movq (%rdi), %rax
callq *0x8(%rax)
movl %eax, %r13d
movq 0x18(%r14), %rdi
movl 0x20(%r14), %edx
movl 0x20(%r15), %ecx
movl 0x20(%r12), %r8d
movl %eax, %esi
callq 0x10026
movl $0x40, %edi
callq 0xc2c0
movq %rax, %r15
movq 0x18(%r14), %rsi
movq %rax, %rdi
movl %r13d, %edx
callq 0x301b2
movq %r15, (%rbx)
jmp 0x30e54
decl %eax
movl %eax, 0x8(%rdi)
movq $0x0, -0x48(%rbp)
jmp 0x30e60
leaq 0x1a491(%rip), %rdi     # 0x4b53e
leaq 0x18d53(%rip), %rsi     # 0x49e07
leaq 0x1a4d1(%rip), %rcx     # 0x4b58c
movl $0x16e, %edx            # imm = 0x16E
callq 0xc180
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x31108
leaq -0x48(%rbp), %rsi
callq 0xcbe3
jmp 0x31108
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x31108
leaq -0x40(%rbp), %rsi
callq 0xcc1a
jmp 0x31108
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x31108
leaq -0x40(%rbp), %rsi
callq 0xcc51
movq %rbx, %rdi
callq 0xc4e0