// File: /workspace/github_c_makefile_star2_O1/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, 0x90c1(%rip)      # 0xf434
je 0x6532
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x18d2d(%rip), %r12     # 0x1f0b8
cmpl $0x0, 0x1897e(%rip)     # 0x1ed10
je 0x6533
movq 0x18961(%rip), %rdi     # 0x1ed00
movl 0x1896b(%rip), %esi     # 0x1ed10
callq 0x7c29
cmpl $0x2, 0x9083(%rip)      # 0xf434
jne 0x63c1
leaq 0x41a1(%rip), %rdi      # 0xa55b
xorl %eax, %eax
callq 0x6b88
movq 0x18930(%rip), %rdi     # 0x1ecf8
testq %rdi, %rdi
je 0x63de
leaq 0x3c5d(%rip), %rsi      # 0xa031
callq 0x6c22
movq %rax, %rbx
jmp 0x63e8
movq 0x8beb(%rip), %rax      # 0xefd0
movq (%rax), %rbx
cvttsd2si 0x18c98(%rip), %eax # 0x1f088
movq 0x18909(%rip), %rsi     # 0x1ed00
movl %eax, 0x10(%rsi)
movslq 0xc(%rsi), %rcx
movq %rcx, (%rsp)
testq %rcx, %rcx
jns 0x640e
movl $0x0, 0xc(%rsi)
leaq 0x416f(%rip), %rdx      # 0xa584
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x7cfd
cmpq $0x0, 0x18c7f(%rip)     # 0x1f0a8
je 0x6433
cvttsd2si (%r12), %r14d
jmp 0x6433
cmpl $0x8, 0x8ffe(%rip)      # 0xf438
movl $0x7f, %eax
cmovel %eax, %ebp
cmpl $0x0, (%rsp)
jle 0x64c1
leaq 0x45f0(%rip), %r15      # 0xaa3f
xorl %r13d, %r13d
testl %r14d, %r14d
je 0x6493
movl %r14d, %eax
cmpq %rax, %r13
jne 0x6493
cmpq $0x0, 0x18c41(%rip)     # 0x1f0a8
je 0x6493
leaq 0x8(%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x21d0
movq 0x208(%r12), %r12
testq %r12, %r12
je 0x6490
cvttsd2si (%r12), %r14d
jmp 0x6452
xorl %r12d, %r12d
movq 0x18866(%rip), %rax     # 0x1ed00
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %edx
addl %ebp, %edx
movq %rbx, %rdi
leaq 0x42dc(%rip), %rsi      # 0xa78d
xorl %eax, %eax
callq 0x21d0
incq %r13
cmpq (%rsp), %r13
jne 0x6452
movq %rbx, %rdi
callq 0x20c0
movq 0x18830(%rip), %rdi     # 0x1ed00
xorl %esi, %esi
callq 0x6f73
cmpq $0x0, 0x18bc9(%rip)     # 0x1f0a8
sete %al
movq 0x18bcf(%rip), %rdi     # 0x1f0b8
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x650e
movq 0x208(%rdi), %rbx
movq %rbx, 0x18bb7(%rip)     # 0x1f0b8
callq 0x2040
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x64f3
movl 0x187fc(%rip), %eax     # 0x1ed10
movl %eax, 0x18b5a(%rip)     # 0x1f074
movl $0x1, 0x8f10(%rip)      # 0xf434
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x240d
jmp 0x6398