// File: /workspace/github_cpp_makefile_star2_O3/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 0x562d
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 0x5b5e
movq %r14, %rdi
leaq 0xd0a(%rip), %rsi       # 0x61db
callq 0x2060
testl %eax, %eax
je 0x55a1
movq %r14, %rdi
leaq 0xcf6(%rip), %rsi       # 0x61de
callq 0x2060
testl %eax, %eax
je 0x55f4
movq %r14, %rdi
leaq 0xce2(%rip), %rsi       # 0x61e1
callq 0x2060
testl %eax, %eax
je 0x55ab
movq %r14, %rdi
leaq 0xcce(%rip), %rsi       # 0x61e4
callq 0x2060
testl %eax, %eax
je 0x55ab
movq %r14, %rdi
leaq 0xcbe(%rip), %rsi       # 0x61eb
callq 0x2060
testl %eax, %eax
je 0x554d
movq %r14, %rdi
leaq 0xcae(%rip), %rsi       # 0x61ee
callq 0x2060
testl %eax, %eax
jne 0x584b
incl %r12d
cmpl %ebp, %r12d
jge 0x57e6
movslq %r12d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0x48(%rsp), %rdx
callq 0x5b5e
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x21e0
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x55fc
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x55fc
movl $0x0, 0x4(%rsp)
jmp 0x55fc
movq 0x8(%rbx,%r13,8), %rsi
movq %r15, %rdi
leaq 0x48(%rsp), %rdx
callq 0x5b5e
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x21e0
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x55ef
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x21c0
incl %r12d
jmp 0x55fc
movl $0x1, 0x4(%rsp)
movq 0x330(%rsp), %rdi
leaq 0x340(%rsp), %rax
cmpq %rax, %rdi
je 0x5621
movq 0x340(%rsp), %rsi
incq %rsi
callq 0x21c0
incl %r12d
cmpl %ebp, %r12d
jl 0x54b5
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 0x58b0
leaq 0x130(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x2300
cmpl $0x1, %ebx
je 0x56d1
testl %ebx, %ebx
jne 0x5912
leaq 0x48(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0x2d8e
leaq 0x48(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x2f6c
leaq 0x48(%rsp), %rdi
callq 0x3086
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x392a
movq -0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x5738
callq 0x3c2e
jmp 0x5738
leaq 0x48(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0x313e
leaq 0x48(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x3500
leaq 0x48(%rsp), %rdi
callq 0x3514
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x392a
movq -0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x571d
callq 0x3c2e
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5738
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21c0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5753
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x386e(%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 0x57b6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x57d2
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 0x9f0(%rip), %rsi       # 0x61f7
leaq 0x9f2(%rip), %rdx       # 0x6200
leaq 0x110(%rsp), %rdi
callq 0x5cfa
movb $0x1, %bpl
leaq 0x110(%rsp), %rsi
movq %r15, %rdi
callq 0x5b9c
xorl %ebp, %ebp
leaq 0x3531(%rip), %rsi      # 0x8d68
leaq 0x3c6(%rip), %rdx       # 0x5c04
movq %r15, %rdi
callq 0x22b0
jmp 0x5972
movl $0x28, %edi
callq 0x20c0
movq %rax, %r15
leaq 0x100(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x98b(%rip), %rsi       # 0x61f7
leaq 0x98d(%rip), %rdx       # 0x6200
leaq 0xf0(%rsp), %rdi
callq 0x5cfa
movb $0x1, %bpl
leaq 0xf0(%rsp), %rsi
movq %r15, %rdi
callq 0x5b9c
xorl %ebp, %ebp
leaq 0x34cc(%rip), %rsi      # 0x8d68
leaq 0x361(%rip), %rdx       # 0x5c04
movq %r15, %rdi
callq 0x22b0
jmp 0x5972
movl $0x28, %edi
callq 0x20c0
movq %rax, %r15
leaq 0xe0(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x930(%rip), %rsi       # 0x6201
leaq 0x935(%rip), %rdx       # 0x620d
leaq 0xd0(%rsp), %rdi
callq 0x5cfa
movb $0x1, %bpl
leaq 0xd0(%rsp), %rsi
movq %r15, %rdi
callq 0x5b9c
xorl %ebp, %ebp
leaq 0x3467(%rip), %rsi      # 0x8d68
leaq 0x2fc(%rip), %rdx       # 0x5c04
movq %r15, %rdi
callq 0x22b0
jmp 0x5972
movl $0x28, %edi
callq 0x20c0
movq %rax, %r15
leaq 0xc0(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x8db(%rip), %rsi       # 0x620e
leaq 0x8de(%rip), %rdx       # 0x6218
leaq 0xb0(%rsp), %rdi
callq 0x5cfa
movb $0x1, %bpl
leaq 0xb0(%rsp), %rsi
movq %r15, %rdi
callq 0x5b9c
xorl %ebp, %ebp
leaq 0x3405(%rip), %rsi      # 0x8d68
leaq 0x29a(%rip), %rdx       # 0x5c04
movq %r15, %rdi
callq 0x22b0
movq %rdx, %r14
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
je 0x5995
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x21c0
testb %bpl, %bpl
jne 0x59a5
jmp 0x5a37
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2130
jmp 0x5a37
jmp 0x59b4
movq %rdx, %r14
movq %rax, %rbx
jmp 0x5a37
movq %rdx, %r14
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
cmpq %r12, %rdi
je 0x59df
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x21c0
testb %bpl, %bpl
jne 0x59ec
jmp 0x5a4c
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2130
jmp 0x5a4c
movq %rdx, %r14
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r12, %rdi
je 0x5a80
movq 0x100(%rsp), %rsi
jmp 0x5a78
jmp 0x5a87
movq %rdx, %r14
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5c6a
jmp 0x5a37
movq %rdx, %r14
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5c34
leaq 0x130(%rsp), %rdi
callq 0x2240
jmp 0x5a4c
movq %rdx, %r14
movq %rax, %rbx
leaq 0x330(%rsp), %rdi
callq 0x2040
jmp 0x5acc
jmp 0x5ac6
movq %rdx, %r14
movq %rax, %rbx
movq 0x110(%rsp), %rdi
cmpq %r12, %rdi
je 0x5a80
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x21c0
testb %bpl, %bpl
jne 0x5a8d
jmp 0x5a9f
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2130
jmp 0x5a9f
jmp 0x5a99
movq %rdx, %r14
movq %rax, %rbx
movq 0x330(%rsp), %rdi
leaq 0x340(%rsp), %rax
cmpq %rax, %rdi
je 0x5acc
movq 0x340(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x5acc
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x5b16
movq %rbx, %rdi
callq 0x2090
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x34ee(%rip), %rdi      # 0x8fd8
movq %rax, %rsi
callq 0x21a0
movq %rax, %rdi
callq 0x20b0
movl $0x1, %ebx
callq 0x22a0
jmp 0x579a
movq %rax, %rbx
jmp 0x5b16
movq %rax, %rbx
callq 0x22a0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5b32
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x5b4e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x22d0
movq %rax, %rdi
callq 0x3c23