// File: /workspace/github_c_makefile_star2_O1/justy989[P]ce/ce_vim.c
// Function: ce_vim_apply_action
bool ce_vim_apply_action(CeVim_t* vim, CeVimAction_t* action, CeView_t* view, CePoint_t* cursor, CeVimVisualData_t* visual,
                         CeVimBufferData_t* buffer_data, const CeConfigOptions_t* config_options){
     if(vim->mode == CE_VIM_MODE_VISUAL_BLOCK && action->verb.function != ce_vim_verb_motion){
          // sort y
          if(visual->point.y < cursor->y){
               visual->block_top_left.y = visual->point.y;
               visual->block_bottom_right.y = cursor->y;
          }else{
               visual->block_top_left.y = cursor->y;
               visual->block_bottom_right.y = visual->point.y;
          }

          // sort x
          if(visual->point.x < cursor->x){
               visual->block_top_left.x = visual->point.x;
               visual->block_bottom_right.x = cursor->x;
          }else{
               visual->block_top_left.x = cursor->x;
               visual->block_bottom_right.x = visual->point.x;
          }

          bool success = true;
          if(action->verb.function == ce_vim_verb_yank ||
             action->verb.function == ce_vim_verb_delete ||
             action->verb.function == ce_vim_verb_change){
               CeVimYank_t* yank = vim->yanks + ce_vim_register_index(action->verb.integer);
               if(action->verb.function == ce_vim_verb_delete || action->verb.function == ce_vim_verb_change){
                    yank = vim->yanks + ce_vim_register_index('"');
               }
               ce_vim_yank_free(yank);
               yank->type = CE_VIM_YANK_TYPE_BLOCK;
               yank->block_line_count = (visual->block_bottom_right.y - visual->block_top_left.y) + 1;
               yank->block = malloc(yank->block_line_count * sizeof(*yank->block));

               // copy each line into yank
               for(int64_t i = visual->block_top_left.y; i <= visual->block_bottom_right.y; i++){
                    CeRange_t motion_range = {(CePoint_t){visual->block_top_left.x, i},
                                              (CePoint_t){visual->block_bottom_right.x, i}};
                    int64_t yank_string_index = i - visual->block_top_left.y;
                    int64_t line_last_index = ce_utf8_last_index(view->buffer->lines[i]);

                    // clamp the range to the line length
                    if(motion_range.start.x > line_last_index) motion_range.start.x = line_last_index;
                    if(motion_range.end.x > line_last_index) motion_range.end.x = line_last_index;
                    if(motion_range.end.x == 0 && line_last_index == 0){
                         yank->block[yank_string_index] = NULL;
                         continue;
                    }

                    int64_t motion_range_len = (motion_range.end.x - motion_range.start.x) + 1;
                    yank->block[yank_string_index] = ce_buffer_dupe_string(view->buffer, motion_range.start, motion_range_len);
               }

               action->do_not_yank = true;

               if(action->verb.function == ce_vim_verb_yank){
                    visual->block_top_left = (CePoint_t){0, 0};
                    visual->block_bottom_right = (CePoint_t){0, 0};
                    vim->mode = CE_VIM_MODE_NORMAL;
                    return success;
               }
          }

          if(action->verb.function == ce_vim_verb_insert_mode ||
             action->verb.function == ce_vim_verb_delete ||
             action->verb.function == ce_vim_verb_change){
               // run verb for each line in range
               for(int64_t i = visual->block_top_left.y; i <= visual->block_bottom_right.y; i++){
                    CeRange_t motion_range = {(CePoint_t){visual->block_top_left.x, i},
                                              (CePoint_t){visual->block_bottom_right.x, i}};
                    int64_t line_last_index = ce_utf8_last_index(view->buffer->lines[i]);

                    // clamp the range to the line length
                    if(motion_range.start.x > line_last_index) motion_range.start.x = line_last_index;
                    if(motion_range.end.x > line_last_index) motion_range.end.x = line_last_index;
                    if(motion_range.end.x == 0 && line_last_index == 0) continue;

                    if(!action->verb.function(vim, action, motion_range, view, cursor, visual, buffer_data, config_options)){
                         success = false;
                    }else if(i != visual->block_top_left.y){
                         if(view->buffer->change_node) view->buffer->change_node->change.chain = true;
                    }
               }

               if(vim->mode != CE_VIM_MODE_INSERT){
                    visual->block_top_left = (CePoint_t){0, 0};
                    visual->block_bottom_right = (CePoint_t){0, 0};
               }
               return success;
          }
     }

     CeRange_t motion_range = {*cursor, *cursor};
     if(action->motion.function){
          int64_t total_multiplier = action->multiplier * action->motion.multiplier;
          for(int64_t i = 0; i < total_multiplier; ++i){
               CeVimMotionResult_t result = action->motion.function(vim, action, view, cursor, visual, config_options,
                                                                    buffer_data, &motion_range);
               if(result == CE_VIM_MOTION_RESULT_FAIL){
                    return false;
               }else if(result == CE_VIM_MOTION_RESULT_SUCCESS_NO_MULTIPLY){
                    break;
               }
          }
     }
     if(action->verb.function && motion_range.start.x >= 0){
          if(!action->verb.function(vim, action, motion_range, view, cursor, visual, buffer_data, config_options)){
               return false;
          }
     }
     return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, 0x60(%rsp)
movq %r8, %r14
movq %rcx, %rbp
movq %rdx, 0x30(%rsp)
movq %rsi, %r13
movq %rdi, 0x38(%rsp)
cmpl $0x4, (%rdi)
jne 0x259f6
movq 0x28(%r13), %rax
leaq 0x50d(%rip), %rcx       # 0x25c31
cmpq %rcx, %rax
je 0x25740
movq 0x8(%r14), %rcx
movq 0x8(%rbp), %rdx
cmpq %rdx, %rcx
jge 0x25745
movq %rcx, 0x18(%r14)
movq 0x8(%rbp), %rcx
jmp 0x25749
jmp 0x259f6
movq %rdx, 0x18(%r14)
movq %rcx, 0x28(%r14)
movq (%r14), %rcx
movq (%rbp), %rdx
cmpq %rdx, %rcx
jge 0x25763
movq %rcx, 0x10(%r14)
movq (%rbp), %rcx
jmp 0x25767
movq %rdx, 0x10(%r14)
movq %rcx, 0x20(%r14)
leaq 0x91e(%rip), %rsi       # 0x26090
cmpq %rsi, %rax
je 0x25793
leaq 0x60d(%rip), %rcx       # 0x25d8b
cmpq %rcx, %rax
je 0x25793
leaq 0x6c8(%rip), %rcx       # 0x25e52
cmpq %rcx, %rax
jne 0x258b9
movq %rbp, 0x68(%rsp)
movl 0x30(%r13), %ecx
leal -0x7f(%rcx), %edx
addl $-0x20, %ecx
cmpl $-0x5f, %edx
movq $-0x1, %rdx
cmovaeq %rcx, %rdx
cmpq %rsi, %rax
leaq 0x698(%rip), %rcx       # 0x25e52
movl $0x2, %esi
cmoveq %rsi, %rdx
cmpq %rcx, %rax
cmoveq %rsi, %rdx
leaq (%rdx,%rdx,2), %rax
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,8), %rbx
addq $0x1050, %rbx           # imm = 0x1050
movq %rbx, %rdi
callq 0x243a6
movl $0x3, (%rbx)
movq 0x28(%r14), %rax
subq 0x18(%r14), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%rbx)
leaq 0x8(,%rax,8), %rdi
callq 0xd4c0
movq %rbx, 0x70(%rsp)
movq %rax, 0x8(%rbx)
movq 0x18(%r14), %rbp
cmpq 0x28(%r14), %rbp
jg 0x25897
movq 0x10(%r14), %rbx
movq 0x18(%r14), %r12
movq 0x20(%r14), %r15
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%rbp,8), %rdi
callq 0xe97d
cmpq %rax, %r15
jl 0x25845
movq %rax, %r15
movq %r15, %rcx
orq %rax, %rcx
je 0x25874
cmpq %rax, %rbx
jl 0x25855
movq %rax, %rbx
subq %rbx, %r15
incq %r15
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0xf79a
jmp 0x25876
xorl %eax, %eax
movq 0x70(%rsp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x3, %r12
subq %r12, %rcx
movq %rax, (%rcx,%rbp,8)
leaq 0x1(%rbp), %rax
cmpq 0x28(%r14), %rbp
movq %rax, %rbp
jl 0x2581c
movb $0x1, 0x3f(%r13)
leaq 0x4e8(%rip), %rax       # 0x25d8b
cmpq %rax, 0x28(%r13)
movq 0x68(%rsp), %rbp
leaq 0x7dd(%rip), %rsi       # 0x26090
je 0x259d1
movq 0x28(%r13), %rcx
cmpq %rsi, %rcx
je 0x258e2
leaq -0x80d(%rip), %rax      # 0x250bc
cmpq %rax, %rcx
je 0x258e2
movb $0x1, %al
leaq 0x57b(%rip), %rdx       # 0x25e52
movb $0x1, %bl
cmpq %rdx, %rcx
jne 0x259ee
movq 0x18(%r14), %r15
movb $0x1, %bl
cmpq 0x28(%r14), %r15
jg 0x259b7
movb $0x1, %bl
movq 0x10(%r14), %rax
movq %rax, 0x40(%rsp)
movq %r15, 0x48(%rsp)
movq 0x20(%r14), %rax
movq %rax, 0x50(%rsp)
movq %r15, 0x58(%rsp)
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%r15,8), %rdi
callq 0xe97d
cmpq %rax, 0x40(%rsp)
jle 0x25931
movq %rax, 0x40(%rsp)
cmpq %rax, 0x50(%rsp)
jle 0x2593d
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rcx
orq %rax, %rcx
je 0x259a6
movups 0x40(%rsp), %xmm0
movups 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rdx
movq %rbp, %rcx
movq %r14, %r8
movq 0x60(%rsp), %r9
callq *0x28(%r13)
testb %al, %al
je 0x259a4
cmpq 0x18(%r14), %r15
je 0x259a6
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
testq %rax, %rax
je 0x259a6
movb $0x1, (%rax)
jmp 0x259a6
xorl %ebx, %ebx
leaq 0x1(%r15), %rax
cmpq 0x28(%r14), %r15
movq %rax, %r15
jl 0x258f4
movq 0x38(%rsp), %rax
cmpl $0x1, (%rax)
je 0x259ec
leaq 0x10(%r14), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
jmp 0x259ec
leaq 0x10(%r14), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq 0x38(%rsp), %rax
movl $0x0, (%rax)
movb $0x1, %bl
xorl %eax, %eax
testb %al, %al
je 0x25ae1
movups (%rbp), %xmm0
movaps %xmm0, 0x40(%rsp)
movups (%rbp), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpq $0x0, 0x10(%r13)
je 0x25a8c
movq 0x8(%r13), %r15
imulq (%r13), %r15
testq %r15, %r15
jle 0x25a86
leaq 0x40(%rsp), %r12
movq %r12, 0x8(%rsp)
movq 0x60(%rsp), %rax
movq %rax, (%rsp)
movq 0x38(%rsp), %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rdx
movq %rbp, %rcx
movq %r14, %r8
movq 0xb0(%rsp), %r9
callq *0x10(%r13)
testl %eax, %eax
je 0x25a61
cmpl $0x2, %eax
jne 0x25a6c
movl $0x8, %eax
xorl %ecx, %ecx
jmp 0x25a70
movl $0x1, %eax
xorl %ecx, %ecx
xorl %ebx, %ebx
jmp 0x25a70
xorl %eax, %eax
movb $0x1, %cl
testb %cl, %cl
je 0x25a7e
decq %r15
jne 0x25a22
movl $0x8, %eax
cmpl $0x8, %eax
sete %al
jmp 0x25a88
movb $0x1, %al
testb %al, %al
je 0x25ae1
movq 0x28(%r13), %rax
testq %rax, %rax
je 0x25adb
cmpq $0x0, 0x40(%rsp)
js 0x25adb
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0xb0(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movq 0x38(%rsp), %rdi
movq %r13, %rsi
movq 0x30(%rsp), %rdx
movq %rbp, %rcx
movq %r14, %r8
movq 0x60(%rsp), %r9
callq *%rax
testb %al, %al
je 0x25adf
movb $0x1, %bl
jmp 0x25ae1
xorl %ebx, %ebx
andb $0x1, %bl
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq