// File: /workspace/github_c_makefile_star2_O3/justy989[P]ce/ce.c
// Function: ce_buffer_load_file
bool ce_buffer_load_file(CeBuffer_t* buffer, const char* filename){
     struct stat statbuf;
     if(stat(filename, &statbuf) != 0) return false;
     bool is_dir = false;

#if defined(PLATFORM_WINDOWS)
     is_dir = (statbuf.st_mode & _S_IFDIR);
#else
     is_dir = S_ISDIR(statbuf.st_mode);
#endif
     if(is_dir){
          errno = EPERM;
          return false;
     }

#if defined(PLATFORM_WINDOWS)
     bool writeable = (_access(filename, 2) == 0);
     bool readable = (_access(filename, 4) == 0);

     if (!writeable && readable) {
          buffer->status = CE_BUFFER_STATUS_READONLY;
     }else if(writeable && readable){
          buffer->status = CE_BUFFER_STATUS_NONE;
     }else{
          ce_log("File %s not read-able or write-able %d", filename, errno);
          return false;
     }
#else
     if(access(filename, W_OK) != 0){
          buffer->status = CE_BUFFER_STATUS_READONLY;
     }else{
          buffer->status = CE_BUFFER_STATUS_NONE;
     }
#endif

     buffer->file_modified_time = statbuf.st_mtime;

     // read the entire file
     size_t content_size;
     char* contents = NULL;

     FILE* file = fopen(filename, "rb");
     if(!file){
          ce_log("%s() fopen('%s', 'rb') failed: '%s'\n", __FUNCTION__, filename, strerror(errno));
          return false;
     }

     fseek(file, 0, SEEK_END);
     content_size = ftell(file);
     fseek(file, 0, SEEK_SET);

     contents = (char*)malloc(content_size + 1);
     fread(contents, content_size, 1, file);
     contents[content_size] = 0;

     if(strlen(contents) != content_size){
          ce_log("%s() file '%s' has early null terminator\n", __FUNCTION__, filename);
          errno = ENOPROTOOPT;
          return false;
     }

     // strip the ending '\n'
     if(contents[content_size - 1] == CE_NEWLINE) contents[content_size - 1] = 0;

     if(!ce_buffer_load_string(buffer, contents, filename)){
          return false;
     }

     fclose(file);

     free(contents);
     ce_log("%s() loaded '%s'\n", __FUNCTION__, filename);
     return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0xd3f0
testl %eax, %eax
jne 0xdfa2
movl $0xf000, %eax           # imm = 0xF000
andl 0x20(%rsp), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0xdfb8
callq 0xd0a0
movl $0x1, (%rax)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movl $0x2, %esi
callq 0xd5a0
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
addl %ecx, %ecx
movl %ecx, 0x18(%r14)
movq 0x60(%rsp), %rax
movq %rax, 0x68(%r14)
leaq 0x1f567(%rip), %rsi     # 0x2d549
movq %rbx, %rdi
callq 0xd5b0
testq %rax, %rax
je 0xe0a5
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xd510
movq %r15, %rdi
callq 0xd3d0
movq %rax, %r13
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd510
leaq 0x1(%r13), %rdi
callq 0xd4c0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
movq %r15, %rcx
callq 0xd160
movb $0x0, (%r12,%r13)
movq %r12, %rdi
callq 0xd210
cmpq %r13, %rax
jne 0xe0d3
cmpb $0xa, -0x1(%r12,%r13)
jne 0xe05f
movb $0x0, -0x1(%r12,%r13)
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0xe0fd
testb %al, %al
je 0xdfa2
movq %r15, %rdi
callq 0xd1f0
movq %r12, %rdi
callq 0xd090
leaq 0x1f523(%rip), %rdi     # 0x2d5af
leaq 0x1f4de(%rip), %rsi     # 0x2d571
movq %rbx, %rdx
xorl %eax, %eax
callq 0xd954
movb $0x1, %bpl
jmp 0xdfa4
callq 0xd0a0
movl (%rax), %edi
callq 0xd650
leaq 0x1f494(%rip), %rdi     # 0x2d54c
leaq 0x1f4b2(%rip), %rsi     # 0x2d571
xorl %ebp, %ebp
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xd954
jmp 0xdfa4
leaq 0x1f4ab(%rip), %rdi     # 0x2d585
leaq 0x1f490(%rip), %rsi     # 0x2d571
xorl %ebp, %ebp
movq %rbx, %rdx
xorl %eax, %eax
callq 0xd954
callq 0xd0a0
movl $0x5c, (%rax)
jmp 0xdfa4