// File: /workspace/github_c_makefile_star2_O2/stetre[P]moonnuklear/src/./nuklear/nuklear.h
// Function: nk_textedit_key
NK_LIB void
nk_textedit_key(struct nk_text_edit *state, enum nk_keys key, int shift_mod,
    const struct nk_user_font *font, float row_height)
{
retry:
    switch (key)
    {
    case NK_KEY_NONE:
    case NK_KEY_CTRL:
    case NK_KEY_ENTER:
    case NK_KEY_SHIFT:
    case NK_KEY_TAB:
    case NK_KEY_COPY:
    case NK_KEY_CUT:
    case NK_KEY_PASTE:
    case NK_KEY_MAX:
    default: break;
    case NK_KEY_TEXT_UNDO:
         nk_textedit_undo(state);
         state->has_preferred_x = 0;
         break;

    case NK_KEY_TEXT_REDO:
        nk_textedit_redo(state);
        state->has_preferred_x = 0;
        break;

    case NK_KEY_TEXT_SELECT_ALL:
        nk_textedit_select_all(state);
        state->has_preferred_x = 0;
        break;

    case NK_KEY_TEXT_INSERT_MODE:
        if (state->mode == NK_TEXT_EDIT_MODE_VIEW)
            state->mode = NK_TEXT_EDIT_MODE_INSERT;
        break;
    case NK_KEY_TEXT_REPLACE_MODE:
        if (state->mode == NK_TEXT_EDIT_MODE_VIEW)
            state->mode = NK_TEXT_EDIT_MODE_REPLACE;
        break;
    case NK_KEY_TEXT_RESET_MODE:
        if (state->mode == NK_TEXT_EDIT_MODE_INSERT ||
            state->mode == NK_TEXT_EDIT_MODE_REPLACE)
            state->mode = NK_TEXT_EDIT_MODE_VIEW;
        break;

    case NK_KEY_LEFT:
        if (shift_mod) {
            nk_textedit_clamp(state);
            nk_textedit_prep_selection_at_cursor(state);
            /* move selection left */
            if (state->select_end > 0)
                --state->select_end;
            state->cursor = state->select_end;
            state->has_preferred_x = 0;
        } else {
            /* if currently there's a selection,
             * move cursor to start of selection */
            if (NK_TEXT_HAS_SELECTION(state))
                nk_textedit_move_to_first(state);
            else if (state->cursor > 0)
               --state->cursor;
            state->has_preferred_x = 0;
        } break;

    case NK_KEY_RIGHT:
        if (shift_mod) {
            nk_textedit_prep_selection_at_cursor(state);
            /* move selection right */
            ++state->select_end;
            nk_textedit_clamp(state);
            state->cursor = state->select_end;
            state->has_preferred_x = 0;
        } else {
            /* if currently there's a selection,
             * move cursor to end of selection */
            if (NK_TEXT_HAS_SELECTION(state))
                nk_textedit_move_to_last(state);
            else ++state->cursor;
            nk_textedit_clamp(state);
            state->has_preferred_x = 0;
        } break;

    case NK_KEY_TEXT_WORD_LEFT:
        if (shift_mod) {
            if( !NK_TEXT_HAS_SELECTION( state ) )
            nk_textedit_prep_selection_at_cursor(state);
            state->cursor = nk_textedit_move_to_word_previous(state);
            state->select_end = state->cursor;
            nk_textedit_clamp(state );
        } else {
            if (NK_TEXT_HAS_SELECTION(state))
                nk_textedit_move_to_first(state);
            else {
                state->cursor = nk_textedit_move_to_word_previous(state);
                nk_textedit_clamp(state );
            }
        } break;

    case NK_KEY_TEXT_WORD_RIGHT:
        if (shift_mod) {
            if( !NK_TEXT_HAS_SELECTION( state ) )
                nk_textedit_prep_selection_at_cursor(state);
            state->cursor = nk_textedit_move_to_word_next(state);
            state->select_end = state->cursor;
            nk_textedit_clamp(state);
        } else {
            if (NK_TEXT_HAS_SELECTION(state))
                nk_textedit_move_to_last(state);
            else {
                state->cursor = nk_textedit_move_to_word_next(state);
                nk_textedit_clamp(state );
            }
        } break;

    case NK_KEY_DOWN: {
        struct nk_text_find find;
        struct nk_text_edit_row row;
        int i, sel = shift_mod;

        if (state->single_line) {
            /* on windows, up&down in single-line behave like left&right */
            key = NK_KEY_RIGHT;
            goto retry;
        }

        if (sel)
            nk_textedit_prep_selection_at_cursor(state);
        else if (NK_TEXT_HAS_SELECTION(state))
            nk_textedit_move_to_last(state);

        /* compute current position of cursor point */
        nk_textedit_clamp(state);
        nk_textedit_find_charpos(&find, state, state->cursor, state->single_line,
            font, row_height);

        /* now find character position down a row */
        if (find.length)
        {
            float x;
            float goal_x = state->has_preferred_x ? state->preferred_x : find.x;
            int start = find.first_char + find.length;

            state->cursor = start;
            nk_textedit_layout_row(&row, state, state->cursor, row_height, font);
            x = row.x0;

            for (i=0; i < row.num_chars && x < row.x1; ++i) {
                float dx = nk_textedit_get_width(state, start, i, font);
                x += dx;
                if (x > goal_x)
                    break;
                ++state->cursor;
            }
            nk_textedit_clamp(state);

            state->has_preferred_x = 1;
            state->preferred_x = goal_x;
            if (sel)
                state->select_end = state->cursor;
        }
    } break;

    case NK_KEY_UP: {
        struct nk_text_find find;
        struct nk_text_edit_row row;
        int i, sel = shift_mod;

        if (state->single_line) {
            /* on windows, up&down become left&right */
            key = NK_KEY_LEFT;
            goto retry;
        }

        if (sel)
            nk_textedit_prep_selection_at_cursor(state);
        else if (NK_TEXT_HAS_SELECTION(state))
            nk_textedit_move_to_first(state);

         /* compute current position of cursor point */
         nk_textedit_clamp(state);
         nk_textedit_find_charpos(&find, state, state->cursor, state->single_line,
                font, row_height);

         /* can only go up if there's a previous row */
         if (find.prev_first != find.first_char) {
            /* now find character position up a row */
            float x;
            float goal_x = state->has_preferred_x ? state->preferred_x : find.x;

            state->cursor = find.prev_first;
            nk_textedit_layout_row(&row, state, state->cursor, row_height, font);
            x = row.x0;

            for (i=0; i < row.num_chars && x < row.x1; ++i) {
                float dx = nk_textedit_get_width(state, find.prev_first, i, font);
                x += dx;
                if (x > goal_x)
                    break;
                ++state->cursor;
            }
            nk_textedit_clamp(state);

            state->has_preferred_x = 1;
            state->preferred_x = goal_x;
            if (sel) state->select_end = state->cursor;
         }
      } break;

    case NK_KEY_DEL:
        if (state->mode == NK_TEXT_EDIT_MODE_VIEW)
            break;
        if (NK_TEXT_HAS_SELECTION(state))
            nk_textedit_delete_selection(state);
        else {
            int n = state->string.len;
            if (state->cursor < n)
                nk_textedit_delete(state, state->cursor, 1);
         }
         state->has_preferred_x = 0;
         break;

    case NK_KEY_BACKSPACE:
        if (state->mode == NK_TEXT_EDIT_MODE_VIEW)
            break;
        if (NK_TEXT_HAS_SELECTION(state))
            nk_textedit_delete_selection(state);
        else {
            nk_textedit_clamp(state);
            if (state->cursor > 0) {
                nk_textedit_delete(state, state->cursor-1, 1);
                --state->cursor;
            }
         }
         state->has_preferred_x = 0;
         break;

    case NK_KEY_TEXT_START:
         if (shift_mod) {
            nk_textedit_prep_selection_at_cursor(state);
            state->cursor = state->select_end = 0;
            state->has_preferred_x = 0;
         } else {
            state->cursor = state->select_start = state->select_end = 0;
            state->has_preferred_x = 0;
         }
         break;

    case NK_KEY_TEXT_END:
         if (shift_mod) {
            nk_textedit_prep_selection_at_cursor(state);
            state->cursor = state->select_end = state->string.len;
            state->has_preferred_x = 0;
         } else {
            state->cursor = state->string.len;
            state->select_start = state->select_end = 0;
            state->has_preferred_x = 0;
         }
         break;

    case NK_KEY_TEXT_LINE_START: {
        if (shift_mod) {
            struct nk_text_find find;
           nk_textedit_clamp(state);
            nk_textedit_prep_selection_at_cursor(state);
            if (state->string.len && state->cursor == state->string.len)
                --state->cursor;
            nk_textedit_find_charpos(&find, state,state->cursor, state->single_line,
                font, row_height);
            state->cursor = state->select_end = find.first_char;
            state->has_preferred_x = 0;
        } else {
            struct nk_text_find find;
            if (state->string.len && state->cursor == state->string.len)
                --state->cursor;
            nk_textedit_clamp(state);
            nk_textedit_move_to_first(state);
            nk_textedit_find_charpos(&find, state, state->cursor, state->single_line,
                font, row_height);
            state->cursor = find.first_char;
            state->has_preferred_x = 0;
        }
      } break;

    case NK_KEY_TEXT_LINE_END: {
        if (shift_mod) {
            struct nk_text_find find;
            nk_textedit_clamp(state);
            nk_textedit_prep_selection_at_cursor(state);
            nk_textedit_find_charpos(&find, state, state->cursor, state->single_line,
                font, row_height);
            state->has_preferred_x = 0;
            state->cursor = find.first_char + find.length;
            if (find.length > 0 && nk_str_rune_at(&state->string, state->cursor-1) == '\n')
                --state->cursor;
            state->select_end = state->cursor;
        } else {
            struct nk_text_find find;
            nk_textedit_clamp(state);
            nk_textedit_move_to_first(state);
            nk_textedit_find_charpos(&find, state, state->cursor, state->single_line,
                font, row_height);

            state->has_preferred_x = 0;
            state->cursor = find.first_char + find.length;
            if (find.length > 0 && nk_str_rune_at(&state->string, state->cursor-1) == '\n')
                --state->cursor;
        }} break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r14
movl %edx, %ebp
movq %rdi, %rbx
leaq 0x13ddf(%rip), %rax     # 0x66b54
pushq $0xc
popq %rcx
pushq $0xd
popq %rdx
addl $-0x3, %esi
cmpl $0x16, %esi
ja 0x53234
movslq (%rax,%rsi,4), %rsi
addq %rax, %rsi
jmpq *%rsi
cmpb $0x0, 0xb8(%rbx)
je 0x530c6
movl %ecx, %esi
jmp 0x52d7b
cmpb $0x0, 0xb8(%rbx)
je 0x530ab
movl %edx, %esi
jmp 0x52d7b
cmpb $0x0, 0xb4(%rbx)
jne 0x53234
movb $0x2, 0xb4(%rbx)
jmp 0x53234
movb 0xb4(%rbx), %al
decb %al
cmpb $0x1, %al
ja 0x53234
movb $0x0, 0xb4(%rbx)
jmp 0x53234
cmpb $0x0, 0xb4(%rbx)
jne 0x53234
movb $0x1, 0xb4(%rbx)
jmp 0x53234
movss %xmm0, 0xc(%rsp)
movq %rbx, %rdi
testl %ebp, %ebp
je 0x530ee
callq 0x46ea3
movq %rbx, %rdi
callq 0x53d7b
movl 0xa8(%rbx), %edx
movzbl 0xb8(%rbx), %ecx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %r8
movss 0xc(%rsp), %xmm0
callq 0x53e8b
movb $0x0, 0xb7(%rbx)
movl 0x10(%r15), %eax
movl 0xc(%r15), %esi
addl %eax, %esi
movl %esi, 0xa8(%rbx)
testl %eax, %eax
jle 0x52e7d
leaq 0x18(%rbx), %rdi
decl %esi
callq 0x12a60
movl 0xa8(%rbx), %esi
cmpl $0xa, %eax
jne 0x52e7d
decl %esi
movl %esi, 0xa8(%rbx)
movl %esi, 0xb0(%rbx)
jmp 0x53234
movl 0xac(%rbx), %eax
movl 0xb0(%rbx), %ecx
testl %ebp, %ebp
je 0x5315f
cmpl %ecx, %eax
jne 0x52ea8
movq %rbx, %rdi
callq 0x53d7b
movq %rbx, %rdi
callq 0x53e16
jmp 0x52f78
cmpb $0x0, 0xb4(%rbx)
je 0x53234
movl 0xac(%rbx), %eax
cmpl 0xb0(%rbx), %eax
jne 0x530e1
movl 0xa8(%rbx), %esi
cmpl 0x90(%rbx), %esi
jge 0x5322d
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x123a0
jmp 0x5322d
cmpb $0x0, 0xb4(%rbx)
je 0x53234
movl 0xac(%rbx), %eax
cmpl 0xb0(%rbx), %eax
jne 0x530e1
movq %rbx, %rdi
callq 0x46ea3
movl 0xa8(%rbx), %esi
testl %esi, %esi
jle 0x5322d
decl %esi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x123a0
decl 0xa8(%rbx)
jmp 0x5322d
movq %rbx, %rdi
callq 0x12390
jmp 0x5322d
movl 0xac(%rbx), %eax
movl 0xb0(%rbx), %ecx
testl %ebp, %ebp
je 0x53171
cmpl %ecx, %eax
jne 0x52f70
movq %rbx, %rdi
callq 0x53d7b
movq %rbx, %rdi
callq 0x53e49
movl %eax, 0xa8(%rbx)
movl %eax, 0xb0(%rbx)
jmp 0x53187
testl %ebp, %ebp
je 0x5319d
movq %rbx, %rdi
callq 0x46ea3
movq %rbx, %rdi
callq 0x53d7b
movl 0xb0(%rbx), %eax
testl %eax, %eax
jle 0x53227
decl %eax
jmp 0x53047
testl %ebp, %ebp
je 0x531bd
movq %rbx, %rdi
callq 0x53d7b
movl 0x90(%rbx), %eax
jmp 0x53047
movq %rbx, %rdi
callq 0x13a80
jmp 0x5322d
testl %ebp, %ebp
movss %xmm0, 0xc(%rsp)
je 0x531d3
movq %rbx, %rdi
callq 0x46ea3
movq %rbx, %rdi
callq 0x53d7b
movl 0x90(%rbx), %eax
movl 0xa8(%rbx), %edx
testl %eax, %eax
setne %cl
cmpl %eax, %edx
sete %sil
andb %cl, %sil
cmpb $0x1, %sil
jne 0x53023
decl %eax
movl %eax, 0xa8(%rbx)
movl %eax, %edx
movzbl 0xb8(%rbx), %ecx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %r8
movss 0xc(%rsp), %xmm0
callq 0x53e8b
movl 0xc(%r15), %eax
movl %eax, 0xb0(%rbx)
jmp 0x53227
testl %ebp, %ebp
je 0x53243
movq %rbx, %rdi
callq 0x53d7b
incl 0xb0(%rbx)
movq %rbx, %rdi
callq 0x46ea3
movl 0xb0(%rbx), %eax
jmp 0x53227
movq %rbx, %rdi
callq 0x128f0
jmp 0x5322d
testl %ebp, %ebp
je 0x53260
movq %rbx, %rdi
callq 0x53d7b
andl $0x0, 0xb0(%rbx)
andl $0x0, 0xa8(%rbx)
jmp 0x5322d
movss %xmm0, 0xc(%rsp)
testl %ebp, %ebp
je 0x53271
movq %rbx, %rdi
callq 0x53d7b
jmp 0x53287
movss %xmm0, 0xc(%rsp)
testl %ebp, %ebp
je 0x5337d
movq %rbx, %rdi
callq 0x53d7b
jmp 0x53393
movq %rbx, %rdi
callq 0x14070
jmp 0x5322d
callq 0x46ea3
movq %rbx, %rdi
callq 0x53da3
movl 0xa8(%rbx), %edx
movzbl 0xb8(%rbx), %ecx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %r8
movss 0xc(%rsp), %xmm0
callq 0x53e8b
movb $0x0, 0xb7(%rbx)
movl 0x10(%r15), %eax
movl 0xc(%r15), %esi
addl %eax, %esi
movl %esi, 0xa8(%rbx)
testl %eax, %eax
jle 0x53234
leaq 0x18(%rbx), %rdi
decl %esi
callq 0x12a60
cmpl $0xa, %eax
jne 0x53234
decl 0xa8(%rbx)
jmp 0x53234
cmpl %ecx, %eax
jne 0x534b0
movq %rbx, %rdi
callq 0x53e16
jmp 0x53181
cmpl %ecx, %eax
jne 0x534c6
movq %rbx, %rdi
callq 0x53e49
movl %eax, 0xa8(%rbx)
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x46ea3
movl 0xac(%rbx), %eax
cmpl 0xb0(%rbx), %eax
jne 0x534dc
movl 0xa8(%rbx), %eax
testl %eax, %eax
jle 0x5322d
decl %eax
jmp 0x53227
movl 0x90(%rbx), %eax
movl %eax, 0xa8(%rbx)
andq $0x0, 0xac(%rbx)
jmp 0x5322d
movl 0x90(%rbx), %eax
testl %eax, %eax
je 0x531ed
cmpl %eax, 0xa8(%rbx)
jne 0x531ed
decl %eax
movl %eax, 0xa8(%rbx)
movq %rbx, %rdi
callq 0x46ea3
movq %rbx, %rdi
callq 0x53da3
movl 0xa8(%rbx), %edx
movzbl 0xb8(%rbx), %ecx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %r8
movss 0xc(%rsp), %xmm0
callq 0x53e8b
movl 0xc(%r15), %eax
movl %eax, 0xa8(%rbx)
movb $0x0, 0xb7(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xac(%rbx), %eax
cmpl 0xb0(%rbx), %eax
jne 0x534e9
incl 0xa8(%rbx)
jmp 0x534f1
andl $0x0, 0xb0(%rbx)
andq $0x0, 0xa8(%rbx)
jmp 0x5322d
movl 0xac(%rbx), %eax
cmpl 0xb0(%rbx), %eax
je 0x53287
movq %rbx, %rdi
callq 0x53dd1
movq %rbx, %rdi
callq 0x46ea3
movl 0xa8(%rbx), %edx
movzbl 0xb8(%rbx), %ecx
leaq 0x18(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %r8
movss 0xc(%rsp), %xmm0
callq 0x53e8b
movl 0x10(%r12), %r15d
testl %r15d, %r15d
je 0x53234
leaq 0xbc(%rbx), %rax
cmpb $0x0, 0xb7(%rbx)
cmoveq %r12, %rax
movss (%rax), %xmm0
movss %xmm0, 0x10(%rsp)
addl 0x24(%rsp), %r15d
movl %r15d, 0xa8(%rbx)
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movss 0xc(%rsp), %xmm0
movq %r14, %rcx
callq 0x53c96
movss (%r12), %xmm0
movss 0x4(%r12), %xmm1
movss %xmm1, 0x14(%rsp)
movl 0x14(%r12), %r13d
xorl %r12d, %r12d
cmpl %r13d, %r12d
jge 0x5347a
movss 0x14(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x5347a
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
movq %r14, %rcx
movss %xmm0, 0xc(%rsp)
callq 0x53d3b
movss 0xc(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0xc(%rsp)
movss 0xc(%rsp), %xmm0
ucomiss 0x10(%rsp), %xmm0
ja 0x5347a
incl 0xa8(%rbx)
incl %r12d
jmp 0x53322
movl 0xac(%rbx), %eax
cmpl 0xb0(%rbx), %eax
je 0x53393
movq %rbx, %rdi
callq 0x53da3
movq %rbx, %rdi
callq 0x46ea3
movl 0xa8(%rbx), %edx
movzbl 0xb8(%rbx), %ecx
leaq 0x18(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %r8
movss 0xc(%rsp), %xmm0
callq 0x53e8b
movl 0x14(%r12), %r15d
cmpl 0xc(%r12), %r15d
je 0x53234
leaq 0xbc(%rbx), %rax
cmpb $0x0, 0xb7(%rbx)
cmoveq %r12, %rax
movss (%rax), %xmm0
movss %xmm0, 0x10(%rsp)
movl %r15d, 0xa8(%rbx)
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movl %r15d, %edx
movss 0xc(%rsp), %xmm0
movq %r14, %rcx
callq 0x53c96
movss (%r12), %xmm0
movss 0x4(%r12), %xmm1
movss %xmm1, 0x14(%rsp)
movl 0x14(%r12), %r13d
xorl %r12d, %r12d
cmpl %r13d, %r12d
jge 0x5347a
movss 0x14(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x5347a
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
movq %r14, %rcx
movss %xmm0, 0xc(%rsp)
callq 0x53d3b
movss 0xc(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0xc(%rsp)
movss 0xc(%rsp), %xmm0
ucomiss 0x10(%rsp), %xmm0
ja 0x5347a
incl 0xa8(%rbx)
incl %r12d
jmp 0x5342b
movq %rbx, %rdi
callq 0x46ea3
movb $0x1, 0xb7(%rbx)
movss 0x10(%rsp), %xmm0
movss %xmm0, 0xbc(%rbx)
testl %ebp, %ebp
je 0x53234
movl 0xa8(%rbx), %eax
movl %eax, 0xb0(%rbx)
jmp 0x53234
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x53da3
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x53dd1
movq %rbx, %rdi
callq 0x53da3
jmp 0x5322d
movq %rbx, %rdi
callq 0x53dd1
movq %rbx, %rdi
callq 0x46ea3
jmp 0x5322d