// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq $0x0, -0x28(%rbp)
callq 0x1fa40
cmpl $0x2, %eax
je 0x1db1b
leaq 0xec4f(%rip), %rax      # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x2d, %edi
callq 0xf740
jmp 0x1dd16
movl $0x1, %edi
callq 0x1fd70
movq %rax, -0x10(%rbp)
leaq 0xec20(%rip), %rax      # 0x2c750
cmpl $0x0, 0x18(%rax)
je 0x1db3b
jmp 0x1dd16
movl $0x2, %edi
callq 0x1fd70
movq %rax, -0x18(%rbp)
leaq 0xec00(%rip), %rax      # 0x2c750
cmpl $0x0, 0x18(%rax)
je 0x1db5b
jmp 0x1dd16
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x10, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x8f70
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x1dbae
leaq 0xebbc(%rip), %rax      # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x1, %edi
callq 0xf740
jmp 0x1dd16
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x81d0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x1dbec
leaq 0xeb7e(%rip), %rax      # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x1, %edi
callq 0xf740
jmp 0x1dd16
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %esi
addl $0x1, %esi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edx
movq -0x10(%rbp), %rax
addl 0x1c(%rax), %edx
movq -0x38(%rbp), %rcx
callq 0x9540
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
leaq 0x511b(%rip), %rsi      # 0x22d47
callq 0x81b0
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x1dc66
leaq 0xeb0d(%rip), %rax      # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x31, %edi
callq 0xf740
movq -0x38(%rbp), %rdi
callq 0x81c0
jmp 0x1dd16
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jle 0x1dca0
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x18(%rax), %esi
addl $0x1, %esi
callq 0x9700
movq %rax, %rdi
movq -0x18(%rbp), %rax
movslq 0x1c(%rax), %rdx
movq -0x8(%rbp), %rcx
movl $0x1, %esi
callq 0x8250
movl %eax, -0x2c(%rbp)
jmp 0x1dca7
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
je 0x1dccf
leaq 0xea96(%rip), %rax      # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x31, %edi
callq 0xf740
movq -0x8(%rbp), %rdi
callq 0x8180
movb %al, -0x39(%rbp)
leaq 0xea6e(%rip), %rax      # 0x2c750
cmpl $0x0, 0x18(%rax)
jne 0x1dd0d
movsbl -0x39(%rbp), %eax
cmpl $0x0, %eax
je 0x1dd0d
leaq 0xea58(%rip), %rax      # 0x2c750
movq 0xb8(%rax), %rsi
addq $-0x4, %rsi
movl $0x31, %edi
callq 0xf740
movq -0x38(%rbp), %rdi
callq 0x81c0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)