// File: /workspace/github_cpp_makefile_star2_O3/vsklad[P]cgen/./bal/anf/anfencoding.hpp
// Function: bal::Ref<bal::GF2NElement<32ul, bal::Literal<bal::Anf>>> bal::add2<32ul>(bal::GF2NElement<32ul, bal::Literal<bal::Anf>>*, bal::GF2NElement<32ul, bal::Literal<bal::Anf>> const*, bal::GF2NElement<32ul, bal::Literal<bal::Anf>> const*)
Ref<GF2NElement<N, Literal<Anf>>> add2(GF2NElement<N, Literal<Anf>>* r,
                                           const GF2NElement<N, Literal<Anf>>* x,
                                           const GF2NElement<N, Literal<Anf>>* y) {
        static_assert(N > 0, "trivial");
        _assert_level_0(x != nullptr && y != nullptr);
        Ref<GF2NElement<N, Literal<Anf>>> result = new_instance_if_unassigned(r);
        
        // because it is possible that result == one of the operands
        literalid_t x_p = (*x)[0]->value;      // previous x
        literalid_t y_p = (*y)[0]->value;      // previous y
        (*result)[0] = eor2((*result)[0].data(), (*x)[0].data(), (*y)[0].data());
        literalid_t r_p = (*result)[0]->value; // previous r
        
        Anf* formula = (*result)[0]->formula;
        update_formula(formula, (*x)[0]);
        update_formula(formula, (*y)[0]);
        
        for (auto i = 1; i < N; i++) {
            const literalid_t x_i = (*x)[i]->value;
            const literalid_t y_i = (*y)[i]->value;
            update_formula(formula, (*x)[i]);
            update_formula(formula, (*y)[i]);
            
            // formula instance is undefined when all operands are constant
            // but the result can be easily calculated and no extra variables required
            if (literal_t__is_constant(x_i) && literal_t__is_constant(y_i) &&
                literal_t__is_constant(r_p) && literal_t__is_constant(x_p) && literal_t__is_constant(y_p)) {
                r_p = x_i ^ y_i ^ x_p ^ y_p ^ (x_p & y_p) ^ (x_p & r_p) ^ (y_p & r_p);
                _assert_level_2(literal_t__is_constant(r_p));
            } else {
                r_p = __add2(formula, LITERALID_UNASSIGNED, x_i, y_i, r_p, x_p, y_p);
                _assert_level_2(literal_t__is_constant(r_p) || literal_t__is_variable(r_p));
            };
            
            (*result)[i] = Literal<Anf>::from_literal(formula, r_p);
            
            x_p = x_i;
            y_p = y_i;
        };
        
        return result;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
testq %rdx, %rdx
je 0x2fc44
movq %rcx, %r15
testq %rcx, %rcx
je 0x2fc44
movq %rdx, %rbx
movq %rdi, %r14
callq 0x2eddc
movq 0x30(%rbx), %rax
movq %rbx, -0x50(%rbp)
movl 0x20(%rax), %ecx
movl %ecx, -0x2c(%rbp)
movq 0x30(%r15), %rcx
movl 0x20(%rcx), %r13d
movq (%r14), %rdx
movq 0x30(%rdx), %rsi
leaq -0x60(%rbp), %rdx
movq %rax, (%rdx)
movq %rcx, 0x8(%rdx)
leaq -0x40(%rbp), %rdi
movl $0x2, %ecx
movq %r14, -0x38(%rbp)
callq 0x2ef78
movq (%r14), %rax
leaq -0x40(%rbp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x30(%rax)
movl 0x20(%rcx), %r12d
movq 0x18(%rcx), %rax
leaq -0x60(%rbp), %rbx
movq %rax, (%rbx)
movq -0x50(%rbp), %rax
movq 0x30(%rax), %rsi
movq %rbx, %rdi
callq 0x2f0d8
movq %r15, -0x68(%rbp)
movq 0x30(%r15), %rsi
movq %rbx, %rdi
callq 0x2f0d8
xorl %r14d, %r14d
movl %r13d, -0x48(%rbp)
movq -0x50(%rbp), %rax
movq 0x38(%rax,%r14,8), %rsi
movl 0x20(%rsi), %eax
movl %eax, -0x44(%rbp)
movq -0x68(%rbp), %r15
movq 0x38(%r15,%r14,8), %rax
movl 0x20(%rax), %r13d
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x2f0d8
movq 0x38(%r15,%r14,8), %rsi
movq %rbx, %rdi
movl -0x44(%rbp), %ebx
movl -0x48(%rbp), %r15d
callq 0x2f0d8
cmpl $0x1, %ebx
movl -0x2c(%rbp), %r9d
ja 0x2fbc0
cmpl $0x1, %r13d
ja 0x2fbc0
cmpl $0x1, %r12d
ja 0x2fbc0
cmpl $0x1, %r9d
ja 0x2fbc0
cmpl $0x1, %r15d
ja 0x2fbc0
movl %r12d, %eax
xorl %r15d, %eax
andl %r9d, %eax
notl %r12d
andl %r15d, %r12d
xorl %eax, %r12d
xorl %r9d, %r12d
xorl %ebx, %r12d
xorl %r13d, %r12d
jmp 0x2fbe2
movq -0x60(%rbp), %rdi
movl %r15d, (%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %ebx, %edx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0xedc5
movl %eax, %r12d
cmpl $-0x1, %eax
je 0x2fc25
movq -0x60(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movl %r12d, %edx
callq 0x2d944
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movq %rcx, 0x38(%rax,%r14,8)
incq %r14
movl %ebx, -0x2c(%rbp)
cmpq $0x1f, %r14
jne 0x2fb42
movq -0x38(%rbp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19d83(%rip), %rdi     # 0x499af
leaq 0x19cbf(%rip), %rsi     # 0x498f2
leaq 0x19cd2(%rip), %rcx     # 0x4990c
movl $0x49, %edx
callq 0xb180
leaq 0x19c8a(%rip), %rdi     # 0x498d5
leaq 0x19ca0(%rip), %rsi     # 0x498f2
leaq 0x19cb3(%rip), %rcx     # 0x4990c
movl $0x2e, %edx
callq 0xb180
jmp 0x2fc67
jmp 0x2fc67
movq %rax, %rbx
movq -0x38(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2fc7f
movq -0x38(%rbp), %rsi
callq 0xba5d
movq %rbx, %rdi
callq 0xb4e0
nop