// File: /workspace/github_c_makefile_star2_O3/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, %r12
movq %rsi, %r15
movq %rdi, %rbx
cmpq $0x0, (%rdi)
je 0xe122
movq %rbx, %rdi
callq 0xdea8
movq %r15, %rdi
callq 0xe279
movq %rax, %r14
movl $0x8, %esi
movq %rax, %rdi
callq 0xd380
movq %rax, (%rbx)
testq %rax, %rax
je 0xe220
movq %r14, 0x8(%rbx)
movq %r12, %rdi
callq 0xd640
movq %rax, 0x10(%rbx)
movb $0x1, %bpl
testq %r14, %r14
jle 0xe254
xorl %r12d, %r12d
leaq 0x8(%rsp), %rbp
movq %r14, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
cmpb $0x0, (%r15)
je 0xe1ac
movq %r15, %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0xe602
cmpl $-0x1, %eax
je 0xe23c
cmpl $0xa, %eax
je 0xe1ac
movq 0x8(%rsp), %rax
cmpb $0x0, (%r13,%rax)
leaq (%r13,%rax), %r13
jne 0xe181
movq %r15, %rdi
movl $0xa, %esi
callq 0xd230
testq %rax, %rax
je 0xe265
movq %rax, %r13
movq %rax, %rbp
subq %r15, %rbp
leaq 0x1(%rbp), %rdi
callq 0xd4c0
movq (%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq (%rbx), %rax
movq (%rax,%r12,8), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xd0b0
movq (%rbx), %rax
movq %r14, (%rax,%r12,8)
movq 0x10(%rsp), %r14
movq (%rbx), %rax
movq (%rax,%r12,8), %rax
movb $0x0, (%rax,%rbp)
leaq 0x8(%rsp), %rbp
incq %r13
incq %r12
movq %r13, %r15
cmpq %r14, %r12
jne 0xe16f
jmp 0xe274
leaq 0x1f39a(%rip), %rdi     # 0x2d5c1
leaq 0x1f3b6(%rip), %rsi     # 0x2d5e4
xorl %ebp, %ebp
movq %r14, %rdx
xorl %eax, %eax
callq 0xd954
jmp 0xe254
leaq 0x1f3b7(%rip), %rdi     # 0x2d5fa
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xd954
movq %rbx, %rdi
callq 0xdea8
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0xd640
movq (%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movb $0x1, %bpl
jmp 0xe254