// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x1, 0xa634(%rip)      # 0x12404
jne 0x7dd7
jmp 0x8013
cmpq $0x0, 0x1a299(%rip)     # 0x22078
je 0x7dec
movq 0x1a2a0(%rip), %rax     # 0x22088
movq %rax, -0x30(%rbp)
cmpl $0x0, 0x19eed(%rip)     # 0x21ce0
jne 0x7e0d
movq 0xa1fc(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x57fc(%rip), %rsi      # 0xd602
movb $0x0, %al
callq 0x2190
movq 0x19ebc(%rip), %rdi     # 0x21cd0
movl 0x19ec6(%rip), %esi     # 0x21ce0
callq 0xa5f0
cmpl $0x2, 0xa5de(%rip)      # 0x12404
jne 0x7e36
leaq 0x57e6(%rip), %rdi      # 0xd615
movb $0x0, %al
callq 0x8c70
cmpq $0x0, 0x19e8a(%rip)     # 0x21cc8
jne 0x7e50
movq 0xa189(%rip), %rax      # 0x11fd0
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x7e67
movq 0x19e71(%rip), %rdi     # 0x21cc8
leaq 0x5227(%rip), %rsi      # 0xd085
callq 0x8dc0
movq %rax, -0x18(%rbp)
movq 0x19e62(%rip), %rax     # 0x21cd0
movl $0x0, 0x10(%rax)
movq 0x19e54(%rip), %rax     # 0x21cd0
cvtsi2sdl 0xc(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
cvttsd2si -0x10(%rbp), %ecx
movq 0x19e3e(%rip), %rax     # 0x21cd0
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rdi
movq 0x19e30(%rip), %rsi     # 0x21cd0
leaq 0x5797(%rip), %rdx      # 0xd63e
xorl %eax, %eax
movl %eax, %ecx
callq 0xa740
cvttsd2si -0x38(%rbp), %ecx
movq 0x19e14(%rip), %rax     # 0x21cd0
movl %ecx, 0xc(%rax)
cmpq $0x0, 0x1a1b1(%rip)     # 0x22078
je 0x7ed4
movq -0x30(%rbp), %rax
cvttsd2si (%rax), %eax
movl %eax, -0x20(%rbp)
movl 0xa52e(%rip), %edx      # 0x12408
xorl %eax, %eax
movl $0x7f, %ecx
cmpl $0x8, %edx
cmovel %ecx, %eax
movl %eax, -0x24(%rbp)
cvttsd2si -0x8(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
movsd -0x8(%rbp), %xmm0
addsd -0x10(%rbp), %xmm0
cvttsd2si %xmm0, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x39(%rbp)
jge 0x7f1f
movl -0x1c(%rbp), %eax
movq 0x19dba(%rip), %rcx     # 0x21cd0
cmpl 0xc(%rcx), %eax
setl %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x7f2b
jmp 0x7fd5
jmp 0x7f2d
xorl %eax, %eax
cmpl $0x0, -0x20(%rbp)
movb %al, -0x3a(%rbp)
je 0x7f53
movl -0x1c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x20(%rbp), %ecx
movb %al, -0x3a(%rbp)
jne 0x7f53
cmpq $0x0, 0x1a12b(%rip)     # 0x22078
setne %al
movb %al, -0x3a(%rbp)
movb -0x3a(%rbp), %al
testb $0x1, %al
jne 0x7f5c
jmp 0x7f9d
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rdx
addq $0x8, %rdx
leaq 0x5b8b(%rip), %rsi      # 0xdafa
movb $0x0, %al
callq 0x2190
movq -0x30(%rbp), %rax
movq 0x208(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x7f99
movq -0x30(%rbp), %rax
cvttsd2si (%rax), %eax
movl %eax, -0x20(%rbp)
jmp 0x7f9b
jmp 0x7f9d
jmp 0x7f2d
movq -0x18(%rbp), %rdi
movq 0x19d28(%rip), %rax     # 0x21cd0
movq 0x18(%rax), %rax
movq (%rax), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl -0x24(%rbp), %edx
leaq 0x587d(%rip), %rsi      # 0xd83d
movb $0x0, %al
callq 0x2190
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x7ef2
movq -0x18(%rbp), %rdi
callq 0x2090
movq 0x19ceb(%rip), %rdi     # 0x21cd0
xorl %eax, %eax
movl %eax, %esi
callq 0x9440
cmpq $0x0, 0x1a082(%rip)     # 0x22078
je 0x7ffd
callq 0x7ac0
movl 0x19cdd(%rip), %eax     # 0x21ce0
movl %eax, 0x1a03b(%rip)     # 0x22044
movl $0x1, 0xa3f1(%rip)      # 0x12404
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)