// File: /workspace/github_cpp_makefile_star2_O1/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 $0x298, %rsp            # imm = 0x298
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x2a8(%rbp), %rax
movq %rax, -0x10(%rax)
xorl %r15d, %r15d
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
movq %r15, 0x10(%rax)
movl $0xff, 0x18(%rax)
leaq -0x278(%rbp), %rax
movq %rax, -0x10(%rax)
movw $0x3250, (%rax)         # imm = 0x3250
movq $0x2, -0x8(%rax)
movb %r15b, 0x2(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movq %r15, 0x28(%rax)
leaq -0x240(%rbp), %rax
movl %r15d, (%rax)
movq %r15, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %r15, 0x20(%rax)
leaq -0x210(%rbp), %rax
movl %r15d, (%rax)
movq %r15, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %r15, 0x20(%rax)
leaq -0x1d8(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
movq %r15, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
cmpl $0x2, %edi
jl 0x25d5
movq 0x8(%rbx), %rsi
leaq -0x190(%rbp), %rdi
leaq -0x2b(%rbp), %rdx
callq 0x2af2
leaq 0x3a41(%rip), %rsi      # 0x6004
leaq -0x190(%rbp), %rdi
callq 0x20a0
testl %eax, %eax
sete %r15b
cmpl $0x2, %r14d
jl 0x25fa
leaq -0x180(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x25fa
movq -0x180(%rbp), %rsi
incq %rsi
callq 0x2210
testb %r15b, %r15b
je 0x269e
leaq -0x60(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
cmpl $0x3, %r14d
jl 0x26d1
movq 0x10(%rbx), %rsi
leaq -0x50(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x2af2
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rbx
movq %rbx, %rsi
callq 0x2250
movq (%rbx), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x265d
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x160(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
leaq -0x170(%rbp), %rdi
callq 0x2d8a
leaq -0x2b8(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x339c
movq -0x170(%rbp), %rdi
jmp 0x2727
cmpl $0x2, %r14d
jl 0x274d
movq 0x8(%rbx), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0x2af2
leaq 0x3953(%rip), %rsi      # 0x6013
leaq -0x70(%rbp), %rdi
callq 0x20a0
testl %eax, %eax
sete %r15b
jmp 0x2750
leaq 0x3934(%rip), %rcx      # 0x600c
leaq -0x70(%rbp), %rdi
movl $0x6, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x2300
leaq -0x140(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
leaq -0x150(%rbp), %rdi
callq 0x2d8a
leaq -0x2b8(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x339c
movq -0x150(%rbp), %rdi
cmpq %r14, %rdi
je 0x2737
movq (%r14), %rsi
incq %rsi
callq 0x2210
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0x29b9
movq -0x60(%rbp), %rsi
jmp 0x29b1
xorl %r15d, %r15d
cmpl $0x2, %r14d
jl 0x276f
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x276f
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
testb %r15b, %r15b
je 0x29b9
leaq -0x40(%rbp), %r15
movq %r15, -0x10(%r15)
xorl %eax, %eax
movq %rax, -0x8(%r15)
movb %al, (%r15)
leaq -0xa0(%rbp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
cmpl $0x4, %r14d
jl 0x28b0
movq 0x10(%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2af2
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %r14
movq %r14, %rsi
callq 0x2250
movq (%r14), %rdi
leaq -0x80(%rbp), %r14
cmpq %r14, %rdi
je 0x27e7
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
movq 0x18(%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2af2
leaq -0xb0(%rbp), %rdi
leaq -0x90(%rbp), %rbx
movq %rbx, %rsi
callq 0x2250
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x2825
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x120(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0x130(%rbp), %rdi
callq 0x2d8a
leaq -0xe0(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
addq %rsi, %rdx
leaq -0xf0(%rbp), %rdi
callq 0x2d8a
leaq -0x2b8(%rbp), %rdi
leaq -0x130(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0x3ad6
movq -0xf0(%rbp), %rdi
cmpq %r13, %rdi
je 0x28a4
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x130(%rbp), %rdi
jmp 0x2979
cmpl $0x3, %r14d
jne 0x2989
movq 0x10(%rbx), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2af2
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rbx
movq %rbx, %rsi
callq 0x2250
movq (%rbx), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x28f9
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 0x2d8a
leaq -0xc0(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x2d8a
leaq -0x2b8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x3ad6
movq -0xd0(%rbp), %rdi
cmpq %r13, %rdi
je 0x2972
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x110(%rbp), %rdi
cmpq %r14, %rdi
je 0x2989
movq (%r14), %rsi
incq %rsi
callq 0x2210
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0x29a4
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
je 0x29b9
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x2b8(%rbp), %rdi
callq 0x2b30
xorl %eax, %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
cmpq %r13, %rdi
je 0x29fc
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x29fc
movq %rax, %rbx
movq -0x110(%rbp), %rdi
cmpq %r14, %rdi
je 0x2a5a
movq -0x100(%rbp), %rsi
jmp 0x2a49
jmp 0x2a57
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
cmpq %r13, %rdi
je 0x2a36
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x2a36
movq %rax, %rbx
movq -0x130(%rbp), %rdi
cmpq %r14, %rdi
je 0x2a5a
movq -0x120(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x2a5a
jmp 0x2a57
jmp 0x2a57
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
je 0x2a75
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2210
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
je 0x2add
movq -0x40(%rbp), %rsi
jmp 0x2ad5
movq %rax, %rbx
movq -0x150(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ac8
movq -0x140(%rbp), %rsi
jmp 0x2ab2
movq %rax, %rbx
movq -0x170(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ac8
movq -0x160(%rbp), %rsi
incq %rsi
callq 0x2210
jmp 0x2ac8
jmp 0x2ac0
jmp 0x2ac5
movq %rax, %rbx
jmp 0x2add
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
je 0x2add
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2210
leaq -0x2b8(%rbp), %rdi
callq 0x2b30
movq %rbx, %rdi
callq 0x2360
nop