// File: /workspace/github_c_makefile_star2_O2/pipde[P]deos-songlib/lib/songlib.c
// Function: closeOutput
void 
closeOutput()
    {
    FILE *fp;
    int samples,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 = (int) skip;

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

    samples = output->samples;

    if(output->samples < 0) output->samples = 0;

    writeRRAHeader(fp,output,"createdBy: songlib",0);

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

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

    for(i = 0; i < 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:
cmpl $0x1, 0x8858(%rip)      # 0xe434
je 0x5d6e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x184c4(%rip), %r12     # 0x1e0b8
movl 0x18116(%rip), %esi     # 0x1dd10
testl %esi, %esi
je 0x5d6f
movq 0x180f7(%rip), %rdi     # 0x1dd00
callq 0x73ab
cmpl $0x2, 0x881f(%rip)      # 0xe434
jne 0x5c25
leaq 0x395d(%rip), %rdi      # 0x957b
xorl %eax, %eax
callq 0x6378
movq 0x180cc(%rip), %rdi     # 0x1dcf8
testq %rdi, %rdi
je 0x5c42
leaq 0x33f9(%rip), %rsi      # 0x9031
callq 0x64a8
movq %rax, %rbx
jmp 0x5c4c
movq 0x8387(%rip), %rax      # 0xdfd0
movq (%rax), %rbx
cvttsd2si 0x18434(%rip), %eax # 0x1e088
movq 0x180a5(%rip), %rsi     # 0x1dd00
movl %eax, 0x10(%rsi)
movl 0xc(%rsi), %eax
movq %rax, %r14
testl %eax, %eax
jns 0x5c6c
andl $0x0, 0xc(%rsi)
leaq 0x3931(%rip), %rdx      # 0x95a4
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x7478
cmpq $0x0, 0x18420(%rip)     # 0x1e0a8
je 0x5c92
cvttsd2si (%r12), %ebp
jmp 0x5c92
cmpl $0x8, 0x879f(%rip)      # 0xe438
pushq $0x7f
popq %rax
cmovnel %r15d, %eax
movl %eax, 0x4(%rsp)
testl %r14d, %r14d
cmovlel %r15d, %r14d
leaq 0x3dbd(%rip), %r15      # 0x9a6f
xorl %r13d, %r13d
cmpq %r14, %r13
je 0x5d25
testl %ebp, %ebp
je 0x5cf9
movl %ebp, %eax
cmpq %rax, %r13
jne 0x5cf9
cmpq $0x0, 0x183db(%rip)     # 0x1e0a8
je 0x5cf9
leaq 0x8(%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x21d0
movq 0x208(%r12), %r12
testq %r12, %r12
je 0x5cf6
cvttsd2si (%r12), %ebp
jmp 0x5cba
xorl %r12d, %r12d
movq 0x18000(%rip), %rax     # 0x1dd00
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %edx
addl 0x4(%rsp), %edx
movq %rbx, %rdi
leaq 0x3aa4(%rip), %rsi      # 0x97bd
xorl %eax, %eax
callq 0x21d0
incq %r13
jmp 0x5cb5
movq %rbx, %rdi
callq 0x20c0
movq 0x17fcc(%rip), %rdi     # 0x1dd00
xorl %esi, %esi
callq 0x67ac
cmpq $0x0, 0x18365(%rip)     # 0x1e0a8
je 0x5d4a
callq 0x5b69
movl 0x17fc0(%rip), %eax     # 0x1dd10
movl %eax, 0x1831e(%rip)     # 0x1e074
movl $0x1, 0x86d4(%rip)      # 0xe434
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8282(%rip), %rax      # 0xdff8
movq (%rax), %rcx
leaq 0x37e8(%rip), %rdi      # 0x9568
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
callq 0x22c0
movl 0x17f7f(%rip), %esi     # 0x1dd10
jmp 0x5c02