// File: /workspace/github_c_makefile_star2_O3/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 0x4388
movl %esi, %ebx
movsd 0x604d(%rip), %xmm2     # 0xa260
movl $0x1, %r15d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
movq 0x20(%rsp), %rcx
movl (%rcx,%r12,4), %esi
movq 0x28(%rsp), %rcx
movl (%rcx,%r12,4), %edx
movq 0x30(%rsp), %rcx
movsd (%rcx,%r12,8), %xmm0
movsd %xmm0, 0x40(%rsp)
leal (,%rsi,4), %ecx
leal (%rcx,%rcx,2), %r14d
testq %r12, %r12
je 0x4288
subl %r13d, %edx
addl %r14d, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd 0x6021(%rip), %xmm0     # 0xa290
movq %rax, %r14
movsd %xmm2, 0x38(%rsp)
callq 0x20b0
movsd 0x38(%rsp), %xmm6
movq %r14, %rax
jmp 0x42d1
addl %edx, %r14d
cmpl $0x84, %r14d
jb 0x42a2
leaq 0x61ca(%rip), %rdi      # 0xa465
xorl %eax, %eax
callq 0x6cc0
movl 0x14(%rsp), %edi
movl %r14d, %esi
callq 0x2f18
movq %rax, 0x8(%rsp)
movl 0xc(%rax), %edi
shll $0x3, %edi
callq 0x6ddf
movsd 0x5f9a(%rip), %xmm1     # 0xa260
movapd %xmm1, %xmm0
movapd %xmm1, %xmm6
movl %r14d, %r13d
movsd 0x5fa7(%rip), %xmm5     # 0xa280
movsd 0x40(%rsp), %xmm3
mulsd %xmm5, %xmm3
movsd 0xb1c5(%rip), %xmm1     # 0xf4b0
divsd %xmm1, %xmm3
xorps %xmm2, %xmm2
cvtsi2sdl 0xb136(%rip), %xmm2 # 0xf430
mulsd %xmm2, %xmm3
mulsd %xmm0, %xmm3
cvttsd2si %xmm3, %edx
movsd 0xb182(%rip), %xmm3     # 0xf490
movapd %xmm3, %xmm4
mulsd %xmm5, %xmm4
divsd %xmm1, %xmm4
mulsd %xmm2, %xmm4
cvttsd2si %xmm4, %ecx
cmpl $0x2, %ecx
cmovll %r15d, %ecx
xorpd %xmm1, %xmm1
ucomisd %xmm3, %xmm1
movl %ecx, %edi
cmovael %r15d, %edi
testl %edx, %edx
cmovnel %ecx, %edi
jle 0x4372
movapd %xmm0, %xmm1
subsd %xmm6, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %edi, %xmm2
divsd %xmm2, %xmm1
movslq %ebp, %rcx
leaq (%rax,%rcx,8), %rcx
movl %edx, %edx
xorl %esi, %esi
movsd %xmm6, (%rcx,%rsi,8)
cmpl %edi, %esi
jae 0x4369
addsd %xmm1, %xmm6
incq %rsi
cmpl %esi, %edx
jne 0x435c
addl %esi, %ebp
incq %r12
movapd %xmm6, %xmm1
movapd %xmm0, %xmm2
cmpq %rbx, %r12
jne 0x4227
jmp 0x4393
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movq 0x8(%rsp), %r15
movl 0xc(%r15), %r8d
cmpl %r8d, %ebp
jge 0x4447
movslq %r8d, %rdx
movslq %ebp, %rsi
subq %rsi, %rdx
leaq 0x1(%rdx), %rcx
andq $-0x2, %rcx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq (%rax,%rsi,8), %rdx
addq $0x8, %rdx
xorl %esi, %esi
movdqa 0x5f4b(%rip), %xmm2     # 0xa320
movdqa 0x5f53(%rip), %xmm3     # 0xa330
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movq %rsi, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
por %xmm2, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edi
notl %edi
testb $0x1, %dil
je 0x4427
movsd %xmm1, -0x8(%rdx,%rsi,8)
pxor %xmm4, %xmm5
pextrw $0x4, %xmm5, %edi
testb $0x1, %dil
je 0x443b
movsd %xmm1, (%rdx,%rsi,8)
addq $0x2, %rsi
cmpq %rsi, %rcx
jne 0x43e5
movl %r8d, %ebp
movq %r15, %rdi
movq %rax, %rsi
movl %ebp, %edx
movq %rax, %rbx
callq 0x44ca
cmpl %ebp, 0xc(%r15)
jne 0x449a
movq %rax, %r14
movq 0x18(%rax), %rax
movq (%rax), %rdi
movl 0xc(%r14), %esi
movl 0x8(%r15), %edx
movsd 0x18(%rsp), %xmm0
callq 0x314c
movq %r14, %rdi
xorl %esi, %esi
callq 0x70a1
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
leaq 0x5fe9(%rip), %rdi      # 0xa48a
leaq 0x5ff9(%rip), %rsi      # 0xa4a1
leaq 0x5ffc(%rip), %rcx      # 0xa4ab
movl $0x412, %edx            # imm = 0x412
callq 0x2120