// File: /workspace/github_c_makefile_star2_O3/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, 0x8fd0(%rip)      # 0xf434
je 0x6623
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x18c3c(%rip), %r12     # 0x1f0b8
movl 0x1888e(%rip), %esi     # 0x1ed10
testl %esi, %esi
je 0x6624
movq 0x1886f(%rip), %rdi     # 0x1ed00
callq 0x7db4
cmpl $0x2, 0x8f97(%rip)      # 0xf434
jne 0x64ad
leaq 0x40f5(%rip), %rdi      # 0xa59b
xorl %eax, %eax
callq 0x6cc0
movq 0x18844(%rip), %rdi     # 0x1ecf8
testq %rdi, %rdi
je 0x64ca
leaq 0x3b71(%rip), %rsi      # 0xa031
callq 0x6d5a
movq %rax, %rbx
jmp 0x64d4
movq 0x8aff(%rip), %rax      # 0xefd0
movq (%rax), %rbx
cvttsd2si 0x18bac(%rip), %eax # 0x1f088
movq 0x1881d(%rip), %rsi     # 0x1ed00
movl %eax, 0x10(%rsi)
movslq 0xc(%rsi), %rcx
movq %rcx, (%rsp)
testq %rcx, %rcx
jns 0x64fa
movl $0x0, 0xc(%rsi)
leaq 0x40c3(%rip), %rdx      # 0xa5c4
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x7e8c
cmpq $0x0, 0x18b93(%rip)     # 0x1f0a8
je 0x651f
cvttsd2si (%r12), %r14d
jmp 0x651f
cmpl $0x8, 0x8f12(%rip)      # 0xf438
movl $0x7f, %eax
cmovel %eax, %ebp
cmpl $0x0, (%rsp)
jle 0x65b2
leaq 0x4544(%rip), %r15      # 0xaa7f
xorl %r13d, %r13d
testl %r14d, %r14d
je 0x657c
movl %r14d, %eax
cmpq %rax, %r13
jne 0x6584
cmpq $0x0, 0x18b55(%rip)     # 0x1f0a8
je 0x6584
leaq 0x8(%r12), %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x21d0
movq 0x208(%r12), %r12
testq %r12, %r12
je 0x6581
cvttsd2si (%r12), %r14d
jmp 0x653e
xorl %r14d, %r14d
jmp 0x6584
xorl %r12d, %r12d
movq 0x18775(%rip), %rax     # 0x1ed00
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %edx
addl %ebp, %edx
movq %rbx, %rdi
leaq 0x422b(%rip), %rsi      # 0xa7cd
xorl %eax, %eax
callq 0x21d0
incq %r13
cmpq (%rsp), %r13
jne 0x653e
movq %rbx, %rdi
callq 0x20c0
movq 0x1873f(%rip), %rdi     # 0x1ed00
xorl %esi, %esi
callq 0x70a1
cmpq $0x0, 0x18ad8(%rip)     # 0x1f0a8
sete %al
movq 0x18ade(%rip), %rdi     # 0x1f0b8
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x65ff
movq 0x208(%rdi), %rbx
movq %rbx, 0x18ac6(%rip)     # 0x1f0b8
callq 0x2040
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x65e4
movl 0x1870b(%rip), %eax     # 0x1ed10
movl %eax, 0x18a69(%rip)     # 0x1f074
movl $0x1, 0x8e1f(%rip)      # 0xf434
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x89cd(%rip), %rax      # 0xeff8
movq (%rax), %rcx
leaq 0x3f53(%rip), %rdi      # 0xa588
movl $0x12, %esi
movl $0x1, %edx
callq 0x22d0
movl 0x186c6(%rip), %esi     # 0x1ed10
jmp 0x648a