// File: /workspace/github_cpp_makefile_star2_O1/ivanoleinik[P]archiver/src/main.cpp
// Function: main
int main(int argc, char** argv) {
    int action = -1;
    enum {
        COMPRESS,
        UNCOMPRESS
    };
    std::string filename_in, filename_out;

    try {
        for (int i = 1; i < argc; i++) {
            std::string option(argv[i]);
            if (option == "-c") {
                action = COMPRESS;
            } else if (option == "-u") {
                action = UNCOMPRESS;
            } else if (option == "-f" || option == "--file") {
                filename_in = std::string(argv[i + 1]);
                i++;
            } else if (option == "-o" || option == "--output") {
                if (i + 1 >= argc)
                    throw HuffException("Bad input");
                filename_out = std::string(argv[i + 1]);
                i++;
            } else {
                throw HuffException("Bad input");
            }
        }

        std::ifstream in(filename_in, std::ifstream::binary);
        if (!in)
            throw HuffException("Bad filename");
        std::ofstream out(filename_out, std::ofstream::binary);

        if (action == COMPRESS) {
            HuffEncode encode = HuffEncode(in);
            encode.write(out);
            encode.write_info();
        } else if (action == UNCOMPRESS) {
            HuffDecode decode = HuffDecode(in);
            decode.write(out);
            decode.write_info();
        } else {
            throw HuffException("Bad action");
        }

        return 0;
    } catch(HuffException &ex) {
        std::cout << ex.what() << std::endl;
        return 1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x538, %rsp            # imm = 0x538
leaq 0x38(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x18(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
cmpl $0x2, %edi
jl 0x53f5
movq %rsi, %rbx
movl %edi, %ebp
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movl $0x1, %r12d
leaq 0x330(%rsp), %r14
leaq 0x130(%rsp), %r15
movslq %r12d, %r13
movq (%rbx,%r13,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x5938
movq %r14, %rdi
leaq 0xf22(%rip), %rsi       # 0x61bb
callq 0x2060
testl %eax, %eax
je 0x5369
movq %r14, %rdi
leaq 0xf0e(%rip), %rsi       # 0x61be
callq 0x2060
testl %eax, %eax
je 0x53bc
movq %r14, %rdi
leaq 0xefa(%rip), %rsi       # 0x61c1
callq 0x2060
testl %eax, %eax
je 0x5373
movq %r14, %rdi
leaq 0xee6(%rip), %rsi       # 0x61c4
callq 0x2060
testl %eax, %eax
je 0x5373
movq %r14, %rdi
leaq 0xed6(%rip), %rsi       # 0x61cb
callq 0x2060
testl %eax, %eax
je 0x5315
movq %r14, %rdi
leaq 0xec6(%rip), %rsi       # 0x61ce
callq 0x2060
testl %eax, %eax
jne 0x5613
incl %r12d
cmpl %ebp, %r12d
jge 0x55ae
movslq %r12d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0x48(%rsp), %rdx
callq 0x5938
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x21e0
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x53c4
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x53c4
movl $0x0, 0x4(%rsp)
jmp 0x53c4
movq 0x8(%rbx,%r13,8), %rsi
movq %r15, %rdi
leaq 0x48(%rsp), %rdx
callq 0x5938
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x21e0
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x53b7
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x21c0
incl %r12d
jmp 0x53c4
movl $0x1, 0x4(%rsp)
movq 0x330(%rsp), %rdi
leaq 0x340(%rsp), %rax
cmpq %rax, %rdi
je 0x53e9
movq 0x340(%rsp), %rsi
incq %rsi
callq 0x21c0
incl %r12d
cmpl %ebp, %r12d
jl 0x527d
leaq 0x330(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movl $0x4, %edx
callq 0x2280
movq 0x330(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x350(%rsp,%rax)
movl 0x4(%rsp), %ebx
jne 0x5678
leaq 0x130(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x2300
cmpl $0x1, %ebx
je 0x5499
testl %ebx, %ebx
jne 0x56da
leaq 0x48(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0x2de8
leaq 0x48(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x2fdc
leaq 0x48(%rsp), %rdi
callq 0x30f6
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x397e
movq -0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x5500
callq 0x3bc4
jmp 0x5500
leaq 0x48(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0x31ae
leaq 0x48(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x3568
leaq 0x48(%rsp), %rdi
callq 0x357c
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x397e
movq -0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x54e5
callq 0x3bc4
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5500
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x551b
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x3aa6(%rip), %rax      # 0x8fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x138(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x130(%rsp,%rcx)
callq 0x2160
leaq 0x228(%rsp), %rdi
callq 0x2070
leaq 0x330(%rsp), %rdi
callq 0x2040
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x557e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x559a
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
movl %ebx, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x20c0
movq %rax, %r15
leaq 0x120(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xc08(%rip), %rsi       # 0x61d7
leaq 0xc0a(%rip), %rdx       # 0x61e0
leaq 0x110(%rsp), %rdi
callq 0x5ad4
movb $0x1, %bpl
leaq 0x110(%rsp), %rsi
movq %r15, %rdi
callq 0x5976
xorl %ebp, %ebp
leaq 0x3769(%rip), %rsi      # 0x8d68
leaq 0x3d8(%rip), %rdx       # 0x59de
movq %r15, %rdi
callq 0x22b0
jmp 0x573a
movl $0x28, %edi
callq 0x20c0
movq %rax, %r15
leaq 0x100(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xba3(%rip), %rsi       # 0x61d7
leaq 0xba5(%rip), %rdx       # 0x61e0
leaq 0xf0(%rsp), %rdi
callq 0x5ad4
movb $0x1, %bpl
leaq 0xf0(%rsp), %rsi
movq %r15, %rdi
callq 0x5976
xorl %ebp, %ebp
leaq 0x3704(%rip), %rsi      # 0x8d68
leaq 0x373(%rip), %rdx       # 0x59de
movq %r15, %rdi
callq 0x22b0
jmp 0x573a
movl $0x28, %edi
callq 0x20c0
movq %rax, %r15
leaq 0xe0(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xb48(%rip), %rsi       # 0x61e1
leaq 0xb4d(%rip), %rdx       # 0x61ed
leaq 0xd0(%rsp), %rdi
callq 0x5ad4
movb $0x1, %bpl
leaq 0xd0(%rsp), %rsi
movq %r15, %rdi
callq 0x5976
xorl %ebp, %ebp
leaq 0x369f(%rip), %rsi      # 0x8d68
leaq 0x30e(%rip), %rdx       # 0x59de
movq %r15, %rdi
callq 0x22b0
jmp 0x573a
movl $0x28, %edi
callq 0x20c0
movq %rax, %r15
leaq 0xc0(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0xaf3(%rip), %rsi       # 0x61ee
leaq 0xaf6(%rip), %rdx       # 0x61f8
leaq 0xb0(%rsp), %rdi
callq 0x5ad4
movb $0x1, %bpl
leaq 0xb0(%rsp), %rsi
movq %r15, %rdi
callq 0x5976
xorl %ebp, %ebp
leaq 0x363d(%rip), %rsi      # 0x8d68
leaq 0x2ac(%rip), %rdx       # 0x59de
movq %r15, %rdi
callq 0x22b0
movq %rdx, %r14
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
je 0x5768
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x5768
movq %rdx, %r14
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x580d
movq %r15, %rdi
callq 0x2130
jmp 0x580d
jmp 0x5780
movq %rdx, %r14
movq %rax, %rbx
jmp 0x580d
movq %rdx, %r14
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
cmpq %r12, %rdi
je 0x57b9
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x57b9
movq %rdx, %r14
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x5822
movq %r15, %rdi
callq 0x2130
jmp 0x5822
movq %rdx, %r14
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
je 0x5861
movq 0x100(%rsp), %rsi
jmp 0x584e
jmp 0x5858
movq %rdx, %r14
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5a44
jmp 0x580d
movq %rdx, %r14
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5a0e
leaq 0x130(%rsp), %rdi
callq 0x2240
jmp 0x5822
movq %rdx, %r14
movq %rax, %rbx
leaq 0x330(%rsp), %rdi
callq 0x2040
jmp 0x58a5
jmp 0x589f
movq %rdx, %r14
movq %rax, %rbx
movq 0x110(%rsp), %rdi
cmpq %r12, %rdi
je 0x5861
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x5861
movq %rdx, %r14
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x5878
movq %r15, %rdi
callq 0x2130
jmp 0x5878
jmp 0x5872
movq %rdx, %r14
movq %rax, %rbx
movq 0x330(%rsp), %rdi
leaq 0x340(%rsp), %rax
cmpq %rax, %rdi
je 0x58a5
movq 0x340(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x58a5
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x58ef
movq %rbx, %rdi
callq 0x2090
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x3715(%rip), %rdi      # 0x8fd8
movq %rax, %rsi
callq 0x21a0
movq %rax, %rdi
callq 0x20b0
movl $0x1, %ebx
callq 0x22a0
jmp 0x5562
movq %rax, %rbx
jmp 0x58ef
movq %rax, %rbx
callq 0x22a0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x590b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x5927
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x22d0
movq %rax, %rdi
callq 0x3bb8
nop