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

    int i,count,prev,curr;
    double freq;
    FILE *in,*out;
    char *source = 0;
    RRA *h;
    static int skip;

    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>]\n",argv[0]);
        exit(-1);
        }

    h = newRRAHeader();
    
    readRRAHeader(in,h,0);

    if (h->channels != 1)
        Fatal("%s requires a mono audio file\n",argv[0]);

    /* skip over the first part */

    skip = initialOffset * h->sampleRate;
    printf("skip is %d\n",skip);
    for (i = 0; i < skip; ++i)
        (void) readRRAAmplitude(in,out,h->bitsPerSample,outputComment);

    /* find first upward zero */

    prev = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);
    curr = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);

    while (prev >= 0 || curr != 0)
        {
        prev = curr;
        curr = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);
        }

    count = 0;
    while (count < 2000)
        {
        prev = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);
        curr = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);
        count += 2;

        /* find next upward zero */
    
        while (prev >= 0 || curr != 0)
            {
            prev = curr;
            curr = readRRAAmplitude(in,out,h->bitsPerSample,outputComment);
            ++count;
            }

        freq = h->sampleRate / (double) count;
        printf("possible wavelength/frequency/note: %d/%f/%s\n",
            count,freq,closestNote(freq));
        }

    fclose(in);
    fclose(out);

    return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r12
movl %edi, %ebx
movl $0x1, %r15d
cmpl $0x2, %edi
jl 0x26b7
movl $0x1, %r15d
movslq %r15d, %rax
movq (%r12,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x26b7
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x265d
leaq 0x2(%rsi), %rdi
jmp 0x2662
movq 0x8(%r12,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x6f, %eax
je 0x2690
cmpl $0x68, %eax
je 0x2926
cmpl $0x76, %eax
je 0x2908
xorl %r14d, %r14d
leaq 0x2be1(%rip), %rdi      # 0x5268
xorl %eax, %eax
callq 0x29a0
jmp 0x26a0
callq 0x2080
movsd %xmm0, 0x6233(%rip)     # 0x88d0
movb $0x1, %r14b
testb %r13b, %r13b
sete %al
andb %r14b, %al
movzbl %al, %eax
addl %eax, %r15d
incl %r15d
cmpl %ebx, %r15d
jl 0x2642
subl %r15d, %ebx
jne 0x26c8
movq 0x5915(%rip), %rax      # 0x7fd8
movq (%rax), %r13
jmp 0x26ec
cmpl $0x2, %ebx
je 0x26f8
cmpl $0x1, %ebx
jne 0x2981
movslq %r15d, %rax
movq (%r12,%rax,8), %rdi
leaq 0x2c86(%rip), %rsi      # 0x536a
callq 0x2a3a
movq %rax, %r13
movq 0x58dd(%rip), %rax      # 0x7fd0
movq (%rax), %r14
jmp 0x2722
movslq %r15d, %rbx
movq (%r12,%rbx,8), %rdi
leaq 0x2c64(%rip), %rsi      # 0x536a
callq 0x2a3a
movq %rax, %r13
movq 0x8(%r12,%rbx,8), %rdi
leaq 0x2ac6(%rip), %rsi      # 0x51e0
callq 0x2a3a
movq %rax, %r14
callq 0x2cab
movq %rax, %r15
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x30d1
cmpl $0x1, (%r15)
je 0x274f
movq (%r12), %rsi
leaq 0x2ab8(%rip), %rdi      # 0x5200
xorl %eax, %eax
callq 0x29a0
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%r15), %xmm0
mulsd 0x6170(%rip), %xmm0     # 0x88d0
cvttsd2si %xmm0, %esi
movl %esi, 0x6182(%rip)      # 0x88ec
leaq 0x2aae(%rip), %rdi      # 0x521f
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x20b0
cmpl $0x0, 0x616a(%rip)      # 0x88ec
jle 0x27a9
leaq 0x16ac(%rip), %rbx      # 0x3e37
movl 0x8(%r15), %edx
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x35d4
incl %r12d
cmpl 0x6145(%rip), %r12d     # 0x88ec
jl 0x278b
movl 0x8(%r15), %edx
leaq 0x1683(%rip), %rbx      # 0x3e37
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x35d4
movl %eax, %r12d
movl 0x8(%r15), %edx
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x35d4
movl %eax, %ebx
testl %r12d, %r12d
jns 0x27e2
testl %ebx, %ebx
je 0x280b
leaq 0x164e(%rip), %r12      # 0x3e37
movl 0x8(%r15), %edx
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rcx
callq 0x35d4
testl %ebx, %ebx
setns %cl
testl %eax, %eax
setne %dl
orb %cl, %dl
movl %eax, %ebx
jne 0x27e9
movq %r13, -0x30(%rbp)
xorl %r12d, %r12d
movq %r15, -0x40(%rbp)
leaq 0x161a(%rip), %r15      # 0x3e37
movq -0x40(%rbp), %r13
movl 0x8(%r13), %edx
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rcx
callq 0x35d4
movl %eax, -0x38(%rbp)
movl 0x8(%r13), %edx
movq %rbx, %rdi
movq %r14, %r13
movq %r14, %rsi
movq %r15, %rcx
callq 0x35d4
movl %eax, %ebx
addl $0x2, %r12d
cmpl $0x0, -0x38(%rbp)
jns 0x2868
testl %ebx, %ebx
jne 0x2868
leaq 0x15d1(%rip), %r15      # 0x3e37
jmp 0x289b
movq -0x30(%rbp), %r14
leaq 0x15c4(%rip), %r15      # 0x3e37
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rcx
callq 0x35d4
incl %r12d
testl %ebx, %ebx
setns %cl
testl %eax, %eax
setne %dl
orb %cl, %dl
movl %eax, %ebx
jne 0x2873
movq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rax), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x25bc
leaq 0x2967(%rip), %rdi      # 0x522b
movl %r12d, %esi
movsd -0x38(%rbp), %xmm0
movq %rax, %rdx
movb $0x1, %al
callq 0x20b0
cmpl $0x7d0, %r12d           # imm = 0x7D0
movq %r13, %r14
jl 0x281d
movq -0x30(%rbp), %rdi
callq 0x2090
movq %r14, %rdi
callq 0x2090
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5831(%rip), %rsi      # 0x8140
movq 0x5832(%rip), %rdx      # 0x8148
leaq 0x293c(%rip), %rdi      # 0x5259
xorl %eax, %eax
callq 0x20b0
jmp 0x297a
leaq 0x2955(%rip), %rdi      # 0x5282
callq 0x2070
leaq 0x295c(%rip), %rdi      # 0x5295
callq 0x2070
leaq 0x297c(%rip), %rdi      # 0x52c1
callq 0x2070
leaq 0x29a0(%rip), %rdi      # 0x52f1
callq 0x2070
leaq 0x29ba(%rip), %rdi      # 0x5317
callq 0x2070
leaq 0x29df(%rip), %rdi      # 0x5348
callq 0x2070
leaq 0x29f7(%rip), %rdi      # 0x536c
callq 0x2070
xorl %edi, %edi
callq 0x2200
movq (%r12), %rsi
leaq 0x2856(%rip), %rdi      # 0x51e2
xorl %eax, %eax
callq 0x20b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2200
nopl (%rax)