// File: /workspace/github_c_makefile_star2_O2/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, 0x8683(%rip)      # 0xe434
je 0x5f53
movsd %xmm0, 0x8(%rsp)
movq 0x182f4(%rip), %r12     # 0x1e0b8
movl 0x17f46(%rip), %esi     # 0x1dd10
testl %esi, %esi
je 0x5f62
movq 0x17f27(%rip), %rdi     # 0x1dd00
callq 0x73ab
cmpl $0x2, 0x864f(%rip)      # 0xe434
jne 0x5df5
leaq 0x378d(%rip), %rdi      # 0x957b
xorl %eax, %eax
callq 0x6378
movq 0x17efc(%rip), %rdi     # 0x1dcf8
testq %rdi, %rdi
je 0x5e12
leaq 0x3229(%rip), %rsi      # 0x9031
callq 0x64a8
movq %rax, %rbx
jmp 0x5e1c
movq 0x81b7(%rip), %rax      # 0xdfd0
movq (%rax), %rbx
movq 0x17edd(%rip), %rsi     # 0x1dd00
andl $0x0, 0x10(%rsi)
movl 0xc(%rsi), %ebp
cvttsd2si 0x10(%rsp), %eax
movl %eax, 0xc(%rsi)
leaq 0x376a(%rip), %rdx      # 0x95a4
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x7478
movq 0x17eb2(%rip), %rax     # 0x1dd00
movl %ebp, 0xc(%rax)
cmpq $0x0, 0x1824f(%rip)     # 0x1e0a8
je 0x5e63
cvttsd2si (%r12), %ebp
jmp 0x5e63
movsd 0x8(%rsp), %xmm1
cmpl $0x8, 0x85c8(%rip)      # 0xe438
pushq $0x7f
popq %rax
cmovnel %r14d, %eax
movl %eax, 0x8(%rsp)
cvttsd2si %xmm1, %eax
movsd 0x10(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movslq %eax, %r14
movslq %ecx, %r13
leaq 0x3bd5(%rip), %r15      # 0x9a6f
cmpq %r13, %r14
jge 0x5f18
movq 0x17e5a(%rip), %rax     # 0x1dd00
movslq 0xc(%rax), %rax
cmpq %rax, %r14
jge 0x5f18
testl %ebp, %ebp
je 0x5eec
cmpl %r14d, %ebp
jne 0x5eec
cmpq $0x0, 0x181e8(%rip)     # 0x1e0a8
je 0x5eec
leaq 0x8(%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x21d0
movq 0x208(%r12), %r12
testq %r12, %r12
je 0x5ee9
cvttsd2si (%r12), %ebp
jmp 0x5eaf
xorl %r12d, %r12d
movq 0x17e0d(%rip), %rax     # 0x1dd00
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax,%r14,4), %edx
addl 0x8(%rsp), %edx
movq %rbx, %rdi
leaq 0x38b1(%rip), %rsi      # 0x97bd
xorl %eax, %eax
callq 0x21d0
incq %r14
jmp 0x5e9a
movq %rbx, %rdi
callq 0x20c0
movq 0x17dd9(%rip), %rdi     # 0x1dd00
xorl %esi, %esi
callq 0x67ac
cmpq $0x0, 0x18172(%rip)     # 0x1e0a8
je 0x5f3d
callq 0x5b69
movl 0x17dcd(%rip), %eax     # 0x1dd10
movl %eax, 0x1812b(%rip)     # 0x1e074
movl $0x1, 0x84e1(%rip)      # 0xe434
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x808f(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x35f5(%rip), %rdi      # 0x9568
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
callq 0x22c0
movl 0x17d8c(%rip), %esi     # 0x1dd10
jmp 0x5dd2