// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %r15
leaq 0x2ccb(%rip), %r13      # 0x5038
movq %rsi, -0x30(%rbp)
movslq %r15d, %r12
cmpl %r15d, %ebx
jle 0x241d
movq (%rdx,%r12,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x241d
movb 0x2(%rsi), %r14b
testb %r14b, %r14b
je 0x2399
leaq 0x2(%rsi), %rdi
jmp 0x239e
movq 0x8(%rdx,%r12,8), %rdi
movzbl 0x1(%rsi), %eax
leal -0x66(%rax), %ecx
cmpl $0xa, %ecx
ja 0x23e8
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movb $0x1, 0x6539(%rip)      # 0x88f4
jmp 0x23e3
callq 0x2080
movq -0x30(%rbp), %rdx
movsd %xmm0, 0x6502(%rip)     # 0x88d0
movb $0x1, %r12b
jmp 0x2406
movb $0x1, 0x6516(%rip)      # 0x88f0
jmp 0x23e3
movb $0x1, 0x6509(%rip)      # 0x88ec
xorl %r12d, %r12d
jmp 0x2406
cmpl $0x76, %eax
je 0x291b
xorl %r12d, %r12d
leaq 0x2f48(%rip), %rdi      # 0x5343
xorl %eax, %eax
callq 0x2958
movq -0x30(%rbp), %rdx
testb %r14b, %r14b
sete %al
andb %r12b, %al
movzbl %al, %eax
addl %eax, %r15d
incl %r15d
jmp 0x2371
subl %r15d, %ebx
jne 0x2444
movq 0x5baf(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
movq 0x5b9d(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x24a7
cmpl $0x2, %ebx
je 0x2475
cmpl $0x1, %ebx
jne 0x293e
movq (%rdx,%r12,8), %rdi
leaq 0x2fe7(%rip), %rsi      # 0x5444
movq %rdi, -0x38(%rbp)
callq 0x2a88
movq %rax, %rcx
movq 0x5b60(%rip), %rax      # 0x7fd0
movq (%rax), %rax
jmp 0x24a3
movq (%rdx,%r12,8), %rdi
leaq 0x2fc4(%rip), %rsi      # 0x5444
movq %rdi, -0x38(%rbp)
movq %rdx, %r14
callq 0x2a88
movq %rax, %rbx
movq 0x8(%r14,%r12,8), %rdi
leaq 0x2da3(%rip), %rsi      # 0x523e
callq 0x2a88
movq %rbx, %rcx
movq %rax, -0x40(%rbp)
xorl %r14d, %r14d
movq %rcx, -0x50(%rbp)
movq %rcx, %rdi
xorl %esi, %esi
callq 0x2f55
movq %rax, %r13
cmpl $0x1, (%rax)
je 0x24d5
movq -0x30(%rbp), %rax
movq (%rax), %rsi
leaq 0x2da5(%rip), %rdi      # 0x5273
xorl %eax, %eax
callq 0x2958
cvtsi2sdl 0x4(%r13), %xmm0
movapd %xmm0, %xmm1
divsd 0x2b21(%rip), %xmm1     # 0x5008
cvttsd2si %xmm1, %r12d
divsd 0x2b1c(%rip), %xmm0     # 0x5010
mulsd 0x2b1c(%rip), %xmm0     # 0x5018
cvttsd2si %xmm0, %eax
movl %eax, 0x63f2(%rip)      # 0x88f8
movl %r12d, %edi
shll $0x5, %edi
callq 0x2b0d
movq %rax, %rcx
movq 0x18(%r13), %rax
movq (%rax), %rdi
cvtsi2sdl 0x4(%r13), %xmm0
movsd 0x63a7(%rip), %xmm1     # 0x88d0
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %eax
movslq %eax, %r8
leaq (%rdi,%r8,4), %rdx
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%rcx)
leal (%r12,%r12,2), %esi
testl %r12d, %r12d
cmovlel %r14d, %r12d
movslq %esi, %rax
leaq (%rdi,%r8,4), %rdi
addq $0x4, %rdi
xorpd %xmm1, %xmm1
pushq $0x1
popq %r8
cmpq %rax, %r8
jge 0x25b2
xorpd %xmm2, %xmm2
xorl %r9d, %r9d
cmpq %r9, %r12
je 0x258e
movl (%rdx,%r9,4), %r10d
subl (%rdi,%r9,4), %r10d
cvtsi2sd %r10d, %xmm3
mulsd %xmm3, %xmm3
addsd %xmm3, %xmm2
incq %r9
jmp 0x256f
addsd %xmm2, %xmm1
cvtsi2sd %r8d, %xmm3
movapd %xmm1, %xmm4
divsd %xmm3, %xmm4
divsd %xmm4, %xmm2
movsd %xmm2, (%rcx,%r8,8)
incq %r8
addq $0x4, %rdi
jmp 0x2563
movslq 0x633f(%rip), %rdx      # 0x88f8
cmpl %esi, %edx
cmovgl %edx, %esi
xorpd %xmm2, %xmm2
xorpd %xmm3, %xmm3
movq %rdx, -0x30(%rbp)
cmpq %rax, %rdx
jge 0x260a
movsd -0x8(%rcx,%rdx,8), %xmm4
movsd (%rcx,%rdx,8), %xmm1
movapd %xmm3, %xmm5
cmpltsd %xmm1, %xmm5
movapd %xmm5, %xmm6
andpd %xmm1, %xmm6
andnpd %xmm2, %xmm5
orpd %xmm6, %xmm5
movapd %xmm5, %xmm2
ucomisd %xmm1, %xmm4
maxsd %xmm3, %xmm1
ja 0x2610
incq %rdx
movapd %xmm1, %xmm3
jmp 0x25ca
movapd %xmm3, %xmm1
jmp 0x2612
movl %edx, %esi
movslq %esi, %rdx
movslq %esi, %rdi
cmpq %rax, %rdx
jge 0x265d
movsd (%rcx,%rdx,8), %xmm3
movsd (%rcx,%rdi,8), %xmm4
ucomisd %xmm3, %xmm4
movl %edx, %edi
ja 0x2631
movl %esi, %edi
movapd %xmm1, %xmm4
cmpltsd %xmm3, %xmm4
movapd %xmm4, %xmm5
andpd %xmm3, %xmm5
andnpd %xmm2, %xmm4
orpd %xmm5, %xmm4
maxsd %xmm1, %xmm3
incq %rdx
movapd %xmm4, %xmm2
movapd %xmm3, %xmm1
movl %edi, %esi
jmp 0x2615
movapd %xmm2, %xmm1
subsd (%rcx,%rdi,8), %xmm1
mulsd 0x29b2(%rip), %xmm1     # 0x5020
addsd %xmm2, %xmm1
movq -0x30(%rbp), %r9
leal (%r9,%r9), %eax
movl %eax, -0x44(%rbp)
pushq $-0x2
popq %rdi
movl %r9d, %eax
cltd
idivl %edi
movl %eax, %r8d
pushq $0x2
popq %r11
movl %r9d, %eax
cltd
idivl %r11d
movl %eax, %r9d
movsd 0x2989(%rip), %xmm2     # 0x5028
movl %esi, %eax
cltd
idivl %r11d
cmpl -0x44(%rbp), %eax
jle 0x273e
leal (%rax,%r8), %ebx
leal (%rax,%r9), %edx
movl %eax, %r12d
subl %r9d, %r12d
movslq %r12d, %r13
cmpl %r13d, %edx
movl %r13d, %edi
cmovgl %edx, %edi
movslq %edi, %r14
leal 0x1(%r14), %edi
leaq (%rcx,%r13,8), %r15
subq %r13, %r14
movl %eax, %r13d
cmpl %edx, %ebx
jge 0x2702
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x26fe
movslq %r13d, %r10
movsd (%rcx,%r10,8), %xmm3
ucomisd (%r15,%rbx,8), %xmm3
jbe 0x26f9
leal (%r12,%rbx), %r13d
incq %rbx
jmp 0x26df
movl %edi, %ebx
jmp 0x26d9
leal 0x2(%rax), %edx
cmpl %edx, %r13d
movl $0x0, %edx
cmovel %r13d, %edx
leal -0x2(%rax), %edi
cmpl %eax, %r13d
cmovel %r13d, %edx
cmpl %edi, %r13d
cmovel %r13d, %edx
cmpl -0x30(%rbp), %edx
jle 0x2736
movslq %edx, %rax
ucomisd (%rcx,%rax,8), %xmm1
jbe 0x2736
cvtsi2sd %r11d, %xmm2
incl %r11d
jmp 0x269f
cvtsi2sd %esi, %xmm1
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
pushq $-0x1
popq %rcx
xorl %edx, %edx
leaq 0x59fa(%rip), %rax      # 0x8150
movq -0x38(%rbp), %rsi
testl %ecx, %ecx
jns 0x2797
cmpq $0x77, %rdx
ja 0x2797
movsd (%rax,%rdx,8), %xmm1
ucomisd %xmm1, %xmm0
jb 0x277b
movsd 0x8(%rax,%rdx,8), %xmm2
ucomisd %xmm0, %xmm2
ja 0x2780
incq %rdx
jmp 0x275a
movapd %xmm0, %xmm3
subsd %xmm1, %xmm3
subsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
movl %edx, %ecx
sbbl $-0x1, %ecx
jmp 0x277b
movb 0x614f(%rip), %dl       # 0x88ec
testq %rsi, %rsi
setne %dil
andb %dl, %dil
testl %ecx, %ecx
jns 0x27c3
testb %dil, %dil
je 0x27c3
leaq 0x2adf(%rip), %rdi      # 0x5296
xorl %eax, %eax
callq 0x20b0
jmp 0x28a2
testb %dil, %dil
je 0x27ee
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
leaq 0x2ae3(%rip), %rdi      # 0x52be
movapd %xmm1, %xmm0
movq %rsi, %rdx
movb $0x1, %al
callq 0x20b0
jmp 0x28a2
testl %ecx, %ecx
setns %r8b
movl %edx, %edi
notb %dil
orb %r8b, %dil
testb $0x1, %dil
je 0x27b0
testb $0x1, %dl
je 0x2827
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
leaq 0x2abe(%rip), %rdi      # 0x52d8
movapd %xmm1, %xmm0
movb $0x1, %al
callq 0x20b0
jmp 0x28a2
testl %ecx, %ecx
js 0x2848
cmpb $0x1, 0x60be(%rip)      # 0x88f0
jne 0x2854
movl %ecx, %eax
leaq 0x5c73(%rip), %rcx      # 0x84b0
movq (%rcx,%rax,8), %rdi
callq 0x2070
jmp 0x28a2
leaq 0x2a4c(%rip), %rdi      # 0x529b
jmp 0x27b7
cmpb $0x1, 0x6099(%rip)      # 0x88f4
jne 0x2866
leaq 0x2a7c(%rip), %rdi      # 0x52e0
jmp 0x281e
movl %ecx, %ecx
leaq 0x5c41(%rip), %rdx      # 0x84b0
movq (%rdx,%rcx,8), %rdx
movsd (%rax,%rcx,8), %xmm1
movapd %xmm1, %xmm3
divsd %xmm0, %xmm3
movsd 0x27a0(%rip), %xmm2     # 0x5028
subsd %xmm3, %xmm2
mulsd 0x279c(%rip), %xmm2     # 0x5030
leaq 0x2a49(%rip), %rdi      # 0x52e4
movb $0x4, %al
callq 0x20b0
movq -0x50(%rbp), %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 0x2a91(%rip), %rdi      # 0x535d
callq 0x2070
leaq 0x2a97(%rip), %rdi      # 0x536f
callq 0x2070
leaq 0x2ab7(%rip), %rdi      # 0x539b
callq 0x2070
leaq 0x2adb(%rip), %rdi      # 0x53cb
callq 0x2070
leaq 0x2af5(%rip), %rdi      # 0x53f1
callq 0x2070
leaq 0x2b1a(%rip), %rdi      # 0x5422
callq 0x2070
leaq 0x2b32(%rip), %rdi      # 0x5446
callq 0x2070
jmp 0x2937
movq 0x581e(%rip), %rsi      # 0x8140
movq 0x581f(%rip), %rdx      # 0x8148
leaq 0x2a04(%rip), %rdi      # 0x5334
xorl %eax, %eax
callq 0x20b0
xorl %edi, %edi
callq 0x2200
movq (%rdx), %rsi
leaq 0x28f8(%rip), %rdi      # 0x5240
xorl %eax, %eax
callq 0x20b0
pushq $-0x1
popq %rdi
callq 0x2200
nop