// File: /workspace/github_cpp_makefile_star2_O3/ipatix[P]wav2agb/wav2agb.cpp
// Function: main
int main(int argc, char *argv[]) {
    try {
        if (argc == 1)
            usage();

        for (int i = 1; i < argc; i++) {
            std::string st(argv[i]);
            if (st == "-s" || st == "--symbol") {
                if (++i >= argc)
                    die("-s: missing symbol name\n");
                arg_sym = argv[i];
                fix_str(arg_sym);
            } else if (st == "-c" || st == "--compress") {
                arg_compress = cmp_type::dpcm;
            } else if (st == "-l" || st == "--lookahead") {
                if (++i >= argc)
                    die("-l: missing parameter");
                set_dpcm_lookahead(std::stoul(argv[i], nullptr, 10));
            } else if (st == "--version") {
                version();
            } else if (st == "--loop-start") {
                if (++i >= argc)
                    die("--loop-start: missing parameter");
                uint32_t start = static_cast<uint32_t>(std::stoul(argv[i], nullptr, 10));
                set_wav_loop_start(start);
            } else if (st == "--loop-end") {
                if (++i >= argc)
                    die("--loop-end: missing parameter");
                uint32_t end = static_cast<uint32_t>(std::stoul(argv[i], nullptr, 10));
                set_wav_loop_end(end);
            } else if (st == "--tune") {
                if (++i >= argc)
                    die("--tune: missing parameter");
                double tune = std::stod(argv[i], nullptr);
                set_wav_tune(tune);
            } else if (st == "--key") {
                if (++i >= argc)
                    die("--key: missing parameter");
                int key = std::stoi(argv[i], nullptr, 10);
                if (key < 0) key = 0;
                if (key > 127) key = 127;
                set_wav_key(static_cast<uint8_t>(key));
            } else if (st == "--rate") {
                if (++i >= argc)
                    die("--rate: missing parameter");
                uint32_t rate = static_cast<uint32_t>(std::stoul(argv[i], nullptr, 10));
                set_wav_rate(rate);
            } else {
                if (st == "--") {
                    if (++i >= argc)
                        die("--: missing file name\n");
                }
                if (!arg_input_file_read) {
                    arg_input_file = argv[i];
                    if (arg_input_file.size() < 1)
                        die("empty input file name\n");
                    arg_input_file_read = true;
                } else if (!arg_output_file_read) {
                    arg_output_file = argv[i];
                    if (arg_output_file.size() < 1)
                        die("empty output file name\n");
                    arg_output_file_read = true;
                } else {
                    die("Too many files specified\n");
                }
            }
        }

        // check arguments
        if (!arg_input_file_read) {
            die("No input file specified\n");
        }

        if (!arg_output_file_read) {
            // create output file name if none is provided
            arg_output_file = filename_without_ext(arg_input_file) + ".s";
            arg_output_file_read = true;
        }

        if (arg_sym.size() == 0) {
            arg_sym = filename_without_dir(filename_without_ext(arg_output_file));
            fix_str(arg_sym);
        }

        convert(arg_input_file, arg_output_file, arg_sym, arg_compress);
        return 0;
    } catch (const std::exception& e) {
        fprintf(stderr, "std lib error:\n%s\n", e.what());
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
cmpl $0x1, %edi
je 0x38ee
jle 0x36f5
movq %rsi, %rbx
movl %edi, %ebp
movl $0x1, %r15d
leaq 0x40(%rsp), %r14
leaq 0x10(%rsp), %r13
movq %rsi, 0x38(%rsp)
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x3c26
movq %r14, %rdi
leaq 0x3076(%rip), %rsi      # 0x61f5
callq 0x2090
testl %eax, %eax
je 0x32ec
movq %r14, %rdi
leaq 0x3062(%rip), %rsi      # 0x61f8
callq 0x2090
testl %eax, %eax
je 0x32ec
movq %r14, %rdi
leaq 0x306d(%rip), %rsi      # 0x621a
callq 0x2090
testl %eax, %eax
je 0x3331
movq %r14, %rdi
leaq 0x3059(%rip), %rsi      # 0x621d
callq 0x2090
testl %eax, %eax
je 0x3331
movq %r14, %rdi
leaq 0x304d(%rip), %rsi      # 0x6228
callq 0x2090
testl %eax, %eax
je 0x3365
movq %r14, %rdi
leaq 0x3039(%rip), %rsi      # 0x622b
callq 0x2090
testl %eax, %eax
je 0x3365
movq %r14, %rdi
leaq 0x3044(%rip), %rsi      # 0x624d
callq 0x2090
testl %eax, %eax
je 0x38fc
movq %r14, %rdi
leaq 0x3037(%rip), %rsi      # 0x6257
callq 0x2090
testl %eax, %eax
je 0x3404
movq %r14, %rdi
leaq 0x304d(%rip), %rsi      # 0x6284
callq 0x2090
testl %eax, %eax
je 0x346b
movq %r14, %rdi
leaq 0x305f(%rip), %rsi      # 0x62ad
callq 0x2090
testl %eax, %eax
je 0x3516
movq %r14, %rdi
leaq 0x3069(%rip), %rsi      # 0x62ce
callq 0x2090
testl %eax, %eax
je 0x35b9
movq %r14, %rdi
leaq 0x3071(%rip), %rsi      # 0x62ed
callq 0x2090
testl %eax, %eax
je 0x366d
movq %r14, %rdi
leaq 0x307b(%rip), %rsi      # 0x630e
callq 0x2090
testl %eax, %eax
jne 0x32a8
incl %r15d
cmpl %ebp, %r15d
jge 0x39bd
cmpb $0x0, 0x6032(%rip)      # 0x92e1
je 0x36c8
cmpb $0x0, 0x6026(%rip)      # 0x92e2
jne 0x39b1
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x5ff0(%rip), %rdi      # 0x92c0
callq 0x22e0
cmpq $0x0, 0x5feb(%rip)      # 0x92c8
je 0x39a5
movb $0x1, 0x5ff8(%rip)      # 0x92e2
jmp 0x3338
incl %r15d
cmpl %ebp, %r15d
jge 0x38cb
movslq %r15d, %rax
movq (%rbx,%rax,8), %r12
movq 0x5f82(%rip), %r13      # 0x9288
movq %r12, %rdi
callq 0x2110
leaq 0x5f6b(%rip), %rdi      # 0x9280
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x2340
leaq 0x10(%rsp), %r13
callq 0x3b27
jmp 0x3338
movb $0x1, 0x5fa8(%rip)      # 0x92e0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x3354
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2220
incl %r15d
cmpl %ebp, %r15d
jl 0x3163
jmp 0x36f5
incl %r15d
cmpl %ebp, %r15d
jge 0x38d9
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3c26
movq 0x10(%rsp), %r12
callq 0x2030
movq %rax, %r13
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x20b0
cmpq %r12, 0x30(%rsp)
je 0x38e2
movl (%r13), %ecx
testl %ecx, %ecx
je 0x33c9
cmpl $0x22, %ecx
jne 0x33cd
jmp 0x390f
movl %ebx, (%r13)
movq %rax, %rdi
callq 0x275c
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
movq 0x38(%rsp), %rbx
leaq 0x10(%rsp), %r13
je 0x3338
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
jmp 0x3338
incl %r15d
cmpl %ebp, %r15d
jge 0x391b
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3c26
movq 0x10(%rsp), %r12
callq 0x2030
movq %rax, %r13
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x20b0
cmpq %r12, 0x30(%rsp)
je 0x3924
movq %rax, %rcx
movl (%r13), %eax
testl %eax, %eax
je 0x34da
cmpl $0x22, %eax
jne 0x34de
jmp 0x3945
incl %r15d
cmpl %ebp, %r15d
jge 0x3930
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3c26
movq 0x10(%rsp), %r12
callq 0x2030
movq %rax, %r13
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x20b0
cmpq %r12, 0x30(%rsp)
je 0x3939
movq %rax, %rcx
movl (%r13), %eax
testl %eax, %eax
je 0x357d
cmpl $0x22, %eax
jne 0x3581
jmp 0x3969
movl %ebx, (%r13)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3500
movq 0x20(%rsp), %rsi
incq %rsi
movq %rcx, %rbx
callq 0x2220
movq %rbx, %rcx
movl %ecx, %edi
callq 0x277d
movq 0x38(%rsp), %rbx
leaq 0x10(%rsp), %r13
jmp 0x3338
incl %r15d
cmpl %ebp, %r15d
jge 0x3951
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3c26
movq 0x10(%rsp), %r12
callq 0x2030
movq %rax, %r13
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x21a0
cmpq %r12, 0x30(%rsp)
je 0x395d
movl (%r13), %eax
testl %eax, %eax
je 0x362d
cmpl $0x22, %eax
jne 0x3631
jmp 0x3981
movl %ebx, (%r13)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35a3
movq 0x20(%rsp), %rsi
incq %rsi
movq %rcx, %rbx
callq 0x2220
movq %rbx, %rcx
movl %ecx, %edi
callq 0x278b
movq 0x38(%rsp), %rbx
leaq 0x10(%rsp), %r13
jmp 0x3338
incl %r15d
cmpl %ebp, %r15d
jge 0x3975
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0x30(%rsp), %rdx
callq 0x3c26
movq %r13, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3ced
movl %eax, %r12d
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3607
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
testl %r12d, %r12d
movl $0x0, %eax
cmovlel %eax, %r12d
cmpl $0x7f, %r12d
movl $0x7f, %eax
cmovgel %eax, %r12d
movl %r12d, %edi
callq 0x27a9
jmp 0x3338
movl %ebx, (%r13)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3659
movq 0x20(%rsp), %rsi
incq %rsi
movsd %xmm0, 0x60(%rsp)
callq 0x2220
movsd 0x60(%rsp), %xmm0
callq 0x2799
movq 0x38(%rsp), %rbx
leaq 0x10(%rsp), %r13
jmp 0x3338
incl %r15d
cmpl %ebp, %r15d
jge 0x398d
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0x30(%rsp), %rdx
callq 0x3c26
movq %r13, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3c63
movq %rax, %r12
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x36bb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
movl %r12d, %edi
callq 0x27b8
jmp 0x3338
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x5bca(%rip), %rdi      # 0x92a0
callq 0x22e0
cmpq $0x0, 0x5bc5(%rip)      # 0x92a8
je 0x3999
movb $0x1, 0x5bf1(%rip)      # 0x92e1
jmp 0x3338
cmpb $0x0, 0x5be5(%rip)      # 0x92e1
je 0x38f3
cmpb $0x0, 0x5bd9(%rip)      # 0x92e2
jne 0x37c1
leaq 0x5b8a(%rip), %rsi      # 0x92a0
leaq 0x10(%rsp), %rdi
callq 0x3b88
leaq 0x2c63(%rip), %rsi      # 0x638a
leaq 0x10(%rsp), %rdi
callq 0x23e0
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3758
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0x375f
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x40(%rsp), %rbx
movq %rdx, 0x8(%rbx)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x5b3e(%rip), %rdi      # 0x92c0
movq %rbx, %rsi
callq 0x2290
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x379f
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2220
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37ba
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
movb $0x1, 0x5b21(%rip)      # 0x92e2
cmpq $0x0, 0x5abf(%rip)      # 0x9288
jne 0x3897
leaq 0x5aea(%rip), %rsi      # 0x92c0
leaq 0x10(%rsp), %rdi
callq 0x3b88
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x2410
cmpq $-0x1, %rax
sete %cl
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
sete %sil
orb %cl, %sil
jne 0x382e
incq %rax
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %rax, %rdx
movq $-0x1, %rcx
callq 0x2230
jmp 0x3849
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x10(%rsp), %rsi
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x3d80
leaq 0x5a30(%rip), %rdi      # 0x9280
leaq 0x40(%rsp), %rbx
movq %rbx, %rsi
callq 0x2290
movq (%rbx), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x3877
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2220
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3892
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
callq 0x3b27
movzbl 0x5a42(%rip), %ecx      # 0x92e0
xorl %ebx, %ebx
leaq 0x59f9(%rip), %rdi      # 0x92a0
leaq 0x5a12(%rip), %rsi      # 0x92c0
leaq 0x59cb(%rip), %rdx      # 0x9280
callq 0x27c6
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x292f(%rip), %rdi      # 0x6201
xorl %eax, %eax
callq 0x3a8d
leaq 0x2957(%rip), %rdi      # 0x6237
jmp 0x38d2
leaq 0x2cde(%rip), %rdi      # 0x65c7
callq 0x2150
callq 0x2464
leaq 0x2a77(%rip), %rdi      # 0x6371
jmp 0x38d2
leaq 0x2d68(%rip), %rdi      # 0x666b
callq 0x2330
xorl %edi, %edi
callq 0x2280
leaq 0x2cb1(%rip), %rdi      # 0x65c7
callq 0x2310
leaq 0x2942(%rip), %rdi      # 0x6264
jmp 0x38d2
leaq 0x2c9c(%rip), %rdi      # 0x65c7
callq 0x2150
leaq 0x2958(%rip), %rdi      # 0x628f
jmp 0x38d2
leaq 0x2c87(%rip), %rdi      # 0x65c7
callq 0x2150
leaq 0x2c7b(%rip), %rdi      # 0x65c7
callq 0x2310
leaq 0x295c(%rip), %rdi      # 0x62b4
jmp 0x38d2
leaq 0x2c69(%rip), %rdi      # 0x65cd
callq 0x2150
leaq 0x2c57(%rip), %rdi      # 0x65c7
callq 0x2310
leaq 0x2958(%rip), %rdi      # 0x62d4
jmp 0x38d2
leaq 0x2c45(%rip), %rdi      # 0x65cd
callq 0x2310
leaq 0x2960(%rip), %rdi      # 0x62f4
jmp 0x38d2
leaq 0x2988(%rip), %rdi      # 0x6328
jmp 0x38d2
leaq 0x2993(%rip), %rdi      # 0x633f
jmp 0x38d2
leaq 0x299f(%rip), %rdi      # 0x6357
jmp 0x38d2
leaq 0x294d(%rip), %rdi      # 0x6311
jmp 0x38d2
jmp 0x3a43
jmp 0x3a0a
jmp 0x3a43
jmp 0x3a43
jmp 0x3a0a
jmp 0x3a43
jmp 0x3a43
jmp 0x3a43
jmp 0x3a14
jmp 0x3a43
jmp 0x3a43
jmp 0x3a14
jmp 0x3a43
jmp 0x3a43
jmp 0x39e9
jmp 0x3a67
movq %rdx, %r15
movq %rax, %r14
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3a6d
movq 0x20(%rsp), %rsi
jmp 0x3a5d
jmp 0x3a67
jmp 0x3a14
jmp 0x3a67
movq %rdx, %r15
movq %rax, %r14
jmp 0x3a25
jmp 0x3a43
movq %rdx, %r15
movq %rax, %r14
cmpl $0x0, (%r13)
jne 0x3a25
movl %ebx, (%r13)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3a49
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
jmp 0x3a49
movq %rdx, %r15
movq %rax, %r14
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x3a6d
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2220
jmp 0x3a6d
movq %rdx, %r15
movq %rax, %r14
movq %r14, %rdi
cmpl $0x1, %r15d
jne 0x3a88
movl %r15d, %esi
callq 0x2430
movl $0x1, %ebx
jmp 0x38ba
callq 0x23c0