// File: /workspace/github_c_makefile_star2_O1/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 0x2669
movl $0x1, %r15d
leaq 0x2a76(%rip), %r13      # 0x5038
movslq %r15d, %rax
movq (%rdx,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x2669
movb 0x2(%rsi), %r14b
testb %r14b, %r14b
je 0x25e1
leaq 0x2(%rsi), %rdi
jmp 0x25e6
movq 0x8(%rdx,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
leal -0x66(%rax), %ecx
cmpl $0xa, %ecx
ja 0x2630
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movb $0x1, 0x62f1(%rip)      # 0x88f4
jmp 0x262b
callq 0x2080
movq -0x30(%rbp), %rdx
movsd %xmm0, 0x62ba(%rip)     # 0x88d0
movb $0x1, %r12b
jmp 0x264e
movb $0x1, 0x62ce(%rip)      # 0x88f0
jmp 0x262b
movb $0x1, 0x62c1(%rip)      # 0x88ec
xorl %r12d, %r12d
jmp 0x264e
cmpl $0x76, %eax
je 0x2bc8
xorl %r12d, %r12d
leaq 0x2d00(%rip), %rdi      # 0x5343
xorl %eax, %eax
callq 0x2c08
movq -0x30(%rbp), %rdx
testb %r14b, %r14b
sete %al
andb %r12b, %al
movzbl %al, %eax
addl %eax, %r15d
incl %r15d
cmpl %ebx, %r15d
jl 0x25c2
subl %r15d, %ebx
jne 0x2690
movq 0x5963(%rip), %rax      # 0x7fd8
movq (%rax), %r14
movq 0x5951(%rip), %rax      # 0x7fd0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x26f6
cmpl $0x2, %ebx
je 0x26c4
cmpl $0x1, %ebx
jne 0x2beb
movslq %r15d, %rax
movq (%rdx,%rax,8), %rdi
leaq 0x2d98(%rip), %rsi      # 0x5444
movq %rdi, -0x38(%rbp)
callq 0x2ca2
movq %rax, %r14
movq 0x5911(%rip), %rax      # 0x7fd0
movq (%rax), %rax
jmp 0x26f2
movslq %r15d, %rbx
movq (%rdx,%rbx,8), %rdi
leaq 0x2d72(%rip), %rsi      # 0x5444
movq %rdi, -0x38(%rbp)
movq %rdx, %r15
callq 0x2ca2
movq %rax, %r14
movq 0x8(%r15,%rbx,8), %rdi
leaq 0x2b51(%rip), %rsi      # 0x523e
callq 0x2ca2
movq %rax, -0x40(%rbp)
movq %r14, -0x48(%rbp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x320e
movq %rax, %r13
cmpl $0x1, (%rax)
je 0x2721
movq -0x30(%rbp), %rax
movq (%rax), %rsi
leaq 0x2b59(%rip), %rdi      # 0x5273
xorl %eax, %eax
callq 0x2c08
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%r13), %xmm0
movapd %xmm0, %xmm1
divsd 0x28d2(%rip), %xmm1     # 0x5008
cvttsd2si %xmm1, %r12d
divsd 0x28cd(%rip), %xmm0     # 0x5010
mulsd 0x28cd(%rip), %xmm0     # 0x5018
cvttsd2si %xmm0, %eax
movl %eax, 0x61a3(%rip)      # 0x88f8
movl %r12d, %edi
shll $0x5, %edi
callq 0x2d35
movq %rax, %rcx
movq 0x18(%r13), %rax
movq (%rax), %r8
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%r13), %xmm0
movsd 0x6155(%rip), %xmm1     # 0x88d0
mulsd %xmm0, %xmm1
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%rcx)
leal (%r12,%r12,2), %eax
cmpl $0x2, %eax
jl 0x280d
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 0x27e3
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 0x27c3
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 0x27b7
movl 0x60e5(%rip), %edi      # 0x88f8
xorpd %xmm1, %xmm1
movl %edi, %esi
cmpl %eax, %edi
jge 0x286a
movslq %edi, %rdx
leaq (%rcx,%rdx,8), %rdx
movl %edi, %esi
xorpd %xmm2, %xmm2
movsd -0x8(%rdx), %xmm4
movsd (%rdx), %xmm3
movapd %xmm2, %xmm5
cmpltsd %xmm3, %xmm5
movapd %xmm5, %xmm6
andpd %xmm3, %xmm6
andnpd %xmm1, %xmm5
orpd %xmm6, %xmm5
movapd %xmm5, %xmm1
ucomisd %xmm3, %xmm4
ja 0x286a
maxsd %xmm2, %xmm3
incl %esi
addq $0x8, %rdx
movapd %xmm3, %xmm2
cmpl %esi, %eax
jne 0x282a
movl %eax, %esi
cmpl %eax, %esi
jge 0x28cb
movslq %esi, %r8
cltq
subq %r8, %rax
movl %esi, %edx
leaq (%rcx,%r8,8), %r8
xorl %r9d, %r9d
movapd %xmm1, %xmm3
movsd (%r8,%r9,8), %xmm4
movslq %esi, %r10
movsd (%rcx,%r10,8), %xmm2
ucomisd %xmm4, %xmm2
jbe 0x289c
leal (%rdx,%r9), %esi
movapd %xmm3, %xmm2
cmpltsd %xmm4, %xmm2
movapd %xmm2, %xmm5
andpd %xmm4, %xmm5
andnpd %xmm1, %xmm2
orpd %xmm5, %xmm2
maxsd %xmm3, %xmm4
incq %r9
movapd %xmm2, %xmm1
movapd %xmm4, %xmm3
cmpq %r9, %rax
jne 0x2883
jmp 0x28cf
movapd %xmm1, %xmm2
leal (%rdi,%rdi), %eax
movl %esi, %ebx
shrl $0x1f, %ebx
addl %esi, %ebx
sarl %ebx
movl %eax, -0x30(%rbp)
cmpl %eax, %ebx
jle 0x29d7
movslq %esi, %rax
movapd %xmm2, %xmm1
subsd (%rcx,%rax,8), %xmm1
mulsd 0x2726(%rip), %xmm1     # 0x5020
addsd %xmm2, %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 0x26f7(%rip), %xmm2     # 0x5028
movl $0x2, %r13d
movq %rdi, %r8
leal (%rbx,%r11), %eax
leal (%rbx,%r10), %r14d
movl %ebx, %edx
cmpl %r14d, %eax
jge 0x298f
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 0x2984
xorl %r12d, %r12d
movslq %edx, %rdi
movsd (%rcx,%rdi,8), %xmm3
ucomisd (%r15,%r12,8), %xmm3
jbe 0x2977
leal (%rax,%r12), %edx
incq %r12
cmpl %r12d, %r9d
jne 0x2963
movl %r14d, %r12d
jmp 0x2987
movl %eax, %r12d
incl %r12d
cmpl %r14d, %r12d
jl 0x295b
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 0x29c1
cltq
ucomisd (%rcx,%rax,8), %xmm1
jbe 0x29c1
xorps %xmm2, %xmm2
cvtsi2sd %r13d, %xmm2
incl %r13d
movl %esi, %eax
cltd
idivl %r13d
movl %eax, %ebx
cmpl -0x30(%rbp), %eax
jg 0x2937
jmp 0x29df
movsd 0x2649(%rip), %xmm2     # 0x5028
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
divsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %edx, %edx
leaq 0x5754(%rip), %rax      # 0x8150
movq -0x48(%rbp), %rbx
movq -0x38(%rbp), %rsi
movsd (%rax,%rdx,8), %xmm1
ucomisd %xmm1, %xmm0
jb 0x2a34
movsd 0x8(%rax,%rdx,8), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x2a34
movapd %xmm0, %xmm3
subsd %xmm1, %xmm3
subsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
jb 0x2a32
leal 0x1(%rdx), %ecx
jmp 0x2a34
movl %edx, %ecx
testl %ecx, %ecx
jns 0x2a45
leaq 0x1(%rdx), %rdi
cmpq $0x77, %rdx
movq %rdi, %rdx
jb 0x2a04
movb 0x5ea1(%rip), %dl       # 0x88ec
testq %rsi, %rsi
setne %dil
andb %dl, %dil
testl %ecx, %ecx
jns 0x2a71
testb %dil, %dil
je 0x2a71
leaq 0x2831(%rip), %rdi      # 0x5296
xorl %eax, %eax
callq 0x20b0
jmp 0x2b50
testb %dil, %dil
je 0x2a9c
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
leaq 0x2835(%rip), %rdi      # 0x52be
movapd %xmm1, %xmm0
movq %rsi, %rdx
movb $0x1, %al
callq 0x20b0
jmp 0x2b50
testl %ecx, %ecx
setns %r8b
movl %edx, %edi
notb %dil
orb %r8b, %dil
testb $0x1, %dil
je 0x2a5e
testb $0x1, %dl
je 0x2ad5
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
divsd %xmm0, %xmm1
leaq 0x2810(%rip), %rdi      # 0x52d8
movapd %xmm1, %xmm0
movb $0x1, %al
callq 0x20b0
jmp 0x2b50
testl %ecx, %ecx
js 0x2af6
cmpb $0x1, 0x5e10(%rip)      # 0x88f0
jne 0x2b02
movl %ecx, %eax
leaq 0x59c5(%rip), %rcx      # 0x84b0
movq (%rcx,%rax,8), %rdi
callq 0x2070
jmp 0x2b50
leaq 0x279e(%rip), %rdi      # 0x529b
jmp 0x2a65
cmpb $0x1, 0x5deb(%rip)      # 0x88f4
jne 0x2b14
leaq 0x27ce(%rip), %rdi      # 0x52e0
jmp 0x2acc
movl %ecx, %ecx
leaq 0x5993(%rip), %rdx      # 0x84b0
movq (%rdx,%rcx,8), %rdx
movsd (%rax,%rcx,8), %xmm1
movapd %xmm1, %xmm3
divsd %xmm0, %xmm3
movsd 0x24f2(%rip), %xmm2     # 0x5028
subsd %xmm3, %xmm2
mulsd 0x24ee(%rip), %xmm2     # 0x5030
leaq 0x279b(%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 0x27e4(%rip), %rdi      # 0x535d
callq 0x2070
leaq 0x27ea(%rip), %rdi      # 0x536f
callq 0x2070
leaq 0x280a(%rip), %rdi      # 0x539b
callq 0x2070
leaq 0x282e(%rip), %rdi      # 0x53cb
callq 0x2070
leaq 0x2848(%rip), %rdi      # 0x53f1
callq 0x2070
leaq 0x286d(%rip), %rdi      # 0x5422
callq 0x2070
leaq 0x2885(%rip), %rdi      # 0x5446
callq 0x2070
jmp 0x2be4
movq 0x5571(%rip), %rsi      # 0x8140
movq 0x5572(%rip), %rdx      # 0x8148
leaq 0x2757(%rip), %rdi      # 0x5334
xorl %eax, %eax
callq 0x20b0
xorl %edi, %edi
callq 0x2200
movq (%rdx), %rsi
leaq 0x264b(%rip), %rdi      # 0x5240
xorl %eax, %eax
callq 0x20b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2200
nop