// File: /workspace/github_cpp_makefile_star2_O3/Ciaxur[P]yagb-emu/include/imgui/imgui_demo.cpp
// Function: ExampleAppConsole::TextEditCallback(ImGuiInputTextCallbackData*)
int     TextEditCallback(ImGuiInputTextCallbackData* data)
    {
        //AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
        switch (data->EventFlag)
        {
        case ImGuiInputTextFlags_CallbackCompletion:
            {
                // Example of TEXT COMPLETION

                // Locate beginning of current word
                const char* word_end = data->Buf + data->CursorPos;
                const char* word_start = word_end;
                while (word_start > data->Buf)
                {
                    const char c = word_start[-1];
                    if (c == ' ' || c == '\t' || c == ',' || c == ';')
                        break;
                    word_start--;
                }

                // Build a list of candidates
                ImVector<const char*> candidates;
                for (int i = 0; i < Commands.Size; i++)
                    if (Strnicmp(Commands[i], word_start, (int)(word_end - word_start)) == 0)
                        candidates.push_back(Commands[i]);

                if (candidates.Size == 0)
                {
                    // No match
                    AddLog("No match for \"%.*s\"!\n", (int)(word_end - word_start), word_start);
                }
                else if (candidates.Size == 1)
                {
                    // Single match. Delete the beginning of the word and replace it entirely so we've got nice casing.
                    data->DeleteChars((int)(word_start - data->Buf), (int)(word_end - word_start));
                    data->InsertChars(data->CursorPos, candidates[0]);
                    data->InsertChars(data->CursorPos, " ");
                }
                else
                {
                    // Multiple matches. Complete as much as we can..
                    // So inputing "C"+Tab will complete to "CL" then display "CLEAR" and "CLASSIFY" as matches.
                    int match_len = (int)(word_end - word_start);
                    for (;;)
                    {
                        int c = 0;
                        bool all_candidates_matches = true;
                        for (int i = 0; i < candidates.Size && all_candidates_matches; i++)
                            if (i == 0)
                                c = toupper(candidates[i][match_len]);
                            else if (c == 0 || c != toupper(candidates[i][match_len]))
                                all_candidates_matches = false;
                        if (!all_candidates_matches)
                            break;
                        match_len++;
                    }

                    if (match_len > 0)
                    {
                        data->DeleteChars((int)(word_start - data->Buf), (int)(word_end - word_start));
                        data->InsertChars(data->CursorPos, candidates[0], candidates[0] + match_len);
                    }

                    // List matches
                    AddLog("Possible matches:\n");
                    for (int i = 0; i < candidates.Size; i++)
                        AddLog("- %s\n", candidates[i]);
                }

                break;
            }
        case ImGuiInputTextFlags_CallbackHistory:
            {
                // Example of HISTORY
                const int prev_history_pos = HistoryPos;
                if (data->EventKey == ImGuiKey_UpArrow)
                {
                    if (HistoryPos == -1)
                        HistoryPos = History.Size - 1;
                    else if (HistoryPos > 0)
                        HistoryPos--;
                }
                else if (data->EventKey == ImGuiKey_DownArrow)
                {
                    if (HistoryPos != -1)
                        if (++HistoryPos >= History.Size)
                            HistoryPos = -1;
                }

                // A better implementation would preserve the data on the current input line along with cursor position.
                if (prev_history_pos != HistoryPos)
                {
                    const char* history_str = (HistoryPos >= 0) ? History[HistoryPos] : "";
                    data->DeleteChars(0, data->BufTextLen);
                    data->InsertChars(0, history_str);
                }
            }
        }
        return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %r15
movl (%rsi), %eax
cmpl $0x80, %eax
je 0x738b5
cmpl $0x40, %eax
jne 0x73a6a
movq 0x18(%r14), %rdi
movslq 0x2c(%r14), %rcx
movq %rcx, -0x58(%rbp)
addq %rdi, %rcx
xorl %r8d, %r8d
movabsq $0x800100100000200, %rax # imm = 0x800100100000200
movq %rcx, %r13
movl %r8d, %edx
cmpq %rdi, %rcx
jbe 0x73733
leaq -0x1(%r13), %rcx
movzbl -0x1(%r13), %esi
leal 0x1(%rdx), %r8d
cmpq $0x3b, %rsi
ja 0x7370f
btq %rsi, %rax
jae 0x7370f
movq %rdi, -0x60(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
cmpl $0x0, 0x110(%r15)
jle 0x738ef
movq %rdx, -0x50(%rbp)
movq %r14, -0x48(%rbp)
xorl %ebx, %ebx
movq $0x0, -0x70(%rbp)
xorl %r12d, %r12d
movl $0x0, -0x2c(%rbp)
xorl %r14d, %r14d
movq %r15, -0x68(%rbp)
movq 0x118(%r15), %rax
movq (%rax,%r14,8), %rdi
movq %r13, %rsi
movq -0x50(%rbp), %rdx
callq 0x73ad4
testl %eax, %eax
jne 0x73842
movslq 0x110(%r15), %rax
cmpq %rax, %r14
jge 0x73a7b
movq 0x118(%r15), %rcx
cmpl %r12d, -0x2c(%rbp)
jne 0x737c4
testl %r12d, %r12d
movq %rcx, -0x78(%rbp)
je 0x737cc
movl %r12d, %eax
shrl $0x1f, %eax
addl %r12d, %eax
sarl %eax
addl %r12d, %eax
jmp 0x737d1
movl %r12d, %r15d
movl -0x2c(%rbp), %eax
jmp 0x73822
movl $0x8, %eax
leal 0x1(%r12), %r15d
cmpl %r15d, %eax
cmovgl %eax, %r15d
movslq %r15d, %rdi
shlq $0x3, %rdi
callq 0x41c63
movq %rax, %rbx
movq -0x70(%rbp), %rsi
testq %rsi, %rsi
je 0x73813
movslq %r12d, %rdx
shlq $0x3, %rdx
movq %rbx, %rdi
movq %rsi, %r12
callq 0xc080
movq %r12, %rdi
callq 0x41d3c
movl -0x40(%rbp), %r12d
movq %rbx, -0x38(%rbp)
movl %r15d, -0x3c(%rbp)
movl %r12d, %eax
movq -0x78(%rbp), %rcx
cltq
movq (%rcx,%r14,8), %rcx
movq %rcx, (%rbx,%rax,8)
movl -0x40(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
movl %eax, -0x40(%rbp)
movq %rbx, -0x70(%rbp)
movl %r15d, %r12d
movq -0x68(%rbp), %r15
incq %r14
movslq 0x110(%r15), %rax
cmpq %rax, %r14
jl 0x7376f
movl -0x2c(%rbp), %eax
testl %eax, %eax
movq -0x48(%rbp), %r14
movq -0x50(%rbp), %rdx
je 0x738ef
cmpl $0x1, %eax
jne 0x73935
movq -0x60(%rbp), %rsi
addl -0x58(%rbp), %esi
subl 0x18(%r14), %esi
subl %edx, %esi
movq %r14, %rdi
callq 0x9c5e2
movl 0x2c(%r14), %esi
movq -0x38(%rbp), %rbx
movq (%rbx), %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x9c662
movl 0x2c(%r14), %esi
leaq 0x4595a(%rip), %rdx     # 0xb9200
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x9c662
jmp 0x73a04
movl 0x130(%r15), %eax
movl 0x14(%r14), %ecx
cmpl $0x4, %ecx
je 0x73915
cmpl $0x3, %ecx
jne 0x73a6a
cmpl $-0x1, %eax
je 0x73a0e
testl %eax, %eax
jle 0x73a6a
decl %eax
movl %eax, 0x130(%r15)
movl %eax, %ecx
jmp 0x73a26
leaq 0x51c2c(%rip), %rsi     # 0xc5522
movq %r15, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x7322e
movq -0x38(%rbp), %rbx
testq %rbx, %rbx
jne 0x73a04
jmp 0x73a6a
cmpl $-0x1, %eax
je 0x73a6a
leal 0x1(%rax), %edx
cmpl 0x120(%r15), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovll %edx, %ecx
jmp 0x73a17
movq -0x38(%rbp), %r12
movslq %eax, %r13
movslq %edx, %r14
testl %eax, %eax
jle 0x7397d
xorl %r15d, %r15d
xorl %ebx, %ebx
testq %r15, %r15
je 0x73965
testl %ebx, %ebx
je 0x73985
movq (%r12,%r15,8), %rax
movsbl (%rax,%r14), %edi
callq 0xc160
cmpl %eax, %ebx
je 0x73975
jmp 0x73985
movq (%r12), %rax
movsbl (%rax,%r14), %edi
callq 0xc160
movl %eax, %ebx
incq %r15
cmpq %r13, %r15
jl 0x73948
incq %r14
movl -0x2c(%rbp), %eax
jmp 0x7393f
testq %r14, %r14
movq -0x68(%rbp), %r15
jle 0x739c7
movq -0x60(%rbp), %rsi
addl -0x58(%rbp), %esi
movq -0x48(%rbp), %rdi
subl 0x18(%rdi), %esi
movq -0x50(%rbp), %rdx
subl %edx, %esi
callq 0x9c5e2
cmpl $0x0, -0x2c(%rbp)
jle 0x73a7b
movq -0x48(%rbp), %rdi
movl 0x2c(%rdi), %esi
movq (%r12), %rdx
movl %r14d, %ecx
addq %rdx, %rcx
callq 0x9c662
leaq 0x51b6a(%rip), %rsi     # 0xc5538
movq %r15, %rdi
xorl %eax, %eax
callq 0x7322e
cmpl $0x0, -0x2c(%rbp)
jle 0x73a3e
leaq 0x51b66(%rip), %rbx     # 0xc554b
xorl %r14d, %r14d
movq (%r12,%r14,8), %rdx
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x7322e
incq %r14
cmpq %r13, %r14
jl 0x739e8
movq %r12, %rbx
movq %rbx, %rdi
callq 0x41d3c
jmp 0x73a6a
movl 0x120(%r15), %ecx
decl %ecx
movl %ecx, 0x130(%r15)
cmpl %ecx, %eax
je 0x73a6a
testl %ecx, %ecx
js 0x73a46
cmpl %ecx, 0x120(%r15)
jle 0x73a9a
movq 0x128(%r15), %rax
movl %ecx, %ecx
movq (%rax,%rcx,8), %rbx
jmp 0x73a4d
movq %r12, %rbx
jmp 0x73907
leaq 0x414d0(%rip), %rbx     # 0xb4f1d
movl 0x20(%r14), %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x9c5e2
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x9c662
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45bf6(%rip), %rdi     # 0xb9678
leaq 0x45c02(%rip), %rsi     # 0xb968b
leaq 0x51ac1(%rip), %rcx     # 0xc5551
movl $0x65c, %edx            # imm = 0x65C
callq 0xc140
leaq 0x45bd7(%rip), %rdi     # 0xb9678
leaq 0x45be3(%rip), %rsi     # 0xb968b
leaq 0x51859(%rip), %rcx     # 0xc5308
jmp 0x73a90
jmp 0x73abf
movq %rax, %rdi
callq 0x39dbe
jmp 0x73abf
jmp 0x73abf
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x73392
movq %rbx, %rdi
callq 0xc560
nop