// File: /workspace/github_cpp_makefile_star2_O1/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 %rsp, %r14
leaq 0xf(,%rcx,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq $0x0, -0x30(%rbp)
testq %rcx, %rcx
movq %rdi, -0x40(%rbp)
je 0x30bb2
movq %rdx, %r12
xorl %r15d, %r15d
xorl %ebx, %ebx
xorl %r9d, %r9d
movq %rcx, -0x38(%rbp)
movq (%r12,%r15,8), %rsi
movl 0x20(%rsi), %eax
cmpl $0x2, %eax
jae 0x30af0
xorl %eax, %r9d
jmp 0x30ba4
testq %rbx, %rbx
je 0x30b1f
movl %eax, %r8d
shrl %r8d
decl %r8d
xorl %r13d, %r13d
movl (%r14,%r13,4), %edx
movl %edx, %edi
xorl %eax, %edi
cmpl $0x1, %edi
jbe 0x30b42
shrl %edx
decl %edx
cmpl %edx, %r8d
jb 0x30b68
incq %r13
cmpq %r13, %rbx
jne 0x30b01
leaq -0x30(%rbp), %rdi
movq %r9, %r13
callq 0x30bef
movq %r13, %r9
movq -0x38(%rbp), %rcx
movq (%r12,%r15,8), %rax
movl 0x20(%rax), %eax
movl %eax, (%r14,%rbx,4)
incq %rbx
jmp 0x30ba4
sete %al
movzbl %al, %eax
xorl %eax, %r9d
decq %rbx
movl %r13d, %eax
cmpq %rax, %rbx
jbe 0x30ba4
movl 0x4(%r14,%r13,4), %eax
movl %eax, (%r14,%r13,4)
leaq 0x1(%r13), %rax
movq %rax, %r13
jmp 0x30b51
movq %r9, -0x48(%rbp)
movq %rbx, %rax
cmpq %r13, %rbx
jbe 0x30b85
movl -0x4(%r14,%rax,4), %ecx
movl %ecx, (%r14,%rax,4)
decq %rax
cmpq %r13, %rax
ja 0x30b74
leaq -0x30(%rbp), %rdi
callq 0x30bef
movq (%r12,%r15,8), %rax
movl 0x20(%rax), %eax
movl %eax, (%r14,%r13,4)
incq %rbx
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %r9
incq %r15
cmpq %rcx, %r15
jne 0x30adc
jmp 0x30bb7
xorl %r9d, %r9d
xorl %ebx, %ebx
movq -0x30(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl %r9d, %ecx
callq 0x30c57
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x2f412
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq