// File: /workspace/github_c_makefile_star2_O1/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 0x268b
movl $0x1, %r15d
movslq %r15d, %rax
movq (%r12,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x268b
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x2631
leaq 0x2(%rsi), %rdi
jmp 0x2636
movq 0x8(%r12,%rax,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x6f, %eax
je 0x2664
cmpl $0x68, %eax
je 0x28fa
cmpl $0x76, %eax
je 0x28dc
xorl %r14d, %r14d
leaq 0x2c0d(%rip), %rdi      # 0x5268
xorl %eax, %eax
callq 0x2974
jmp 0x2674
callq 0x2080
movsd %xmm0, 0x625f(%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 0x2616
subl %r15d, %ebx
jne 0x269c
movq 0x5941(%rip), %rax      # 0x7fd8
movq (%rax), %r13
jmp 0x26c0
cmpl $0x2, %ebx
je 0x26cc
cmpl $0x1, %ebx
jne 0x2955
movslq %r15d, %rax
movq (%r12,%rax,8), %rdi
leaq 0x2cb2(%rip), %rsi      # 0x536a
callq 0x2a0e
movq %rax, %r13
movq 0x5909(%rip), %rax      # 0x7fd0
movq (%rax), %r14
jmp 0x26f6
movslq %r15d, %rbx
movq (%r12,%rbx,8), %rdi
leaq 0x2c90(%rip), %rsi      # 0x536a
callq 0x2a0e
movq %rax, %r13
movq 0x8(%r12,%rbx,8), %rdi
leaq 0x2af2(%rip), %rsi      # 0x51e0
callq 0x2a0e
movq %rax, %r14
callq 0x2c8b
movq %rax, %r15
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x3098
cmpl $0x1, (%r15)
je 0x2723
movq (%r12), %rsi
leaq 0x2ae4(%rip), %rdi      # 0x5200
xorl %eax, %eax
callq 0x2974
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%r15), %xmm0
mulsd 0x619c(%rip), %xmm0     # 0x88d0
cvttsd2si %xmm0, %esi
movl %esi, 0x61ae(%rip)      # 0x88ec
leaq 0x2ada(%rip), %rdi      # 0x521f
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x20b0
cmpl $0x0, 0x6196(%rip)      # 0x88ec
jle 0x277d
leaq 0x1656(%rip), %rbx      # 0x3db5
movl 0x8(%r15), %edx
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x3584
incl %r12d
cmpl 0x6171(%rip), %r12d     # 0x88ec
jl 0x275f
movl 0x8(%r15), %edx
leaq 0x162d(%rip), %rbx      # 0x3db5
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x3584
movl %eax, %r12d
movl 0x8(%r15), %edx
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x3584
movl %eax, %ebx
testl %r12d, %r12d
jns 0x27b6
testl %ebx, %ebx
je 0x27df
leaq 0x15f8(%rip), %r12      # 0x3db5
movl 0x8(%r15), %edx
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rcx
callq 0x3584
testl %ebx, %ebx
setns %cl
testl %eax, %eax
setne %dl
orb %cl, %dl
movl %eax, %ebx
jne 0x27bd
movq %r13, -0x30(%rbp)
xorl %r12d, %r12d
movq %r15, -0x40(%rbp)
leaq 0x15c4(%rip), %r15      # 0x3db5
movq -0x40(%rbp), %r13
movl 0x8(%r13), %edx
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rcx
callq 0x3584
movl %eax, -0x38(%rbp)
movl 0x8(%r13), %edx
movq %rbx, %rdi
movq %r14, %r13
movq %r14, %rsi
movq %r15, %rcx
callq 0x3584
movl %eax, %ebx
addl $0x2, %r12d
cmpl $0x0, -0x38(%rbp)
jns 0x283c
testl %ebx, %ebx
jne 0x283c
leaq 0x157b(%rip), %r15      # 0x3db5
jmp 0x286f
movq -0x30(%rbp), %r14
leaq 0x156e(%rip), %r15      # 0x3db5
movq -0x40(%rbp), %rax
movl 0x8(%rax), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rcx
callq 0x3584
incl %r12d
testl %ebx, %ebx
setns %cl
testl %eax, %eax
setne %dl
orb %cl, %dl
movl %eax, %ebx
jne 0x2847
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 0x258c
leaq 0x2993(%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 0x27f1
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 0x585d(%rip), %rsi      # 0x8140
movq 0x585e(%rip), %rdx      # 0x8148
leaq 0x2968(%rip), %rdi      # 0x5259
xorl %eax, %eax
callq 0x20b0
jmp 0x294e
leaq 0x2981(%rip), %rdi      # 0x5282
callq 0x2070
leaq 0x2988(%rip), %rdi      # 0x5295
callq 0x2070
leaq 0x29a8(%rip), %rdi      # 0x52c1
callq 0x2070
leaq 0x29cc(%rip), %rdi      # 0x52f1
callq 0x2070
leaq 0x29e6(%rip), %rdi      # 0x5317
callq 0x2070
leaq 0x2a0b(%rip), %rdi      # 0x5348
callq 0x2070
leaq 0x2a23(%rip), %rdi      # 0x536c
callq 0x2070
xorl %edi, %edi
callq 0x2200
movq (%r12), %rsi
leaq 0x2882(%rip), %rdi      # 0x51e2
xorl %eax, %eax
callq 0x20b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2200
nopl (%rax)