// File: /workspace/github_cpp_makefile_star2_O1/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 0x31834
movq %rcx, %r15
testq %rcx, %rcx
je 0x31834
movq %rdx, %rbx
movq %rdi, %r14
callq 0x308e7
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 0x30a92
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 0x30bef
movq %r15, -0x68(%rbp)
movq 0x30(%r15), %rsi
movq %rbx, %rdi
callq 0x30bef
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 0x30bef
movq 0x38(%r15,%r14,8), %rsi
movq %rbx, %rdi
movl -0x44(%rbp), %ebx
movl -0x48(%rbp), %r15d
callq 0x30bef
cmpl $0x1, %ebx
movl -0x2c(%rbp), %r9d
ja 0x31791
cmpl $0x1, %r13d
ja 0x31791
cmpl $0x1, %r12d
ja 0x31791
cmpl $0x1, %r9d
ja 0x31791
cmpl $0x1, %r15d
ja 0x31791
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
cmpl $0x2, %r12d
jb 0x317b3
jmp 0x317f6
movq -0x60(%rbp), %rdi
movl %r15d, (%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %ebx, %edx
movl %r13d, %ecx
movl %r12d, %r8d
callq 0x1012d
movl %eax, %r12d
cmpl $-0x1, %eax
je 0x31815
movq -0x60(%rbp), %rsi
leaq -0x40(%rbp), %rdi
movl %r12d, %edx
callq 0x2f412
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 0x3170d
movq -0x38(%rbp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a216(%rip), %rdi     # 0x4ba13
leaq 0x1a152(%rip), %rsi     # 0x4b956
leaq 0x1a165(%rip), %rcx     # 0x4b970
movl $0x46, %edx
callq 0xc180
leaq 0x1a21d(%rip), %rdi     # 0x4ba39
leaq 0x1a133(%rip), %rsi     # 0x4b956
leaq 0x1a146(%rip), %rcx     # 0x4b970
movl $0x49, %edx
callq 0xc180
leaq 0x1a0fe(%rip), %rdi     # 0x4b939
leaq 0x1a114(%rip), %rsi     # 0x4b956
leaq 0x1a127(%rip), %rcx     # 0x4b970
movl $0x2e, %edx
callq 0xc180
jmp 0x31857
jmp 0x31857
movq %rax, %rbx
movq -0x38(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3186f
movq -0x38(%rbp), %rsi
callq 0xccf6
movq %rbx, %rdi
callq 0xc4e0
nop