// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xd3d0
cmpl $0x0, %eax
je 0xe2a1
movb $0x0, -0x1(%rbp)
jmp 0xe4ca
movb $0x0, -0xa9(%rbp)
movl -0x90(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
sete %al
andb $0x1, %al
movb %al, -0xa9(%rbp)
testb $0x1, -0xa9(%rbp)
je 0xe2e0
callq 0xd0a0
movl $0x1, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0xe4ca
movq -0x18(%rbp), %rdi
movl $0x2, %esi
callq 0xd580
cmpl $0x0, %eax
je 0xe300
movq -0x10(%rbp), %rax
movl $0x2, 0x18(%rax)
jmp 0xe30b
movq -0x10(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movq $0x0, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x341b8(%rip), %rsi     # 0x424e5
callq 0xd590
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
jne 0xe382
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
callq 0xd0a0
movl (%rax), %edi
callq 0xd630
movq -0xd0(%rbp), %rdx
movq %rax, %rcx
leaq 0x3417d(%rip), %rdi     # 0x424e8
leaq 0x3419b(%rip), %rsi     # 0x4250d
movb $0x0, %al
callq 0xd8f0
movb $0x0, -0x1(%rbp)
jmp 0xe4ca
movq -0xc8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0xd4f0
movq -0xc8(%rbp), %rdi
callq 0xd3b0
movq %rax, -0xb8(%rbp)
movq -0xc8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0xd4f0
movq -0xb8(%rbp), %rdi
addq $0x1, %rdi
callq 0xd4a0
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movq -0xc8(%rbp), %rcx
movl $0x1, %edx
callq 0xd150
movq -0xc0(%rbp), %rax
movq -0xb8(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0xc0(%rbp), %rdi
callq 0xd200
cmpq -0xb8(%rbp), %rax
je 0xe446
movq -0x18(%rbp), %rdx
leaq 0x340fd(%rip), %rdi     # 0x42521
leaq 0x340e2(%rip), %rsi     # 0x4250d
movb $0x0, %al
callq 0xd8f0
callq 0xd0a0
movl $0x5c, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0xe4ca
movq -0xc0(%rbp), %rax
movq -0xb8(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0xe477
movq -0xc0(%rbp), %rax
movq -0xb8(%rbp), %rcx
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xe4e0
testb $0x1, %al
jne 0xe495
movb $0x0, -0x1(%rbp)
jmp 0xe4ca
movq -0xc8(%rbp), %rdi
callq 0xd1e0
movq -0xc0(%rbp), %rdi
callq 0xd090
movq -0x18(%rbp), %rdx
leaq 0x34093(%rip), %rdi     # 0x4254b
leaq 0x3404e(%rip), %rsi     # 0x4250d
movb $0x0, %al
callq 0xd8f0
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)