// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce.c
// Function: ce_buffer_load_string
bool ce_buffer_load_string(CeBuffer_t* buffer, const char* string, const char* name){
     if(buffer->lines) ce_buffer_free(buffer);

     int64_t line_count = ce_util_count_string_lines(string);

     // allocate for the number of lines contained in the string
     buffer->lines = (char**)calloc(line_count, sizeof(*buffer->lines));
     if(!buffer->lines){
          ce_log("%s() failed to allocate %ld lines\n", __FUNCTION__, line_count);
          return false;
     }

     buffer->line_count = line_count;
     buffer->name = strdup(name);

     // loop over each line
     const char* newline = NULL;
     size_t line_len = 0;
     for(int64_t i = 0; i < line_count; i++){
          FindNewlineResult_t res = find_next_newline(string);
          if(res.status == FNS_INVALID){
               ce_log("%s() saw invalid utf-8 bytes\n");
               ce_buffer_free(buffer);
               return false;
          }

          // look for the newline
          newline = strchr(string, CE_NEWLINE);

          if(newline){
               // allocate space for the line, excluding the newline character
               line_len = newline - string;
               buffer->lines[i] = (char*)malloc(line_len + 1);
               buffer->lines[i] = strncpy(buffer->lines[i], string, line_len);
               buffer->lines[i][line_len] = 0;

               string = newline + 1;
          }else{
               // if this is the end, just dupe it
               buffer->lines[i] = strdup(string);
               break;
          }
     }

     return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
cmpq $0x0, (%rdi)
je 0xe082
movq %rbx, %rdi
callq 0xde1c
movq %r12, %rdi
callq 0xe1cf
pushq $0x8
popq %rsi
movq %rax, %r14
movq %rax, %rdi
callq 0xd380
movq %rax, (%rbx)
testq %rax, %rax
je 0xe191
movq %r12, (%rsp)
movq %r14, 0x8(%rbx)
movq %r15, %rdi
callq 0xd640
movq %rax, 0x10(%rbx)
xorl %ebp, %ebp
testq %r14, %r14
cmovleq %rbp, %r14
movq %r14, 0x10(%rsp)
leaq 0x8(%rsp), %r12
movb $0x1, %r13b
cmpq 0x10(%rsp), %rbp
je 0xe1ac
andq $0x0, 0x8(%rsp)
movq (%rsp), %r15
cmpb $0x0, (%r15)
je 0xe105
movq %r15, %rdi
movq %r12, %rsi
callq 0xe53f
cmpl $-0x1, %eax
je 0xe176
cmpl $0xa, %eax
je 0xe105
addq 0x8(%rsp), %r15
jmp 0xe0e3
movq %rbp, %r14
movq (%rsp), %rbp
movq %rbp, %rdi
pushq $0xa
popq %rsi
callq 0xd230
testq %rax, %rax
je 0xe1be
movq %rax, %r15
movq %rax, %r13
subq %rbp, %r13
leaq 0x1(%r13), %rdi
callq 0xd4c0
movq (%rbx), %rcx
movq %r14, %rdx
movq %rax, (%rcx,%r14,8)
movq (%rbx), %rax
movq (%rax,%r14,8), %r14
movq %r14, %rdi
movq %rbp, %rsi
movq %rdx, %rbp
movq %r13, %rdx
callq 0xd0b0
movq (%rbx), %rax
movq %r14, (%rax,%rbp,8)
movq (%rbx), %rax
movq (%rax,%rbp,8), %rax
movb $0x0, (%rax,%r13)
incq %r15
incq %rbp
movq %r15, (%rsp)
jmp 0xe0cb
leaq 0x1c47d(%rip), %rdi     # 0x2a5fa
xorl %r13d, %r13d
xorl %eax, %eax
callq 0xd8e5
movq %rbx, %rdi
callq 0xde1c
jmp 0xe1ac
leaq 0x1c429(%rip), %rdi     # 0x2a5c1
leaq 0x1c445(%rip), %rsi     # 0x2a5e4
xorl %r13d, %r13d
movq %r14, %rdx
xorl %eax, %eax
callq 0xd8e5
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
callq 0xd640
movq (%rbx), %rcx
movq %rax, (%rcx,%r14,8)
jmp 0xe1ac