// File: /workspace/github_c_makefile_star2_O3/pipde[P]deos-songlib/utils/identify/identify.c
// Function: main
int
main(int argc,char **argv)
    {
    int argIndex = 1;

    int i,index;
    double freq;
    FILE *in,*out;
    char *source = 0;
    RRA *r;

    argIndex = processOptions(argc,argv);

    if (argc-argIndex == 0)
        {
        in = stdin;
        out = stdout;
        }
    else if (argc-argIndex == 1)
        {
        source = argv[argIndex];
        in = OpenFile(source,"r");
        out = stdout;
        }
    else if (argc-argIndex == 2)
        {
        source = argv[argIndex];
        in = OpenFile(source,"r");
        out = OpenFile(argv[argIndex+1],"w");
        }
    else
        {
        printf("usage: %s [<input rra file> [<output wave file>]]\n",argv[0]);
        exit(-1);
        }

    r = readRRA(in,0);
    
    if (r->channels != 1)
        Fatal("%s only works on mono audio files\n",argv[0]);

    freq = processData(out,r);

    index = -1;
    for (i = 0; index < 0 && i < 120; ++i)
        {
        if (freq >= freqs[i] && freq < freqs[i+1])
            {
            if (freq - freqs[i] >= freqs[i+1] - freq)
                index = i+1;
            else
                index = i;
            }
        }

    if (Pitch && source && index < 0)
        printf("echo rraidentity failed to identify %s\n",source);
    else if (Pitch && source != 0)
        printf("rratune %f %s %s.repitch\n",
            freqs[index] / freq,source,source);
    else if (Pitch && index < 0)
        printf("echo rraidentity failed to identify %s\n",source);
    else if (Pitch)
        printf("rratune %f\n", freqs[index] / freq);
    else if (index < 0)
        printf("rraidentity failed to identify %s\n",source);
    else if (Note)
        printf("%s\n", notes[index]);
    else if (Frequency)
        printf("%f\n", freq);
    else
        printf("closest note to %s (freq = %f) is %s (freq = %f)\n"
            "error is %.2f%%, factor is %f\n",
            source,freq, notes[index],freqs[index],
            (1 - freqs[index] / freq) * 100, freqs[index] / freq
            );
            
    fclose(in);
    fclose(out);

    return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rdx
movl %edi, %ebx
movl $0x1, %r15d
cmpl $0x2, %edi
movq %rsi, -0x30(%rbp)
jl 0x2699
movl $0x1, %r15d
leaq 0x2a46(%rip), %r13      # 0x5038
movslq %r15d, %rax
movq (%rdx,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x2699
movb 0x2(%rsi), %r14b
testb %r14b, %r14b
je 0x2611
leaq 0x2(%rsi), %rdi
jmp 0x2616
movq 0x8(%rdx,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
leal -0x66(%rax), %ecx
cmpl $0xa, %ecx
ja 0x2660
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movb $0x1, 0x62c1(%rip)      # 0x88f4
jmp 0x265b
callq 0x2080
movq -0x30(%rbp), %rdx
movsd %xmm0, 0x628a(%rip)     # 0x88d0
movb $0x1, %r12b
jmp 0x267e
movb $0x1, 0x629e(%rip)      # 0x88f0
jmp 0x265b
movb $0x1, 0x6291(%rip)      # 0x88ec
xorl %r12d, %r12d
jmp 0x267e
cmpl $0x76, %eax
je 0x2bf6
xorl %r12d, %r12d
leaq 0x2cd0(%rip), %rdi      # 0x5343
xorl %eax, %eax
callq 0x2c34
movq -0x30(%rbp), %rdx
testb %r14b, %r14b
sete %al
andb %r12b, %al
movzbl %al, %eax
addl %eax, %r15d
incl %r15d
cmpl %ebx, %r15d
jl 0x25f2
subl %r15d, %ebx
jne 0x26c0
movq 0x5933(%rip), %rax      # 0x7fd8
movq (%rax), %r14
movq 0x5921(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x2726
cmpl $0x2, %ebx
je 0x26f4
cmpl $0x1, %ebx
jne 0x2c19
movslq %r15d, %rax
movq (%rdx,%rax,8), %rdi
leaq 0x2d68(%rip), %rsi      # 0x5444
movq %rdi, -0x38(%rbp)
callq 0x2cce
movq %rax, %r14
movq 0x58e1(%rip), %rax      # 0x7fd0
movq (%rax), %rax
jmp 0x2722
movslq %r15d, %rbx
movq (%rdx,%rbx,8), %rdi
leaq 0x2d42(%rip), %rsi      # 0x5444
movq %rdi, -0x38(%rbp)
movq %rdx, %r15
callq 0x2cce
movq %rax, %r14
movq 0x8(%r15,%rbx,8), %rdi
leaq 0x2b21(%rip), %rsi      # 0x523e
callq 0x2cce
movq %rax, -0x40(%rbp)
movq %r14, -0x48(%rbp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x3236
movq %rax, %r13
cmpl $0x1, (%rax)
je 0x2751
movq -0x30(%rbp), %rax
movq (%rax), %rsi
leaq 0x2b29(%rip), %rdi      # 0x5273
xorl %eax, %eax
callq 0x2c34
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%r13), %xmm0
movapd %xmm0, %xmm1
divsd 0x28a2(%rip), %xmm1     # 0x5008
cvttsd2si %xmm1, %r12d
divsd 0x289d(%rip), %xmm0     # 0x5010
mulsd 0x289d(%rip), %xmm0     # 0x5018
cvttsd2si %xmm0, %eax
movl %eax, 0x6173(%rip)      # 0x88f8
movl %r12d, %edi
shll $0x5, %edi
callq 0x2d53
movq %rax, %rcx
movq 0x18(%r13), %rax
movq (%rax), %r8
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%r13), %xmm0
movsd 0x6125(%rip), %xmm1     # 0x88d0
mulsd %xmm0, %xmm1
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%rcx)
leal (%r12,%r12,2), %eax
cmpl $0x2, %eax
jl 0x283d
cvttsd2si %xmm1, %edx
movslq %edx, %r9
leaq (%r8,%r9,4), %rdx
movl %eax, %esi
movl %r12d, %edi
leaq (%r8,%r9,4), %r8
addq $0x4, %r8
xorpd %xmm1, %xmm1
movl $0x1, %r9d
xorpd %xmm2, %xmm2
testl %r12d, %r12d
jle 0x2813
xorl %r10d, %r10d
movl (%rdx,%r10,4), %r11d
subl (%r8,%r10,4), %r11d
xorps %xmm3, %xmm3
cvtsi2sd %r11d, %xmm3
mulsd %xmm3, %xmm3
addsd %xmm3, %xmm2
incq %r10
cmpq %r10, %rdi
jne 0x27f3
xorps %xmm3, %xmm3
cvtsi2sd %r9d, %xmm3
addsd %xmm2, %xmm1
movapd %xmm1, %xmm4
divsd %xmm3, %xmm4
divsd %xmm4, %xmm2
movsd %xmm2, (%rcx,%r9,8)
incq %r9
addq $0x4, %r8
cmpq %rsi, %r9
jne 0x27e7
movl 0x60b5(%rip), %edi      # 0x88f8
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movl %edi, %esi
cmpl %eax, %edi
jge 0x28a0
movslq %edi, %rdx
leaq (%rcx,%rdx,8), %rdx
movl %edi, %esi
movapd %xmm2, %xmm3
movsd -0x8(%rdx), %xmm4
movsd (%rdx), %xmm2
movapd %xmm3, %xmm5
cmpltsd %xmm2, %xmm5
movapd %xmm5, %xmm6
andpd %xmm2, %xmm6
andnpd %xmm1, %xmm5
orpd %xmm6, %xmm5
movapd %xmm5, %xmm1
ucomisd %xmm2, %xmm4
maxsd %xmm3, %xmm2
ja 0x28a0
incl %esi
addq $0x8, %rdx
cmpl %esi, %eax
jne 0x285a
movapd %xmm1, %xmm3
movl %eax, %esi
jmp 0x2901
cmpl %eax, %esi
jge 0x28fd
movslq %esi, %r8
cltq
subq %r8, %rax
movl %esi, %edx
leaq (%rcx,%r8,8), %r8
xorl %r9d, %r9d
movsd (%r8,%r9,8), %xmm4
movslq %esi, %r10
movsd (%rcx,%r10,8), %xmm3
ucomisd %xmm4, %xmm3
jbe 0x28ce
leal (%rdx,%r9), %esi
movapd %xmm2, %xmm3
cmpltsd %xmm4, %xmm3
movapd %xmm3, %xmm5
andpd %xmm4, %xmm5
andnpd %xmm1, %xmm3
orpd %xmm5, %xmm3
maxsd %xmm2, %xmm4
incq %r9
movapd %xmm3, %xmm1
movapd %xmm4, %xmm2
cmpq %r9, %rax
jne 0x28b5
jmp 0x2901
movapd %xmm1, %xmm3
leal (%rdi,%rdi), %eax
movl %esi, %ebx
shrl $0x1f, %ebx
addl %esi, %ebx
sarl %ebx
movl %eax, -0x30(%rbp)
cmpl %eax, %ebx
jle 0x2a09
movslq %esi, %rax
movapd %xmm3, %xmm1
subsd (%rcx,%rax,8), %xmm1
mulsd 0x26f4(%rip), %xmm1     # 0x5020
addsd %xmm3, %xmm1
movl %edi, %r9d
shrl $0x1f, %r9d
addl %edi, %r9d
movl %r9d, %r10d
sarl %r10d
movl %r10d, %r11d
negl %r11d
andl $-0x2, %r9d
movslq %r10d, %rax
shlq $0x3, %rax
movq %rcx, %rdx
subq %rax, %rdx
movq %rdx, -0x50(%rbp)
movsd 0x26c5(%rip), %xmm2     # 0x5028
movl $0x2, %r13d
movq %rdi, %r8
leal (%rbx,%r11), %eax
leal (%rbx,%r10), %r14d
movl %ebx, %edx
cmpl %r14d, %eax
jge 0x29c1
movl %ebx, %eax
subl %r10d, %eax
movslq %ebx, %rdx
movq -0x50(%rbp), %rdi
leaq (%rdi,%rdx,8), %r15
movl %ebx, %edx
cmpl %r14d, %eax
jge 0x29b6
xorl %r12d, %r12d
movslq %edx, %rdi
movsd (%rcx,%rdi,8), %xmm3
ucomisd (%r15,%r12,8), %xmm3
jbe 0x29a9
leal (%rax,%r12), %edx
incq %r12
cmpl %r12d, %r9d
jne 0x2995
movl %r14d, %r12d
jmp 0x29b9
movl %eax, %r12d
incl %r12d
cmpl %r14d, %r12d
jl 0x298d
leal 0x2(%rbx), %eax
cmpl %eax, %edx
movl $0x0, %eax
cmovel %edx, %eax
leal -0x2(%rbx), %edi
cmpl %ebx, %edx
cmovel %edx, %eax
cmpl %edi, %edx
cmovel %edx, %eax
movq %r8, %rdi
cmpl %edi, %eax
jle 0x29f3
cltq
ucomisd (%rcx,%rax,8), %xmm1
jbe 0x29f3
xorps %xmm2, %xmm2
cvtsi2sd %r13d, %xmm2
incl %r13d
movl %esi, %eax
cltd
idivl %r13d
movl %eax, %ebx
cmpl -0x30(%rbp), %eax
jg 0x2969
jmp 0x2a11
movsd 0x2617(%rip), %xmm2     # 0x5028
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %edx, %edx
leaq 0x5722(%rip), %rax      # 0x8150
movq -0x48(%rbp), %rbx
movq -0x38(%rbp), %rsi
movsd (%rax,%rdx,8), %xmm1
ucomisd %xmm1, %xmm0
jb 0x2a62
movsd 0x8(%rax,%rdx,8), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x2a62
movapd %xmm0, %xmm3
subsd %xmm1, %xmm3
subsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
movl %edx, %ecx
sbbl $-0x1, %ecx
testl %ecx, %ecx
jns 0x2a73
leaq 0x1(%rdx), %rdi
cmpq $0x77, %rdx
movq %rdi, %rdx
jb 0x2a36
movb 0x5e73(%rip), %dl       # 0x88ec
testq %rsi, %rsi
setne %dil
andb %dl, %dil
testl %ecx, %ecx
jns 0x2a9f
testb %dil, %dil
je 0x2a9f
leaq 0x2803(%rip), %rdi      # 0x5296
xorl %eax, %eax
callq 0x20b0
jmp 0x2b7e
testb %dil, %dil
je 0x2aca
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
leaq 0x2807(%rip), %rdi      # 0x52be
movapd %xmm1, %xmm0
movq %rsi, %rdx
movb $0x1, %al
callq 0x20b0
jmp 0x2b7e
testl %ecx, %ecx
setns %r8b
movl %edx, %edi
notb %dil
orb %r8b, %dil
testb $0x1, %dil
je 0x2a8c
testb $0x1, %dl
je 0x2b03
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
leaq 0x27e2(%rip), %rdi      # 0x52d8
movapd %xmm1, %xmm0
movb $0x1, %al
callq 0x20b0
jmp 0x2b7e
testl %ecx, %ecx
js 0x2b24
cmpb $0x1, 0x5de2(%rip)      # 0x88f0
jne 0x2b30
movl %ecx, %eax
leaq 0x5997(%rip), %rcx      # 0x84b0
movq (%rcx,%rax,8), %rdi
callq 0x2070
jmp 0x2b7e
leaq 0x2770(%rip), %rdi      # 0x529b
jmp 0x2a93
cmpb $0x1, 0x5dbd(%rip)      # 0x88f4
jne 0x2b42
leaq 0x27a0(%rip), %rdi      # 0x52e0
jmp 0x2afa
movl %ecx, %ecx
leaq 0x5965(%rip), %rdx      # 0x84b0
movq (%rdx,%rcx,8), %rdx
movsd (%rax,%rcx,8), %xmm1
movapd %xmm1, %xmm3
divsd %xmm0, %xmm3
movsd 0x24c4(%rip), %xmm2     # 0x5028
subsd %xmm3, %xmm2
mulsd 0x24c0(%rip), %xmm2     # 0x5030
leaq 0x276d(%rip), %rdi      # 0x52e4
movb $0x4, %al
callq 0x20b0
movq %rbx, %rdi
callq 0x2090
movq -0x40(%rbp), %rdi
callq 0x2090
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x27b6(%rip), %rdi      # 0x535d
callq 0x2070
leaq 0x27bc(%rip), %rdi      # 0x536f
callq 0x2070
leaq 0x27dc(%rip), %rdi      # 0x539b
callq 0x2070
leaq 0x2800(%rip), %rdi      # 0x53cb
callq 0x2070
leaq 0x281a(%rip), %rdi      # 0x53f1
callq 0x2070
leaq 0x283f(%rip), %rdi      # 0x5422
callq 0x2070
leaq 0x2857(%rip), %rdi      # 0x5446
callq 0x2070
jmp 0x2c12
movq 0x5543(%rip), %rsi      # 0x8140
movq 0x5544(%rip), %rdx      # 0x8148
leaq 0x2729(%rip), %rdi      # 0x5334
xorl %eax, %eax
callq 0x20b0
xorl %edi, %edi
callq 0x2200
movq (%rdx), %rsi
leaq 0x261d(%rip), %rdi      # 0x5240
xorl %eax, %eax
callq 0x20b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2200