// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movsd %xmm0, -0x8(%rbp)
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movl $0x0, -0x34(%rbp)
movsd 0x8d07(%rip), %xmm0     # 0xd328
movsd %xmm0, -0x60(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x4801
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x58(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x46dc
imull $0xc, -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
jl 0x4686
cmpl $0x84, -0x74(%rbp)
jl 0x469a
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
leaq 0x8e4c(%rip), %rdi      # 0xd4df
movb $0x0, %al
callq 0x8c70
movl -0xc(%rbp), %edi
movl -0x74(%rbp), %esi
callq 0x3180
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movslq 0xc(%rax), %rax
shlq $0x3, %rax
movl %eax, %edi
callq 0x8ec0
movq %rax, -0x70(%rbp)
movsd 0x8c60(%rip), %xmm0     # 0xd328
movsd %xmm0, -0x60(%rbp)
movsd 0x8c53(%rip), %xmm0     # 0xd328
movsd %xmm0, -0x68(%rbp)
jmp 0x4706
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
imull $0xc, -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
subl -0x74(%rbp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x8c7c(%rip), %xmm0     # 0xd378
callq 0x2080
movsd %xmm0, -0x60(%rbp)
movsd -0x58(%rbp), %xmm0
callq 0x3980
mulsd -0x60(%rbp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x78(%rbp)
jne 0x473b
xorps %xmm0, %xmm0
ucomisd 0xdd33(%rip), %xmm0     # 0x12460
jb 0x473b
movl $0x1, -0x84(%rbp)
jmp 0x4771
cvtsi2sdl 0xdcbd(%rip), %xmm0 # 0x12400
movsd %xmm0, -0x90(%rbp)
movsd 0xdd0d(%rip), %xmm0     # 0x12460
callq 0x48b0
movaps %xmm0, %xmm1
movsd -0x90(%rbp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x84(%rbp)
cmpl $0x1, -0x84(%rbp)
jge 0x4784
movl $0x1, -0x84(%rbp)
movsd -0x60(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
cvtsi2sdl -0x84(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x78(%rbp), %eax
jge 0x47f1
movsd -0x68(%rbp), %xmm0
movq -0x70(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x34(%rbp)
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
cmpl -0x84(%rbp), %eax
jge 0x47e4
movsd -0x80(%rbp), %xmm0
addsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
jmp 0x47e6
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x47a6
jmp 0x47f3
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x462d
jmp 0x4803
movl -0x34(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x482c
movsd -0x68(%rbp), %xmm0
movq -0x70(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4803
movq -0x48(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl -0x34(%rbp), %edx
callq 0x48d0
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x34(%rbp), %eax
jne 0x484e
jmp 0x486d
leaq 0x8caf(%rip), %rdi      # 0xd504
leaq 0x8cbf(%rip), %rsi      # 0xd51b
movl $0x412, %edx            # imm = 0x412
leaq 0x8cbd(%rip), %rcx      # 0xd525
callq 0x20f0
movsd -0x8(%rbp), %xmm0
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
movq -0x50(%rbp), %rax
movl 0xc(%rax), %esi
movq -0x48(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x31c0
movq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9440
movq -0x70(%rbp), %rdi
callq 0x2030
addq $0x90, %rsp
popq %rbp
retq
nop