// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movq %rdx, 0x30(%rsp)
movq %rsi, %rbp
movq %rdi, %r13
cmpl $0x4, (%rdi)
jne 0x257d9
movq 0x28(%rbp), %rax
leaq 0x4fb(%rip), %rdx       # 0x25b02
cmpq %rdx, %rax
je 0x257d9
movq 0x8(%rbx), %rdi
movq 0x8(%rcx), %rdx
cmpq %rdx, %rdi
jge 0x25627
movq %rdi, 0x18(%rbx)
movq 0x8(%rcx), %rdi
jmp 0x2562b
movq %rdx, 0x18(%rbx)
movq %rdi, 0x28(%rbx)
movq (%rbx), %rdx
movq (%rcx), %rsi
cmpq %rsi, %rdx
jge 0x25643
movq %rdx, 0x10(%rbx)
movq (%rcx), %rdx
jmp 0x25647
movq %rsi, 0x10(%rbx)
movq %rdx, 0x20(%rbx)
leaq 0x8e5(%rip), %rsi       # 0x25f37
cmpq %rsi, %rax
movq %r13, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
je 0x2567d
leaq 0x5e8(%rip), %rdx       # 0x25c50
cmpq %rdx, %rax
je 0x2567d
leaq 0x69f(%rip), %rdx       # 0x25d13
cmpq %rdx, %rax
jne 0x257b0
movq %r12, 0x70(%rsp)
movl 0x30(%rbp), %ecx
leal -0x7f(%rcx), %edx
addl $-0x20, %ecx
cmpl $-0x5f, %edx
movq $-0x1, %rdx
cmovaeq %rcx, %rdx
cmpq %rsi, %rax
leaq 0x670(%rip), %rcx       # 0x25d13
movl $0x2, %esi
cmoveq %rsi, %rdx
cmpq %rcx, %rax
cmoveq %rsi, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x1050(,%rax,8), %r14
addq %r13, %r14
movq %r14, %rdi
callq 0x243bf
movl $0x3, (%r14)
movq 0x28(%rbx), %rax
subq 0x18(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%r14)
leaq 0x8(,%rax,8), %rdi
callq 0xd4c0
movq %r14, 0x38(%rsp)
movq %rax, 0x8(%r14)
movq 0x18(%rbx), %r15
movq 0x28(%rbx), %rdi
cmpq %rdi, %r15
jg 0x25782
movq 0x10(%rbx), %r14
movq 0x18(%rbx), %r13
movq 0x20(%rbx), %r12
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%r15,8), %rdi
callq 0xe8d0
cmpq %rax, %r12
jl 0x2572d
movq %rax, %r12
movq %r12, %rcx
orq %rax, %rcx
je 0x2575c
cmpq %rax, %r14
jl 0x2573d
movq %rax, %r14
subq %r14, %r12
incq %r12
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xf60a
jmp 0x2575e
xorl %eax, %eax
movq 0x38(%rsp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x3, %r13
subq %r13, %rcx
movq %rax, (%rcx,%r15,8)
leaq 0x1(%r15), %rax
movq 0x28(%rbx), %rdi
cmpq %rdi, %r15
movq %rax, %r15
jl 0x25704
movb $0x1, 0x3f(%rbp)
movq 0x28(%rbp), %rax
leaq 0x4bf(%rip), %rdx       # 0x25c50
cmpq %rdx, %rax
movq 0x70(%rsp), %r12
movq 0x68(%rsp), %r13
movq 0x60(%rsp), %rcx
leaq 0x78d(%rip), %rsi       # 0x25f37
je 0x2599b
cmpq %rsi, %rax
je 0x25897
leaq -0x77b(%rip), %rdx      # 0x25045
cmpq %rdx, %rax
je 0x25897
leaq 0x543(%rip), %rdx       # 0x25d13
cmpq %rdx, %rax
je 0x25897
movups (%rcx), %xmm0
movaps %xmm0, 0x40(%rsp)
movq %rcx, %r15
movups (%rcx), %xmm0
movaps %xmm0, 0x50(%rsp)
cmpq $0x0, 0x10(%rbp)
je 0x25839
movq 0x8(%rbp), %r14
imulq (%rbp), %r14
testq %r14, %r14
jle 0x25839
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %r12, (%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq 0x30(%rsp), %rdx
movq %r15, %rcx
movq %rbx, %r8
movq 0xb0(%rsp), %r9
callq *0x10(%rbp)
testl %eax, %eax
je 0x25890
cmpl $0x2, %eax
je 0x25839
decq %r14
jne 0x25801
movq 0x28(%rbp), %rax
testq %rax, %rax
je 0x259b1
cmpq $0x0, 0x40(%rsp)
js 0x259b1
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0xb0(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq 0x30(%rsp), %rdx
movq %r15, %rcx
movq %rbx, %r8
movq %r12, %r9
callq *%rax
testb %al, %al
jne 0x259b1
xorl %eax, %eax
jmp 0x259b3
movq 0x18(%rbx), %r15
movb $0x1, %al
movl %eax, 0x38(%rsp)
cmpq %rdi, %r15
jg 0x25980
movb $0x1, %al
movl %eax, 0x38(%rsp)
movq %r12, %r14
movq 0x10(%rbx), %r13
movq %r13, 0x40(%rsp)
movq %r15, 0x48(%rsp)
movq 0x20(%rbx), %r12
movq %r12, 0x50(%rsp)
movq %r15, 0x58(%rsp)
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq (%rax,%r15,8), %rdi
callq 0xe8d0
cmpq %rax, %r13
jle 0x258ee
movq %rax, 0x40(%rsp)
cmpq %rax, %r12
jle 0x258fb
movq %rax, 0x50(%rsp)
movq %rax, %r12
orq %rax, %r12
movq 0x68(%rsp), %r13
je 0x25962
movups 0x40(%rsp), %xmm0
movups 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq 0x30(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq %rbx, %r8
movq %r14, %r12
movq %r14, %r9
callq *0x28(%rbp)
testb %al, %al
je 0x25967
cmpq 0x18(%rbx), %r15
je 0x2596f
movq 0x30(%rsp), %rax
movq 0x40(%rax), %rax
movq 0x40(%rax), %rax
testq %rax, %rax
je 0x2596f
movb $0x1, (%rax)
jmp 0x2596f
movq %r14, %r12
jmp 0x2596f
movl $0x0, 0x38(%rsp)
leaq 0x1(%r15), %rax
cmpq 0x28(%rbx), %r15
movq %rax, %r15
jl 0x258b0
cmpl $0x1, (%r13)
je 0x25995
addq $0x10, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movl 0x38(%rsp), %eax
jmp 0x259b3
addq $0x10, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
movl $0x0, (%r13)
movb $0x1, %al
andb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq