// File: /workspace/github_c_makefile_star2_O1/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, 0x8edc(%rip)      # 0xf434
je 0x6738
movsd %xmm0, 0x8(%rsp)
movq 0x18b4d(%rip), %r12     # 0x1f0b8
cmpl $0x0, 0x1879e(%rip)     # 0x1ed10
je 0x6747
movq 0x18781(%rip), %rdi     # 0x1ed00
movl 0x1878b(%rip), %esi     # 0x1ed10
callq 0x7c29
cmpl $0x2, 0x8ea3(%rip)      # 0xf434
jne 0x65a1
leaq 0x3fc1(%rip), %rdi      # 0xa55b
xorl %eax, %eax
callq 0x6b88
movq 0x18750(%rip), %rdi     # 0x1ecf8
testq %rdi, %rdi
je 0x65be
leaq 0x3a7d(%rip), %rsi      # 0xa031
callq 0x6c22
movq %rax, %rbx
jmp 0x65c8
movq 0x8a0b(%rip), %rax      # 0xefd0
movq (%rax), %rbx
movq 0x18731(%rip), %rsi     # 0x1ed00
movl $0x0, 0x10(%rsi)
movl 0xc(%rsi), %ebp
cvttsd2si 0x10(%rsp), %eax
movl %eax, 0xc(%rsi)
leaq 0x3f9b(%rip), %rdx      # 0xa584
movq $0x0, (%rsp)
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x7cfd
movq 0x186fe(%rip), %rax     # 0x1ed00
movl %ebp, 0xc(%rax)
cmpq $0x0, 0x18a9b(%rip)     # 0x1f0a8
je 0x6617
cvttsd2si (%r12), %ebp
jmp 0x6617
movsd 0x8(%rsp), %xmm1
cmpl $0x8, 0x8e14(%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 0x66d5
movslq %eax, %r13
leaq 0x43e5(%rip), %r15      # 0xaa3f
movq 0x1869f(%rip), %rax     # 0x1ed00
movslq 0xc(%rax), %rax
cmpq %rax, %r13
jge 0x66d5
testl %ebp, %ebp
je 0x66a7
cmpl %r13d, %ebp
jne 0x66a7
cmpq $0x0, 0x18a2d(%rip)     # 0x1f0a8
je 0x66a7
leaq 0x8(%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x21d0
movq 0x208(%r12), %r12
testq %r12, %r12
je 0x66a4
cvttsd2si (%r12), %ebp
jmp 0x666a
xorl %r12d, %r12d
movq 0x18652(%rip), %rax     # 0x1ed00
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %edx
addl (%rsp), %edx
movq %rbx, %rdi
leaq 0x40c7(%rip), %rsi      # 0xa78d
xorl %eax, %eax
callq 0x21d0
incq %r13
cmpl %r14d, %r13d
jne 0x665a
movq %rbx, %rdi
callq 0x20c0
movq 0x1861c(%rip), %rdi     # 0x1ed00
xorl %esi, %esi
callq 0x6f73
cmpq $0x0, 0x189b5(%rip)     # 0x1f0a8
sete %al
movq 0x189bb(%rip), %rdi     # 0x1f0b8
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x6722
movq 0x208(%rdi), %rbx
movq %rbx, 0x189a3(%rip)     # 0x1f0b8
callq 0x2040
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x6707
movl 0x185e8(%rip), %eax     # 0x1ed10
movl %eax, 0x18946(%rip)     # 0x1f074
movl $0x1, 0x8cfc(%rip)      # 0xf434
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2429
jmp 0x6578