// File: /workspace/github_c_makefile_star2_O1/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 0x25387
movq %r9, %r13
movl %r8d, %ebp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq 0xa0(%rsp), %r9
leaq 0xbfa9(%rip), %rcx      # 0x31178
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r9, 0x10(%rsp)
movq %r14, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x60(%rsp)
leaq 0x1010(%rbx), %r14
movq %r14, %rdi
callq 0x123d0
cmpq $0xe, %rax
jle 0x25228
movl $0x0, (%r14)
movl $0x5, %ebp
jmp 0x25389
movl %ebp, 0x1010(%rbx,%rax,4)
movl $0x0, 0x1014(%rbx,%rax,4)
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x2539a
movl %eax, %ebp
cmpl $0x5, %eax
jne 0x252c3
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %rcx
movq 0x18(%rsp), %r8
movq %r13, %r9
callq 0x256ea
movl $0x0, 0x1010(%rbx)
cmpb $0x0, 0x19d9(%rbx)
jne 0x252cf
cmpb $0x1, 0x5d(%rsp)
jne 0x252cf
leaq 0x1938(%rbx), %rdi
leaq 0x20(%rsp), %rsi
movl $0x9, %ecx
rep  movsq (%rsi), %es:(%rdi)
cmpq $0x0, 0x19d0(%rbx)
je 0x252b6
leaq 0x19d0(%rbx), %rdi
callq 0x10370
movq $0x0, 0x19c8(%rbx)
jmp 0x252cf
cmpl $0x1, %ebp
ja 0x252cf
movl $0x0, (%r14)
addq $0x1980, %rbx           # imm = 0x1980
leaq 0x20(%rsp), %rsi
movl $0x9, %ecx
movq %rbx, %rdi
rep  movsq (%rsi), %es:(%rdi)
jmp 0x25389
cmpl $0xa, %ebp
je 0x25348
cmpl $0x1b, %ebp
je 0x25348
movq 0x40(%r12), %rax
movq (%rax), %rax
movq 0x8(%r15), %rcx
movq (%rax,%rcx,8), %rdi
movq %r9, %r13
callq 0xe97d
movq %r13, %r9
movq (%r15), %rsi
cmpq %rax, %rsi
jge 0x25348
movq 0x40(%r12), %rdi
movzbl 0x19d8(%rbx), %r9d
movq 0x8(%r15), %rdx
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movl $0x1, %ecx
movq %r15, %r8
callq 0xfc21
movq %r13, %r9
movb $0x1, 0x19d8(%rbx)
cmpb $0x0, 0x19d9(%rbx)
jne 0x25365
leaq 0x19c8(%rbx), %rdi
movl %ebp, %esi
movq %r9, %r13
callq 0x102e7
movq %r13, %r9
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
movl %ebp, %r8d
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x244bc
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq