// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x98(%rbp)
subq $0x5, %rax
ja 0x33b01
movq -0x98(%rbp), %rax
leaq 0x116c0(%rip), %rcx     # 0x451b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x4(%rbp)
jmp 0x33d63
movq -0x10(%rbp), %rax
testb $0x1, 0x19d9(%rax)
jne 0x33b2d
movq -0x10(%rbp), %rdi
addq $0x19c8, %rdi           # imm = 0x19C8
movl -0x2c(%rbp), %esi
callq 0x11df0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x2c(%rbp), %r8d
movq 0x10(%rbp), %r9
callq 0x323c0
movl %eax, -0x4(%rbp)
jmp 0x33d63
cmpl $0xa, -0x2c(%rbp)
je 0x33be1
cmpl $0x1b, -0x2c(%rbp)
je 0x33be1
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xf1f0
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
cmpq -0x40(%rbp), %rax
jge 0x33bdf
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x20(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x20(%rbp), %r9
movq -0x10(%rbp), %rax
movb 0x19d8(%rax), %al
movq (%rcx), %rsi
movq 0x8(%rcx), %rdx
movl $0x1, %ecx
andb $0x1, %al
movq (%r9), %r10
movq %r10, (%rsp)
movq 0x8(%r9), %r9
movq %r9, 0x8(%rsp)
movzbl %al, %r9d
callq 0x110a0
movq -0x10(%rbp), %rax
movb $0x1, 0x19d8(%rax)
jmp 0x33be1
movq -0x10(%rbp), %rax
testb $0x1, 0x19d9(%rax)
jne 0x33c01
movq -0x10(%rbp), %rdi
addq $0x19c8, %rdi           # imm = 0x19C8
movl -0x2c(%rbp), %esi
callq 0x11df0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x2c(%rbp), %r8d
movq 0x10(%rbp), %r9
callq 0x323c0
movl %eax, -0x4(%rbp)
jmp 0x33d63
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0xd290
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x32350
testb $0x1, %al
jne 0x33c5c
movq -0x10(%rbp), %rax
movl $0x0, 0x1010(%rax)
jmp 0x33d5c
movq -0x10(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x33d70
movl %eax, -0x8c(%rbp)
cmpl $0x5, -0x8c(%rbp)
jne 0x33d13
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x38(%rbp), %r9
movq 0x10(%rbp), %rax
leaq -0x88(%rbp), %rsi
movq %rax, (%rsp)
callq 0x34110
movq -0x10(%rbp), %rax
movl $0x0, 0x1010(%rax)
movq -0x10(%rbp), %rax
testb $0x1, 0x19d9(%rax)
jne 0x33d11
testb $0x1, -0x4b(%rbp)
je 0x33d11
movq -0x10(%rbp), %rdi
addq $0x1938, %rdi           # imm = 0x1938
leaq -0x88(%rbp), %rsi
movl $0x48, %edx
callq 0xd400
movq -0x10(%rbp), %rax
cmpq $0x0, 0x19d0(%rax)
je 0x33d02
movq -0x10(%rbp), %rdi
addq $0x19d0, %rdi           # imm = 0x19D0
callq 0x11f10
movq -0x10(%rbp), %rax
movq $0x0, 0x19c8(%rax)
jmp 0x33d35
cmpl $0x0, -0x8c(%rbp)
je 0x33d25
cmpl $0x1, -0x8c(%rbp)
jne 0x33d33
movq -0x10(%rbp), %rax
movl $0x0, 0x1010(%rax)
jmp 0x33d35
movq -0x10(%rbp), %rdi
addq $0x1980, %rdi           # imm = 0x1980
leaq -0x88(%rbp), %rsi
movl $0x48, %edx
callq 0xd400
movl -0x8c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x33d63
movl $0x5, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nop