// File: /workspace/github_c_makefile_star2_O0/pipde[P]deos-songlib/utils/identify/identify.c
// Function: processData
static double
processData(FILE *out,RRA *r)
    {
    int i,min,limit;
    int length,window;
    double freq = 0;
    int *data;
    double *errors;
    int count;
    double first,firstDivisor,threshold,worst;

    window = r->sampleRate / MinFrequency;
    length = window * SPAN;
    skip = (r->sampleRate / MaxFrequency) / 2;
    //printf("skip is %d\n",skip);

    errors = (double *) New(sizeof(double) * length);

    //printf("initial offset: %f\n",initialOffset); 

    data = r->data[0] + (int) (initialOffset * r->sampleRate);

    count = correlate(data,length,window,errors);

#ifdef WRITE_ERROR
    writeTempRRA(errors,count,0);
#endif

    limit = findMinError(errors,count,&worst);
    //printf("best is %f at %d, worst is %f\n",errors[limit],limit,worst);
    //printf("error span is %f\n",worst - errors[limit]);
    //getchar();

    threshold = worst - 0.01 * ErrorPercent * (worst - errors[limit]);

    //printf("limit is %d\n",limit);

    freq = r->sampleRate * 1.0 / limit;
    //printf("frequency estimate is %f\n",freq);
    first = freq;
    firstDivisor = 1;

    i = 2;
    while (limit / i > skip * 2)
        {
        min = findMinErrorAt(errors,limit / i);
        //printf("for divisor %d, min found at %d\n",i,min);
        //printf("error is %f, theshold is %f\n",errors[min],threshold);
        if (min > skip && errors[min] < threshold)
            {
            freq = r->sampleRate / (double) min;
            //printf("better frequency found: %f!\n",freq);
            firstDivisor = i;
            }
        ++i;
        }

    return first * firstDivisor;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm0
divsd 0x6fa7(%rip), %xmm0     # 0x98b0
cvttsd2si %xmm0, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm0
divsd 0x6f8e(%rip), %xmm0     # 0x98b8
movsd 0x36ee(%rip), %xmm1     # 0x6020
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x6fb0(%rip)      # 0x98f0
movslq -0x20(%rbp), %rax
shlq $0x3, %rax
movl %eax, %edi
callq 0x3020
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
movsd 0x6f5a(%rip), %xmm0     # 0x98c0
movq -0x10(%rbp), %rcx
cvtsi2sdl 0x4(%rcx), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
movq -0x40(%rbp), %rcx
callq 0x2ad0
movl %eax, -0x44(%rbp)
movq -0x40(%rbp), %rdi
movl -0x44(%rbp), %esi
leaq -0x68(%rbp), %rdx
callq 0x2bc0
movl %eax, -0x1c(%rbp)
movsd -0x68(%rbp), %xmm1
movsd 0x365d(%rip), %xmm0     # 0x6018
mulsd 0x6f05(%rip), %xmm0     # 0x98c8
movsd -0x68(%rbp), %xmm2
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm0
movsd 0x3606(%rip), %xmm1     # 0x6010
mulsd %xmm1, %xmm0
cvtsi2sdl -0x1c(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x35e2(%rip), %xmm0     # 0x6010
movsd %xmm0, -0x58(%rbp)
movl $0x2, -0x14(%rbp)
movl -0x1c(%rbp), %eax
cltd
idivl -0x14(%rbp)
movl 0x6ea9(%rip), %ecx      # 0x98f0
shll %ecx
cmpl %ecx, %eax
jle 0x2ab1
movq -0x40(%rbp), %rdi
movl -0x1c(%rbp), %eax
cltd
idivl -0x14(%rbp)
movl %eax, %esi
callq 0x2cc0
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl 0x6e85(%rip), %eax      # 0x98f0
jle 0x2aa6
movq -0x40(%rbp), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x60(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2aa6
movq -0x10(%rbp), %rax
cvtsi2sdl 0x4(%rax), %xmm0
cvtsi2sdl -0x18(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
cvtsi2sdl -0x14(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2a3a
movsd -0x50(%rbp), %xmm0
mulsd -0x58(%rbp), %xmm0
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)