// File: /workspace/github_c_makefile_star2_O3/heltilda[P]cicada/ciclib.c
// Function: cclib_save
void cclib_save()
{
    FILE *fileToWrite;
    window *fileNameWindow, *stringWindow;
    linkedlist *fileNameLL, *stringLL = NULL;
    ccInt bytesWritten, rtrn;
    char *fileString, closeFileRetrn;
    
    if (numBIF_args() != 2)  {  setError(wrong_argument_count_err, pcCodePtr-1);  return;  }
    
    
        // get arguments:  file name, string to write
    
    fileNameWindow = getBIFstringArg(1);
    if (errCode != passed)  return;
    stringWindow = getBIFstringArg(2);
    if (errCode != passed)  return;   
    
    fileNameLL = &(fileNameWindow->variable_ptr->mem.data);
    stringLL = &(stringWindow->variable_ptr->mem.data);
    
    
        // defragment the string; copy the file name into a separate buffer
    
    rtrn = defragmentLinkedList(stringLL);
    if (rtrn != passed)  {  setError(out_of_memory_err, pcCodePtr-1);  return;  }
    
    fileString = (char *) malloc(fileNameWindow->width+1);
    if (fileString == NULL)  {  setError(out_of_memory_err, pcCodePtr-1);  return;  }
    getElements(fileNameLL, fileNameWindow->offset+1, fileNameWindow->offset+fileNameWindow->width, fileString);
    fileString[fileNameWindow->width] = 0;
    
    
        // try to open the file; throw error if unsuccessful
    
    fileToWrite = fopen(fileString, "wb");
    if (fileToWrite == NULL)  {  setError(IO_error, pcCodePtr-1);  free((void *) fileString);  return;  }
    
    
        // write the string to the file
    
    if (stringLL->elementNum > 0)  {
        bytesWritten = (ccInt) fwrite(element(stringLL, stringWindow->offset+1), 1, stringWindow->width, fileToWrite);    }
    else  bytesWritten = 0;
    if (bytesWritten != stringWindow->width)  {  setError(IO_error, pcCodePtr-1);  }
    
    
        // close the file
    
    closeFileRetrn = fclose(fileToWrite);
    if ((errCode == passed) && (closeFileRetrn != 0))  {  setError(IO_error, pcCodePtr-1);  }
    
    free((void *) fileString);    // clean up
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
callq 0x19254
cmpl $0x2, %eax
jne 0x17a32
movl $0x1, %edi
callq 0x1943c
leaq 0xdd56(%rip), %rbx      # 0x25760
cmpl $0x0, 0x18(%rbx)
jne 0x17a23
movq %rax, %r12
movl $0x2, %edi
callq 0x1943c
cmpl $0x0, 0x18(%rbx)
je 0x17a5c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdd27(%rip), %rax      # 0x25760
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x2d, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcfa3
movq %rax, %r14
movq 0x10(%r12), %r13
movq 0x10(%rax), %r15
addq $0x10, %r15
movq %r15, %rdi
callq 0x8c00
testl %eax, %eax
je 0x17a8a
movq 0xb8(%rbx), %rsi
addq $-0x4, %rsi
movl $0x1, %edi
jmp 0x17a49
movq %r13, (%rsp)
movslq 0x1c(%r12), %rbp
leaq 0x1(%rbp), %rdi
callq 0x81d0
testq %rax, %rax
je 0x17a78
movq %rax, %r13
movq (%rsp), %rdi
addq $0x10, %rdi
movl 0x18(%r12), %eax
leal 0x1(%rax), %esi
addl %eax, %ebp
movl %ebp, %edx
movq %r13, %rcx
callq 0x90a5
movslq 0x1c(%r12), %rax
movb $0x0, (%r13,%rax)
leaq 0x4325(%rip), %rsi      # 0x1bdf7
movq %r13, %rdi
callq 0x81b0
testq %rax, %rax
je 0x17b3e
movq %rax, %r12
cmpl $0x0, (%r15)
jle 0x17b0c
movl 0x18(%r14), %esi
incl %esi
movq %r15, %rdi
callq 0x91d8
movslq 0x1c(%r14), %rdx
movl $0x1, %esi
movq %rax, %rdi
movq %r12, %rcx
callq 0x8270
jmp 0x17b0e
xorl %eax, %eax
cmpl 0x1c(%r14), %eax
je 0x17b29
movq 0xb8(%rbx), %rsi
addq $-0x4, %rsi
movl $0x31, %edi
callq 0xcfa3
movq %r12, %rdi
callq 0x8170
cmpl $0x0, 0x18(%rbx)
jne 0x17b53
movzbl %al, %eax
testl %eax, %eax
je 0x17b53
movq 0xb8(%rbx), %rsi
addq $-0x4, %rsi
movl $0x31, %edi
callq 0xcfa3
movq %r13, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x81c0