// File: /workspace/github_cpp_makefile_star2_O3/sbme-tutorials[P]huffman-encoding/main.cpp
// Function: main
int main(int argc, char *argv[])
{
    // To encode: ./a.exe -encode output_file_name < ./data/omaha.pgm
    Huffman H;
    int indexArgv = 1; // 0 is the exe
    if (indexArgv < argc && std::string(argv[indexArgv]) == "-encode")
    {
        indexArgv++;
        std::string encodedFileName;
        if (indexArgv < argc)
        {
            encodedFileName = std::string(argv[indexArgv]);
            H.encode(encodedFileName);
            indexArgv++;
        }
        else
        {
            encodedFileName = "output";
            H.encode(encodedFileName);
        }
    }
    else if (indexArgv < argc && std::string(argv[indexArgv]) == "-decode")
    {
        indexArgv++;
        std::string encodedFileName;
        std::string decodedFileName;
        if (indexArgv + 1 < argc)
        {
            encodedFileName = std::string(argv[indexArgv]);
            decodedFileName = std::string(argv[++indexArgv]);
            H.decode(encodedFileName, decodedFileName);
            indexArgv += 2;
        }
        else if (indexArgv < argc)
        {
            encodedFileName = std::string(argv[indexArgv]);
            H.decode(encodedFileName, encodedFileName);
            indexArgv++;
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
leaq -0x268(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq %rax, 0x10(%rcx)
movl $0xff, 0x18(%rcx)
leaq -0x238(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movw $0x3250, (%rcx)         # imm = 0x3250
movq $0x2, -0x8(%rcx)
movb %al, 0x2(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rcx)
movq %rax, 0x28(%rcx)
leaq -0x200(%rbp), %rcx
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0x1d0(%rbp), %rcx
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0x198(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq %rax, 0x40(%rcx)
movups %xmm0, 0x30(%rcx)
movups %xmm0, 0x20(%rcx)
movups %xmm0, 0x10(%rcx)
cmpl $0x2, %edi
jl 0x2951
movq %rsi, %rbx
movl %edi, %r14d
movq 0x8(%rsi), %rsi
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x2a6e
leaq 0x3a46(%rip), %rsi      # 0x6004
leaq -0x50(%rbp), %r12
movq %r12, %rdi
callq 0x20a0
movl %eax, %r15d
movq (%r12), %rdi
leaq -0x40(%rbp), %r13
cmpq %r13, %rdi
je 0x25e6
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
testl %r15d, %r15d
je 0x2756
movq 0x8(%rbx), %rsi
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x2a6e
leaq 0x3a0c(%rip), %rsi      # 0x6013
movq %r12, %rdi
callq 0x20a0
movl %eax, %r15d
movq (%r12), %rdi
cmpq %r13, %rdi
je 0x2627
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
testl %r15d, %r15d
jne 0x2951
movq %r13, -0x50(%rbp)
xorl %eax, %eax
movq %rax, -0x48(%rbp)
movb %al, -0x40(%rbp)
leaq -0x60(%rbp), %r15
movq %r15, -0x10(%r15)
movq %rax, -0x8(%r15)
movb %al, (%r15)
cmpl $0x4, %r14d
jb 0x284d
movq 0x10(%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2a6e
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %r14
movq %r14, %rsi
callq 0x2250
movq (%r14), %rdi
leaq -0x80(%rbp), %r14
cmpq %r14, %rdi
je 0x2695
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
movq 0x18(%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2a6e
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rbx
movq %rbx, %rsi
callq 0x2250
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x26d0
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x100(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0x110(%rbp), %rdi
callq 0x2d0a
leaq -0xc0(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x2d0a
leaq -0x278(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x3a5c
movq -0xd0(%rbp), %rdi
cmpq %r12, %rdi
je 0x274a
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x110(%rbp), %rdi
jmp 0x2917
movq %r13, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movb $0x0, -0x40(%rbp)
cmpl $0x2, %r14d
jne 0x27c4
leaq 0x3899(%rip), %rcx      # 0x600c
leaq -0x50(%rbp), %rdi
movl $0x6, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x2300
leaq -0x120(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0x130(%rbp), %rdi
callq 0x2d0a
leaq -0x278(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x332e
movq -0x130(%rbp), %rdi
jmp 0x283c
movq 0x10(%rbx), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x2a6e
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rbx
movq %rbx, %rsi
callq 0x2250
movq (%rbx), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x2800
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x140(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0x150(%rbp), %rdi
callq 0x2d0a
leaq -0x278(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x332e
movq -0x150(%rbp), %rdi
cmpq %r14, %rdi
je 0x293c
movq (%r14), %rsi
jmp 0x2934
cmpl $0x3, %r14d
jne 0x2927
movq 0x10(%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2a6e
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rbx
movq %rbx, %rsi
callq 0x2250
movq (%rbx), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x2896
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0xe0(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xf0(%rbp), %rdi
callq 0x2d0a
leaq -0xa0(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x2d0a
leaq -0x278(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x3a5c
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0x2910
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0xf0(%rbp), %rdi
cmpq %r14, %rdi
je 0x2927
movq (%r14), %rsi
incq %rsi
callq 0x2210
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0x293c
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x2951
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x278(%rbp), %rdi
callq 0x2aac
xorl %eax, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0x2994
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x2994
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
cmpq %r14, %rdi
je 0x29f2
movq -0xe0(%rbp), %rsi
jmp 0x29e1
jmp 0x29ef
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
cmpq %r12, %rdi
je 0x29ce
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x29ce
movq %rax, %rbx
movq -0x110(%rbp), %rdi
cmpq %r14, %rdi
je 0x29f2
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x29f2
jmp 0x29ef
jmp 0x29ef
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0x2a3e
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x2a3e
movq %rax, %rbx
movq -0x150(%rbp), %rdi
cmpq %r14, %rdi
je 0x2a3e
movq -0x140(%rbp), %rsi
jmp 0x29ff
movq %rax, %rbx
movq -0x130(%rbp), %rdi
cmpq %r14, %rdi
je 0x2a3e
movq -0x120(%rbp), %rsi
jmp 0x29ff
jmp 0x2a3b
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x2a5a
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x2a5a
jmp 0x2a57
movq %rax, %rbx
leaq -0x278(%rbp), %rdi
callq 0x2aac
movq %rbx, %rdi
callq 0x2360