// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x14(%rbp)
movq $0x0, -0x40(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x26f0
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x0, %eax
jne 0x2370
movq 0x6c82(%rip), %rax      # 0x8fd8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq 0x6c6c(%rip), %rax      # 0x8fd0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x2424
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x1, %eax
jne 0x23af
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq 0x4530(%rip), %rsi      # 0x68c6
callq 0x2f20
movq %rax, -0x30(%rbp)
movq 0x6c2a(%rip), %rax      # 0x8fd0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x2422
movl -0x8(%rbp), %eax
subl -0x14(%rbp), %eax
cmpl $0x2, %eax
jne 0x2401
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq 0x44f1(%rip), %rsi      # 0x68c6
callq 0x2f20
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3e50(%rip), %rsi      # 0x6246
callq 0x2f20
movq %rax, -0x38(%rbp)
jmp 0x2420
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x3e39(%rip), %rdi      # 0x6248
movb $0x0, %al
callq 0x2090
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21d0
jmp 0x2422
jmp 0x2424
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3890
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0x1, (%rax)
je 0x2453
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x3e2f(%rip), %rdi      # 0x627b
movb $0x0, %al
callq 0x2dd0
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x28e0
movsd %xmm0, -0x28(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x18(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x49(%rbp)
jge 0x2488
cmpl $0x78, -0x18(%rbp)
setl %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x2494
jmp 0x2523
movsd -0x28(%rbp), %xmm0
movslq -0x18(%rbp), %rcx
leaq 0x6c8c(%rip), %rax      # 0x9130
ucomisd (%rax,%rcx,8), %xmm0
jb 0x2513
movsd -0x28(%rbp), %xmm1
movl -0x18(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x6c70(%rip), %rax      # 0x9130
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2513
movsd -0x28(%rbp), %xmm0
movslq -0x18(%rbp), %rcx
leaq 0x6c55(%rip), %rax      # 0x9130
subsd (%rax,%rcx,8), %xmm0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x6c40(%rip), %rax      # 0x9130
movsd (%rax,%rcx,8), %xmm1
subsd -0x28(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x250b
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2511
movl -0x18(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x2513
jmp 0x2515
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x2473
cmpl $0x0, 0x73ba(%rip)      # 0x98e4
je 0x2550
cmpq $0x0, -0x40(%rbp)
je 0x2550
cmpl $0x0, -0x1c(%rbp)
jge 0x2550
movq -0x40(%rbp), %rsi
leaq 0x3d5a(%rip), %rdi      # 0x629e
movb $0x0, %al
callq 0x2090
jmp 0x26d1
cmpl $0x0, 0x738d(%rip)      # 0x98e4
je 0x2590
cmpq $0x0, -0x40(%rbp)
je 0x2590
movslq -0x1c(%rbp), %rcx
leaq 0x6bc5(%rip), %rax      # 0x9130
movsd (%rax,%rcx,8), %xmm0
divsd -0x28(%rbp), %xmm0
movq -0x40(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq 0x3d42(%rip), %rdi      # 0x62c6
movb $0x1, %al
callq 0x2090
jmp 0x26cf
cmpl $0x0, 0x734d(%rip)      # 0x98e4
je 0x25b6
cmpl $0x0, -0x1c(%rbp)
jge 0x25b6
movq -0x40(%rbp), %rsi
leaq 0x3cf4(%rip), %rdi      # 0x629e
movb $0x0, %al
callq 0x2090
jmp 0x26cd
cmpl $0x0, 0x7327(%rip)      # 0x98e4
je 0x25e7
movslq -0x1c(%rbp), %rcx
leaq 0x6b66(%rip), %rax      # 0x9130
movsd (%rax,%rcx,8), %xmm0
divsd -0x28(%rbp), %xmm0
leaq 0x3d05(%rip), %rdi      # 0x62e0
movb $0x1, %al
callq 0x2090
jmp 0x26cb
cmpl $0x0, -0x1c(%rbp)
jge 0x2604
movq -0x40(%rbp), %rsi
leaq 0x3cab(%rip), %rdi      # 0x62a3
movb $0x0, %al
callq 0x2090
jmp 0x26c9
cmpl $0x0, 0x72dd(%rip)      # 0x98e8
je 0x262f
movslq -0x1c(%rbp), %rcx
leaq 0x6e78(%rip), %rax      # 0x9490
movq (%rax,%rcx,8), %rsi
leaq 0x41f5(%rip), %rdi      # 0x6818
movb $0x0, %al
callq 0x2090
jmp 0x26c7
cmpl $0x0, 0x72b6(%rip)      # 0x98ec
je 0x264d
movsd -0x28(%rbp), %xmm0
leaq 0x3ca4(%rip), %rdi      # 0x62e8
movb $0x1, %al
callq 0x2090
jmp 0x26c5
movq -0x40(%rbp), %rsi
movsd -0x28(%rbp), %xmm0
movslq -0x1c(%rbp), %rcx
leaq 0x6e2f(%rip), %rax      # 0x9490
movq (%rax,%rcx,8), %rdx
movslq -0x1c(%rbp), %rcx
leaq 0x6ac0(%rip), %rax      # 0x9130
movsd (%rax,%rcx,8), %xmm1
movslq -0x1c(%rbp), %rcx
leaq 0x6ab0(%rip), %rax      # 0x9130
movsd (%rax,%rcx,8), %xmm3
divsd -0x28(%rbp), %xmm3
movsd 0x397e(%rip), %xmm2     # 0x6010
subsd %xmm3, %xmm2
movsd 0x396a(%rip), %xmm3     # 0x6008
mulsd %xmm3, %xmm2
movslq -0x1c(%rbp), %rcx
leaq 0x6a83(%rip), %rax      # 0x9130
movsd (%rax,%rcx,8), %xmm3
divsd -0x28(%rbp), %xmm3
leaq 0x3c2e(%rip), %rdi      # 0x62ec
movb $0x4, %al
callq 0x2090
jmp 0x26c7
jmp 0x26c9
jmp 0x26cb
jmp 0x26cd
jmp 0x26cf
jmp 0x26d1
movq -0x30(%rbp), %rdi
callq 0x2070
movq -0x38(%rbp), %rdi
callq 0x2070
xorl %eax, %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)