// File: vsklad[P]cgen/main.cpp
// Function: main
int main(int argc, const char * argv[]) {
    try {
        CGenCommandInfo info;
        CGenCommandLineReader command_line_reader(argc, argv);
        command_line_reader.parse(info);
        
        switch(info.command) {
            case cmdNone:
                std::cout << ERROR_COMMAND_NONE << std::endl;
                print_help();
            case cmdEncode:
                if (info.algorithm == algNone) {
                    throw std::invalid_argument(ERROR_MISSING_ALGORITHM);
                };
                
                generate_output_file_name(info);
                if (info.output_file_name.empty()) {
                    throw std::invalid_argument(ERROR_MISSING_OUTPUT_FILE_NAME);
                };
                
                _assert_level_1(info.b_formula_type_specified);
                std::cout << "Encoding " << (info.algorithm == algSHA1 ? "SHA-1" : "SHA-256");
                std::cout << " into " << get_formula_type_title(info.formula_type) << std::endl;
                
                if (info.formula_type == ftCnf) {
                    encode_cnf(info.algorithm, info.rounds,
                               info.variables_map,
                               info.add_max_args, info.xor_max_args,
                               info.output_file_name.c_str(),
                               info.output_format, info.trace_format,
                               info.b_reindex_variables,
                               info.b_normalize_variables_specified,
                               info.b_assign_after_encoding,
                               info.mode);
                } else if (info.formula_type == ftAnf) {
                    encode_anf(info.algorithm, info.rounds,
                               info.variables_map,
                               info.add_max_args, info.xor_max_args,
                               info.output_file_name.c_str(),
                               info.output_format, info.trace_format,
                               info.b_reindex_variables,
                               info.b_normalize_variables_specified,
                               info.b_assign_after_encoding,
                               info.mode);
                } else {
                    _assert_level_1(false);
                };
                break;
            case cmdProcess:
                _assert_level_1(info.b_formula_type_specified);
                generate_output_file_name(info);
                std::cout << "Processing " << get_formula_type_title(info.formula_type) << " formula" << std::endl;
                if (info.formula_type == ftCnf) {
                    process_cnf(info.variables_map,
                                info.input_file_name.data(), info.output_file_name.data(),
                                info.output_format, info.trace_format,
                                info.b_reindex_variables, info.b_normalize_variables_specified, info.mode);
                } else if (info.formula_type == ftAnf) {
                    process_anf(info.variables_map,
                                info.input_file_name.data(), info.output_file_name.data(),
                                info.output_format, info.trace_format,
                                info.b_reindex_variables, info.b_normalize_variables_specified, info.mode);
                } else {
                    _assert_level_1(false);
                };
                break;
            case cmdHelp:
                print_help();
                break;
            case cmdVersion:
                print_version();
                break;
        };
    }
    catch (TextReaderException e) {
        std::cerr << ERROR_COMMAND_LINE_PARSE << ": " << e.get_line() << std::endl;
        std::cerr << "Position " << e.get_pos() << ": " << e.get_message() << std::endl;
        std::cerr << "See --help for reference" << std::endl;
        return 1;
    }
    catch (std::invalid_argument e) {
        std::cerr << ERROR_INVALID_ARGUMENT << ": " << e.what() << std::endl;
        return 1;
    }
    catch (std::out_of_range e) {
        std::cerr << ERROR_OUT_OF_RANGE << ": " << e.what() << std::endl;
        return 1;
    };
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x330, %rsp            # imm = 0x330
movl $0x0, -0x24(%rbp)
movl %edi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x58850
movl -0x28(%rbp), %esi
movq -0x30(%rbp), %rdx
leaq -0x140(%rbp), %rdi
callq 0x58900
jmp 0x57d91
leaq -0x140(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x23550
jmp 0x57da6
movl -0xd8(%rbp), %eax
movq %rax, -0x1c8(%rbp)
subq $0x4, %rax
ja 0x5838d
movq -0x1c8(%rbp), %rax
leaq 0x101c1(%rip), %rcx     # 0x67f8c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x583b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x583aa
movq 0x2b197(%rip), %rdi     # 0x82fa0
leaq 0x10602(%rip), %rsi     # 0x68412
callq 0xd320
movq %rax, -0x1d0(%rbp)
jmp 0x57e1e
movq -0x1d0(%rbp), %rdi
movq 0x2b154(%rip), %rsi     # 0x82f80
callq 0xd360
jmp 0x57e33
callq 0x57670
jmp 0x57e3a
jmp 0x57e3c
cmpl $0x0, -0xd4(%rbp)
jne 0x57eac
movl $0x10, %edi
callq 0xd150
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1d8(%rbp)
leaq 0x105c4(%rip), %rsi     # 0x68427
callq 0xd5f0
jmp 0x57e6a
movq -0x1d8(%rbp), %rdi
movq 0x2b160(%rip), %rsi     # 0x82fd8
movq 0x2b141(%rip), %rdx     # 0x82fc0
callq 0xd570
jmp 0x587c4
movq -0x1d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
callq 0xd210
jmp 0x583aa
leaq -0xd8(%rbp), %rdi
callq 0x57950
jmp 0x57eba
leaq -0xd8(%rbp), %rdi
addq $0x78, %rdi
callq 0xd540
testb $0x1, %al
jne 0x57ed0
jmp 0x57f37
movl $0x10, %edi
callq 0xd150
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1e0(%rbp)
leaq 0x1055e(%rip), %rsi     # 0x6844c
callq 0xd5f0
jmp 0x57ef5
movq -0x1e0(%rbp), %rdi
movq 0x2b0d5(%rip), %rsi     # 0x82fd8
movq 0x2b0b6(%rip), %rdx     # 0x82fc0
callq 0xd570
jmp 0x587c4
movq -0x1e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
callq 0xd210
jmp 0x583aa
testb $0x1, -0x40(%rbp)
je 0x57f3f
jmp 0x57f5e
leaq 0x10528(%rip), %rdi     # 0x6846e
leaq 0x10472(%rip), %rsi     # 0x683bf
movl $0x77, %edx
leaq 0x10533(%rip), %rcx     # 0x6848c
callq 0xd1c0
movq 0x2b03b(%rip), %rdi     # 0x82fa0
leaq 0x1053d(%rip), %rsi     # 0x684a9
callq 0xd320
movq %rax, -0x1e8(%rbp)
jmp 0x57f7a
movq -0x1e8(%rbp), %rdi
movl -0xd4(%rbp), %eax
subl $0x1, %eax
leaq 0xce10(%rip), %rax      # 0x64da1
leaq 0xe201(%rip), %rsi      # 0x66199
cmoveq %rax, %rsi
callq 0xd320
jmp 0x57fa3
movq 0x2aff6(%rip), %rdi     # 0x82fa0
leaq 0x10502(%rip), %rsi     # 0x684b3
callq 0xd320
movq %rax, -0x1f0(%rbp)
jmp 0x57fbf
movl -0xd0(%rbp), %edi
callq 0x589c0
movq %rax, -0x1f8(%rbp)
jmp 0x57fd3
movq -0x1f8(%rbp), %rsi
movq -0x1f0(%rbp), %rdi
callq 0xd320
movq %rax, -0x200(%rbp)
jmp 0x57fef
movq -0x200(%rbp), %rdi
movq 0x2af83(%rip), %rsi     # 0x82f80
callq 0xd360
jmp 0x58004
cmpl $0x0, -0xd0(%rbp)
jne 0x580cb
movl -0xd4(%rbp), %eax
movl %eax, -0x218(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x214(%rbp)
leaq -0xc0(%rbp), %rax
movq %rax, -0x210(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x208(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x204(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd120
movl -0x218(%rbp), %edi
movl -0x214(%rbp), %esi
movq -0x210(%rbp), %rdx
movl -0x208(%rbp), %ecx
movl -0x204(%rbp), %r8d
movq %rax, %r9
movl -0xcc(%rbp), %r10d
movl -0xc8(%rbp), %r11d
movl -0x38(%rbp), %r12d
movzbl -0x3e(%rbp), %ebx
movzbl -0x3d(%rbp), %r14d
movzbl -0x3f(%rbp), %r15d
movq %rsp, %rax
movl %r12d, 0x28(%rax)
andl $0x1, %r15d
movl %r15d, 0x20(%rax)
andl $0x1, %r14d
movl %r14d, 0x18(%rax)
andl $0x1, %ebx
movl %ebx, 0x10(%rax)
movl %r11d, 0x8(%rax)
movl %r10d, (%rax)
callq 0x2cad0
jmp 0x580c6
jmp 0x581b0
cmpl $0x1, -0xd0(%rbp)
jne 0x5818f
movl -0xd4(%rbp), %eax
movl %eax, -0x230(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x22c(%rbp)
leaq -0xc0(%rbp), %rax
movq %rax, -0x228(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x220(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x21c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd120
movl -0x230(%rbp), %edi
movl -0x22c(%rbp), %esi
movq -0x228(%rbp), %rdx
movl -0x220(%rbp), %ecx
movl -0x21c(%rbp), %r8d
movq %rax, %r9
movl -0xcc(%rbp), %r10d
movl -0xc8(%rbp), %r11d
movl -0x38(%rbp), %r12d
movzbl -0x3e(%rbp), %ebx
movzbl -0x3d(%rbp), %r14d
movzbl -0x3f(%rbp), %r15d
movq %rsp, %rax
movl %r12d, 0x28(%rax)
andl $0x1, %r15d
movl %r15d, 0x20(%rax)
andl $0x1, %r14d
movl %r14d, 0x18(%rax)
andl $0x1, %ebx
movl %ebx, 0x10(%rax)
movl %r11d, 0x8(%rax)
movl %r10d, (%rax)
callq 0x2c490
jmp 0x5818d
jmp 0x581ae
leaq 0xbcd1(%rip), %rdi      # 0x63e67
leaq 0x10222(%rip), %rsi     # 0x683bf
movl $0x90, %edx
leaq 0x102e3(%rip), %rcx     # 0x6848c
callq 0xd1c0
jmp 0x581b0
jmp 0x5838d
testb $0x1, -0x40(%rbp)
je 0x581bd
jmp 0x581dc
leaq 0x102aa(%rip), %rdi     # 0x6846e
leaq 0x101f4(%rip), %rsi     # 0x683bf
movl $0x94, %edx
leaq 0x102b5(%rip), %rcx     # 0x6848c
callq 0xd1c0
leaq -0xd8(%rbp), %rdi
callq 0x57950
jmp 0x581ea
movq 0x2adaf(%rip), %rdi     # 0x82fa0
leaq 0x102c2(%rip), %rsi     # 0x684ba
callq 0xd320
movq %rax, -0x238(%rbp)
jmp 0x58206
movl -0xd0(%rbp), %edi
callq 0x589c0
movq %rax, -0x240(%rbp)
jmp 0x5821a
movq -0x240(%rbp), %rsi
movq -0x238(%rbp), %rdi
callq 0xd320
movq %rax, -0x248(%rbp)
jmp 0x58236
movq -0x248(%rbp), %rdi
leaq 0x99d2(%rip), %rsi      # 0x61c16
callq 0xd320
movq %rax, -0x250(%rbp)
jmp 0x58252
movq -0x250(%rbp), %rdi
movq 0x2ad20(%rip), %rsi     # 0x82f80
callq 0xd360
jmp 0x58267
cmpl $0x0, -0xd0(%rbp)
jne 0x582e1
leaq -0xc0(%rbp), %rax
movq %rax, -0x260(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xd400
movq %rax, -0x258(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd400
movq -0x260(%rbp), %rdi
movq -0x258(%rbp), %rsi
movq %rax, %rdx
movl -0xcc(%rbp), %ecx
movl -0xc8(%rbp), %r8d
movl -0x38(%rbp), %r11d
movzbl -0x3e(%rbp), %r9d
movzbl -0x3d(%rbp), %r10d
movq %rsp, %rax
movl %r11d, 0x8(%rax)
andl $0x1, %r10d
movl %r10d, (%rax)
andl $0x1, %r9d
callq 0x2d200
jmp 0x582dc
jmp 0x58379
cmpl $0x1, -0xd0(%rbp)
jne 0x58358
leaq -0xc0(%rbp), %rax
movq %rax, -0x270(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xd400
movq %rax, -0x268(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xd400
movq -0x270(%rbp), %rdi
movq -0x268(%rbp), %rsi
movq %rax, %rdx
movl -0xcc(%rbp), %ecx
movl -0xc8(%rbp), %r8d
movl -0x38(%rbp), %r11d
movzbl -0x3e(%rbp), %r9d
movzbl -0x3d(%rbp), %r10d
movq %rsp, %rax
movl %r11d, 0x8(%rax)
andl $0x1, %r10d
movl %r10d, (%rax)
andl $0x1, %r9d
callq 0x2d010
jmp 0x58356
jmp 0x58377
leaq 0xbb08(%rip), %rdi      # 0x63e67
leaq 0x10059(%rip), %rsi     # 0x683bf
movl $0xa2, %edx
leaq 0x1011a(%rip), %rcx     # 0x6848c
callq 0xd1c0
jmp 0x58379
jmp 0x5838d
callq 0x57670
jmp 0x58382
jmp 0x5838d
callq 0x57620
jmp 0x5838b
jmp 0x5838d
leaq -0x140(%rbp), %rdi
callq 0x58a00
leaq -0xd8(%rbp), %rdi
callq 0x58a60
jmp 0x58796
leaq -0x140(%rbp), %rdi
callq 0x58a00
leaq -0xd8(%rbp), %rdi
callq 0x58a60
movl -0x14c(%rbp), %eax
movl %eax, -0x274(%rbp)
movl $0x3, %ecx
cmpl %ecx, %eax
jne 0x58586
movq -0x148(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0xd3e0
movq %rax, %rsi
leaq -0x1c0(%rbp), %rdi
callq 0x53220
jmp 0x583ff
movq -0x280(%rbp), %rdi
callq 0xd110
movq 0x2abde(%rip), %rdi     # 0x82ff0
leaq 0x100c0(%rip), %rsi     # 0x684d9
callq 0xd320
movq %rax, -0x288(%rbp)
jmp 0x58427
movq -0x288(%rbp), %rdi
leaq 0x9f80(%rip), %rsi      # 0x623b5
callq 0xd320
movq %rax, -0x290(%rbp)
jmp 0x58443
leaq -0x1c0(%rbp), %rdi
callq 0x58b20
movq %rax, -0x298(%rbp)
jmp 0x58458
movq -0x298(%rbp), %rsi
movq -0x290(%rbp), %rdi
callq 0xd320
movq %rax, -0x2a0(%rbp)
jmp 0x58474
movq -0x2a0(%rbp), %rdi
movq 0x2aafe(%rip), %rsi     # 0x82f80
callq 0xd360
jmp 0x58489
movq 0x2ab60(%rip), %rdi     # 0x82ff0
leaq 0x1005d(%rip), %rsi     # 0x684f4
callq 0xd320
movq %rax, -0x2a8(%rbp)
jmp 0x584a5
leaq -0x1c0(%rbp), %rdi
callq 0x58b40
movq %rax, -0x2b0(%rbp)
jmp 0x584ba
movq -0x2b0(%rbp), %rsi
movq -0x2a8(%rbp), %rdi
callq 0xd0a0
movq %rax, -0x2b8(%rbp)
jmp 0x584d6
movq -0x2b8(%rbp), %rdi
leaq 0x9ed1(%rip), %rsi      # 0x623b5
callq 0xd320
movq %rax, -0x2c0(%rbp)
jmp 0x584f2
leaq -0x1c0(%rbp), %rdi
callq 0x58b60
movq %rax, -0x2c8(%rbp)
jmp 0x58507
movq -0x2c8(%rbp), %rsi
movq -0x2c0(%rbp), %rdi
callq 0xd320
movq %rax, -0x2d0(%rbp)
jmp 0x58523
movq -0x2d0(%rbp), %rdi
movq 0x2aa4f(%rip), %rsi     # 0x82f80
callq 0xd360
jmp 0x58538
movq 0x2aab1(%rip), %rdi     # 0x82ff0
leaq 0xffb8(%rip), %rsi      # 0x684fe
callq 0xd320
movq %rax, -0x2d8(%rbp)
jmp 0x58554
movq -0x2d8(%rbp), %rdi
movq 0x2aa1e(%rip), %rsi     # 0x82f80
callq 0xd360
jmp 0x58569
movl $0x1, -0x24(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x283c0
callq 0xd520
jmp 0x5879d
movl -0x274(%rbp), %eax
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x58655
movq -0x148(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0xd3e0
movq %rax, %rsi
leaq -0x170(%rbp), %rdi
callq 0x58ae0
movq -0x2e8(%rbp), %rdi
callq 0xd110
movq 0x2aa22(%rip), %rdi     # 0x82ff0
leaq 0xfefe(%rip), %rsi      # 0x684d3
callq 0xd320
movq %rax, -0x2e0(%rbp)
jmp 0x585e3
movq -0x2e0(%rbp), %rdi
leaq 0x9dc4(%rip), %rsi      # 0x623b5
callq 0xd320
movq %rax, -0x2f0(%rbp)
jmp 0x585ff
leaq -0x170(%rbp), %rdi
callq 0xd490
movq -0x2f0(%rbp), %rdi
movq %rax, %rsi
callq 0xd320
movq %rax, -0x2f8(%rbp)
jmp 0x58623
movq -0x2f8(%rbp), %rdi
movq 0x2a94f(%rip), %rsi     # 0x82f80
callq 0xd360
jmp 0x58638
movl $0x1, -0x24(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xd658
callq 0xd520
jmp 0x5879d
movl -0x274(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x587b0
movq -0x148(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0xd3e0
movq %rax, %rsi
leaq -0x160(%rbp), %rdi
callq 0x58aa0
movq -0x308(%rbp), %rdi
callq 0xd110
movq 0x2a953(%rip), %rdi     # 0x82ff0
leaq 0xfe22(%rip), %rsi      # 0x684c6
callq 0xd320
movq %rax, -0x300(%rbp)
jmp 0x586b2
movq -0x300(%rbp), %rdi
leaq 0x9cf5(%rip), %rsi      # 0x623b5
callq 0xd320
movq %rax, -0x310(%rbp)
jmp 0x586ce
leaq -0x160(%rbp), %rdi
callq 0xd490
movq -0x310(%rbp), %rdi
movq %rax, %rsi
callq 0xd320
movq %rax, -0x318(%rbp)
jmp 0x586f2
movq -0x318(%rbp), %rdi
movq 0x2a880(%rip), %rsi     # 0x82f80
callq 0xd360
jmp 0x58707
movl $0x1, -0x24(%rbp)
leaq -0x160(%rbp), %rdi
callq 0xd648
callq 0xd520
jmp 0x5879d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0xd648
callq 0xd520
jmp 0x58746
jmp 0x587b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xd658
callq 0xd520
jmp 0x5876d
jmp 0x587b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x283c0
callq 0xd520
jmp 0x58794
jmp 0x587b0
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
addq $0x330, %rsp            # imm = 0x330
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq -0x148(%rbp), %rdi
callq 0xd5a0
movq %rax, %rdi
callq 0x11090
nopw %cs:(%rax,%rax)
nop