// File: /workspace/github_c_makefile_star2_O0/pipde[P]deos-songlib/utils/repitch/repitch.c
// Function: processData
static void
processData(FILE *in,FILE *out,RRA *r, RRA *r2)
    {
    int amplitudes[3000];
    int error = 10000000;
    int errorLoc = 0;
    int i;
    for (i=0; i < r->samples; ++i) {
        int amp = readRRAAmplitude(in, out, r->bitsPerSample, outputComment);

            if (i>=50000 && i<53000)
            {
                amplitudes[i-50000] = amp;
            }
        }
    int k;
    for(k=skip; k < 2900; k++) // skip a certain number of samples based on octave
    {
        int l;
        int error1 = 0;
        for (l=0; l<skip; l++) {
           error1 += abs(amplitudes[l] - amplitudes[k+l]);
        }
        if ((abs(error1)) < (abs(error)))
        {
            error = error1;
            errorLoc = k;
        }
    }
    int closest = 0;
    int difference = 500;
    for (k=0; k<100; k++)
    {
        int newDif = abs(errorLoc - targetFreqs[k]);

        if (newDif <= difference)
        {
            difference = newDif;
            closest = targetFreqs[k];
        }
    }
    printf("Wavelength: %d samples \n", errorLoc);
    printf("Original Frequency: %d Hz\n", 44100/errorLoc);
    printf("Lowest error: %d \n", error);

    step = (double)errorLoc / closest;
    printf("Step: %f \n", step);
    int old = r2->samples;
    r2->samples = (int) (r2->samples / step);
    r2->samples = old;
    writeRRAHeader(out,r2,"modifiedBy: rrarepitch",0);

    double t = 0;
    while (t < r2->samples)
        {
        fprintf(out,"%d\n",(int) interp(r2->data[0],r2->samples,t));
        t = t + step;
        }

    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f40, %rsp           # imm = 0x2F40
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x989680, -0x2f04(%rbp) # imm = 0x989680
movl $0x0, -0x2f08(%rbp)
movl $0x0, -0x2f0c(%rbp)
movl -0x2f0c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x17ce
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x2402(%rip), %rcx      # 0x3b80
callq 0x2ed0
movl %eax, -0x2f10(%rbp)
cmpl $0xc350, -0x2f0c(%rbp)  # imm = 0xC350
jl 0x17bb
cmpl $0xcf08, -0x2f0c(%rbp)  # imm = 0xCF08
jge 0x17bb
movl -0x2f10(%rbp), %ecx
movl -0x2f0c(%rbp), %eax
subl $0xc350, %eax           # imm = 0xC350
cltq
movl %ecx, -0x2f00(%rbp,%rax,4)
jmp 0x17bd
movl -0x2f0c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2f0c(%rbp)
jmp 0x1759
movl 0x698c(%rip), %eax      # 0x8160
movl %eax, -0x2f14(%rbp)
cmpl $0xb54, -0x2f14(%rbp)   # imm = 0xB54
jge 0x18a0
movl $0x0, -0x2f1c(%rbp)
movl $0x0, -0x2f18(%rbp)
movl -0x2f18(%rbp), %eax
cmpl 0x6956(%rip), %eax      # 0x8160
jge 0x1854
movslq -0x2f18(%rbp), %rax
movl -0x2f00(%rbp,%rax,4), %eax
movl -0x2f14(%rbp), %ecx
addl -0x2f18(%rbp), %ecx
movslq %ecx, %rcx
subl -0x2f00(%rbp,%rcx,4), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
addl -0x2f1c(%rbp), %eax
movl %eax, -0x2f1c(%rbp)
movl -0x2f18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2f18(%rbp)
jmp 0x17fe
movl -0x2f1c(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl -0x2f04(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
cmpl %ecx, %eax
jge 0x188a
movl -0x2f1c(%rbp), %eax
movl %eax, -0x2f04(%rbp)
movl -0x2f14(%rbp), %eax
movl %eax, -0x2f08(%rbp)
jmp 0x188c
movl -0x2f14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2f14(%rbp)
jmp 0x17da
movl $0x0, -0x2f20(%rbp)
movl $0x1f4, -0x2f24(%rbp)   # imm = 0x1F4
movl $0x0, -0x2f14(%rbp)
cmpl $0x64, -0x2f14(%rbp)
jge 0x192f
movl -0x2f08(%rbp), %eax
movslq -0x2f14(%rbp), %rdx
leaq 0x6895(%rip), %rcx      # 0x8170
subl (%rcx,%rdx,4), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x2f28(%rbp)
movl -0x2f28(%rbp), %eax
cmpl -0x2f24(%rbp), %eax
jg 0x191c
movl -0x2f28(%rbp), %eax
movl %eax, -0x2f24(%rbp)
movslq -0x2f14(%rbp), %rcx
leaq 0x685d(%rip), %rax      # 0x8170
movl (%rax,%rcx,4), %eax
movl %eax, -0x2f20(%rbp)
jmp 0x191e
movl -0x2f14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2f14(%rbp)
jmp 0x18be
movl -0x2f08(%rbp), %esi
leaq 0x376c(%rip), %rdi      # 0x50a8
movb $0x0, %al
callq 0x1090
movl $0xac44, %eax           # imm = 0xAC44
cltd
idivl -0x2f08(%rbp)
movl %eax, %esi
leaq 0x3769(%rip), %rdi      # 0x50c1
movb $0x0, %al
callq 0x1090
movl -0x2f04(%rbp), %esi
leaq 0x3770(%rip), %rdi      # 0x50dc
movb $0x0, %al
callq 0x1090
cvtsi2sdl -0x2f08(%rbp), %xmm0
cvtsi2sdl -0x2f20(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x67a1(%rip)     # 0x8130
movsd 0x6799(%rip), %xmm0     # 0x8130
leaq 0x3751(%rip), %rdi      # 0x50ef
movb $0x1, %al
callq 0x1090
movq -0x20(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x2f2c(%rbp)
movq -0x20(%rbp), %rax
cvtsi2sdl 0xc(%rax), %xmm0
divsd 0x676d(%rip), %xmm0     # 0x8130
cvttsd2si %xmm0, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movl -0x2f2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq 0x3710(%rip), %rdx      # 0x50fa
xorl %eax, %eax
movl %eax, %ecx
callq 0x3740
xorps %xmm0, %xmm0
movsd %xmm0, -0x2f38(%rbp)
movsd -0x2f38(%rbp), %xmm1
movq -0x20(%rbp), %rax
cvtsi2sdl 0xc(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1a72
movq -0x10(%rbp), %rax
movq %rax, -0x2f40(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movl 0xc(%rax), %esi
movsd -0x2f38(%rbp), %xmm0
callq 0x1a80
movq -0x2f40(%rbp), %rdi
cvttsd2si %xmm0, %edx
leaq 0x3814(%rip), %rsi      # 0x5265
movb $0x0, %al
callq 0x1120
movsd -0x2f38(%rbp), %xmm0
addsd 0x66c8(%rip), %xmm0     # 0x8130
movsd %xmm0, -0x2f38(%rbp)
jmp 0x19fe
addq $0x2f40, %rsp           # imm = 0x2F40
popq %rbp
retq
nopl (%rax,%rax)