// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x18(%rbp)
cmpl $0x1, 0xa86e(%rip)      # 0x12404
jne 0x7b9d
jmp 0x7da8
cmpq $0x0, 0x1a4d3(%rip)     # 0x22078
je 0x7bb2
movq 0x1a4da(%rip), %rax     # 0x22088
movq %rax, -0x20(%rbp)
cmpl $0x0, 0x1a127(%rip)     # 0x21ce0
jne 0x7bd3
movq 0xa436(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x5a36(%rip), %rsi      # 0xd602
movb $0x0, %al
callq 0x2190
movq 0x1a0f6(%rip), %rdi     # 0x21cd0
movl 0x1a100(%rip), %esi     # 0x21ce0
callq 0xa5f0
cmpl $0x2, 0xa818(%rip)      # 0x12404
jne 0x7bfc
leaq 0x5a20(%rip), %rdi      # 0xd615
movb $0x0, %al
callq 0x8c70
cmpq $0x0, 0x1a0c4(%rip)     # 0x21cc8
jne 0x7c16
movq 0xa3c3(%rip), %rax      # 0x11fd0
movq (%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x7c2d
movq 0x1a0ab(%rip), %rdi     # 0x21cc8
leaq 0x5461(%rip), %rsi      # 0xd085
callq 0x8dc0
movq %rax, -0x8(%rbp)
cvttsd2si 0x1a423(%rip), %ecx # 0x22058
movq 0x1a094(%rip), %rax     # 0x21cd0
movl %ecx, 0x10(%rax)
movq 0x1a08a(%rip), %rax     # 0x21cd0
movl 0xc(%rax), %eax
movl %eax, -0xc(%rbp)
movq 0x1a07d(%rip), %rax     # 0x21cd0
cmpl $0x0, 0xc(%rax)
jge 0x7c67
movq 0x1a070(%rip), %rax     # 0x21cd0
movl $0x0, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq 0x1a05e(%rip), %rsi     # 0x21cd0
leaq 0x59c5(%rip), %rdx      # 0xd63e
xorl %eax, %eax
movl %eax, %ecx
callq 0xa740
cmpq $0x0, 0x1a3ee(%rip)     # 0x22078
je 0x7c97
movq -0x20(%rbp), %rax
cvttsd2si (%rax), %eax
movl %eax, -0x14(%rbp)
movl 0xa76b(%rip), %edx      # 0x12408
xorl %eax, %eax
movl $0x7f, %ecx
cmpl $0x8, %edx
cmovel %ecx, %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x7d6a
jmp 0x7cc2
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x21(%rbp)
je 0x7ce8
movl -0x10(%rbp), %ecx
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x21(%rbp)
jne 0x7ce8
cmpq $0x0, 0x1a396(%rip)     # 0x22078
setne %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0x7cf1
jmp 0x7d32
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
addq $0x8, %rdx
leaq 0x5df6(%rip), %rsi      # 0xdafa
movb $0x0, %al
callq 0x2190
movq -0x20(%rbp), %rax
movq 0x208(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x7d2e
movq -0x20(%rbp), %rax
cvttsd2si (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x7d30
jmp 0x7d32
jmp 0x7cc2
movq -0x8(%rbp), %rdi
movq 0x19f93(%rip), %rax     # 0x21cd0
movq 0x18(%rax), %rax
movq (%rax), %rax
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl -0x18(%rbp), %edx
leaq 0x5ae8(%rip), %rsi      # 0xd83d
movb $0x0, %al
callq 0x2190
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x7cb4
movq -0x8(%rbp), %rdi
callq 0x2090
movq 0x19f56(%rip), %rdi     # 0x21cd0
xorl %eax, %eax
movl %eax, %esi
callq 0x9440
cmpq $0x0, 0x1a2ed(%rip)     # 0x22078
je 0x7d92
callq 0x7ac0
movl 0x19f48(%rip), %eax     # 0x21ce0
movl %eax, 0x1a2a6(%rip)     # 0x22044
movl $0x1, 0xa65c(%rip)      # 0x12404
addq $0x30, %rsp
popq %rbp
retq
nop