// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce_vim.c
// Function: ce_vim_handle_key
CeVimParseResult_t ce_vim_handle_key(CeVim_t* vim, CeView_t* view, CePoint_t* cursor, CeVimVisualData_t* visual, CeRune_t key,
                                     CeVimBufferData_t* buffer_data, const CeConfigOptions_t* config_options){
     switch(vim->mode){
     default:
          return CE_VIM_PARSE_INVALID;
     case CE_VIM_MODE_INSERT:
          if(!vim->verb_last_action) ce_rune_node_insert(&vim->insert_rune_head, key);
          return insert_mode_handle_key(vim, view, cursor, visual, key, config_options);
     case CE_VIM_MODE_REPLACE:
          if(key != CE_NEWLINE && key != 27){ // escape
               int64_t last_index = ce_utf8_last_index(view->buffer->lines[cursor->y]);
               if(cursor->x < last_index){
                    ce_buffer_remove_string_change(view->buffer, *cursor, 1, cursor,
                                                   *cursor, vim->chain_undo);
                    vim->chain_undo = true;
              }
          }

          if(!vim->verb_last_action) ce_rune_node_insert(&vim->insert_rune_head, key);
          return insert_mode_handle_key(vim, view, cursor, visual, key, config_options);
     case CE_VIM_MODE_NORMAL:
     case CE_VIM_MODE_VISUAL:
     case CE_VIM_MODE_VISUAL_LINE:
     case CE_VIM_MODE_VISUAL_BLOCK:
     {
          CeVimAction_t action = {};

          if(!ce_vim_append_key(vim, key)){
               vim->current_command[0] = 0;
               break;
          }

          CeVimParseResult_t result = ce_vim_parse_action(&action, vim);

          if(result == CE_VIM_PARSE_COMPLETE){
               ce_vim_apply_action(vim, &action, view, cursor, visual, buffer_data, config_options);
               vim->current_command[0] = 0;

               if(!vim->verb_last_action && action.repeatable){
                    vim->last_action = action;
                    if(vim->last_insert_rune_head){
                         ce_rune_node_free(&vim->last_insert_rune_head);
                    }
                    vim->insert_rune_head = NULL;
               }
          }else if(result == CE_VIM_PARSE_INVALID || result == CE_VIM_PARSE_KEY_NOT_HANDLED){
               vim->current_command[0] = 0;
          }

          vim->current_action = action;
          return result;
     } break;
     }

     return CE_VIM_PARSE_COMPLETE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl (%rdi), %eax
cmpq $0x5, %rax
ja 0x22780
movq %r9, %r13
movl %r8d, %ebp
movq %rdx, %r10
movq %rsi, %r8
movq %rdi, %rbx
movq 0xa0(%rsp), %r9
leaq 0xabf6(%rip), %rdx      # 0x2d1c0
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %r10, %r12
movq %r8, %r15
movq %rcx, 0x18(%rsp)
movq %r9, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x60(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x21a27
testb %al, %al
je 0x22688
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x22793
movl %eax, %ebp
cmpl $0x5, %eax
jne 0x22697
movq %r14, (%rsp)
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %rcx
movq 0x18(%rsp), %r8
movq %r13, %r9
callq 0x229e3
andl $0x0, 0x1010(%rbx)
cmpb $0x0, 0x19d9(%rbx)
jne 0x226a3
cmpb $0x1, 0x5d(%rsp)
jne 0x226a3
leaq 0x1938(%rbx), %rdi
pushq $0x9
popq %rcx
leaq 0x20(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
cmpq $0x0, 0x19d0(%rbx)
je 0x2267e
leaq 0x19d0(%rbx), %rdi
callq 0xfe39
andq $0x0, 0x19c8(%rbx)
jmp 0x226a3
andl $0x0, 0x1010(%rbx)
pushq $0x5
popq %rbp
jmp 0x22782
cmpl $0x1, %ebp
ja 0x226a3
andl $0x0, 0x1010(%rbx)
addq $0x1980, %rbx           # imm = 0x1980
pushq $0x9
popq %rcx
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
rep  movsq (%rsi), %es:(%rdi)
jmp 0x22782
cmpl $0xa, %ebp
je 0x22732
cmpl $0x1b, %ebp
je 0x22732
movq 0x40(%r8), %rax
movq (%rax), %rax
movq 0x8(%r10), %rdx
movq (%rax,%rdx,8), %rdi
movq %r9, %r14
movq %rcx, %r12
movq %r8, %r15
movq %r10, %r13
callq 0xe784
movq %r13, %r10
movq %r15, %r8
movq %r12, %rcx
movq %r14, %r9
movq (%r13), %rsi
cmpq %rax, %rsi
jge 0x22732
movq 0x40(%r8), %rdi
movzbl 0x19d8(%rbx), %r9d
movq 0x8(%r10), %rdx
movups (%r10), %xmm0
movups %xmm0, (%rsp)
pushq $0x1
popq %rcx
movq %r10, %r8
callq 0xf77c
movq %r13, %r10
movq %r15, %r8
movq %r12, %rcx
movq %r14, %r9
movb $0x1, 0x19d8(%rbx)
cmpb $0x0, 0x19d9(%rbx)
jne 0x22761
leaq 0x19c8(%rbx), %rdi
movl %ebp, %esi
movq %r9, %r14
movq %rcx, %r12
movq %r8, %r15
movq %r10, %r13
callq 0xfdbe
movq %r13, %r10
movq %r15, %r8
movq %r12, %rcx
movq %r14, %r9
movq %rbx, %rdi
movq %r8, %rsi
movq %r10, %rdx
movl %ebp, %r8d
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21a5a
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq