// File: /workspace/github_c_makefile_star2_O0/pipde[P]deos-songlib/lib/songlib.c
// Function: aresample
RRA *
aresample(RRA *note,double *factors,int factorLength)
    {
    int UP = 0,DOWN = 1,OFF = 2;
    int i;
    int amping = OFF;
    double maxAmp = drawAmpFactor;
    double t;
    double amp;
    double oldfactor;
    RRA *h;

    h = newRRA(SampleRate,note->bitsPerSample,1,note->samples);

    maxAmp /= 0.8;
    i = 0;
    t = 0;
    amp = 1;
    oldfactor = factors[0];
    while (t < note->samples)
        {
        if (i >= h->samples) growRRA(h);

        h->data[0][i] = interp(note->data[0],note->samples,t); // * amp;

        if (t > factorLength - 1)
            t += factors[factorLength - 1];
        else
            {
            t += factors[(int) t];
            if ((int) t < factorLength && factors[(int) t] != oldfactor)
                {
                //printf("factor change from %.16f to %.16f at %f\n",oldfactor,
                    //factors[(int) t],t);
                if (amping == OFF)
                    {
                    maxAmp = maxAmp * 0.8;
                    amping = UP;
                    //printf("changing to UP at %f\n",t);
                    }
                //printf("   amping is %d, amp is %f\n",amping,amp);
                oldfactor = factors[(int) t];
                }
            }
        ++i;

        if (amping == UP)
            {
            amp *= 1.01;
            //printf("amping up %f at %f\n",amp,t);
            }

        if (amping == UP && amp >= maxAmp)
            {
            amping = DOWN;
            //printf("changing to DOWN at %f\n",t);
            }

        if (amping == DOWN)
            {
            amp *= 0.9999;
            //printf("amping down %f at %f\n",amp,t);
            }

        if (amp < 1)
            {
            amping = OFF;
            //printf("changing to OFF at %f\n",t);
            }

        if (amping == OFF) amp = 1;
        }

    //printf("factor length is %d\n",factorLength);

    /* remove the excess capacity */

    shrinkRRA(h,i);

    dDebug("leaving\n");

    return h;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x1, -0x1c(%rbp)
movl $0x2, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
movsd 0xdb62(%rip), %xmm0     # 0x12468
movsd %xmm0, -0x30(%rbp)
movl 0xdaef(%rip), %edi      # 0x12400
movq -0x8(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x8(%rbp), %rax
movl 0xc(%rax), %ecx
movl $0x1, %edx
callq 0x9190
movq %rax, -0x50(%rbp)
movsd -0x30(%rbp), %xmm0
movsd 0x8a46(%rip), %xmm1     # 0xd380
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x89ce(%rip), %xmm0     # 0xd328
movsd %xmm0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x38(%rbp), %xmm1
movq -0x8(%rbp), %rax
cvtsi2sdl 0xc(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4aff
movl -0x24(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jl 0x4999
movq -0x50(%rbp), %rdi
callq 0xa5c0
movq 0x1d320(%rip), %rax     # 0x21cc0
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx), %rdi
movq -0x8(%rbp), %rcx
movl 0xc(%rcx), %esi
movsd -0x38(%rbp), %xmm0
callq *%rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movsd -0x38(%rbp), %xmm0
movl -0x14(%rbp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4a00
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x4a79
movq -0x10(%rbp), %rax
cvttsd2si -0x38(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
cvttsd2si -0x38(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4a77
movq -0x10(%rbp), %rax
cvttsd2si -0x38(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x4a41
jp 0x4a41
jmp 0x4a77
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x4a61
movsd 0x892f(%rip), %xmm0     # 0xd380
mulsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cvttsd2si -0x38(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x4a79
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x4a9c
movsd 0x88f6(%rip), %xmm0     # 0xd388
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x4ab6
movsd -0x40(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jb 0x4ab6
movl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x4ad0
movsd 0x88ca(%rip), %xmm0     # 0xd390
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x8850(%rip), %xmm0     # 0xd328
ucomisd -0x40(%rbp), %xmm0
jbe 0x4ae5
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x4afa
movsd 0x8833(%rip), %xmm0     # 0xd328
movsd %xmm0, -0x40(%rbp)
jmp 0x496c
movq -0x50(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0xa5f0
movq -0x50(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)