// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r8d, %r15d
movl %ecx, %r13d
movq %rdx, %r14
movq %rdi, %rbx
movq (%rsi), %rax
movq %rsi, -0x38(%rbp)
movq %rsi, %rdi
callq *0x58(%rax)
movq %rbx, -0x60(%rbp)
cmpl 0x8(%rbx), %eax
jne 0x1b3d5
movq 0x18(%r14), %rbx
addq $0x8, %r14
movl $0x0, -0x2c(%rbp)
movzbl %r15b, %eax
movl %eax, -0x44(%rbp)
movzbl %r13b, %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %r12
movq %r14, -0x58(%rbp)
movl %r13d, -0x3c(%rbp)
cmpq %r14, %rbx
je 0x1b371
movl 0x40(%rbx), %eax
testl %eax, %eax
je 0x1b29b
cmpl $0x2, %eax
je 0x1b361
jmp 0x1b3b6
movq %rbx, %r13
addq $0x20, %rbx
movq (%rbx), %rdx
leaq -0x80(%rbp), %rdi
movq %r12, %rsi
callq 0x1a675
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
movq %rbx, -0x50(%rbp)
movq %rbx, %rsi
callq 0xc360
leaq 0x40(%r13), %rcx
movl -0x44(%rbp), %eax
movl %eax, (%rsp)
leaq -0xc0(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
leaq -0x80(%rbp), %r12
movq %r12, %r8
movl -0x40(%rbp), %r9d
callq 0x1ab92
movq %r13, %rbx
movq %r14, %rdi
callq 0xc110
movq -0x60(%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xdc3c
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x1b386
movl %eax, %r14d
cmpb $0x0, -0x3c(%rbp)
je 0x1b344
cmpq $0x0, 0x28(%rbx)
je 0x1b334
movq -0x50(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
addl $-0x30, %eax
cmpl $0xa, %eax
jb 0x1b344
movq -0x38(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %r15, %rdx
callq 0x2e362
addl %r14d, -0x2c(%rbp)
movq %r15, %rdi
callq 0xde58
leaq -0x80(%rbp), %rdi
callq 0xde58
movq -0x58(%rbp), %r14
movq -0x38(%rbp), %r12
movq %rbx, %rdi
callq 0xc2e0
movq %rax, %rbx
jmp 0x1b27d
movl -0x2c(%rbp), %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0xc130
movq %rax, %r14
leaq 0x1d416(%rip), %rsi     # 0x387ae
movq %rax, %rdi
callq 0xc4e0
movq 0x35c31(%rip), %rsi     # 0x50fd8
movq 0x35c12(%rip), %rdx     # 0x50fc0
movq %r14, %rdi
callq 0xc490
leaq 0x1d3b6(%rip), %rdi     # 0x38773
leaq 0x1d021(%rip), %rsi     # 0x383e5
leaq 0x1d329(%rip), %rcx     # 0x386f4
movl $0x175, %edx            # imm = 0x175
callq 0xc180
leaq 0x1d2eb(%rip), %rdi     # 0x386c7
leaq 0x1d002(%rip), %rsi     # 0x383e5
leaq 0x1d30a(%rip), %rcx     # 0x386f4
movl $0x171, %edx            # imm = 0x171
callq 0xc180
jmp 0x1b3f6
movq %rax, %rbx
jmp 0x1b406
movq %rax, %rbx
movq %r14, %rdi
callq 0xc1d0
leaq -0xc0(%rbp), %rdi
callq 0xde58
jmp 0x1b428
movq %rax, %rbx
jmp 0x1b428
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0xc110
leaq -0x80(%rbp), %rdi
callq 0xde58
movq %rbx, %rdi
callq 0xc4c0