// File: vsklad[P]cgen/commands.cpp
// Function: variables_merge(bal::VariablesArray&, bal::Formula&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, CGenVariableInfo, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, CGenVariableInfo>>> const&, bool, bool)
bal::variables_size_t variables_merge(bal::VariablesArray& variables,
                                      bal::Formula& formula,
                                      const CGenVariablesMap& variables_map,
                                      const bool apply_except,
                                      const bool reassign_in_formula) {
    assert(formula.variables_size() == variables.size());
    bal::variables_size_t changes_count = 0;
    for (auto it = variables_map.begin(); it != variables_map.end(); it++ ) {
        // other types must have been resolved into values at this point
        _assert_level_1(it->second.mode == vmValue || it->second.mode == vmCompute);
        if (it->second.mode == vmValue) {
            const bal::VariablesArray variable_template = variable_get_template(formula, it->first.c_str());
            bal::VariablesArray variable_value = variable_generate_value(formula, it->first, it->second,
                                                                         variable_template, apply_except,
                                                                         reassign_in_formula);
            bal::variables_size_t assignment_result = variables.assign_template_from(variable_template, variable_value);
            if (assignment_result != bal::VARIABLEID_ERROR) {
                changes_count += assignment_result;
            } else {
                throw std::invalid_argument("Conflicting binary variable assignment");
            };
            
            if (apply_except && !is_binary_variable_name(it->first)) {
                // update any unassigned variables within template
                // with values that has been specified or generated
                formula.named_variable_update_unassigned(it->first, variable_value);
            };
        };
    };
    return changes_count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %cl
movb %cl, -0x19(%rbp)
andb $0x1, %al
movb %al, -0x1a(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *0x58(%rax)
movl %eax, -0xac(%rbp)
movq -0x8(%rbp), %rdi
callq 0x102f0
movl %eax, %ecx
movl -0xac(%rbp), %eax
cmpl %ecx, %eax
jne 0x2bf5c
jmp 0x2bf7b
leaq 0x36810(%rip), %rdi     # 0x62773
leaq 0x36527(%rip), %rsi     # 0x62491
movl $0x171, %edx            # imm = 0x171
leaq 0x3682a(%rip), %rcx     # 0x627a0
callq 0xd1c0
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2e300
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2e360
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2e330
testb $0x1, %al
jne 0x2bfb2
jmp 0x2c25c
leaq -0x28(%rbp), %rdi
callq 0x2e390
movq %rax, %rcx
movb $0x1, %al
cmpl $0x0, 0x20(%rcx)
movb %al, -0xad(%rbp)
je 0x2bfe2
leaq -0x28(%rbp), %rdi
callq 0x2e390
cmpl $0x2, 0x20(%rax)
sete %al
movb %al, -0xad(%rbp)
movb -0xad(%rbp), %al
testb $0x1, %al
jne 0x2bfee
jmp 0x2bff0
jmp 0x2c00f
leaq 0x36828(%rip), %rdi     # 0x6281f
leaq 0x36493(%rip), %rsi     # 0x62491
movl $0x175, %edx            # imm = 0x175
leaq 0x36796(%rip), %rcx     # 0x627a0
callq 0xd1c0
leaq -0x28(%rbp), %rdi
callq 0x2e390
cmpl $0x0, 0x20(%rax)
jne 0x2c243
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x28(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x2e390
movq %rax, %rdi
callq 0xd120
movq -0xc8(%rbp), %rsi
movq %rax, %rdx
leaq -0x50(%rbp), %rdi
callq 0x2a470
movq -0xc0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
callq 0x2e390
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0xd130
jmp 0x2c080
leaq -0x28(%rbp), %rdi
callq 0x2e390
movq -0xb8(%rbp), %rsi
movq %rax, %rcx
addq $0x20, %rcx
movzbl -0x19(%rbp), %r9d
movzbl -0x1a(%rbp), %edx
andl $0x1, %edx
movq %rsp, %rax
movl %edx, (%rax)
andl $0x1, %r9d
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rdx
leaq -0x50(%rbp), %r8
callq 0x2afe0
jmp 0x2c0c2
leaq -0x90(%rbp), %rdi
callq 0xd1b0
movq -0x8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x103f0
movl %eax, -0xcc(%rbp)
jmp 0x2c0e7
movl -0xcc(%rbp), %eax
movl %eax, -0xa0(%rbp)
cmpl $0x7fffffff, -0xa0(%rbp) # imm = 0x7FFFFFFF
je 0x2c161
movl -0xa0(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0x2c1c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x2c238
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xd1b0
jmp 0x2c238
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x2c22f
movl $0x10, %edi
callq 0xd150
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xd8(%rbp)
leaq 0x366db(%rip), %rsi     # 0x6285a
callq 0xd5f0
jmp 0x2c186
movq -0xd8(%rbp), %rdi
movq 0x56e44(%rip), %rsi     # 0x82fd8
movq 0x56e25(%rip), %rdx     # 0x82fc0
callq 0xd570
jmp 0x2c274
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
callq 0xd210
jmp 0x2c22f
testb $0x1, -0x19(%rbp)
je 0x2c21b
leaq -0x28(%rbp), %rdi
callq 0x2e390
movq %rax, %rdi
callq 0x26c60
movb %al, -0xd9(%rbp)
jmp 0x2c1e4
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0x2c21b
jmp 0x2c1f0
movq -0x10(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x2e390
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
leaq -0x70(%rbp), %rdx
callq 0x55320
jmp 0x2c219
jmp 0x2c21b
leaq -0x70(%rbp), %rdi
callq 0x10850
leaq -0x50(%rbp), %rdi
callq 0x10850
jmp 0x2c243
leaq -0x70(%rbp), %rdi
callq 0x10850
leaq -0x50(%rbp), %rdi
callq 0x10850
jmp 0x2c268
jmp 0x2c245
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x2e3c0
movq %rax, -0xa8(%rbp)
jmp 0x2bf8f
movl -0x20(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x98(%rbp), %rdi
callq 0xd5a0
nopw %cs:(%rax,%rax)