// File: 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
subq $0x80, %rsp
movq %rdi, -0x78(%rbp)
movq %rdi, %rax
movq %rax, -0x70(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x20(%rbp), %rax
movq %rsp, %rcx
movq %rcx, -0x30(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x68(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movslq -0x4c(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x44f9c
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x1, 0x20(%rax)
ja 0x44de6
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x20(%rax), %eax
xorl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x44f8c
movl $0x0, -0x50(%rbp)
movslq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
ja 0x44f8a
movslq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0x44e45
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x48(%rbp), %rdi
callq 0x44fe0
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x4c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl 0x20(%rcx), %edx
movslq -0x50(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x44f8a
movq -0x68(%rbp), %rcx
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl 0x20(%rax), %eax
movslq -0x50(%rbp), %rdx
xorl (%rcx,%rdx,4), %eax
shrl %eax
cmpl $0x0, %eax
jne 0x44ed8
movq -0x68(%rbp), %rcx
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl 0x20(%rax), %eax
movslq -0x50(%rbp), %rdx
xorl (%rcx,%rdx,4), %eax
cmpl $0x1, %eax
jne 0x44e8e
movl -0x24(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x54(%rbp)
movslq -0x54(%rbp), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x44ec7
movq -0x68(%rbp), %rax
movl -0x54(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movslq -0x54(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x44e94
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x44f8a
movq -0x68(%rbp), %rcx
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl 0x20(%rax), %eax
shrl %eax
subl $0x1, %eax
movslq -0x50(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x44f76
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movslq -0x50(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x44f39
movq -0x68(%rbp), %rax
movq -0x60(%rbp), %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %edx
movq -0x60(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x60(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x44f08
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x48(%rbp), %rdi
callq 0x44fe0
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x4c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl 0x20(%rcx), %edx
movslq -0x50(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x44f8a
jmp 0x44f78
jmp 0x44f7a
jmp 0x44f7c
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x44ded
jmp 0x44f8c
jmp 0x44f8e
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x44dac
movq -0x68(%rbp), %rsi
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rdx
movl -0x24(%rbp), %ecx
callq 0x45090
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
movl %eax, %edx
callq 0x42170
movq -0x70(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)