// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movl 0x30(%rsi), %eax
leal -0x7f(%rax), %ecx
addl $-0x20, %eax
cmpl $-0x5f, %ecx
movq $-0x1, %rcx
cmovaeq %rax, %rcx
leaq (%rcx,%rcx,2), %rax
cmpq $0x0, 0x1058(%rdi,%rax,8)
je 0x29e0d
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %r15
leaq 0xc0(%rsp), %rcx
leaq (%rdi,%rax,8), %rax
addq $0x1050, %rax           # imm = 0x1050
movq 0x10(%rcx), %rdx
movq %rdx, 0x20(%rsp)
movq 0x18(%rcx), %r12
movq %rax, 0x10(%rsp)
movl (%rax), %esi
cmpl $0x1, %esi
je 0x29a4f
cmpl $0x2, %esi
je 0x29a3f
cmpl $0x3, %esi
jne 0x29a88
movq %r15, 0x38(%rsp)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r15
movq %r12, 0x30(%rsp)
addq %r12, %r15
movq %r14, %rbp
movq 0x40(%r14), %r12
subq 0x8(%r12), %r15
jle 0x29b5c
movq %rbx, %r13
leaq 0x1(%r15), %rdi
callq 0xd4c0
movq %rax, %rbx
movq %rax, %rdi
movl $0xa, %esi
movq %r15, %rdx
callq 0xd2a0
movb $0x0, (%rbx,%r15)
movq %r12, %rdi
callq 0xda40
movq %rax, %r15
movq %rdx, %r12
movq 0x40(%rbp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
movq %r12, %rcx
callq 0xda6e
testb %al, %al
je 0x29c13
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x20(%rsi)
movb $0x1, 0x1(%rsi)
movq %rbx, 0x8(%rsi)
movq %r15, 0x10(%rsi)
movq %r12, 0x18(%rsi)
movq %r13, %rbx
movups (%r13), %xmm0
movaps %xmm0, 0x20(%rsi)
movups (%r13), %xmm0
movaps %xmm0, 0x30(%rsi)
movq 0x40(%rbp), %rdi
movl %eax, %r14d
callq 0xfad6
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl %r14d, %eax
movq %rbp, %r12
movq 0x10(%rsp), %r14
jmp 0x29c26
movq %rbx, 0x18(%rsp)
movzbl %r8b, %eax
addq %rax, %r12
xorl %ebx, %ebx
jmp 0x29aa2
movq %rbx, 0x18(%rsp)
testb %r8b, %r8b
je 0x29a9d
movq 0x20(%rsp), %r13
leaq 0x1(%r13), %rbx
movq 0x40(%r14), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rdi
callq 0xe485
leaq -0x1(%rax), %rcx
cmpq %rax, %r13
cmovlq %rbx, %rcx
xorl %ebx, %ebx
testq %rcx, %rcx
cmovgq %rcx, %rbx
jmp 0x29aa2
leaq 0x7945(%rip), %rdi      # 0x313d4
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xd954
jmp 0x29e0f
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xd640
movq %rax, %r13
testq %rbx, %rbx
je 0x29abd
movq %rbx, %rdx
jmp 0x29b16
movq 0x40(%r14), %rbx
cmpq 0x8(%rbx), %r12
jne 0x29b14
movq %r13, %rdi
callq 0xd210
testq %rax, %rax
jle 0x29b14
cmpb $0xa, -0x1(%r13,%rax)
jne 0x29b14
cmpq $0x1, %rax
je 0x29af6
decq %rax
movq %r13, %rdi
incq %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0xd580
movb $0xa, (%r13)
movq (%rbx), %rax
movq 0x8(%rbx), %r12
movq -0x8(%rax,%r12,8), %rdi
decq %r12
callq 0xe485
movq %rax, %rdx
jmp 0x29b16
xorl %edx, %edx
movq 0x40(%r14), %rdi
movq %r13, 0x20(%rsp)
movq %r13, %rsi
movq %rdx, %r13
movq %r12, %rcx
callq 0xda6e
movl %eax, %ebx
testb %al, %al
je 0x29e0f
movq 0x10(%rsp), %rcx
movl (%rcx), %eax
cmpl $0x1, %eax
movq %r14, 0x28(%rsp)
movq %r15, 0x38(%rsp)
movq %r12, 0x30(%rsp)
je 0x29b71
cmpl $0x2, %eax
jne 0x29b9d
movq %r13, %r15
jmp 0x29ba3
movl $0x0, 0xc(%rsp)
movq %rbp, %r12
movq 0x10(%rsp), %r14
jmp 0x29c2e
movq 0x40(%r14), %r15
movq 0x8(%rcx), %rdi
callq 0xe485
movq 0x18(%rsp), %rcx
movq (%rcx), %rsi
movq 0x8(%rcx), %rdx
movq %r15, %rdi
movq %rax, %rcx
callq 0xeffa
movq %rax, %r15
movq %rdx, %r12
jmp 0x29ba3
xorl %r15d, %r15d
xorl %r12d, %r12d
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rsi
movaps %xmm0, 0x30(%rsi)
movaps %xmm0, 0x20(%rsi)
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
movb 0x3c(%rbp), %al
movb %al, (%rsi)
movb $0x1, 0x1(%rsi)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsi)
movq %r13, 0x10(%rsi)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%rsi)
movq 0x18(%rsp), %r14
movups (%r14), %xmm0
movaps %xmm0, 0x20(%rsi)
movq %r15, 0x30(%rsi)
movq %r12, 0x38(%rsi)
movq 0x28(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0xfad6
movq %r15, (%r14)
movq %r12, 0x8(%r14)
movq 0x38(%rsp), %rax
movl $0x0, (%rax)
jmp 0x29e0f
movl $0x0, 0xc(%rsp)
movq %rbp, %r12
movq 0x10(%rsp), %r14
movq %r13, %rbx
testb %al, %al
je 0x29e0d
movq %rbx, 0x18(%rsp)
cmpq $0x0, 0x10(%r14)
jle 0x29dfe
movq 0x30(%rsp), %rax
leaq (,%rax,8), %rax
movq %rax, 0x80(%rsp)
xorl %r13d, %r13d
movq %r12, 0x28(%rsp)
movq 0x8(%r14), %rax
cmpq $0x0, (%rax,%r13,8)
je 0x29df1
movq 0x30(%rsp), %rax
leaq (%rax,%r13), %rbx
movq 0x40(%r12), %rax
movq (%rax), %rax
addq 0x80(%rsp), %rax
movq (%rax,%r13,8), %rdi
callq 0xe485
movq 0x20(%rsp), %r15
subq %rax, %r15
jle 0x29d4b
movq %rax, %rbp
leaq 0x1(%r15), %rdi
callq 0xd4c0
movq %r12, %r14
movq %rax, %r12
movq %rax, %rdi
movl $0x20, %esi
movq %r15, %rdx
callq 0xd2a0
movb $0x0, (%r12,%r15)
movq 0x40(%r14), %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xda6e
movl %eax, %r15d
testb %al, %al
je 0x29d3a
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movl 0xc(%rsp), %eax
andb $0x1, %al
movb %al, 0x40(%rsp)
movb $0x1, 0x41(%rsp)
movq %r12, 0x48(%rsp)
movq %rbp, 0x50(%rsp)
movq %rbx, 0x58(%rsp)
movq 0x18(%rsp), %rax
movups (%rax), %xmm0
leaq 0x60(%rsp), %rcx
movups %xmm0, (%rcx)
movups (%rax), %xmm0
movups %xmm0, 0x10(%rcx)
movq 0x40(%r14), %rdi
leaq 0x40(%rsp), %rsi
callq 0xfad6
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq %r14, %r12
testb %r15b, %r15b
movq 0x10(%rsp), %r14
je 0x29dea
movq 0x8(%r14), %rax
movq (%rax,%r13,8), %rdi
callq 0xd640
movq %rax, %r15
movq 0x40(%r12), %rdi
movq %rax, %rsi
movq 0x20(%rsp), %r12
movq %r12, %rdx
movq %rbx, %rcx
callq 0xda6e
movl %eax, %ebp
testb %al, %al
je 0x29de3
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movl 0xc(%rsp), %eax
andb $0x1, %al
movb %al, 0x40(%rsp)
movb $0x1, 0x41(%rsp)
movq %r15, 0x48(%rsp)
movq %r12, 0x50(%rsp)
movq %rbx, 0x58(%rsp)
movq 0x18(%rsp), %rax
movups (%rax), %xmm0
leaq 0x60(%rsp), %rcx
movups %xmm0, (%rcx)
movups (%rax), %xmm0
movups %xmm0, 0x10(%rcx)
movq 0x28(%rsp), %rbx
movq 0x40(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0xfad6
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq %rbx, %r12
jmp 0x29dec
movq 0x28(%rsp), %r12
jmp 0x29dec
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x29e0d
incq %r13
cmpq 0x10(%r14), %r13
jl 0x29c5b
movq 0x38(%rsp), %rax
movl $0x0, (%rax)
movb $0x1, %bl
jmp 0x29e0f
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq