// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %r8, %r14
movq %rcx, %rbp
movq %rdx, %r13
movq %rdi, 0x30(%rsp)
cmpl $0x4, (%rdi)
movq %rsi, 0x28(%rsp)
jne 0x22bed
movq 0x28(%rsi), %rcx
leaq 0x4ee(%rip), %rax       # 0x22f09
cmpq %rax, %rcx
je 0x22bed
movq 0x8(%r14), %rax
movq 0x8(%rbp), %rdx
cmpq %rdx, %rax
jge 0x22a3b
movq %rax, 0x18(%r14)
movq 0x8(%rbp), %rax
jmp 0x22a3f
movq %rdx, 0x18(%r14)
movq %rax, 0x28(%r14)
movq (%r14), %rdx
movq (%rbp), %rsi
cmpq %rsi, %rdx
jge 0x22a59
movq %rdx, 0x10(%r14)
movq (%rbp), %rdx
jmp 0x22a5d
movq %rsi, 0x10(%r14)
movq %rdx, 0x20(%r14)
leaq 0x8bd(%rip), %rdx       # 0x23325
cmpq %rdx, %rcx
movq %rbp, 0x68(%rsp)
movq %r12, 0x60(%rsp)
je 0x22a93
leaq 0x5d7(%rip), %rdx       # 0x23055
cmpq %rdx, %rcx
je 0x22a93
leaq 0x683(%rip), %rdx       # 0x2310d
cmpq %rdx, %rcx
jne 0x22bb8
movq 0x28(%rsp), %rax
movl 0x30(%rax), %eax
leal -0x7f(%rax), %edx
addl $-0x20, %eax
cmpl $-0x5f, %edx
pushq $-0x1
popq %rdx
cmovaeq %rax, %rdx
leaq 0x873(%rip), %rax       # 0x23325
cmpq %rax, %rcx
leaq 0x651(%rip), %rax       # 0x2310d
pushq $0x2
popq %rsi
cmoveq %rsi, %rdx
cmpq %rax, %rcx
cmoveq %rsi, %rdx
imulq $0x18, %rdx, %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax), %rbx
addq $0x1050, %rbx           # imm = 0x1050
movq %rbx, %rdi
callq 0x2196f
movl $0x3, (%rbx)
movq 0x28(%r14), %rax
subq 0x18(%r14), %rax
leaq 0x10(%r14), %rcx
movq %rcx, 0x70(%rsp)
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%rbx)
leaq 0x8(,%rax,8), %rdi
callq 0xd4c0
movq %rbx, 0x38(%rsp)
movq %rax, 0x8(%rbx)
movq 0x18(%r14), %r12
movq 0x28(%r14), %rax
cmpq %rax, %r12
jg 0x22b96
movq 0x10(%r14), %rbx
movq 0x18(%r14), %rbp
movq 0x20(%r14), %r15
movq 0x40(%r13), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rdi
callq 0xe784
cmpq %rax, %r15
jl 0x22b4c
movq %rax, %r15
movq %r15, %rcx
orq %rax, %rcx
je 0x22b76
cmpq %rax, %rbx
jl 0x22b5c
movq %rax, %rbx
subq %rbx, %r15
incq %r15
movq 0x40(%r13), %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0xf361
jmp 0x22b78
xorl %eax, %eax
movq 0x38(%rsp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x3, %rbp
subq %rbp, %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
movq 0x68(%rsp), %rbp
jmp 0x22b1f
movq 0x28(%rsp), %rcx
movb $0x1, 0x3f(%rcx)
movq 0x28(%rcx), %rcx
leaq 0x4ab(%rip), %rdx       # 0x23055
cmpq %rdx, %rcx
movq 0x60(%rsp), %r12
je 0x22da3
leaq 0x766(%rip), %rdx       # 0x23325
cmpq %rdx, %rcx
movq 0x28(%rsp), %rsi
je 0x22cc1
leaq -0x6d1(%rip), %rdx      # 0x22503
cmpq %rdx, %rcx
je 0x22cc1
leaq 0x529(%rip), %rdx       # 0x2310d
cmpq %rdx, %rcx
je 0x22cc1
movups (%rbp), %xmm0
movaps %xmm0, 0x40(%rsp)
movups (%rbp), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpq $0x0, 0x10(%rsi)
je 0x22c61
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rsp), %rcx
imulq (%rcx), %rax
xorl %ebx, %ebx
testq %rax, %rax
cmovgq %rax, %rbx
movq 0x28(%rsp), %rsi
leaq 0x40(%rsp), %r15
subq $0x1, %rbx
jb 0x22c61
movq %r15, 0x8(%rsp)
movq %r12, (%rsp)
movq 0x30(%rsp), %rdi
movq %r13, %rdx
movq %rbp, %rcx
movq %r14, %r8
movq 0xb0(%rsp), %r9
callq *0x10(%rsi)
testl %eax, %eax
je 0x22cba
cmpl $0x2, %eax
movq 0x28(%rsp), %rsi
jne 0x22c2b
movq 0x28(%rsi), %rax
testq %rax, %rax
je 0x22dba
cmpq $0x0, 0x40(%rsp)
js 0x22dba
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0xb0(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r13, %rdx
movq %rbp, %rcx
movq %r14, %r8
movq %r12, %r9
callq *%rax
testb %al, %al
jne 0x22dba
xorl %ebx, %ebx
jmp 0x22dbc
leaq 0x10(%r14), %rcx
movq %rcx, 0x38(%rsp)
movq 0x18(%r14), %r12
movb $0x1, %bl
cmpq %rax, %r12
jg 0x22d88
movq 0x10(%r14), %r15
movq %r15, 0x40(%rsp)
movq %r12, 0x48(%rsp)
movq 0x20(%r14), %rbp
movq %rbp, 0x50(%rsp)
movq %r12, 0x58(%rsp)
movq 0x40(%r13), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rdi
callq 0xe784
cmpq %rax, %r15
jle 0x22d0f
movq %rax, 0x40(%rsp)
cmpq %rax, %rbp
jle 0x22d1c
movq %rax, 0x50(%rsp)
movq %rax, %rbp
orq %rax, %rbp
je 0x22d7c
movups 0x40(%rsp), %xmm0
movups 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r13, %rdx
movq 0x68(%rsp), %rcx
movq %r14, %r8
movq 0x60(%rsp), %r9
callq *0x28(%rsi)
testb %al, %al
je 0x22d7a
cmpq 0x18(%r14), %r12
je 0x22d7c
movq 0x40(%r13), %rax
movq 0x40(%rax), %rax
testq %rax, %rax
je 0x22d7c
movb $0x1, (%rax)
jmp 0x22d7c
xorl %ebx, %ebx
incq %r12
movq 0x28(%r14), %rax
jmp 0x22cd0
movq 0x30(%rsp), %rax
cmpl $0x1, (%rax)
je 0x22dbc
xorps %xmm0, %xmm0
movq 0x38(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
jmp 0x22dbc
xorps %xmm0, %xmm0
movq 0x70(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq 0x30(%rsp), %rax
andl $0x0, (%rax)
movb $0x1, %bl
andb $0x1, %bl
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq