// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl (%rsi), %eax
cmpl $0x80, %eax
je 0x74a35
cmpl $0x40, %eax
jne 0x74c2f
movq 0x18(%rbx), %rax
movslq 0x2c(%rbx), %r15
addq %rax, %r15
movabsq $0x800100100000200, %rcx # imm = 0x800100100000200
movq %r15, -0x48(%rbp)
cmpq %rax, %r15
jbe 0x748d5
movzbl -0x1(%r15), %edx
cmpq $0x3b, %rdx
ja 0x748ce
btq %rdx, %rcx
jae 0x748ce
xorl %edx, %edx
testb %dl, %dl
jne 0x748b0
jmp 0x748d5
decq %r15
movb $0x1, %dl
jmp 0x748c8
movq %rbx, -0x58(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
cmpl $0x0, 0x110(%r14)
movq %r15, -0x60(%rbp)
movq %r14, -0x68(%rbp)
jle 0x749cf
movq -0x48(%rbp), %rax
movl %eax, %r13d
subl %r15d, %r13d
xorl %ebx, %ebx
movq 0x118(%r14), %rax
movq (%rax,%rbx,8), %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x74c98
testl %eax, %eax
jne 0x749bc
movslq 0x110(%r14), %rax
cmpq %rax, %rbx
jge 0x74c40
movq 0x118(%r14), %r14
movl -0x40(%rbp), %r12d
movl -0x3c(%rbp), %eax
cmpl %eax, %r12d
jne 0x749a1
testl %eax, %eax
je 0x74954
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
addl %eax, %ecx
jmp 0x74959
movl $0x8, %ecx
incl %r12d
cmpl %r12d, %ecx
cmovgl %ecx, %r12d
cmpl %r12d, %eax
jge 0x749a1
movslq %r12d, %rdi
shlq $0x3, %rdi
callq 0x424fb
movq %rax, %r15
movq -0x38(%rbp), %rsi
testq %rsi, %rsi
je 0x74999
movslq -0x40(%rbp), %rdx
shlq $0x3, %rdx
movq %r15, %rdi
callq 0xc080
movq -0x38(%rbp), %rdi
callq 0x425d4
movq %r15, -0x38(%rbp)
movl %r12d, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq (%r14,%rbx,8), %rdx
movq %rdx, (%rax,%rcx,8)
incl -0x40(%rbp)
movq -0x68(%rbp), %r14
movq -0x60(%rbp), %r15
incq %rbx
movslq 0x110(%r14), %rax
cmpq %rax, %rbx
jl 0x74902
movslq -0x40(%rbp), %rbx
testq %rbx, %rbx
je 0x74a8d
cmpl $0x1, %ebx
jne 0x74aad
movl %r15d, %esi
movq -0x58(%rbp), %rbx
subl 0x18(%rbx), %esi
movq -0x48(%rbp), %rdx
subl %r15d, %edx
movq %rbx, %rdi
callq 0x9e06a
cmpl $0x0, -0x40(%rbp)
jle 0x74c40
movl 0x2c(%rbx), %esi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x9e0e2
movl 0x2c(%rbx), %esi
leaq 0x467da(%rip), %rdx     # 0xbb200
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x9e0e2
jmp 0x74bc7
movl 0x130(%r14), %eax
movl 0x14(%rbx), %ecx
cmpl $0x4, %ecx
je 0x74a66
cmpl $0x3, %ecx
jne 0x74be7
cmpl $-0x1, %eax
je 0x74bd7
testl %eax, %eax
jle 0x74be7
leal -0x1(%rax), %ecx
jmp 0x74be0
cmpl $-0x1, %eax
je 0x74be7
leal 0x1(%rax), %edx
movl %edx, 0x130(%r14)
cmpl 0x120(%r14), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovll %edx, %ecx
jmp 0x74be0
movq -0x48(%rbp), %rdx
subl %r15d, %edx
leaq 0x52ab7(%rip), %rsi     # 0xc7552
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x743c6
jmp 0x74bc7
movq -0x48(%rbp), %rax
subl %r15d, %eax
movq -0x38(%rbp), %rcx
movq %rcx, -0x70(%rbp)
movq %rax, -0x48(%rbp)
movl %eax, %r14d
testl %ebx, %ebx
jle 0x74b32
movl %r14d, -0x4c(%rbp)
movslq %r14d, %r15
xorl %r13d, %r13d
movb $0x1, %r12b
movl $0x1, %r14d
cmpq $0x1, %r14
jne 0x74af6
movq -0x70(%rbp), %rax
movq (%rax), %rax
movsbl (%rax,%r15), %edi
callq 0xc160
movl %eax, %r13d
jmp 0x74b16
testl %r13d, %r13d
je 0x74b13
movq -0x70(%rbp), %rax
movq -0x8(%rax,%r14,8), %rax
movsbl (%rax,%r15), %edi
callq 0xc160
cmpl %eax, %r13d
je 0x74b16
xorl %r12d, %r12d
cmpq %rbx, %r14
jge 0x74b24
incq %r14
testb $0x1, %r12b
jne 0x74ada
movl %r12d, %eax
andb $0x1, %al
movzbl %al, %eax
movl -0x4c(%rbp), %r14d
jmp 0x74b3a
movb $0x1, %r12b
movl $0x1, %eax
addl %eax, %r14d
testb $0x1, %r12b
jne 0x74ac3
testl %r14d, %r14d
movq -0x58(%rbp), %rbx
movq -0x68(%rbp), %r15
jle 0x74b85
movq -0x60(%rbp), %rsi
subl 0x18(%rbx), %esi
movq %rbx, %rdi
movq -0x48(%rbp), %rdx
callq 0x9e06a
cmpl $0x0, -0x40(%rbp)
jle 0x74c40
movl 0x2c(%rbx), %esi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movl %r14d, %ecx
addq %rdx, %rcx
movq %rbx, %rdi
callq 0x9e0e2
leaq 0x529dc(%rip), %rsi     # 0xc7568
movq %r15, %rdi
xorl %eax, %eax
callq 0x743c6
cmpl $0x0, -0x40(%rbp)
jle 0x74bc7
leaq 0x529d8(%rip), %rbx     # 0xc757b
xorl %r14d, %r14d
movq -0x38(%rbp), %rax
movq (%rax,%r14,8), %rdx
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x743c6
incq %r14
movslq -0x40(%rbp), %rax
cmpq %rax, %r14
jl 0x74ba6
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x74c2f
callq 0x425d4
jmp 0x74c2f
movl 0x120(%r14), %ecx
decl %ecx
movl %ecx, 0x130(%r14)
movl 0x130(%r14), %ecx
cmpl %ecx, %eax
je 0x74c2f
testl %ecx, %ecx
js 0x74c0c
cmpl %ecx, 0x120(%r14)
jle 0x74c5f
movq 0x128(%r14), %rax
movq (%rax,%rcx,8), %r14
jmp 0x74c13
leaq 0x4230a(%rip), %r14     # 0xb6f1d
movl 0x20(%rbx), %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9e06a
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x9e0e2
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x46a31(%rip), %rdi     # 0xbb678
leaq 0x46a3d(%rip), %rsi     # 0xbb68b
leaq 0x5292c(%rip), %rcx     # 0xc7581
movl $0x65c, %edx            # imm = 0x65C
callq 0xc140
leaq 0x46a12(%rip), %rdi     # 0xbb678
leaq 0x46a1e(%rip), %rsi     # 0xbb68b
leaq 0x526c4(%rip), %rcx     # 0xc7338
jmp 0x74c55
movq %rax, %rdi
callq 0x3a5b4
jmp 0x74c84
jmp 0x74c84
jmp 0x74c84
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x74530
movq %rbx, %rdi
callq 0xc560