// File: /workspace/github_cpp_makefile_star2_O2/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), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rsi, %rbx
movl %edi, %ebp
xorl %ecx, %ecx
leaq 0x18(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %cl, (%rax)
movb %cl, (%rdx)
pushq $0x1
popq %r12
pushq $-0x1
popq %rax
movl %eax, 0x4(%rsp)
leaq 0x330(%rsp), %r14
leaq 0x130(%rsp), %r15
cmpl %ebp, %r12d
jge 0x4eb2
movslq %r12d, %r13
movq (%rbx,%r13,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x5280
movq %r14, %rdi
leaq 0x13ef(%rip), %rsi      # 0x61bb
callq 0x52bb
testb %al, %al
je 0x4de2
movl $0x0, 0x4(%rsp)
jmp 0x4ea2
movq %r14, %rdi
leaq 0x13d2(%rip), %rsi      # 0x61be
callq 0x52bb
testb %al, %al
je 0x4e01
pushq $0x1
popq %rax
movl %eax, 0x4(%rsp)
jmp 0x4ea2
movq %r14, %rdi
leaq 0x13b6(%rip), %rsi      # 0x61c1
callq 0x52bb
testb %al, %al
jne 0x4e27
movq %r14, %rdi
leaq 0x13a6(%rip), %rsi      # 0x61c4
callq 0x52bb
testb %al, %al
je 0x4e43
movq 0x8(%rbx,%r13,8), %rsi
movq %r15, %rdi
leaq 0x48(%rsp), %rdx
callq 0x5280
incl %r12d
leaq 0x28(%rsp), %rdi
jmp 0x4e92
movq %r14, %rdi
leaq 0x137e(%rip), %rsi      # 0x61cb
callq 0x52bb
testb %al, %al
jne 0x4e6d
movq %r14, %rdi
leaq 0x136e(%rip), %rsi      # 0x61ce
callq 0x52bb
testb %al, %al
je 0x506b
incl %r12d
cmpl %ebp, %r12d
jge 0x4fbd
movslq %r12d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0x48(%rsp), %rdx
callq 0x5280
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x21a0
movq %r15, %rdi
callq 0x2090
movq %r14, %rdi
callq 0x2090
incl %r12d
jmp 0x4da7
leaq 0x330(%rsp), %rdi
leaq 0x28(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x2260
movq 0x330(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x350(%rsp,%rax)
movl 0x4(%rsp), %ebx
jne 0x5014
leaq 0x130(%rsp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x22e0
cmpl $0x1, %ebx
je 0x4f41
testl %ebx, %ebx
jne 0x50bf
leaq 0x48(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0x29aa
leaq 0x48(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x2aee
leaq 0x48(%rsp), %rdi
callq 0x2bce
leaq 0x48(%rsp), %rdi
callq 0x5338
jmp 0x4f79
leaq 0x48(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0x2c20
leaq 0x48(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x2eb8
leaq 0x48(%rsp), %rdi
callq 0x2ec8
leaq 0x48(%rsp), %rdi
callq 0x5358
leaq 0x130(%rsp), %rdi
callq 0x2210
leaq 0x330(%rsp), %rdi
callq 0x2030
xorl %ebx, %ebx
leaq 0x8(%rsp), %rdi
callq 0x2090
leaq 0x28(%rsp), %rdi
callq 0x2090
movl %ebx, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x20b0
movq %rax, %r15
leaq 0x1208(%rip), %rsi      # 0x61d7
leaq 0x110(%rsp), %rdi
leaq 0x130(%rsp), %rdx
callq 0x5280
movb $0x1, %bpl
leaq 0x110(%rsp), %rsi
movq %r15, %rdi
callq 0x52c8
xorl %ebp, %ebp
leaq 0x4d70(%rip), %rsi      # 0x9d70
leaq 0x311(%rip), %rdx       # 0x5318
movq %r15, %rdi
callq 0x2290
jmp 0x510e
pushq $0x28
popq %rdi
callq 0x20b0
movq %rax, %r15
leaq 0x11bb(%rip), %rsi      # 0x61e1
leaq 0xd0(%rsp), %rdi
leaq 0x130(%rsp), %rdx
callq 0x5280
movb $0x1, %bpl
leaq 0xd0(%rsp), %rsi
movq %r15, %rdi
callq 0x52c8
xorl %ebp, %ebp
leaq 0x4d19(%rip), %rsi      # 0x9d70
leaq 0x2ba(%rip), %rdx       # 0x5318
movq %r15, %rdi
callq 0x2290
jmp 0x510e
pushq $0x28
popq %rdi
callq 0x20b0
movq %rax, %r15
leaq 0x115a(%rip), %rsi      # 0x61d7
leaq 0xf0(%rsp), %rdi
leaq 0x130(%rsp), %rdx
callq 0x5280
movb $0x1, %bpl
leaq 0xf0(%rsp), %rsi
movq %r15, %rdi
callq 0x52c8
xorl %ebp, %ebp
leaq 0x4cc2(%rip), %rsi      # 0x9d70
leaq 0x263(%rip), %rdx       # 0x5318
movq %r15, %rdi
callq 0x2290
jmp 0x510e
pushq $0x28
popq %rdi
callq 0x20b0
movq %rax, %r15
leaq 0x111d(%rip), %rsi      # 0x61ee
leaq 0xb0(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x5280
movb $0x1, %bpl
leaq 0xb0(%rsp), %rsi
movq %r15, %rdi
callq 0x52c8
xorl %ebp, %ebp
leaq 0x4c71(%rip), %rsi      # 0x9d70
leaq 0x212(%rip), %rdx       # 0x5318
movq %r15, %rdi
callq 0x2290
movq %rdx, %r14
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x2090
testb %bpl, %bpl
jne 0x5131
jmp 0x51d0
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2110
jmp 0x51d0
movq %rdx, %r14
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
jmp 0x5192
jmp 0x519e
jmp 0x5152
movq %rdx, %r14
movq %rax, %rbx
jmp 0x51d0
movq %rdx, %r14
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x2090
testb %bpl, %bpl
jne 0x517a
jmp 0x51e5
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2110
jmp 0x51e5
movq %rdx, %r14
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x2090
testb %bpl, %bpl
jne 0x51a4
jmp 0x51fe
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x2110
jmp 0x51fe
movq %rdx, %r14
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5358
jmp 0x51d0
movq %rdx, %r14
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5338
leaq 0x130(%rsp), %rdi
callq 0x2210
jmp 0x51e5
movq %rdx, %r14
movq %rax, %rbx
leaq 0x330(%rsp), %rdi
callq 0x2030
jmp 0x5213
jmp 0x520d
jmp 0x51f8
movq %rdx, %r14
movq %rax, %rbx
leaq 0x330(%rsp), %rdi
callq 0x2090
jmp 0x5213
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x525b
movq %rbx, %rdi
callq 0x2070
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq 0x4da7(%rip), %rdi      # 0x9fd8
movq %rax, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20a0
callq 0x2280
pushq $0x1
popq %rbx
jmp 0x4f95
movq %rax, %rbx
jmp 0x525b
movq %rax, %rbx
callq 0x2280
leaq 0x8(%rsp), %rdi
callq 0x2090
leaq 0x28(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x331f
nop