// File: marknelson[P]LZW/lzw.cpp
// Function: main
int main(int argc, char* argv[])
{
    int max_code = 32767;
    if ( argc >= 2 && !strcmp( "-max", argv[1] ) ) {
        if ( sscanf( argv[2], "%d", &max_code ) != 1 )
            usage();
        argc -= 2;
        argv += 2;
    }
    if ( argc < 2 )
            usage();
        bool compress;
        if ( std::string( "-c" ) == argv[1] )
            compress = true;
        else if ( std::string( "-d" ) == argv[1] )
            compress = false;
        else
            usage();
        std::istream *in = &std::cin;
        std::ostream *out = &std::cout;
        bool delete_instream = false;
        bool delete_ostream = false;
        if ( argc == 3 ) {
            in = new std::ifstream( argv[2] );
            delete_instream = true;
        }
        if ( argc == 4 ) {
            out = new std::ofstream( argv[3] );
            delete_ostream = true;
            if ( std::string("-") != argv[2] ) {
                in = new std::ifstream( argv[2] );
                delete_instream = true;
            }
        }
        if ( compress )
            lzw::compress( *in, *out, max_code );
        else
            lzw::decompress( *in, *out, max_code );
        if ( delete_instream )
            delete in;
        if ( delete_ostream )
            delete out;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x7fff, -0x14(%rbp)    # imm = 0x7FFF
cmpl $0x2, -0x8(%rbp)
jl 0x24d8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x5d9b(%rip), %rdi      # 0x8230
callq 0x2250
cmpl $0x0, %eax
jne 0x24d8
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x5d87(%rip), %rsi      # 0x8235
leaq -0x14(%rbp), %rdx
movb $0x0, %al
callq 0x2180
cmpl $0x1, %eax
je 0x24c3
callq 0x2430
movl -0x8(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x24e3
callq 0x2430
leaq -0x39(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x22c0
movq -0xc0(%rbp), %rdx
leaq 0x5d37(%rip), %rsi      # 0x8238
leaq -0x38(%rbp), %rdi
callq 0x2220
jmp 0x250c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x38(%rbp), %rdi
callq 0x28b0
movb %al, -0xc1(%rbp)
jmp 0x2525
leaq -0x38(%rbp), %rdi
callq 0x2100
leaq -0x39(%rbp), %rdi
callq 0x21c0
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x2543
jmp 0x257d
movb $0x1, -0x15(%rbp)
jmp 0x261b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x256f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2100
leaq -0x39(%rbp), %rdi
callq 0x21c0
jmp 0x28a0
leaq -0x71(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x22c0
movq -0xd0(%rbp), %rdx
leaq 0x5ca0(%rip), %rsi      # 0x823b
leaq -0x70(%rbp), %rdi
callq 0x2220
jmp 0x25a6
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x70(%rbp), %rdi
callq 0x28b0
movb %al, -0xd1(%rbp)
jmp 0x25bf
leaq -0x70(%rbp), %rdi
callq 0x2100
leaq -0x71(%rbp), %rdi
callq 0x21c0
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x25dd
jmp 0x2614
movb $0x0, -0x15(%rbp)
jmp 0x2619
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x2606
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x2100
leaq -0x71(%rbp), %rdi
callq 0x21c0
jmp 0x28a0
callq 0x2430
jmp 0x261b
movq 0xa9b6(%rip), %rax      # 0xcfd8
movq %rax, -0x80(%rbp)
movq 0xa99b(%rip), %rax      # 0xcfc8
movq %rax, -0x88(%rbp)
movb $0x0, -0x89(%rbp)
movb $0x0, -0x8a(%rbp)
cmpl $0x3, -0x8(%rbp)
jne 0x26a4
movl $0x208, %edi            # imm = 0x208
callq 0x21a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movl $0x8, %edx
callq 0x22d0
jmp 0x2673
movq -0xe0(%rbp), %rax
movq %rax, -0x80(%rbp)
movb $0x1, -0x89(%rbp)
jmp 0x26a4
movq -0xe0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x2170
jmp 0x28a0
cmpl $0x4, -0x8(%rbp)
jne 0x2812
movl $0x200, %edi            # imm = 0x200
callq 0x21a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movl $0x10, %edx
callq 0x21d0
jmp 0x26d9
movq -0xe8(%rbp), %rax
movq %rax, -0x88(%rbp)
movb $0x1, -0x8a(%rbp)
leaq -0xb1(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x22c0
movq -0xf0(%rbp), %rdx
leaq 0x5b2f(%rip), %rsi      # 0x823e
leaq -0xb0(%rbp), %rdi
callq 0x2220
jmp 0x271d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x28e0
movb %al, -0xf1(%rbp)
jmp 0x2739
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0xb1(%rbp), %rdi
callq 0x21c0
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x2760
jmp 0x2810
movl $0x208, %edi            # imm = 0x208
callq 0x21a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x100(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movl $0x8, %edx
callq 0x22d0
jmp 0x278b
movq -0x100(%rbp), %rax
movq %rax, -0x80(%rbp)
movb $0x1, -0x89(%rbp)
jmp 0x2810
movq -0xe8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x2170
jmp 0x28a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x27e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0xb1(%rbp), %rdi
callq 0x21c0
jmp 0x28a0
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x2170
jmp 0x28a0
jmp 0x2812
testb $0x1, -0x15(%rbp)
je 0x282d
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x2910
jmp 0x2840
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x2d00
testb $0x1, -0x89(%rbp)
je 0x2869
movq -0x80(%rbp), %rax
movq %rax, -0x108(%rbp)
cmpq $0x0, %rax
je 0x2867
movq -0x108(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x2869
testb $0x1, -0x8a(%rbp)
je 0x2895
movq -0x88(%rbp), %rax
movq %rax, -0x110(%rbp)
cmpq $0x0, %rax
je 0x2893
movq -0x110(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x2895
xorl %eax, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x22b0
nopl (%rax)