// File: /workspace/github_cpp_makefile_star2_O1/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 0x38e6
jle 0x36ed
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 0x3c0c
movq %r14, %rdi
leaq 0x307e(%rip), %rsi      # 0x61f5
callq 0x2090
testl %eax, %eax
je 0x32e4
movq %r14, %rdi
leaq 0x306a(%rip), %rsi      # 0x61f8
callq 0x2090
testl %eax, %eax
je 0x32e4
movq %r14, %rdi
leaq 0x3075(%rip), %rsi      # 0x621a
callq 0x2090
testl %eax, %eax
je 0x3329
movq %r14, %rdi
leaq 0x3061(%rip), %rsi      # 0x621d
callq 0x2090
testl %eax, %eax
je 0x3329
movq %r14, %rdi
leaq 0x3055(%rip), %rsi      # 0x6228
callq 0x2090
testl %eax, %eax
je 0x335d
movq %r14, %rdi
leaq 0x3041(%rip), %rsi      # 0x622b
callq 0x2090
testl %eax, %eax
je 0x335d
movq %r14, %rdi
leaq 0x304c(%rip), %rsi      # 0x624d
callq 0x2090
testl %eax, %eax
je 0x38f4
movq %r14, %rdi
leaq 0x303f(%rip), %rsi      # 0x6257
callq 0x2090
testl %eax, %eax
je 0x33fc
movq %r14, %rdi
leaq 0x3055(%rip), %rsi      # 0x6284
callq 0x2090
testl %eax, %eax
je 0x3463
movq %r14, %rdi
leaq 0x3067(%rip), %rsi      # 0x62ad
callq 0x2090
testl %eax, %eax
je 0x350e
movq %r14, %rdi
leaq 0x3071(%rip), %rsi      # 0x62ce
callq 0x2090
testl %eax, %eax
je 0x35b1
movq %r14, %rdi
leaq 0x3079(%rip), %rsi      # 0x62ed
callq 0x2090
testl %eax, %eax
je 0x3665
movq %r14, %rdi
leaq 0x3083(%rip), %rsi      # 0x630e
callq 0x2090
testl %eax, %eax
jne 0x32a0
incl %r15d
cmpl %ebp, %r15d
jge 0x39b5
cmpb $0x0, 0x603a(%rip)      # 0x92e1
je 0x36c0
cmpb $0x0, 0x602e(%rip)      # 0x92e2
jne 0x39a9
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x5ff8(%rip), %rdi      # 0x92c0
callq 0x22e0
cmpq $0x0, 0x5ff3(%rip)      # 0x92c8
je 0x399d
movb $0x1, 0x6000(%rip)      # 0x92e2
jmp 0x3330
incl %r15d
cmpl %ebp, %r15d
jge 0x38c3
movslq %r15d, %rax
movq (%rbx,%rax,8), %r12
movq 0x5f8a(%rip), %r13      # 0x9288
movq %r12, %rdi
callq 0x2110
leaq 0x5f73(%rip), %rdi      # 0x9280
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x2340
leaq 0x10(%rsp), %r13
callq 0x3b1f
jmp 0x3330
movb $0x1, 0x5fb0(%rip)      # 0x92e0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x334c
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2220
incl %r15d
cmpl %ebp, %r15d
jl 0x315b
jmp 0x36ed
incl %r15d
cmpl %ebp, %r15d
jge 0x38d1
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3c0c
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 0x38da
movl (%r13), %ecx
testl %ecx, %ecx
je 0x33c1
cmpl $0x22, %ecx
jne 0x33c5
jmp 0x3907
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 0x3330
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
jmp 0x3330
incl %r15d
cmpl %ebp, %r15d
jge 0x3913
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3c0c
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 0x391c
movq %rax, %rcx
movl (%r13), %eax
testl %eax, %eax
je 0x34d2
cmpl $0x22, %eax
jne 0x34d6
jmp 0x393d
incl %r15d
cmpl %ebp, %r15d
jge 0x3928
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3c0c
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 0x3931
movq %rax, %rcx
movl (%r13), %eax
testl %eax, %eax
je 0x3575
cmpl $0x22, %eax
jne 0x3579
jmp 0x3961
movl %ebx, (%r13)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x34f8
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 0x3330
incl %r15d
cmpl %ebp, %r15d
jge 0x3949
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0xf(%rsp), %rdx
callq 0x3c0c
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 0x3955
movl (%r13), %eax
testl %eax, %eax
je 0x3625
cmpl $0x22, %eax
jne 0x3629
jmp 0x3979
movl %ebx, (%r13)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x359b
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 0x3330
incl %r15d
cmpl %ebp, %r15d
jge 0x396d
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0x30(%rsp), %rdx
callq 0x3c0c
movq %r13, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3cd3
movl %eax, %r12d
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35ff
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 0x3330
movl %ebx, (%r13)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3651
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 0x3330
incl %r15d
cmpl %ebp, %r15d
jge 0x3985
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq 0x30(%rsp), %rdx
callq 0x3c0c
movq %r13, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3c49
movq %rax, %r12
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x36b3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
movl %r12d, %edi
callq 0x27b8
jmp 0x3330
movslq %r15d, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x5bd2(%rip), %rdi      # 0x92a0
callq 0x22e0
cmpq $0x0, 0x5bcd(%rip)      # 0x92a8
je 0x3991
movb $0x1, 0x5bf9(%rip)      # 0x92e1
jmp 0x3330
cmpb $0x0, 0x5bed(%rip)      # 0x92e1
je 0x38eb
cmpb $0x0, 0x5be1(%rip)      # 0x92e2
jne 0x37b9
leaq 0x5b92(%rip), %rsi      # 0x92a0
leaq 0x10(%rsp), %rdi
callq 0x3b6d
leaq 0x2c6b(%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 0x3750
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0x3757
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 0x5b46(%rip), %rdi      # 0x92c0
movq %rbx, %rsi
callq 0x2290
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x3797
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2220
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37b2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
movb $0x1, 0x5b29(%rip)      # 0x92e2
cmpq $0x0, 0x5ac7(%rip)      # 0x9288
jne 0x388f
leaq 0x5af2(%rip), %rsi      # 0x92c0
leaq 0x10(%rsp), %rdi
callq 0x3b6d
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
je 0x3825
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x10(%rsp), %rsi
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x3d66
jmp 0x3841
incq %rax
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %rax, %rdx
movq $-0x1, %rcx
callq 0x2230
leaq 0x5a38(%rip), %rdi      # 0x9280
leaq 0x40(%rsp), %rbx
movq %rbx, %rsi
callq 0x2290
movq (%rbx), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x386f
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2220
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x388a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
callq 0x3b1f
movzbl 0x5a4a(%rip), %ecx      # 0x92e0
xorl %ebx, %ebx
leaq 0x5a01(%rip), %rdi      # 0x92a0
leaq 0x5a1a(%rip), %rsi      # 0x92c0
leaq 0x59d3(%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 0x2937(%rip), %rdi      # 0x6201
xorl %eax, %eax
callq 0x3a85
leaq 0x295f(%rip), %rdi      # 0x6237
jmp 0x38ca
leaq 0x2ce6(%rip), %rdi      # 0x65c7
callq 0x2150
callq 0x2464
leaq 0x2a7f(%rip), %rdi      # 0x6371
jmp 0x38ca
leaq 0x2d70(%rip), %rdi      # 0x666b
callq 0x2330
xorl %edi, %edi
callq 0x2280
leaq 0x2cb9(%rip), %rdi      # 0x65c7
callq 0x2310
leaq 0x294a(%rip), %rdi      # 0x6264
jmp 0x38ca
leaq 0x2ca4(%rip), %rdi      # 0x65c7
callq 0x2150
leaq 0x2960(%rip), %rdi      # 0x628f
jmp 0x38ca
leaq 0x2c8f(%rip), %rdi      # 0x65c7
callq 0x2150
leaq 0x2c83(%rip), %rdi      # 0x65c7
callq 0x2310
leaq 0x2964(%rip), %rdi      # 0x62b4
jmp 0x38ca
leaq 0x2c71(%rip), %rdi      # 0x65cd
callq 0x2150
leaq 0x2c5f(%rip), %rdi      # 0x65c7
callq 0x2310
leaq 0x2960(%rip), %rdi      # 0x62d4
jmp 0x38ca
leaq 0x2c4d(%rip), %rdi      # 0x65cd
callq 0x2310
leaq 0x2968(%rip), %rdi      # 0x62f4
jmp 0x38ca
leaq 0x2990(%rip), %rdi      # 0x6328
jmp 0x38ca
leaq 0x299b(%rip), %rdi      # 0x633f
jmp 0x38ca
leaq 0x29a7(%rip), %rdi      # 0x6357
jmp 0x38ca
leaq 0x2955(%rip), %rdi      # 0x6311
jmp 0x38ca
jmp 0x3a3b
jmp 0x3a02
jmp 0x3a3b
jmp 0x3a3b
jmp 0x3a02
jmp 0x3a3b
jmp 0x3a3b
jmp 0x3a3b
jmp 0x3a0c
jmp 0x3a3b
jmp 0x3a3b
jmp 0x3a0c
jmp 0x3a3b
jmp 0x3a3b
jmp 0x39e1
jmp 0x3a5f
movq %rdx, %r15
movq %rax, %r14
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3a65
movq 0x20(%rsp), %rsi
jmp 0x3a55
jmp 0x3a5f
jmp 0x3a0c
jmp 0x3a5f
movq %rdx, %r15
movq %rax, %r14
jmp 0x3a1d
jmp 0x3a3b
movq %rdx, %r15
movq %rax, %r14
cmpl $0x0, (%r13)
jne 0x3a1d
movl %ebx, (%r13)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3a41
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2220
jmp 0x3a41
movq %rdx, %r15
movq %rax, %r14
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x3a65
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x2220
jmp 0x3a65
movq %rdx, %r15
movq %rax, %r14
movq %r14, %rdi
cmpl $0x1, %r15d
jne 0x3a80
movl %r15d, %esi
callq 0x2430
movl $0x1, %ebx
jmp 0x38b2
callq 0x23c0