// File: vsklad[P]cgen/./bal/variables/variablesarray.hpp
// Function: bal::VariablesArray::assign_template_from(bal::VariablesArray const&, bal::VariablesArray const&)
inline variables_size_t assign_template_from(const VariablesArray& template_, const VariablesArray& value) {
            _assert_level_1(template_.size_ == value.size_);
            variables_size_t changes_count = 0;
            for (container_size_t i = 0; i < template_.size_; i++) {
                literalid_t lhs_literal = template_.data_[i];
                literalid_t rhs_literal = value.data_[i];
                
                // an unassigned literal means there is nothing to assign or to assign to
                // equalence means there is nothing to assign as well
                while (!literal_t__is_unassigned(rhs_literal) &&
                       !literal_t__is_unassigned(lhs_literal) && lhs_literal != rhs_literal) {
                    
                    if (literal_t__is_variable(lhs_literal)) {
                        rhs_literal = literal_t__substitute_literal(lhs_literal, rhs_literal);
                        literal_t__unnegate(lhs_literal);
                        
                        const variableid_t variableid = literal_t__variable_id(lhs_literal);
                        _assert_level_1(variableid < size_);

                        // the value must not be set OR it cannot be set to two different values OR
                        // for variables, higher variable id gets assigned with the lower one
                        // i.e. swap variables if necessary
                        if (data_[variableid] != rhs_literal) {
                            if (literal_t__is_variable(rhs_literal) && rhs_literal > lhs_literal) {
                                std::swap(rhs_literal, lhs_literal);
                                continue;
                            } else if (data_[variableid] == lhs_literal || literal_t__is_unassigned(data_[variableid])) {
                                data_[variableid] = rhs_literal;
                                changes_count++;
                            } else if (literal_t__is_negation_of(data_[variableid], lhs_literal)) {
                                data_[variableid] = literal_t__negated(rhs_literal);
                                changes_count++;
                            } else if (literal_t__is_constant(data_[variableid]) || literal_t__is_variable(data_[variableid])) {
                                lhs_literal = data_[variableid];
                                continue;
                            } else {
                                return VARIABLEID_ERROR;
                            };
                        };
                    } else if (literal_t__is_constant(lhs_literal) && literal_t__is_variable(rhs_literal)) {
                        // { const = var } => { var = const }
                        std::swap(rhs_literal, lhs_literal);
                        continue;
                    } else if (lhs_literal != rhs_literal) {
                        // any remaining literals must match whatever they are
                        return VARIABLEID_ERROR;
                    };
                    break;
                };
            };
            return changes_count;
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x1041e
jmp 0x1043d
leaq 0x4b411(%rip), %rdi     # 0x5b836
leaq 0x4b300(%rip), %rsi     # 0x5b72c
movl $0x8d, %edx
leaq 0x4b41d(%rip), %rcx     # 0x5b855
callq 0xd1c0
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0x106b1
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl -0x28(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x30(%rbp)
movb %al, -0x41(%rbp)
je 0x1049d
xorl %eax, %eax
cmpl $-0x1, -0x2c(%rbp)
movb %al, -0x41(%rbp)
je 0x1049d
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
testb $0x1, %al
jne 0x104a9
jmp 0x106a1
xorl %eax, %eax
cmpl $0x1, -0x2c(%rbp)
movb %al, -0x42(%rbp)
jbe 0x104be
cmpl $-0x2, -0x2c(%rbp)
setbe %al
movb %al, -0x42(%rbp)
movb -0x42(%rbp), %al
testb $0x1, %al
jne 0x104ca
jmp 0x10654
movq -0x40(%rbp), %rcx
movl -0x30(%rbp), %eax
movl -0x2c(%rbp), %edi
xorl $-0x1, %edi
andl $0x1, %edi
xorl %edx, %edx
movl $0x1, %esi
cmpl $0x0, %edi
cmovnel %esi, %edx
xorl %edx, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shrl %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x8(%rcx), %eax
jae 0x1050a
jmp 0x10529
leaq 0x4b3af(%rip), %rdi     # 0x5b8c0
leaq 0x4b214(%rip), %rsi     # 0x5b72c
movl $0x9d, %edx
leaq 0x4b331(%rip), %rcx     # 0x5b855
callq 0xd1c0
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x30(%rbp), %eax
je 0x10652
xorl %eax, %eax
cmpl $0x1, -0x30(%rbp)
movb %al, -0x43(%rbp)
jbe 0x10554
cmpl $-0x2, -0x30(%rbp)
setbe %al
movb %al, -0x43(%rbp)
movb -0x43(%rbp), %al
testb $0x1, %al
jne 0x1055d
jmp 0x10577
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jbe 0x10577
leaq -0x30(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x114e0
jmp 0x1047b
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x2c(%rbp), %eax
je 0x10599
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
cmpl $-0x1, (%rax,%rcx,4)
jne 0x105b7
movq -0x40(%rbp), %rax
movl -0x30(%rbp), %edx
movq (%rax), %rax
movl -0x34(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1064e
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
xorl -0x2c(%rbp), %eax
cmpl $0x1, %eax
jne 0x105ea
movq -0x40(%rbp), %rax
movl -0x30(%rbp), %edx
xorl $0x1, %edx
movq (%rax), %rax
movl -0x34(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1064c
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
cmpl $0x1, (%rax,%rcx,4)
jbe 0x1062e
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movl -0x34(%rbp), %eax
movl %eax, %edx
xorl %eax, %eax
cmpl $0x1, (%rcx,%rdx,4)
movb %al, -0x44(%rbp)
jbe 0x10625
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
cmpl $-0x2, (%rax,%rcx,4)
setbe %al
movb %al, -0x44(%rbp)
movb -0x44(%rbp), %al
testb $0x1, %al
jne 0x1062e
jmp 0x10643
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
jmp 0x1047b
movl $0x7fffffff, -0x4(%rbp) # imm = 0x7FFFFFFF
jmp 0x106b7
jmp 0x1064e
jmp 0x10650
jmp 0x10652
jmp 0x1069f
cmpl $0x1, -0x2c(%rbp)
ja 0x1068a
xorl %eax, %eax
cmpl $0x1, -0x30(%rbp)
movb %al, -0x45(%rbp)
jbe 0x1066f
cmpl $-0x2, -0x30(%rbp)
setbe %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x10678
jmp 0x1068a
leaq -0x30(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x114e0
jmp 0x1047b
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0x1069b
movl $0x7fffffff, -0x4(%rbp) # imm = 0x7FFFFFFF
jmp 0x106b7
jmp 0x1069d
jmp 0x1069f
jmp 0x106a1
jmp 0x106a3
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1044b
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq