// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %r15
movslq %r15d, %r14
cmpl %r15d, %ebx
jle 0x243c
movq (%r12,%r14,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x243c
movb 0x2(%rsi), %r13b
testb %r13b, %r13b
je 0x23e5
leaq 0x2(%rsi), %rdi
jmp 0x23ea
movq 0x8(%r12,%r14,8), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x6f, %eax
je 0x2418
cmpl $0x68, %eax
je 0x2633
cmpl $0x76, %eax
je 0x2689
xorl %r14d, %r14d
leaq 0x2e59(%rip), %rdi      # 0x5268
xorl %eax, %eax
callq 0x26c8
jmp 0x2428
callq 0x2080
movsd %xmm0, 0x64ab(%rip)     # 0x88d0
movb $0x1, %r14b
testb %r13b, %r13b
sete %al
andb %r14b, %al
movzbl %al, %eax
addl %eax, %r15d
incl %r15d
jmp 0x23c5
subl %r15d, %ebx
jne 0x244d
movq 0x5b90(%rip), %rax      # 0x7fd8
movq (%rax), %rbx
jmp 0x246e
cmpl $0x2, %ebx
je 0x247a
cmpl $0x1, %ebx
jne 0x26ac
movq (%r12,%r14,8), %rdi
leaq 0x2f04(%rip), %rsi      # 0x536a
callq 0x27f8
movq %rax, %rbx
movq 0x5b5b(%rip), %rax      # 0x7fd0
movq (%rax), %rax
jmp 0x249e
movq (%r12,%r14,8), %rdi
leaq 0x2ee5(%rip), %rsi      # 0x536a
callq 0x27f8
movq %rax, %rbx
movq 0x8(%r12,%r14,8), %rdi
leaq 0x2d47(%rip), %rsi      # 0x51e0
callq 0x27f8
movq %rax, -0x30(%rbp)
callq 0x2a54
movq %rax, %r15
movq %rbx, %r14
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x2db9
cmpl $0x1, (%r15)
je 0x24d2
movq (%r12), %rsi
leaq 0x2d35(%rip), %rdi      # 0x5200
xorl %eax, %eax
callq 0x26c8
cvtsi2sdl 0x4(%r15), %xmm0
mulsd 0x63f0(%rip), %xmm0     # 0x88d0
cvttsd2si %xmm0, %esi
movl %esi, 0x6402(%rip)      # 0x88ec
leaq 0x2d2e(%rip), %rdi      # 0x521f
xorl %eax, %eax
callq 0x20b0
pushq $-0x1
popq %r13
movq %r14, -0x40(%rbp)
movq -0x30(%rbp), %rcx
movl 0x8(%r15), %edx
movl 0x63de(%rip), %eax      # 0x88ec
movl %eax, -0x38(%rbp)
movq -0x40(%rbp), %rdi
movq %rcx, %rbx
movq %rcx, %rsi
leaq 0x1533(%rip), %rcx      # 0x3a55
callq 0x328e
movq %rbx, %rcx
incl %r13d
cmpl -0x38(%rbp), %r13d
jl 0x2504
movl %eax, %r12d
movq -0x40(%rbp), %r13
movl 0x8(%r15), %edx
movq %r13, %rdi
movq %rbx, %rsi
leaq 0x150a(%rip), %rcx      # 0x3a55
callq 0x328e
testl %r12d, %r12d
setns %cl
testl %eax, %eax
setne %dl
orb %cl, %dl
movl %eax, %r12d
jne 0x253a
xorl %r12d, %r12d
cmpl $0x7cf, %r12d           # imm = 0x7CF
jg 0x2611
movl 0x8(%r15), %edx
movq %r13, %rdi
movq -0x30(%rbp), %r13
movq %r13, %rsi
leaq 0x14ce(%rip), %rcx      # 0x3a55
callq 0x328e
movl %eax, %ebx
movl 0x8(%r15), %edx
movq -0x40(%rbp), %rdi
movq %r13, %rsi
leaq 0x14b5(%rip), %rcx      # 0x3a55
callq 0x328e
movl %eax, %r13d
addl $0x2, %r12d
testl %ebx, %ebx
jns 0x25b5
testl %r13d, %r13d
je 0x25d7
movl 0x8(%r15), %edx
movq %r14, %rdi
movq -0x30(%rbp), %rsi
leaq 0x148e(%rip), %rcx      # 0x3a55
callq 0x328e
movl %r13d, %ebx
incl %r12d
movl %eax, %r13d
jmp 0x25ac
cvtsi2sdl 0x4(%r15), %xmm0
cvtsi2sd %r12d, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x234c
leaq 0x2c34(%rip), %rdi      # 0x522b
movl %r12d, %esi
movsd -0x38(%rbp), %xmm0
movq %rax, %rdx
movb $0x1, %al
callq 0x20b0
movq %r14, %r13
jmp 0x2565
movq %r13, %rdi
callq 0x2090
movq -0x30(%rbp), %rdi
callq 0x2090
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2c48(%rip), %rdi      # 0x5282
callq 0x2070
leaq 0x2c4f(%rip), %rdi      # 0x5295
callq 0x2070
leaq 0x2c6f(%rip), %rdi      # 0x52c1
callq 0x2070
leaq 0x2c93(%rip), %rdi      # 0x52f1
callq 0x2070
leaq 0x2cad(%rip), %rdi      # 0x5317
callq 0x2070
leaq 0x2cd2(%rip), %rdi      # 0x5348
callq 0x2070
leaq 0x2cea(%rip), %rdi      # 0x536c
callq 0x2070
jmp 0x26a5
movq 0x5ab0(%rip), %rsi      # 0x8140
movq 0x5ab1(%rip), %rdx      # 0x8148
leaq 0x2bbb(%rip), %rdi      # 0x5259
xorl %eax, %eax
callq 0x20b0
xorl %edi, %edi
callq 0x2200
movq (%r12), %rsi
leaq 0x2b2b(%rip), %rdi      # 0x51e2
xorl %eax, %eax
callq 0x20b0
pushq $-0x1
popq %rdi
callq 0x2200
nop