// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movl %r8d, %ebx
movl %ecx, -0x30(%rbp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq (%rsi), %rax
movq %rsi, %rdi
callq *0x58(%rax)
movq %r12, -0x80(%rbp)
cmpl 0x8(%r12), %eax
jne 0x212d4
movq 0x18(%r14), %r13
addq $0x8, %r14
cmpq %r14, %r13
je 0x21267
movzbl %bl, %eax
movl %eax, -0x38(%rbp)
movzbl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x2c(%rbp)
movl 0x40(%r13), %eax
testl %eax, %eax
je 0x2113e
cmpl $0x2, %eax
je 0x21251
jmp 0x212b5
movq %r14, %r12
movq 0x20(%r13), %rdx
leaq -0x78(%rbp), %rdi
movq %r15, %rsi
callq 0x202df
leaq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq 0x20(%r13), %rsi
movq 0x28(%r13), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
callq 0x1f204
leaq 0x40(%r13), %rcx
movl -0x38(%rbp), %eax
movl %eax, (%rsp)
leaq -0x58(%rbp), %rdi
movq %r15, %rbx
movq %r15, %rsi
movq %r14, %rdx
leaq -0x78(%rbp), %r8
movl -0x34(%rbp), %r9d
callq 0x20914
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
movq %r12, %r14
je 0x211b8
callq 0xc280
movq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0xf7c2
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0x21283
movl %eax, %r12d
movq %rbx, %r15
cmpb $0x0, -0x30(%rbp)
je 0x21205
leaq 0x20(%r13), %rsi
cmpq $0x0, 0x28(%r13)
je 0x211f9
movq (%rsi), %rax
movsbl (%rax), %eax
addl $-0x30, %eax
cmpl $0xa, %eax
jb 0x21205
movq %r15, %rdi
leaq -0x58(%rbp), %rdx
callq 0x3d334
cmpl $0x0, -0x40(%rbp)
je 0x21229
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x21221
callq 0xc350
movq $0x0, -0x58(%rbp)
xorl %eax, %eax
movl %eax, -0x50(%rbp)
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x2124d
movq -0x78(%rbp), %rdi
testq %rdi, %rdi
je 0x21245
callq 0xc350
movq $0x0, -0x78(%rbp)
xorl %eax, %eax
movl %eax, -0x70(%rbp)
movl %eax, -0x60(%rbp)
addl %r12d, -0x2c(%rbp)
movq %r13, %rdi
callq 0xc330
movq %rax, %r13
cmpq %r14, %rax
jne 0x21128
jmp 0x2126e
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0xc130
movq %rax, %r14
leaq 0x275c7(%rip), %rsi     # 0x4885e
movq %rax, %rdi
callq 0xc520
movq 0x3dd2a(%rip), %rsi     # 0x5efd0
movq 0x3dd0b(%rip), %rdx     # 0x5efb8
movq %r14, %rdi
callq 0xc4b0
leaq 0x27567(%rip), %rdi     # 0x48823
leaq 0x271d2(%rip), %rsi     # 0x48495
leaq 0x274da(%rip), %rcx     # 0x487a4
movl $0x175, %edx            # imm = 0x175
callq 0xc180
leaq 0x2749c(%rip), %rdi     # 0x48777
leaq 0x271b3(%rip), %rsi     # 0x48495
leaq 0x274bb(%rip), %rcx     # 0x487a4
movl $0x171, %edx            # imm = 0x171
callq 0xc180
jmp 0x212f5
movq %rax, %rbx
jmp 0x21305
movq %rax, %rbx
movq %r14, %rdi
callq 0xc1e0
cmpl $0x0, -0x40(%rbp)
je 0x21318
leaq -0x40(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0xc66b
movl $0x0, -0x50(%rbp)
jmp 0x21341
movq %rax, %rbx
jmp 0x21341
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x21341
callq 0xc280
cmpl $0x0, -0x60(%rbp)
je 0x21354
leaq -0x60(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0xc696
movq %rbx, %rdi
callq 0xc4e0