// File: /workspace/github_c_makefile_star2_O3/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 %r8, 0x8(%rsp)
movq %rcx, %r12
movl 0x30(%rsi), %eax
leal -0x7f(%rax), %ecx
addl $-0x20, %eax
cmpl $-0x5f, %ecx
movq $-0x1, %rcx
cmovaeq %rax, %rcx
movq %rdi, %r15
leaq (%rcx,%rcx,2), %rcx
movq 0x1058(%rdi,%rcx,8), %rdi
testq %rdi, %rdi
je 0x29b83
movq %r9, %r14
movq %rdx, %rbx
movq %rsi, %rbp
movb 0xc0(%rsp), %al
leaq (%r15,%rcx,8), %rcx
addq $0x1050, %rcx           # imm = 0x1050
movq %rcx, 0x10(%rsp)
movl (%rcx), %esi
cmpl $0x1, %esi
movq %r9, 0x20(%rsp)
je 0x298d0
cmpl $0x2, %esi
je 0x298c0
cmpl $0x3, %esi
jne 0x299c0
movq %r15, 0x28(%rsp)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq %r12, 0x38(%rsp)
leaq (%rax,%r12), %rbp
movq 0x8(%rsp), %rcx
movq 0x40(%rcx), %r12
subq 0x8(%r12), %rbp
jle 0x299d5
leaq 0x1(%rbp), %rdi
callq 0xd4c0
movq %rax, %r15
movq %rax, %rdi
movl $0xa, %esi
movq %rbp, %rdx
callq 0xd2a0
movb $0x0, (%r15,%rbp)
movq %r12, %rdi
callq 0xda40
movq %rax, %r12
movq %rdx, %rbp
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0xda6e
testb %al, %al
je 0x29b83
movq %rbx, 0x30(%rsp)
leaq 0x40(%rsp), %rsi
movq $0x0, (%rsi)
movb $0x1, 0x1(%rsi)
movq %r15, 0x8(%rsi)
movq %r12, 0x10(%rsi)
movq %rbp, 0x18(%rsi)
movq 0x20(%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 0xf976
movq 0x10(%rsp), %rbp
movq 0x10(%rbp), %rax
movb $0x1, %dl
jmp 0x299e6
movzbl %al, %eax
addq %rax, %r12
callq 0xd640
movq %rax, %r13
jmp 0x29918
testb %al, %al
je 0x2990b
movq %rbx, %r13
incq %rbx
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rdi
callq 0xe445
cmpq %r13, %rax
leaq -0x1(%rax), %rax
cmovgq %rbx, %rax
movq %rax, %rbx
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
testq %rbx, %rbx
js 0x298c6
callq 0xd640
movq %rax, %r13
testq %rbx, %rbx
jne 0x29970
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rbx
cmpq 0x8(%rbx), %r12
jne 0x2996e
movq %r13, %rdi
callq 0xd210
testq %rax, %rax
jle 0x2996e
cmpb $0xa, -0x1(%r13,%rax)
jne 0x2996e
cmpq $0x1, %rax
je 0x29954
decq %rax
leaq 0x1(%r13), %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0xd580
movb $0xa, (%r13)
movq (%rbx), %rax
movq -0x8(%rax,%r12,8), %rdi
decq %r12
callq 0xe445
movq %rax, %rbx
jmp 0x29970
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0xda6e
testb %al, %al
je 0x29b83
movq 0x10(%rsp), %rcx
movl (%rcx), %eax
cmpl $0x1, %eax
movq %r15, 0x28(%rsp)
movq %r13, 0x18(%rsp)
je 0x29b8a
cmpl $0x2, %eax
jne 0x29bbc
movq %rbx, %r13
movq %rbx, %r15
movq %r12, %rbx
jmp 0x29bc8
leaq 0x6abd(%rip), %rdi      # 0x30484
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xd954
jmp 0x29c24
movq %rbx, 0x30(%rsp)
xorl %edx, %edx
movq 0x20(%rsp), %r12
movq 0x10(%rsp), %rbp
testq %rax, %rax
jle 0x29c17
movq 0x38(%rsp), %rcx
leaq (,%rcx,8), %rcx
movq %rcx, 0x80(%rsp)
xorl %r14d, %r14d
movq 0x8(%rbp), %rcx
cmpq $0x0, (%rcx,%r14,8)
je 0x29b72
movl %edx, 0x18(%rsp)
movq 0x38(%rsp), %rax
leaq (%rax,%r14), %rbx
movq 0x8(%rsp), %rbp
movq 0x40(%rbp), %rax
movq (%rax), %rax
addq 0x80(%rsp), %rax
movq (%rax,%r14,8), %rdi
callq 0xe445
movq 0x30(%rsp), %r13
subq %rax, %r13
jle 0x29ae7
movq %rax, %r15
leaq 0x1(%r13), %rdi
callq 0xd4c0
movq %rax, %r12
movq %rax, %rdi
movl $0x20, %esi
movq %r13, %rdx
callq 0xd2a0
movb $0x0, (%r12,%r13)
movq 0x40(%rbp), %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0xda6e
testb %al, %al
je 0x29b83
movq $0x0, 0x40(%rsp)
movl 0x18(%rsp), %eax
andb $0x1, %al
movb %al, 0x40(%rsp)
movb $0x1, 0x41(%rsp)
movq %r12, 0x48(%rsp)
movq %r15, 0x50(%rsp)
movq %rbx, 0x58(%rsp)
movq 0x20(%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 0xf976
movb $0x1, %al
movl %eax, 0x18(%rsp)
movq 0x10(%rsp), %rbp
movq 0x8(%rbp), %rax
movq (%rax,%r14,8), %rdi
callq 0xd640
movq %rax, %r15
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
movq %r15, %rsi
movq 0x30(%rsp), %r13
movq %r13, %rdx
movq %rbx, %rcx
callq 0xda6e
testb %al, %al
je 0x29b83
movq $0x0, 0x40(%rsp)
movl 0x18(%rsp), %eax
andb $0x1, %al
movb %al, 0x40(%rsp)
movb $0x1, 0x41(%rsp)
movq %r15, 0x48(%rsp)
movq %r13, 0x50(%rsp)
movq %rbx, 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 0xf976
movq 0x10(%rbp), %rax
movb $0x1, %dl
incq %r14
cmpq %rax, %r14
jl 0x29a07
jmp 0x29c17
xorl %ebx, %ebx
jmp 0x29c24
movq %rbx, %r13
movq %r12, %rbx
movq 0x8(%rsp), %rax
movq 0x40(%rax), %r15
movq 0x8(%rcx), %rdi
callq 0xe445
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r15, %rdi
movq %rax, %rcx
callq 0xee7a
movq %rax, %r15
movq %rdx, %r12
jmp 0x29bc8
movq %rbx, %r13
movq %r12, %rbx
xorl %r15d, %r15d
xorl %r12d, %r12d
leaq 0x40(%rsp), %rsi
movq $0x0, (%rsi)
movb 0x3c(%rbp), %al
movb %al, (%rsi)
movb $0x1, 0x1(%rsi)
movq 0x18(%rsp), %rax
movq %rax, 0x8(%rsi)
movq %r13, 0x10(%rsi)
movq %rbx, 0x18(%rsi)
movq 0x20(%rsp), %rbx
movups (%rbx), %xmm0
movups %xmm0, 0x20(%rsi)
movq %r15, 0x30(%rsi)
movq %r12, 0x38(%rsi)
movq 0x8(%rsp), %rax
movq 0x40(%rax), %rdi
callq 0xf976
movq %r15, (%rbx)
movq %r12, 0x8(%rbx)
movq 0x28(%rsp), %rax
movl $0x0, (%rax)
movb $0x1, %bl
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq