// File: /workspace/github_c_makefile_star2_O1/pipde[P]deos-songlib/lib/songlib.c
// Function: adraw
void
adraw(double length,int inst,int count,int* octaves,int *pitches,double *lengths)
    {
    int i,j;
    int index;
    int octave,pitch;
    RRA *note = 0,*resampled = 0;
    double beats;
    double factor,oldfactor,*factors;
    int baseNote,factorCount;

    dTrace("entering\n");;
    //printf("count is %d\n",count);

    index = 0;
    factor = 1.0;

    /* extract the arguments */

    for (i = 0; i < count; ++i)
        {
        double delta;
        int steps;

        octave = octaves[i];
        pitch = pitches[i];
        beats = lengths[i];

        //printf("[%d,%d,%f]\n",octave,pitch,beats);

        if (i == 0)
            {
            baseNote = octave * NOTES + pitch;
            if (baseNote < 0 || baseNote >= OCTAVES * NOTES)
                Fatal("adraw: bad octave/pitch pair: "
                    "%d,%d\n",octave,pitch);
            note = getNumberedNote(inst,baseNote);
            //printf("%d samples total\n",note->samples);
            factors = (double *) New(sizeof(double) * note->samples);
            factor = 1;
            oldfactor = 1;
            //printf("resampling factor starting at %f\n",factor);
            }
        else
            {
            oldfactor = factor;
            factor = pow(SEMITONE,(octave * NOTES + pitch) - baseNote);
            //printf("resampling factor changing from %f to %f\n",oldfactor,factor);
            }

        factorCount = (int) (beatsToSamples(beats) * factor);
        //printf("factorCount is %d\n",factorCount);
        if (factorCount == 0 && drawRamp <= 0.0)
            steps = 1;
        else
            steps = SampleRate * beatsToSeconds(drawRamp);
        if (steps < 1) steps = 1;
        delta = (factor - oldfactor) / steps;
        //printf("delta is %f, factorCount is %d, steps is %d\n",
        //    delta,factorCount,steps);

        for (j = 0; j < factorCount; ++j)
            {
            factors [index++] = oldfactor;
            if (j < steps) oldfactor += delta;
            }
        }

    /* fill out the rest of the array with the last value of factor */

    for ( ; index < note->samples; ++index)
        factors[index] = oldfactor;

    resampled = aresample(note,factors,index);

    assert(note->samples == index);
    
    dplay(length,resampled->data[0],resampled->samples,note->bitsPerSample);

    freeRRA(resampled,0);
    free(factors);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movl %edi, 0x14(%rsp)
movsd %xmm0, 0x18(%rsp)
testl %esi, %esi
jle 0x43ba
movl %esi, %r14d
movsd 0x601a(%rip), %xmm2     # 0xa260
movl $0x1, %r12d
xorl %r13d, %r13d
xorl %ebx, %ebx
movq $0x0, 0x8(%rsp)
movq 0x20(%rsp), %rcx
movl (%rcx,%r13,4), %esi
movq 0x28(%rsp), %rcx
movl (%rcx,%r13,4), %edx
movq 0x30(%rsp), %rcx
movsd (%rcx,%r13,8), %xmm0
movsd %xmm0, 0x40(%rsp)
leal (,%rsi,4), %ecx
leal (%rcx,%rcx,2), %r15d
testq %r13, %r13
je 0x42ba
subl %ebp, %edx
addl %r15d, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd 0x5fef(%rip), %xmm0     # 0xa290
movq %rax, %r15
movsd %xmm2, 0x38(%rsp)
callq 0x20b0
movsd 0x38(%rsp), %xmm6
movq %r15, %rax
jmp 0x4303
addl %edx, %r15d
cmpl $0x84, %r15d
jb 0x42d4
leaq 0x6158(%rip), %rdi      # 0xa425
xorl %eax, %eax
callq 0x6b88
movl 0x14(%rsp), %edi
movl %r15d, %esi
callq 0x2f35
movq %rax, 0x8(%rsp)
movl 0xc(%rax), %edi
shll $0x3, %edi
callq 0x6cb5
movsd 0x5f68(%rip), %xmm1     # 0xa260
movapd %xmm1, %xmm0
movapd %xmm1, %xmm6
movl %r15d, %ebp
movsd 0x5f75(%rip), %xmm5     # 0xa280
movsd 0x40(%rsp), %xmm3
mulsd %xmm5, %xmm3
movsd 0xb193(%rip), %xmm1     # 0xf4b0
divsd %xmm1, %xmm3
xorps %xmm2, %xmm2
cvtsi2sdl 0xb104(%rip), %xmm2 # 0xf430
mulsd %xmm2, %xmm3
mulsd %xmm0, %xmm3
cvttsd2si %xmm3, %edx
movsd 0xb150(%rip), %xmm3     # 0xf490
movapd %xmm3, %xmm4
mulsd %xmm5, %xmm4
divsd %xmm1, %xmm4
mulsd %xmm2, %xmm4
cvttsd2si %xmm4, %ecx
cmpl $0x2, %ecx
cmovll %r12d, %ecx
xorpd %xmm1, %xmm1
ucomisd %xmm3, %xmm1
movl %ecx, %edi
cmovael %r12d, %edi
testl %edx, %edx
cmovnel %ecx, %edi
jle 0x43a4
movapd %xmm0, %xmm1
subsd %xmm6, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %edi, %xmm2
divsd %xmm2, %xmm1
movslq %ebx, %rcx
leaq (%rax,%rcx,8), %rcx
movl %edx, %edx
xorl %esi, %esi
movsd %xmm6, (%rcx,%rsi,8)
cmpl %edi, %esi
jae 0x439b
addsd %xmm1, %xmm6
incq %rsi
cmpl %esi, %edx
jne 0x438e
addl %esi, %ebx
incq %r13
movapd %xmm6, %xmm1
movapd %xmm0, %xmm2
cmpq %r14, %r13
jne 0x425a
jmp 0x43c5
movq $0x0, 0x8(%rsp)
xorl %ebx, %ebx
movq 0x8(%rsp), %r12
movslq 0xc(%r12), %rsi
cmpl %esi, %ebx
jge 0x43ee
movslq %ebx, %rcx
leaq (%rax,%rcx,8), %rdx
subq %rcx, %rsi
xorl %ecx, %ecx
movsd %xmm1, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rsi
jne 0x43df
addl %ecx, %ebx
movq %r12, %rdi
movq %rax, %rsi
movl %ebx, %edx
movq %rax, %r14
callq 0x4473
cmpl %ebx, 0xc(%r12)
jne 0x4443
movq %rax, %r15
movq 0x18(%rax), %rax
movq (%rax), %rdi
movl 0xc(%r15), %esi
movl 0x8(%r12), %edx
movsd 0x18(%rsp), %xmm0
callq 0x3175
movq %r15, %rdi
xorl %esi, %esi
callq 0x6f73
movq %r14, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
leaq 0x6000(%rip), %rdi      # 0xa44a
leaq 0x6010(%rip), %rsi      # 0xa461
leaq 0x6013(%rip), %rcx      # 0xa46b
movl $0x412, %edx            # imm = 0x412
callq 0x2120