// File: /workspace/github_cpp_makefile_star2_O2/vsklad[P]cgen/./bal/encoding/literal.hpp
// Function: bal::Ref<bal::Literal<bal::Anf>> bal::eor<bal::Anf>(bal::Literal<bal::Anf>*, bal::Literal<bal::Anf> const* const*, unsigned long)
Ref<Literal<FORMULA_T>> eor(Literal<FORMULA_T>* const r,
                                const Literal<FORMULA_T>* const args[], const std::size_t args_size) {
        literalid_t constant = 0;
        literalid_t optimized_args[args_size];
        std::size_t optimized_args_size = 0;
        FORMULA_T* formula = nullptr;
        
        for (auto i = 0; i < args_size; i++) {
            if (literal_t__is_constant(args[i]->value)) {
                constant ^= args[i]->value;
            } else {
                // eliminate if the variables are negated or duplicated
                // build a sorted list because:
                // INCONCLUSIVE: lower indexes first - order matters
                // grouping of lower indexes reduces length of variables chain (?)
                for (auto j = 0; j <= optimized_args_size; j++) {
                    if (j == optimized_args_size) {
                        // at the end, no duplicates, append to lagrs
                        update_formula(formula, args[i]);
                        optimized_args[j] = args[i]->value;
                        optimized_args_size++;
                        break;
                    } else if (literal_t__is_same_variable(args[i]->value, optimized_args[j])) {
                        if ((literal_t__is_negation_of(args[i]->value, optimized_args[j]))) {
                            // negated means always 1
                            constant ^= 1;
                        };
                        // remove from variable_args
                        for (auto k = j; k < optimized_args_size - 1; k++) {
                            optimized_args[k] = optimized_args[k + 1];
                        };
                        optimized_args_size--;
                        break;
#if defined(XOR_ARGS_ORDER_ASCENDING) || defined(XOR_ARGS_ORDER_DESCENDING)
                    } else if (literal_t__variable_id(args[i]->value)
#if defined(XOR_ARGS_ORDER_ASCENDING)
                               <
#elif defined(XOR_ARGS_ORDER_DESCENDING)
                               >
#endif
                               literal_t__variable_id(optimized_args[j])) {
                        // insertion point found
                        for (auto k = optimized_args_size; k > j; k--) {
                            optimized_args[k] = optimized_args[k - 1];
                        };
                        update_formula(formula, args[i]);
                        optimized_args[j] = args[i]->value;
                        optimized_args_size++;
                        break;
#endif
                    };
                };
            };
        };
        
        return Literal<FORMULA_T>::from_literal(formula, eor(formula, optimized_args, optimized_args_size, constant));
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, -0x48(%rbp)
movq %rsp, %r12
leaq 0xf(,%rcx,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
leaq -0x30(%rbp), %rax
andq $0x0, (%rax)
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rcx, -0x40(%rbp)
movq %rdx, -0x38(%rbp)
cmpq %rcx, %r14
je 0x25b4a
movq (%rdx,%r14,8), %rsi
movl 0x20(%rsi), %eax
cmpl $0x2, %eax
jae 0x25a9a
xorl %eax, %r13d
jmp 0x25b42
movl %eax, %r8d
shrl %r8d
decl %r8d
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x25ac9
movl (%r12,%r15,4), %r9d
movl %r9d, %edi
xorl %eax, %edi
cmpl $0x1, %edi
jbe 0x25ae7
shrl %r9d
decl %r9d
cmpl %r9d, %r8d
jb 0x25b0d
incq %r15
jmp 0x25aa6
leaq -0x30(%rbp), %rdi
callq 0x25b82
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq (%rdx,%r14,8), %rax
movl 0x20(%rax), %eax
movl %eax, (%r12,%rbx,4)
jmp 0x25b3f
sete %al
movzbl %al, %eax
decq %rbx
cmpq %rbx, %r15
movq %rbx, %rsi
cmovaq %r15, %rsi
cmpq %r15, %rsi
je 0x25a92
movl 0x4(%r12,%r15,4), %edi
movl %edi, (%r12,%r15,4)
incq %r15
jmp 0x25afa
movq %rbx, %rax
cmpq %r15, %rax
jbe 0x25b23
movl -0x4(%r12,%rax,4), %ecx
movl %ecx, (%r12,%rax,4)
decq %rax
jmp 0x25b10
leaq -0x30(%rbp), %rdi
callq 0x25b82
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq (%rdx,%r14,8), %rax
movl 0x20(%rax), %eax
movl %eax, (%r12,%r15,4)
incq %rbx
incq %r14
jmp 0x25a7d
movq -0x30(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movl %r13d, %ecx
callq 0x25be2
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x248c8
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq