// File: /workspace/github_cpp_makefile_star2_O2/vsklad[P]cgen/commands.cpp
// Function: void encode_impl<acl::SHA1<bal::Literal<bal::Anf>>>(acl::SHA1<bal::Literal<bal::Anf>>::Bit::Formula&, unsigned int, 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>>>&, unsigned int, unsigned int, char const*, CGenOutputFormat, bool, bool, bool, bal::FormulaProcessingMode)
void encode_impl(typename SHA::Bit::Formula& formula, const uint32_t rounds,
                 CGenVariablesMap& variables_map,
                 const uint32_t add_max_args, const uint32_t xor_max_args,
                 const char* const output_file_name, const CGenOutputFormat output_format,
                 const bool b_reindex_variables, const bool b_normalize_variables,
                 const bool b_assign_after_encoding, const bal::FormulaProcessingMode mode) {

    if (rounds == 0 || rounds > SHA::ROUNDS_NUMBER) {
        throw std::invalid_argument(ERROR_ROUNDS_RANGE);
    };
    
    if (add_max_args > 0) {
        formula.set_add_max_args(add_max_args);
    };
    if (xor_max_args > 0) {
        formula.set_xor_max_args(xor_max_args);
    };
    formula.add_parameter("encoder", "add_max_args", formula.get_add_max_args());
    formula.add_parameter("encoder", "xor_max_args", formula.get_xor_max_args());
    
    formula.add_parameter("encoder", "xor_args_structure", "chain"); // "pyramid"
#if defined(XOR_ARGS_ORDER_ASCENDING)
    formula.add_parameter("encoder", "xor_args_order", "ascending");
#elif defined(XOR_ARGS_ORDER_DESCENDING)
    formula.add_parameter("encoder", "xor_args_order", "descending");
#else
    formula.add_parameter("encoder", "xor_args_order", "none");
#endif
    
    formula.add_parameter("encoder", "algorithm", SHA::NAME);
    formula.add_parameter("encoder", "rounds", rounds);
 
    // assume 1 block but expand if necessary
    bal::VariablesArray M_array(SHA::MESSAGE_BLOCK_SIZE, SHA::WORD_SIZE);
    M_array.assign_unassigned();
    
    // handling of message M is special because it is used to optimise the encoding itself
    auto M_it = variables_map.find("M");
    if (!b_assign_after_encoding && M_it != variables_map.end()) {
        if (M_it->second.mode == vmCompute) {
            throw std::invalid_argument(ERROR_COMPUTE_MESSAGE_NOT_SUPPORTED);
        } else if (M_it->second.mode == vmRandom) {
            variable_define_random(M_it->second, M_array);
        } else {
            _assert_level_0(M_it->second.mode == vmValue);
            // check that the message size is a multiple of the block size
            constexpr auto MESSAGE_BLOCK_SIZE_BITS = SHA::MESSAGE_BLOCK_SIZE * SHA::WORD_SIZE;
            if ((M_it->second.data.size() % MESSAGE_BLOCK_SIZE_BITS) != 0) {
                std::stringstream error_message;
                error_message << "Message (M) size must be a multiple of the block size ";
                error_message << std::dec << "(" << MESSAGE_BLOCK_SIZE_BITS << ")";
                throw std::invalid_argument(error_message.str());
            } else if (M_it->second.data.size() > MESSAGE_BLOCK_SIZE_BITS) {
                // expand the message template
                M_array = bal::VariablesArray(M_it->second.data.size() / SHA::WORD_SIZE, SHA::WORD_SIZE);
                M_array.assign_unassigned();
            };
        };
        M_array = variable_generate_value(formula, "M", M_it->second, M_array, true, true);
    };
    
    SHA sha;
    
    const std::size_t M_size = M_array.size() / SHA::WORD_SIZE;
    formula.add_parameter("encoder", "message_blocks", M_size / SHA::MESSAGE_BLOCK_SIZE);
    
    bal::Ref<typename SHA::Word> M[M_size];
    bal::Ref<typename SHA::Word> H[SHA::HASH_SIZE];
    
    formula.generate_unassigned_variable_literals(M_array.data(), M_array.size());

    assign(M, M_size, formula, M_array);
    
    bal::FormulaTracer<SHA::WORD_SIZE, typename SHA::Bit> tracer(formula);
    sha.execute(M, M_size, H, tracer, rounds);
    
    bool is_valid = true;
    
    if (variables_map.size() > 0) {
        // take the same route as process function
        print_statistics(formula);
        variables_define(formula, variables_map);
        is_valid = process_impl<typename SHA::Bit::Formula, true>(formula, variables_map, b_reindex_variables, mode);
    };
    
    if (is_valid && b_normalize_variables) {
        normalize_variables(formula, b_reindex_variables);
    };
    
    if (is_valid) {
        save(formula, output_file_name, output_format);
    } else {
        throw std::invalid_argument("Encoding failed");
    };
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %r9, -0x88(%rbp)
movl %esi, %r12d
leal -0x51(%r12), %eax
cmpl $-0x51, %eax
jbe 0x1cc10
movl %r8d, %ebx
movq %rdx, %r15
movq %rdi, %r14
testl %ecx, %ecx
je 0x1c67a
movq %r14, %rdi
movl %ecx, %esi
callq 0x239de
testl %ebx, %ebx
je 0x1c688
movq %r14, %rdi
movl %ebx, %esi
callq 0x23b56
leaq 0x1c2d4(%rip), %rsi     # 0x38963
leaq -0x210(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0xc0e0
leaq 0x1b90a(%rip), %rsi     # 0x37fb0
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0xc0e0
movl 0x70(%r14), %ecx
testl %ecx, %ecx
jne 0x1c6c6
movq (%r14), %rax
movq %r14, %rdi
callq *0x18(%rax)
movl %eax, %ecx
leaq -0x210(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movq %r14, %rdi
callq 0x2e5dc
leaq -0x50(%rbp), %rdi
callq 0xc110
leaq -0x210(%rbp), %rdi
callq 0xc110
leaq 0x1c26e(%rip), %rsi     # 0x38963
leaq -0x210(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0xc0e0
leaq 0x1b8b1(%rip), %rsi     # 0x37fbd
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0xc0e0
movl 0x74(%r14), %ecx
testl %ecx, %ecx
jne 0x1c72c
movq (%r14), %rax
movq %r14, %rdi
callq *0x30(%rax)
movl %eax, %ecx
leaq -0x210(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movq %r14, %rdi
callq 0x2e5dc
leaq -0x50(%rbp), %rdi
callq 0xc110
leaq -0x210(%rbp), %rdi
callq 0xc110
leaq 0x1c208(%rip), %rsi     # 0x38963
leaq -0x210(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0xc0e0
leaq 0x1e3a4(%rip), %rsi     # 0x3ab16
leaq -0x50(%rbp), %rdi
leaq -0x2b(%rbp), %rdx
callq 0xc0e0
leaq 0x1c1f8(%rip), %rsi     # 0x3897e
leaq -0x70(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0xc0e0
leaq -0x210(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x70(%rbp), %rcx
pushq $0x1
popq %r8
movq %r14, %rdi
callq 0x2e47c
leaq -0x70(%rbp), %rdi
callq 0xc110
leaq -0x50(%rbp), %rdi
callq 0xc110
leaq -0x210(%rbp), %rdi
callq 0xc110
leaq 0x1c190(%rip), %rsi     # 0x38963
leaq -0x210(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0xc0e0
leaq 0x1e33f(%rip), %rsi     # 0x3ab29
leaq -0x50(%rbp), %rdi
leaq -0x2b(%rbp), %rdx
callq 0xc0e0
leaq 0x1e33a(%rip), %rsi     # 0x3ab38
leaq -0x70(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0xc0e0
leaq -0x210(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x70(%rbp), %rcx
pushq $0x1
popq %r8
movq %r14, %rdi
callq 0x2e47c
leaq -0x70(%rbp), %rdi
callq 0xc110
leaq -0x50(%rbp), %rdi
callq 0xc110
leaq -0x210(%rbp), %rdi
callq 0xc110
leaq 0x1c118(%rip), %rsi     # 0x38963
leaq -0x210(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0xc0e0
leaq 0x1e2e0(%rip), %rsi     # 0x3ab42
leaq -0x50(%rbp), %rdi
leaq -0x2b(%rbp), %rdx
callq 0xc0e0
leaq 0x1e2d6(%rip), %rsi     # 0x3ab4c
leaq -0x70(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0xc0e0
leaq -0x210(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x70(%rbp), %rcx
pushq $0x1
popq %r8
movq %r14, %rdi
callq 0x2e47c
leaq -0x70(%rbp), %rdi
callq 0xc110
leaq -0x50(%rbp), %rdi
callq 0xc110
leaq -0x210(%rbp), %rdi
callq 0xc110
leaq 0x1c0a0(%rip), %rsi     # 0x38963
leaq -0x210(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0xc0e0
leaq 0x1e278(%rip), %rsi     # 0x3ab52
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0xc0e0
leaq -0x210(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movq %r14, %rdi
movl %r12d, %ecx
callq 0x2e5dc
leaq -0x50(%rbp), %rdi
callq 0xc110
leaq -0x210(%rbp), %rdi
callq 0xc110
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0xdf92
movl $0x20, 0x1c(%rbx)
movq %rbx, %rdi
callq 0x1c4ae
leaq 0x1e220(%rip), %rsi     # 0x3ab59
leaq -0x210(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0xc0e0
leaq -0x210(%rbp), %rsi
movq %r15, %rdi
callq 0x19c10
movq %rax, %r13
movb 0x28(%rbp), %bl
leaq -0x210(%rbp), %rdi
callq 0xc110
leaq 0x8(%r15), %rax
cmpq %rax, %r13
sete %al
orb %bl, %al
jne 0x1ca56
movq %r13, %rbx
addq $0x40, %rbx
movl 0x40(%r13), %eax
testl %eax, %eax
je 0x1c9a2
cmpl $0x1, %eax
jne 0x1cc75
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x1a597
jmp 0x1c9ef
movl 0x60(%r13), %esi
testw $0x1ff, %si             # imm = 0x1FF
jne 0x1ccce
cmpl $0x201, %esi            # imm = 0x201
jb 0x1c9ef
shrl $0x5, %esi
leaq -0x210(%rbp), %rdi
pushq $0x20
popq %rdx
callq 0xdbc2
leaq -0x50(%rbp), %rdi
leaq -0x210(%rbp), %r13
movq %r13, %rsi
callq 0x18e2a
movq %r13, %rdi
callq 0xde58
leaq -0x50(%rbp), %rdi
callq 0x1c4ae
leaq 0x1e163(%rip), %rsi     # 0x3ab59
leaq -0x230(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0xc0e0
subq $0x8, %rsp
leaq -0x210(%rbp), %rdi
leaq -0x230(%rbp), %rdx
leaq -0x50(%rbp), %r8
pushq $0x1
popq %r9
movq %r14, %rsi
movq %rbx, %rcx
pushq $0x1
callq 0x1ab92
popq %rax
popq %rcx
leaq -0x50(%rbp), %rdi
leaq -0x210(%rbp), %rbx
movq %rbx, %rsi
callq 0x18e2a
movq %rbx, %rdi
callq 0xde58
leaq -0x230(%rbp), %rdi
callq 0xc110
movl -0x48(%rbp), %ebx
leaq 0x1bf03(%rip), %rsi     # 0x38963
leaq -0x210(%rbp), %rdi
leaq -0x2b(%rbp), %rdx
callq 0xc0e0
leaq 0x1e272(%rip), %rsi     # 0x3ace9
leaq -0x70(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0xc0e0
movl %ebx, %ecx
shrl $0x9, %ecx
leaq -0x210(%rbp), %rsi
leaq -0x70(%rbp), %rdx
movq %r14, %rdi
callq 0x2e5dc
movl %ebx, %r13d
shrl $0x5, %r13d
leaq -0x70(%rbp), %rdi
callq 0xc110
leaq -0x210(%rbp), %rdi
callq 0xc110
movq %rsp, -0x80(%rbp)
leal 0xf(,%r13,8), %eax
andl $-0x10, %eax
movl %ebx, %ecx
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
movl %ecx, -0x74(%rbp)
cmpl $0x20, %ecx
jb 0x1caec
leal (,%r13,8), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc160
xorps %xmm0, %xmm0
andq $0x0, -0x1f0(%rbp)
movaps %xmm0, -0x200(%rbp)
movaps %xmm0, -0x210(%rbp)
movq -0x50(%rbp), %rsi
movl -0x48(%rbp), %edx
movq %r14, %rdi
callq 0x23cda
leaq -0x50(%rbp), %rcx
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x23d14
leaq 0x33abb(%rip), %rax     # 0x505e8
leaq -0x70(%rbp), %r8
movq %rax, (%r8)
movq %r14, 0x8(%r8)
leaq -0x29(%rbp), %rdi
leaq -0x210(%rbp), %rcx
movq %rbx, %rsi
movq %r13, %rdx
movl %r12d, %r9d
callq 0x23e2c
cmpq $0x0, 0x28(%r15)
movzbl 0x18(%rbp), %r12d
je 0x1cb86
movq %r14, %rdi
callq 0x1a056
movq %r14, %rdi
movq %r15, %rsi
callq 0x1a7ec
movl 0x30(%rbp), %ecx
movq %r14, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x246b6
movl %eax, %r15d
jmp 0x1cb89
movb $0x1, %r15b
movb 0x20(%rbp), %al
andb %r15b, %al
cmpb $0x1, %al
jne 0x1cb9e
movq %r14, %rdi
movl %r12d, %esi
callq 0x1ee67
testb %r15b, %r15b
je 0x1cc40
movl 0x10(%rbp), %edx
movq %r14, %rdi
movq -0x88(%rbp), %rsi
callq 0x1a39c
pushq $0x20
popq %r14
leaq (%r14,%rbp), %rdi
addq $-0x210, %rdi           # imm = 0xFDF0
callq 0x23cce
addq $-0x8, %r14
cmpq $-0x8, %r14
jne 0x1cbbd
cmpl $0x20, -0x74(%rbp)
jb 0x1cbf4
addq $-0x8, %rbx
shll $0x3, %r13d
leaq (%rbx,%r13), %rdi
callq 0x23cce
addq $-0x8, %r13
jne 0x1cbe5
movq -0x80(%rbp), %rsp
leaq -0x50(%rbp), %rdi
callq 0xde58
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0xc130
movq %rax, %rbx
leaq 0x1ded6(%rip), %rsi     # 0x3aaf8
movq %rax, %rdi
callq 0xc4e0
movq 0x343a7(%rip), %rsi     # 0x50fd8
movq 0x34388(%rip), %rdx     # 0x50fc0
movq %rbx, %rdi
callq 0xc490
pushq $0x10
popq %rdi
callq 0xc130
movq %rax, %r15
leaq 0x1e0a6(%rip), %rsi     # 0x3acf8
movq %rax, %rdi
callq 0xc4e0
movq 0x34377(%rip), %rsi     # 0x50fd8
movq 0x34358(%rip), %rdx     # 0x50fc0
movq %r15, %rdi
callq 0xc490
jmp 0x1cd7d
cmpl $0x2, %eax
jne 0x1ccaf
pushq $0x10
popq %rdi
callq 0xc130
movq %rax, %rbx
leaq 0x1decf(%rip), %rsi     # 0x3ab5b
movq %rax, %rdi
callq 0xc4e0
movq 0x3433d(%rip), %rsi     # 0x50fd8
movq 0x3431e(%rip), %rdx     # 0x50fc0
movq %rbx, %rdi
callq 0xc490
jmp 0x1cd7d
leaq 0x1ded1(%rip), %rdi     # 0x3ab87
leaq 0x1b728(%rip), %rsi     # 0x383e5
leaq 0x1dee0(%rip), %rcx     # 0x3aba4
movl $0x1f2, %edx            # imm = 0x1F2
callq 0xc180
leaq -0x210(%rbp), %rdi
callq 0xc1c0
leaq -0x200(%rbp), %rbx
leaq 0x1dfca(%rip), %rsi     # 0x3acb2
movq %rbx, %rdi
callq 0xc290
movq -0x200(%rbp), %rax
movq -0x18(%rax), %rax
movl -0x1e8(%rbp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x2, %ecx
movl %ecx, -0x1e8(%rbp,%rax)
leaq 0x1714c(%rip), %rsi     # 0x33e62
movq %rbx, %rdi
callq 0xc290
movl $0x200, %esi            # imm = 0x200
movq %rax, %rdi
callq 0xc190
leaq 0x214d9(%rip), %rsi     # 0x3e20b
movq %rax, %rdi
callq 0xc290
pushq $0x10
popq %rdi
callq 0xc130
movq %rax, %rbx
leaq -0x1f8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0xc410
movb $0x1, %r15b
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
callq 0xc4b0
xorl %r15d, %r15d
movq 0x3426a(%rip), %rsi     # 0x50fd8
movq 0x3424b(%rip), %rdx     # 0x50fc0
movq %rbx, %rdi
callq 0xc490
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0xc110
testb %r15b, %r15b
jne 0x1cd93
jmp 0x1cda0
movq %rax, %r14
movq %rbx, %rdi
callq 0xc1d0
jmp 0x1cda0
movq %rax, %r14
leaq -0x210(%rbp), %rdi
callq 0xc1f0
jmp 0x1ceef
jmp 0x1ce23
jmp 0x1ce23
movq %rax, %r14
movq %rbx, %rdi
callq 0xc1d0
jmp 0x1ceef
jmp 0x1ce23
movq %rax, %r14
movq %r15, %rdi
callq 0xc1d0
jmp 0x1ceb4
movq %rax, %r14
leaq -0x230(%rbp), %rdi
jmp 0x1ce19
jmp 0x1ce23
movq %rax, %r14
movq %rbx, %rdi
callq 0xc1d0
jmp 0x1cef8
jmp 0x1ceb1
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0xc110
jmp 0x1ce0b
movq %rax, %r14
jmp 0x1ce12
jmp 0x1ce23
movq %rax, %r14
leaq -0x210(%rbp), %rdi
callq 0xc110
jmp 0x1ceef
movq %rax, %r14
jmp 0x1ceef
jmp 0x1ce87
jmp 0x1ce76
jmp 0x1ce82
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0xc110
jmp 0x1ce42
movq %rax, %r14
jmp 0x1ce8a
jmp 0x1ce76
jmp 0x1ce82
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0xc110
jmp 0x1ce59
movq %rax, %r14
jmp 0x1ce8a
jmp 0x1ce76
jmp 0x1ce82
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0xc110
jmp 0x1ce70
movq %rax, %r14
jmp 0x1ce8a
jmp 0x1ce76
jmp 0x1ce82
movq %rax, %r14
jmp 0x1cea1
jmp 0x1ce82
movq %rax, %r14
jmp 0x1cea1
movq %rax, %r14
jmp 0x1cef8
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0xc110
jmp 0x1cea1
movq %rax, %r14
leaq -0x50(%rbp), %rdi
callq 0xc110
leaq -0x210(%rbp), %rdi
callq 0xc110
jmp 0x1cef8
jmp 0x1ceb1
movq %rax, %r14
pushq $0x20
popq %r15
leaq (%r15,%rbp), %rdi
addq $-0x210, %rdi           # imm = 0xFDF0
callq 0x23cce
addq $-0x8, %r15
cmpq $-0x8, %r15
jne 0x1ceb8
cmpl $0x20, -0x74(%rbp)
jb 0x1ceef
addq $-0x8, %rbx
shll $0x3, %r13d
leaq (%rbx,%r13), %rdi
callq 0x23cce
addq $-0x8, %r13
jne 0x1cee0
leaq -0x50(%rbp), %rdi
callq 0xde58
movq %r14, %rdi
callq 0xc4c0