// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce_vim.c
// Function: paste_text
static bool paste_text(CeVim_t* vim, const CeVimAction_t* action, CeRange_t motion_range, CeView_t* view,
                       CePoint_t* cursor, const CeConfigOptions_t* config_options, bool after){
     CeVimYank_t* yank = vim->yanks + ce_vim_register_index(action->verb.integer);
     if(!yank->text) return false;

     CePoint_t insertion_point = motion_range.end;

     switch(yank->type){
     default:
          ce_log("unsupported yank type %d\n", yank->type);
          return false;
     case CE_VIM_YANK_TYPE_LINE:
          insertion_point.x = 0;
          if(after) insertion_point.y++;
          break;
     case CE_VIM_YANK_TYPE_STRING:
          if(after){
               insertion_point.x++;
               int64_t line_len = ce_utf8_strlen(view->buffer->lines[insertion_point.y]);
               if(insertion_point.x > line_len) insertion_point.x = line_len - 1;
               if(insertion_point.x < 0) insertion_point.x = 0;
          }
          break;
     case CE_VIM_YANK_TYPE_BLOCK:
     {
          bool chain = false;

          // if the buffer isn't long enough, insert some lines
          int64_t line_count_check = insertion_point.y + yank->block_line_count;
          if(line_count_check > view->buffer->line_count){
               int64_t line_diff = line_count_check - view->buffer->line_count;
               char* newline_str = malloc(line_diff + 1);
               memset(newline_str, '\n', line_diff);
               newline_str[line_diff] = 0;

               CePoint_t newline_point = ce_buffer_end_point(view->buffer);
               if(!ce_buffer_insert_string(view->buffer, newline_str, newline_point)) return false;

               // commit the change
               CeBufferChange_t change = {};
               change.chain = chain;
               change.insertion = true;
               change.string = newline_str;
               change.location = newline_point;
               change.cursor_before = *cursor;
               change.cursor_after = *cursor;
               ce_buffer_change(view->buffer, &change);
               chain = true;
          }

          for(int64_t i = 0; i < yank->block_line_count; i++){
               if(!yank->block[i]) continue;
               CePoint_t point = {insertion_point.x, insertion_point.y + i};

               // if the line isn't long enough, append space so it is long enough
               int64_t line_len = ce_utf8_strlen(view->buffer->lines[point.y]);
               if(insertion_point.x > line_len){
                    int64_t space_len = (insertion_point.x - line_len);
                    char* space_str = malloc(space_len + 1);
                    memset(space_str, ' ', space_len);
                    space_str[space_len] = 0;

                    CePoint_t space_point = {line_len, point.y};
                    if(!ce_buffer_insert_string(view->buffer, space_str, space_point)) return false;

                    // commit the change
                    CeBufferChange_t change = {};
                    change.chain = chain;
                    change.insertion = true;
                    change.string = space_str;
                    change.location = space_point;
                    change.cursor_before = *cursor;
                    change.cursor_after = *cursor;
                    ce_buffer_change(view->buffer, &change);
                    chain = true;
               }

               char* insert_str = strdup(yank->block[i]);
               if(!ce_buffer_insert_string(view->buffer, insert_str, point)) return false;

               // commit the change
               CeBufferChange_t change = {};
               change.chain = chain;
               change.insertion = true;
               change.string = insert_str;
               change.location = point;
               change.cursor_before = *cursor;
               change.cursor_after = *cursor;
               ce_buffer_change(view->buffer, &change);
               chain = true;
          }

          vim->mode = CE_VIM_MODE_NORMAL;
          return true;
     }
     }

     char* insert_str = strdup(yank->text);

     // if we are inserting at the end of a file, put the newline at the beginning and insert at the end of the previous line
     if(insertion_point.x == 0 && insertion_point.y == view->buffer->line_count){
          int64_t insert_len = strlen(insert_str);
          if(insert_len > 0){
               int64_t last_index = insert_len - 1;
               if(insert_str[last_index] == CE_NEWLINE){
                    for(int64_t i = last_index; i > 0; i--){
                         insert_str[i] = insert_str[i - 1];
                    }
                    insert_str[0] = CE_NEWLINE;
                    insertion_point.y = view->buffer->line_count - 1;
                    insertion_point.x = ce_utf8_strlen(view->buffer->lines[insertion_point.y]);
               }
          }
     }

     if(!ce_buffer_insert_string(view->buffer, insert_str, insertion_point)) return false;

     CePoint_t cursor_end = {};

     switch(yank->type){
     default:
          break;
     case CE_VIM_YANK_TYPE_LINE:
          cursor_end = insertion_point;
          break;
     case CE_VIM_YANK_TYPE_STRING:
          cursor_end = ce_buffer_advance_point(view->buffer, *cursor, ce_utf8_strlen(yank->text));
          break;
     }

     // commit the change
     CeBufferChange_t change = {};
     change.chain = action->chain_undo;
     change.insertion = true;
     change.string = insert_str;
     change.location = insertion_point;
     change.cursor_before = *cursor;
     change.cursor_after = cursor_end;
     ce_buffer_change(view->buffer, &change);

     *cursor = cursor_end;
     vim->mode = CE_VIM_MODE_NORMAL;

     return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %r14
movq %rdx, 0x8(%rsp)
movl 0x30(%rsi), %eax
leal -0x7f(%rax), %ecx
addl $-0x20, %eax
cmpl $-0x5f, %ecx
pushq $-0x1
popq %rcx
cmovaeq %rax, %rcx
movq %rdi, %r12
imulq $0x18, %rcx, %rax
movq 0x1058(%rdi,%rax), %rdi
testq %rdi, %rdi
je 0x26b18
movq %rsi, %rbp
leaq 0xc0(%rsp), %rcx
leaq (%r12,%rax), %rdx
addq $0x1050, %rdx           # imm = 0x1050
movq 0x10(%rcx), %rbx
movq 0x18(%rcx), %rax
movq %rax, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
movl (%rdx), %esi
cmpl $0x1, %esi
movq %r14, 0x28(%rsp)
je 0x2688d
cmpl $0x2, %esi
je 0x26880
cmpl $0x3, %esi
jne 0x2691c
movq %r12, 0x30(%rsp)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %r12
addq 0x10(%rsp), %r12
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rbp
subq 0x8(%rbp), %r12
jle 0x2697f
leaq 0x1(%r12), %rdi
callq 0xd4c0
movq %rax, %r15
pushq $0xa
popq %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0xd2a0
movb $0x0, (%r15,%r12)
movq %rbp, %rdi
callq 0xd9cc
movq %rax, %r12
movq %rdx, %rbp
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0xd9ef
testb %al, %al
je 0x26b18
movq %rbx, 0x38(%rsp)
leaq 0x40(%rsp), %rsi
andq $0x0, (%rsi)
movb $0x1, 0x1(%rsi)
movq %r15, 0x8(%rsi)
movq %r12, 0x10(%rsi)
movq %rbp, 0x18(%rsi)
movq 0x28(%rsp), %r12
movups (%r12), %xmm0
movups %xmm0, 0x20(%rsi)
movups (%r12), %xmm0
movups %xmm0, 0x30(%rsi)
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0xf64d
movb $0x1, %cl
jmp 0x2698b
movzbl %r8b, %eax
addq %rax, 0x10(%rsp)
xorl %ebx, %ebx
jmp 0x268cf
testb %r8b, %r8b
je 0x268cf
movq %rbx, %r15
incq %rbx
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xe38c
leaq -0x1(%rax), %rcx
cmpq %rax, %r15
cmovlq %rbx, %rcx
xorl %ebx, %ebx
testq %rcx, %rcx
cmovgq %rcx, %rbx
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xd640
movq %rax, %r15
testq %rbx, %rbx
jne 0x26933
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rbx
movq 0x10(%rsp), %rax
cmpq 0x8(%rbx), %rax
jne 0x26931
movq %r15, %rdi
callq 0xd210
testq %rax, %rax
jle 0x26931
cmpb $0xa, -0x1(%r15,%rax)
jne 0x26931
decq %rax
testq %rax, %rax
jle 0x26bbb
movb -0x1(%r15,%rax), %cl
movb %cl, (%r15,%rax)
jmp 0x26905
leaq 0x6af9(%rip), %rdi      # 0x2d41c
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xd8e5
jmp 0x26ba7
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq 0x10(%rsp), %rcx
callq 0xd9ef
testb %al, %al
je 0x26b18
movq 0x20(%rsp), %rcx
movl (%rcx), %eax
cmpl $0x1, %eax
movq %r12, 0x30(%rsp)
je 0x26b1f
cmpl $0x2, %eax
jne 0x26b4b
movq %rbx, %r14
movq 0x10(%rsp), %r12
jmp 0x26b51
movq %rbx, 0x38(%rsp)
xorl %ecx, %ecx
movq 0x28(%rsp), %r12
movq 0x10(%rsp), %rax
leaq (,%rax,8), %rax
movq %rax, 0x80(%rsp)
xorl %ebx, %ebx
movq 0x20(%rsp), %rbp
cmpq 0x10(%rbp), %rbx
jge 0x26b9d
movq 0x8(%rbp), %rax
cmpq $0x0, (%rax,%rbx,8)
je 0x26b10
movl %ecx, 0x1c(%rsp)
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %r14
movq 0x8(%rsp), %rbp
movq 0x40(%rbp), %rax
movq (%rax), %rax
addq 0x80(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0xe38c
movq 0x38(%rsp), %r13
subq %rax, %r13
jle 0x26a8c
movq %rax, %r15
leaq 0x1(%r13), %rdi
callq 0xd4c0
movq %rax, %r12
movq %rax, %rdi
pushq $0x20
popq %rsi
movq %r13, %rdx
callq 0xd2a0
movb $0x0, (%r12,%r13)
movq 0x40(%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xd9ef
testb %al, %al
je 0x26b18
andq $0x0, 0x40(%rsp)
movl 0x1c(%rsp), %eax
andb $0x1, %al
movb %al, 0x40(%rsp)
movb $0x1, 0x41(%rsp)
movq %r12, 0x48(%rsp)
movq %r15, 0x50(%rsp)
movq %r14, 0x58(%rsp)
movq 0x28(%rsp), %r12
movups (%r12), %xmm0
leaq 0x60(%rsp), %rax
movups %xmm0, (%rax)
movups (%r12), %xmm0
movups %xmm0, 0x10(%rax)
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
leaq 0x40(%rsp), %rsi
callq 0xf64d
movb $0x1, %al
movl %eax, 0x1c(%rsp)
movq 0x20(%rsp), %rbp
movq 0x8(%rbp), %rax
movq (%rax,%rbx,8), %rdi
callq 0xd640
movq %rax, %r15
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
movq %r15, %rsi
movq 0x38(%rsp), %r13
movq %r13, %rdx
movq %r14, %rcx
callq 0xd9ef
testb %al, %al
je 0x26b18
andq $0x0, 0x40(%rsp)
movl 0x1c(%rsp), %eax
andb $0x1, %al
movb %al, 0x40(%rsp)
movb $0x1, 0x41(%rsp)
movq %r15, 0x48(%rsp)
movq %r13, 0x50(%rsp)
movq %r14, 0x58(%rsp)
movups (%r12), %xmm0
leaq 0x60(%rsp), %rax
movups %xmm0, (%rax)
movups (%r12), %xmm0
movups %xmm0, 0x10(%rax)
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
leaq 0x40(%rsp), %rsi
callq 0xf64d
movb $0x1, %cl
incq %rbx
jmp 0x269a7
xorl %ebx, %ebx
jmp 0x26ba7
movq 0x8(%rsp), %rax
movq 0x40(%rax), %r12
movq 0x8(%rcx), %rdi
callq 0xe38c
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r12, %rdi
movq %rax, %rcx
callq 0xec3a
movq %rax, %r14
movq %rdx, %r12
jmp 0x26b51
xorl %r14d, %r14d
xorl %r12d, %r12d
leaq 0x40(%rsp), %rsi
andq $0x0, (%rsi)
movb 0x3c(%rbp), %al
movb %al, (%rsi)
movb $0x1, 0x1(%rsi)
movq %r15, 0x8(%rsi)
movq %rbx, 0x10(%rsi)
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsi)
movq 0x28(%rsp), %rbx
movups (%rbx), %xmm0
movups %xmm0, 0x20(%rsi)
movq %r14, 0x30(%rsi)
movq %r12, 0x38(%rsi)
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0xf64d
movq %r14, (%rbx)
movq %r12, 0x8(%rbx)
movq 0x30(%rsp), %rax
andl $0x0, (%rax)
movb $0x1, %bl
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0xa, (%r15)
movq (%rbx), %rax
movq 0x10(%rsp), %rcx
movq -0x8(%rax,%rcx,8), %rdi
decq %rcx
movq %rcx, 0x10(%rsp)
callq 0xe38c
movq %rax, %rbx
jmp 0x26933