// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
cmpl $0x1, %edi
je 0x34a4
movq %rsi, %rbx
movl %edi, %ebp
pushq $0x1
popq %r13
leaq 0x38(%rsp), %r14
leaq 0x18(%rsp), %r15
leaq 0x3258(%rip), %r12      # 0x61f5
cmpl %ebp, %r13d
jge 0x3321
movslq %r13d, %rax
movq (%rbx,%rax,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x3896
movq %r14, %rdi
movq %r12, %rsi
callq 0x38d1
testb %al, %al
jne 0x2fda
movq %r14, %rdi
leaq 0x3227(%rip), %rsi      # 0x61f8
callq 0x38d1
testb %al, %al
je 0x3000
incl %r13d
cmpl %ebp, %r13d
jge 0x348d
movslq %r13d, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x728c(%rip), %rdi      # 0xa280
callq 0x23d0
callq 0x3780
jmp 0x302d
movq %r14, %rdi
leaq 0x3210(%rip), %rsi      # 0x621a
callq 0x38d1
testb %al, %al
jne 0x3026
movq %r14, %rdi
leaq 0x3200(%rip), %rsi      # 0x621d
callq 0x38d1
testb %al, %al
je 0x303d
movb $0x1, 0x72b3(%rip)      # 0xa2e0
movq %r14, %rdi
callq 0x2428
incl %r13d
jmp 0x2f9d
movq %r14, %rdi
leaq 0x31e1(%rip), %rsi      # 0x6228
callq 0x38d1
testb %al, %al
jne 0x3063
movq %r14, %rdi
leaq 0x31d1(%rip), %rsi      # 0x622b
callq 0x38d1
testb %al, %al
je 0x30a2
incl %r13d
cmpl %ebp, %r13d
jge 0x349b
movslq %r13d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3896
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x38de
movq %rax, %rdi
callq 0x260c
movq %r15, %rdi
callq 0x2428
jmp 0x302d
movq %r14, %rdi
leaq 0x31a1(%rip), %rsi      # 0x624d
callq 0x38d1
testb %al, %al
jne 0x35c4
movq %r14, %rdi
leaq 0x3194(%rip), %rsi      # 0x6257
callq 0x38d1
testb %al, %al
je 0x3115
incl %r13d
cmpl %ebp, %r13d
jge 0x35d7
movslq %r13d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3896
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x38de
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x2428
movq 0x10(%rsp), %rdi
callq 0x2629
jmp 0x302d
movq %r14, %rdi
leaq 0x3165(%rip), %rsi      # 0x6284
callq 0x38d1
testb %al, %al
je 0x3171
incl %r13d
cmpl %ebp, %r13d
jge 0x35e3
movslq %r13d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3896
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x38de
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x2428
movq 0x10(%rsp), %rdi
callq 0x2637
jmp 0x302d
movq %r14, %rdi
leaq 0x3132(%rip), %rsi      # 0x62ad
callq 0x38d1
testb %al, %al
je 0x31cc
incl %r13d
cmpl %ebp, %r13d
jge 0x35ef
movslq %r13d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3896
movq %r15, %rdi
xorl %esi, %esi
callq 0x38fa
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x2428
movsd 0x10(%rsp), %xmm0
callq 0x2645
jmp 0x302d
movq %r14, %rdi
leaq 0x30f8(%rip), %rsi      # 0x62ce
callq 0x38d1
testb %al, %al
je 0x3239
incl %r13d
cmpl %ebp, %r13d
jge 0x35fb
movslq %r13d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3896
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x3913
movl %eax, 0x10(%rsp)
movq %r15, %rdi
callq 0x2428
movl 0x10(%rsp), %edi
testl %edi, %edi
movl $0x0, %eax
cmovlel %eax, %edi
cmpl $0x7f, %edi
pushq $0x7f
popq %rax
cmovgel %eax, %edi
callq 0x2655
jmp 0x302d
movq %r14, %rdi
leaq 0x30aa(%rip), %rsi      # 0x62ed
callq 0x38d1
testb %al, %al
je 0x3295
incl %r13d
cmpl %ebp, %r13d
jge 0x3607
movslq %r13d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3896
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x38de
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x2428
movq 0x10(%rsp), %rdi
callq 0x2664
jmp 0x302d
movq %r14, %rdi
leaq 0x306f(%rip), %rsi      # 0x630e
callq 0x38d1
testb %al, %al
je 0x32b4
incl %r13d
cmpl %ebp, %r13d
jge 0x3613
cmpb $0x0, 0x7026(%rip)      # 0xa2e1
movslq %r13d, %rax
je 0x32f7
cmpb $0x0, 0x701b(%rip)      # 0xa2e2
jne 0x361f
movq (%rbx,%rax,8), %rsi
leaq 0x6fe8(%rip), %rdi      # 0xa2c0
callq 0x23d0
cmpq $0x0, 0x6fe3(%rip)      # 0xa2c8
je 0x362b
movb $0x1, 0x6ff0(%rip)      # 0xa2e2
jmp 0x302d
movq (%rbx,%rax,8), %rsi
leaq 0x6f9e(%rip), %rdi      # 0xa2a0
callq 0x23d0
cmpq $0x0, 0x6f99(%rip)      # 0xa2a8
je 0x3637
movb $0x1, 0x6fc5(%rip)      # 0xa2e1
jmp 0x302d
cmpb $0x0, 0x6fb9(%rip)      # 0xa2e1
je 0x35b8
cmpb $0x0, 0x6fad(%rip)      # 0xa2e2
jne 0x338b
leaq 0x6f62(%rip), %rsi      # 0xa2a0
leaq 0x18(%rsp), %rdi
callq 0x37e0
leaq 0x303b(%rip), %rdx      # 0x638a
leaq 0x38(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x392f
leaq 0x6f5b(%rip), %rdi      # 0xa2c0
leaq 0x38(%rsp), %rbx
movq %rbx, %rsi
callq 0x2260
movq %rbx, %rdi
callq 0x2428
leaq 0x18(%rsp), %rdi
callq 0x2428
movb $0x1, 0x6f57(%rip)      # 0xa2e2
cmpq $0x0, 0x6ef5(%rip)      # 0xa288
jne 0x3459
leaq 0x6f20(%rip), %rsi      # 0xa2c0
leaq 0x18(%rsp), %rdi
callq 0x37e0
xorl %ebx, %ebx
leaq 0x3224(%rip), %r13      # 0x65d7
leaq 0x18(%rsp), %r14
pushq $-0x1
popq %r15
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpq $0x1, %rbp
je 0x33f5
movsbl (%rbp,%r13), %esi
movq %r14, %rdi
movq %r15, %rdx
callq 0x2410
cmpq %rbx, %rax
movq %rbx, %rcx
cmovaq %rax, %rcx
cmpq $-0x1, %rax
setne %al
cmovneq %rcx, %rbx
orb %al, %r12b
incq %rbp
jmp 0x33c1
cmpq $0x0, 0x20(%rsp)
setne %al
andb %r12b, %al
cmpb $0x1, %al
jne 0x341f
incq %rbx
leaq 0x38(%rsp), %rdi
leaq 0x18(%rsp), %rsi
pushq $-0x1
popq %rcx
movq %rbx, %rdx
callq 0x2220
jmp 0x342e
leaq 0x38(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x22c0
leaq 0x6e4b(%rip), %rdi      # 0xa280
leaq 0x38(%rsp), %rbx
movq %rbx, %rsi
callq 0x2260
movq %rbx, %rdi
callq 0x2428
leaq 0x18(%rsp), %rdi
callq 0x2428
callq 0x3780
movzbl 0x6e80(%rip), %ecx      # 0xa2e0
xorl %ebx, %ebx
leaq 0x6e37(%rip), %rdi      # 0xa2a0
leaq 0x6e50(%rip), %rsi      # 0xa2c0
leaq 0x6e09(%rip), %rdx      # 0xa280
callq 0x2672
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2d6d(%rip), %rdi      # 0x6201
xorl %eax, %eax
callq 0x36e8
leaq 0x2d95(%rip), %rdi      # 0x6237
jmp 0x3494
movq 0x6b25(%rip), %r15      # 0x9fd0
movq (%r15), %rcx
leaq 0x2eeb(%rip), %rdi      # 0x63a0
pushq $0x8
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rsi
pushq $0xa
popq %rbp
movl %ebp, %edi
callq 0x2270
movq (%r15), %rcx
leaq 0x2ecf(%rip), %rdi      # 0x63a9
pushq $0x32
popq %rsi
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rsi
movl %ebp, %edi
callq 0x2270
movq (%r15), %rcx
leaq 0x2ee3(%rip), %rdi      # 0x63dc
pushq $0x9
popq %rsi
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rcx
leaq 0x2ed8(%rip), %rdi      # 0x63e6
pushq $0x4c
popq %rsi
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rcx
leaq 0x2f10(%rip), %rdi      # 0x6433
pushq $0x48
popq %rsi
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rcx
leaq 0x2f44(%rip), %rdi      # 0x647c
pushq $0x35
popq %rsi
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rcx
leaq 0x2f65(%rip), %rdi      # 0x64b2
pushq $0x39
popq %rsi
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rcx
leaq 0x2f8a(%rip), %rdi      # 0x64ec
pushq $0x37
popq %rsi
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rcx
leaq 0x2fad(%rip), %rdi      # 0x6524
pushq $0x33
popq %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rcx
leaq 0x2fc8(%rip), %rdi      # 0x6558
movq %r14, %rsi
movq %rbx, %rdx
callq 0x23f0
movq (%r15), %rcx
leaq 0x2fe7(%rip), %rdi      # 0x658c
pushq $0x3a
popq %rsi
movq %rbx, %rdx
callq 0x23f0
pushq $0x1
popq %rdi
callq 0x2250
leaq 0x2db2(%rip), %rdi      # 0x6371
jmp 0x3494
leaq 0x30a2(%rip), %rdi      # 0x666d
callq 0x2310
xorl %edi, %edi
callq 0x2250
leaq 0x2c86(%rip), %rdi      # 0x6264
jmp 0x3494
leaq 0x2ca5(%rip), %rdi      # 0x628f
jmp 0x3494
leaq 0x2cbe(%rip), %rdi      # 0x62b4
jmp 0x3494
leaq 0x2cd2(%rip), %rdi      # 0x62d4
jmp 0x3494
leaq 0x2ce6(%rip), %rdi      # 0x62f4
jmp 0x3494
leaq 0x2cf7(%rip), %rdi      # 0x6311
jmp 0x3494
leaq 0x2d31(%rip), %rdi      # 0x6357
jmp 0x3494
leaq 0x2d0d(%rip), %rdi      # 0x633f
jmp 0x3494
leaq 0x2cea(%rip), %rdi      # 0x6328
jmp 0x3494
jmp 0x3678
jmp 0x368a
jmp 0x368a
jmp 0x3678
jmp 0x368a
jmp 0x368a
jmp 0x368a
jmp 0x3678
jmp 0x368a
jmp 0x368a
jmp 0x368a
jmp 0x3678
jmp 0x3678
jmp 0x368a
jmp 0x368a
jmp 0x3665
jmp 0x369c
movq %rdx, %rbx
movq %rax, %r14
leaq 0x18(%rsp), %rdi
jmp 0x3695
jmp 0x369c
jmp 0x369c
jmp 0x368a
movq %rdx, %rbx
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x2428
jmp 0x3690
movq %rdx, %rbx
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x2428
jmp 0x36a2
movq %rdx, %rbx
movq %rax, %r14
movq %r14, %rdi
cmpl $0x1, %ebx
jne 0x36e3
callq 0x20f0
movq 0x691a(%rip), %rcx      # 0x9fd0
movq (%rcx), %rbx
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x2cc4(%rip), %rsi      # 0x638d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x22d0
callq 0x2360
pushq $0x1
popq %rbx
jmp 0x347c
callq 0x23a0