// File: /workspace/github_c_makefile_star2_O3/pipde[P]deos-songlib/lib/songlib.c
// Function: closeOutputSelection
void 
closeOutputSelection(double start,double duration)
    {
    FILE *fp;
    int i,commentLocation,offset = 0;
    COMMENT *temp;
    
    if (closed == 1) return;

    if(commentBuffer != NULL)
        temp = head;

    if (maxLocation == 0)
        fprintf(stderr,"RRA file is empty\n");

    shrinkRRA(output,maxLocation);

    if (closed == 2)
        Fatal("new output RRA file has not been opened\n");

    if (outputName == 0)
        fp = stdout;
    else
        fp = OpenFile(outputName,"w");

    output->skip = 0;

    //writeRRA(fp,output,"createdBy: songlib",0);

    double samples = output->samples;
    output->samples = duration;
    writeRRAHeader(fp,output,"createdBy: songlib",0);
    output->samples = samples;

    if(commentBuffer != NULL)
        commentLocation = temp->location; 
    //fprintf(stderr,"commentLocation = %d\n",commentLocation);

    offset = (bitsPerSample == 8 ? 127:0);

    for(i = (int) start; i < (int) (start + duration) && i < output->samples; ++i)
        {
        while(commentLocation && (i == commentLocation) && commentBuffer != NULL)
            {
            fprintf(fp,"%s\n",temp->comment);
            temp = temp->next;
            //fprintf(stderr,"commentLocation = %d\n",commentLocation);
            if(temp)
                commentLocation = temp->location;
            else
                break;
            }
        fprintf(fp,"%d\n",output->data[0][i] + offset);
        }

    fclose(fp);

    freeRRA(output,0);
    
    if (commentBuffer != NULL) closeComments();

    samplesWritten = maxLocation;

    closed = 1;

    //return 0;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movsd %xmm1, 0x10(%rsp)
cmpl $0x1, 0x8dca(%rip)      # 0xf434
je 0x6853
movsd %xmm0, 0x8(%rsp)
movq 0x18a3b(%rip), %r12     # 0x1f0b8
movl 0x1868d(%rip), %esi     # 0x1ed10
testl %esi, %esi
je 0x6862
movq 0x1866e(%rip), %rdi     # 0x1ed00
callq 0x7db4
cmpl $0x2, 0x8d96(%rip)      # 0xf434
jne 0x66ae
leaq 0x3ef4(%rip), %rdi      # 0xa59b
xorl %eax, %eax
callq 0x6cc0
movq 0x18643(%rip), %rdi     # 0x1ecf8
testq %rdi, %rdi
je 0x66cb
leaq 0x3970(%rip), %rsi      # 0xa031
callq 0x6d5a
movq %rax, %rbx
jmp 0x66d5
movq 0x88fe(%rip), %rax      # 0xefd0
movq (%rax), %rbx
movq 0x18624(%rip), %rsi     # 0x1ed00
movl $0x0, 0x10(%rsi)
movl 0xc(%rsi), %ebp
cvttsd2si 0x10(%rsp), %eax
movl %eax, 0xc(%rsi)
leaq 0x3ece(%rip), %rdx      # 0xa5c4
movq $0x0, (%rsp)
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x7e8c
movq 0x185f1(%rip), %rax     # 0x1ed00
movl %ebp, 0xc(%rax)
cmpq $0x0, 0x1898e(%rip)     # 0x1f0a8
je 0x6724
cvttsd2si (%r12), %ebp
jmp 0x6724
movsd 0x8(%rsp), %xmm1
cmpl $0x8, 0x8d07(%rip)      # 0xf438
movl $0x7f, %eax
movq (%rsp), %rcx
cmovel %eax, %ecx
movq %rcx, (%rsp)
cvttsd2si %xmm1, %eax
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %r14d
cmpl %r14d, %eax
jge 0x67f0
movslq %eax, %r13
leaq 0x4318(%rip), %r15      # 0xaa7f
movq 0x18592(%rip), %rax     # 0x1ed00
movslq 0xc(%rax), %rcx
cmpq %rcx, %r13
jge 0x67f0
testl %ebp, %ebp
je 0x67b7
cmpl %r13d, %ebp
jne 0x67be
cmpq $0x0, 0x18920(%rip)     # 0x1f0a8
je 0x67be
leaq 0x8(%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x21d0
movq 0x208(%r12), %r12
testq %r12, %r12
je 0x67bb
cvttsd2si (%r12), %ebp
testl %ebp, %ebp
jne 0x677b
xorl %ebp, %ebp
jmp 0x67be
xorl %ebp, %ebp
jmp 0x67c5
xorl %r12d, %r12d
movq 0x1853b(%rip), %rax     # 0x1ed00
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %edx
addl (%rsp), %edx
movq %rbx, %rdi
leaq 0x3ff0(%rip), %rsi      # 0xa7cd
xorl %eax, %eax
callq 0x21d0
incq %r13
cmpl %r14d, %r13d
jne 0x6767
movq %rbx, %rdi
callq 0x20c0
movq 0x18501(%rip), %rdi     # 0x1ed00
xorl %esi, %esi
callq 0x70a1
cmpq $0x0, 0x1889a(%rip)     # 0x1f0a8
sete %al
movq 0x188a0(%rip), %rdi     # 0x1f0b8
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x683d
movq 0x208(%rdi), %rbx
movq %rbx, 0x18888(%rip)     # 0x1f0b8
callq 0x2040
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x6822
movl 0x184cd(%rip), %eax     # 0x1ed10
movl %eax, 0x1882b(%rip)     # 0x1f074
movl $0x1, 0x8be1(%rip)      # 0xf434
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x878f(%rip), %rax      # 0xeff8
movq (%rax), %rcx
leaq 0x3d15(%rip), %rdi      # 0xa588
movl $0x12, %esi
movl $0x1, %edx
callq 0x22d0
movl 0x18488(%rip), %esi     # 0x1ed10
jmp 0x668b