// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x250, %rsp            # imm = 0x250
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x270(%rbp), %rdi
callq 0x2844
cmpl $0x2, %r14d
jl 0x2791
movq 0x8(%rbx), %rsi
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x2946
leaq 0x2ac2(%rip), %rsi      # 0x5004
leaq -0x48(%rbp), %r15
movq %r15, %rdi
callq 0x2936
movl %eax, %r12d
movq %r15, %rdi
callq 0x20e0
testb %r12b, %r12b
je 0x25af
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpl $0x2, %r14d
jne 0x26a8
leaq 0x2a8d(%rip), %rsi      # 0x500c
leaq -0x48(%rbp), %rdi
callq 0x23a0
leaq -0x128(%rbp), %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x22a0
leaq -0x270(%rbp), %rdi
movq %rbx, %rsi
callq 0x302e
jmp 0x26f8
movq 0x8(%rbx), %rsi
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x2946
leaq 0x2a4c(%rip), %rsi      # 0x5013
movq %r15, %rdi
callq 0x2936
movl %eax, %r12d
movq %r15, %rdi
callq 0x20e0
testb %r12b, %r12b
je 0x2791
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x58(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
cmpl $0x4, %r14d
jb 0x2700
movq 0x10(%rbx), %rsi
leaq -0x88(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x2946
leaq -0x48(%rbp), %rdi
leaq -0x88(%rbp), %r14
movq %r14, %rsi
callq 0x2240
movq %r14, %rdi
callq 0x20e0
movq 0x18(%rbx), %rsi
leaq -0x88(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x2946
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rbx
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20e0
leaq -0x108(%rbp), %rbx
leaq -0x48(%rbp), %rsi
movq %rbx, %rdi
callq 0x22a0
leaq -0xe8(%rbp), %r14
leaq -0x68(%rbp), %rsi
movq %r14, %rdi
callq 0x22a0
leaq -0x270(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3504
jmp 0x276f
movq 0x10(%rbx), %rsi
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rdx
callq 0x2946
leaq -0x48(%rbp), %r14
leaq -0x68(%rbp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20e0
leaq -0x148(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
leaq -0x270(%rbp), %rdi
movq %rbx, %rsi
callq 0x302e
movq %rbx, %rdi
jmp 0x2783
cmpl $0x3, %r14d
jne 0x277f
movq 0x10(%rbx), %rsi
leaq -0x88(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x2946
leaq -0x48(%rbp), %r14
leaq -0x88(%rbp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20e0
leaq -0xc8(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22a0
leaq -0xa8(%rbp), %r14
leaq -0x48(%rbp), %rsi
movq %r14, %rdi
callq 0x22a0
leaq -0x270(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3504
movq %r14, %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x20e0
leaq -0x68(%rbp), %rdi
callq 0x20e0
leaq -0x48(%rbp), %rdi
callq 0x20e0
leaq -0x270(%rbp), %rdi
callq 0x2982
xorl %eax, %eax
addq $0x250, %rsp            # imm = 0x250
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x20e0
jmp 0x27c3
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
jmp 0x27e9
jmp 0x27f4
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x20e0
jmp 0x27e2
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x20e0
jmp 0x27f7
jmp 0x27f4
jmp 0x27f4
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x2813
movq %rax, %rbx
leaq -0x148(%rbp), %rdi
jmp 0x2813
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
callq 0x20e0
jmp 0x2821
jmp 0x281e
jmp 0x282c
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x20e0
jmp 0x282f
movq %rax, %rbx
leaq -0x270(%rbp), %rdi
callq 0x2982
movq %rbx, %rdi
callq 0x2370
nop