// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce.c
// Function: ce_buffer_insert_string
bool ce_buffer_insert_string(CeBuffer_t* buffer, const char* string, CePoint_t point){
     if(buffer->status == CE_BUFFER_STATUS_READONLY) return false;

     if(!ce_buffer_point_is_valid(buffer, point)){
          if(buffer->line_count == 0 && ce_points_equal(point, (CePoint_t){0, 0})){
               int64_t line_count = ce_util_count_string_lines(string);
               buffer_realloc_lines(buffer, line_count);
          }else if(point.y == buffer->line_count && point.x == 0){
               // allow inserting a string after a buffer by resizing
               if(!buffer_realloc_lines(buffer, buffer->line_count + 1)) return false;
               buffer->lines[point.y] = calloc(1, 1); // allocate an empty string
          }else{
               return false;
          }
     }

     int64_t string_lines = ce_util_count_string_lines(string);
     if(string_lines == 0){
          return true; // sure, yeah, we inserted that empty string
     }else if(string_lines == 1){
          char* line = buffer->lines[point.y];
          size_t insert_len = strlen(string);
          size_t existing_len = strlen(line);
          size_t total_len = insert_len + existing_len;

          // re-alloc the new size
          line = realloc(line, total_len + 1);
          if(!line) return false;

          // figure out where to move from and to
          char* src = ce_utf8_iterate_to(line, point.x);
          char* dst = src + insert_len;
          size_t src_len = strlen(src);
          memmove(dst, src, src_len);

          // insert the string
          memcpy(src, string, insert_len);

          // tidy up
          line[total_len] = 0;
          buffer->lines[point.y] = line;
          buffer->status = CE_BUFFER_STATUS_MODIFIED;
          return true;
     }

     int64_t shift_lines = string_lines - 1;
     int64_t old_line_count = buffer->line_count;

     // allocate space to fit the buffer plus the new multiline string
     if(!buffer_realloc_lines(buffer, buffer->line_count + shift_lines)){
          return false;
     }

     // shift down all the line pointers
     int64_t first_new_line = point.y + 1;
     char** src_line = buffer->lines + first_new_line;
     char** dst_line = src_line + shift_lines;
     size_t move_count = old_line_count - first_new_line;
     memmove(dst_line, src_line, move_count * sizeof(src_line));

     // save the last part of the first line to stick on the end of the multiline string
     char* end_string = NULL;
     int64_t end_string_len = strlen(buffer->lines[point.y] + point.x);
     if(end_string_len) end_string = strdup(buffer->lines[point.y] + point.x);

     // insert the first line of the string at the point specified
     const char* next_newline = strchr(string, CE_NEWLINE);
     assert(next_newline);
     size_t first_line_len = next_newline - string;
     size_t new_line_len = point.x + first_line_len;
     buffer->lines[point.y] = realloc(buffer->lines[point.y], new_line_len + 1);
     if(*string != CE_NEWLINE){ // if the first character is a newline, there is no first line of the string
          memcpy(buffer->lines[point.y] + point.x, string, first_line_len);
     }
     buffer->lines[point.y][new_line_len] = 0;

     // copy in each of the new lines
     string = next_newline + 1;
     next_newline = strchr(string, CE_NEWLINE);
     int64_t next_line = point.y + 1;
     while(next_newline){
          new_line_len = next_newline - string;
          buffer->lines[next_line] = calloc(1, new_line_len + 1);
          memcpy(buffer->lines[next_line], string, new_line_len);
          buffer->lines[next_line][new_line_len] = 0;
          string = next_newline + 1;
          next_newline = strchr(string, CE_NEWLINE);
          next_line++;
     }

     // copy in the last line
     new_line_len = strlen(string);
     int64_t last_line_len = new_line_len + end_string_len;
     buffer->lines[next_line] = calloc(1, last_line_len + 1);
     memcpy(buffer->lines[next_line], string, new_line_len);

     // attach the end part of the line we inserted into at the end of the last line
     if(end_string){
          memcpy(buffer->lines[next_line] + new_line_len, end_string, end_string_len);
          free(end_string);
     }

     buffer->lines[next_line][last_line_len] = 0;

     buffer->status = CE_BUFFER_STATUS_MODIFIED;
     return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpl $0x2, 0x18(%rdi)
jne 0xda18
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %rbx
movq %rdx, %rsi
movq %rcx, %rdx
callq 0xe425
testq %rax, %rax
je 0xdafc
movq %rbp, %rdi
callq 0xe1cf
movb $0x1, %r14b
testq %rax, %rax
je 0xda06
movq %rax, %r13
cmpq $0x1, %rax
jne 0xdb5c
movq (%rbx), %rax
movq (%rax,%r15,8), %r13
movq %rbp, %rdi
callq 0xd210
movq %r15, 0x18(%rsp)
movq %rax, %r15
movq %r13, %rdi
callq 0xd210
movq %r15, 0x8(%rsp)
movq %rax, 0x10(%rsp)
leaq (%rax,%r15), %rsi
incq %rsi
movq %r13, %rdi
callq 0xd520
testq %rax, %rax
je 0xda03
movq %rax, %r13
movq 0x8(%rsp), %r15
addq %r15, 0x10(%rsp)
movq %rax, %rdi
movq %r12, %rsi
callq 0xe4a6
movq %rax, %r12
movq %rbp, (%rsp)
movq %r15, %rbp
addq %rax, %rbp
movq %rax, %rdi
callq 0xd210
movq %rbp, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xd580
movq %r12, %rdi
movq (%rsp), %rsi
movq %r15, %rdx
callq 0xd420
movq 0x10(%rsp), %rax
movb $0x0, (%r13,%rax)
movq (%rbx), %rax
movq 0x18(%rsp), %rcx
movq %r13, (%rax,%rcx,8)
jmp 0xdd2d
movq 0x8(%rbx), %rax
testq %rax, %rax
jne 0xdb25
movq %r12, %rcx
orq %r15, %rcx
jne 0xdb25
movq %rbp, %rdi
callq 0xe1cf
movq %rbx, %rdi
movq %rax, %rsi
callq 0xedbf
jmp 0xda38
xorq %r15, %rax
orq %r12, %rax
jne 0xda03
leaq 0x1(%r15), %rsi
movq %rbx, %rdi
callq 0xedbf
testb %al, %al
je 0xda03
pushq $0x1
popq %rdi
movq %rdi, %rsi
callq 0xd380
movq (%rbx), %rcx
movq %rax, (%rcx,%r15,8)
jmp 0xda38
movq %rbp, (%rsp)
movq 0x8(%rbx), %rbp
leaq -0x1(,%r13), %rsi
addq %rbp, %rsi
movq %rbx, %rdi
callq 0xedbf
testb %al, %al
je 0xda03
decq %r13
leaq 0x1(%r15), %rax
leaq 0x8(,%r15,8), %r14
movq (%rbx), %rsi
addq %r14, %rsi
leaq (%rsi,%r13,8), %rdi
subq %rax, %rbp
shlq $0x3, %rbp
movq %rbp, %rdx
callq 0xd580
movq (%rbx), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x18(%rsp)
leaq (%rax,%r12), %r13
movq %r13, %rdi
callq 0xd210
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0xdbd8
movq %r13, %rdi
callq 0xd640
movq %rax, 0x8(%rsp)
jmp 0xdbe1
movq $0x0, 0x8(%rsp)
movq (%rsp), %rbp
pushq $0xa
popq %rsi
movq %rbp, %rdi
callq 0xd230
testq %rax, %rax
je 0xdd39
movq %rax, %r13
movq %rbp, %rcx
movq %rax, %rbp
subq %rcx, %rbp
leaq (%r12,%rbp), %rax
movq %rax, 0x20(%rsp)
leaq (%r12,%rbp), %rsi
incq %rsi
movq 0x18(%rsp), %rdi
callq 0xd520
movq (%rsp), %rsi
movq (%rbx), %rcx
movq %rax, (%rcx,%r15,8)
cmpb $0xa, (%rsi)
je 0xdc41
movq (%rbx), %rax
addq (%rax,%r15,8), %r12
movq %r12, %rdi
movq %rbp, %rdx
callq 0xd420
movq (%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0x20(%rsp), %rcx
movb $0x0, (%rax,%rcx)
incq %r13
pushq $0xa
popq %rsi
movq %r13, %rdi
callq 0xd230
movq %rax, %r12
pushq $0x1
popq %r15
testq %r12, %r12
je 0xdcbb
movq %r12, %rbp
subq %r13, %rbp
leaq 0x1(%rbp), %rsi
movq %r15, %rdi
callq 0xd380
movq (%rbx), %rcx
movq %rax, (%rcx,%r14)
movq (%rbx), %rax
movq (%rax,%r14), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xd420
movq (%rbx), %rax
movq (%rax,%r14), %rax
movb $0x0, (%rax,%rbp)
movq %r12, %r13
incq %r13
movq %r13, %rdi
pushq $0xa
popq %rsi
callq 0xd230
movq %rax, %r12
addq $0x8, %r14
jmp 0xdc66
movq %r13, %rdi
callq 0xd210
movq %rax, %r15
movq 0x10(%rsp), %rbp
leaq (%rax,%rbp), %r12
leaq (%rax,%rbp), %rsi
incq %rsi
pushq $0x1
popq %rdi
callq 0xd380
movq (%rbx), %rcx
movq %rax, (%rcx,%r14)
movq (%rbx), %rax
movq (%rax,%r14), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0xd420
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0xdd1e
movq (%rbx), %rax
addq (%rax,%r14), %r15
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xd420
movq %r13, %rdi
callq 0xd090
movq (%rbx), %rax
movq (%rax,%r14), %rax
movb $0x0, (%rax,%r12)
movb $0x1, %r14b
movl $0x1, 0x18(%rbx)
jmp 0xda06
leaq 0x1c92b(%rip), %rdi     # 0x2a66b
leaq 0x1c931(%rip), %rsi     # 0x2a678
leaq 0x1c92f(%rip), %rcx     # 0x2a67d
movl $0x310, %edx            # imm = 0x310
callq 0xd280