// File: /workspace/github_cpp_makefile_star2_O2/donfreiday[P]gb/./imgui/imgui_demo.cpp
// Function: ExampleAppConsole::TextEditCallback(ImGuiTextEditCallbackData*)
int     TextEditCallback(ImGuiTextEditCallbackData* 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" will complete to "CL" and display "CLEAR" and "CLASSIFY"
                    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 != 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)
                {
                    snprintf(data->Buf, data->BufSize, "%s", (HistoryPos >= 0) ? History[HistoryPos] : "");
                    data->BufDirty = true;
                    data->CursorPos = data->SelectionStart = data->SelectionEnd = (int)strlen(data->Buf);
                }
            }
        }
        return 0;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r15
movl (%rsi), %eax
cmpl $0x80, %eax
je 0x27225
cmpl $0x40, %eax
jne 0x2747a
movq %rdi, -0x48(%rbp)
movq 0x18(%r15), %rdi
movq %r15, -0x60(%rbp)
movslq 0x28(%r15), %rcx
movq %rcx, -0x50(%rbp)
addq %rdi, %rcx
xorl %edx, %edx
movabsq $0x800100100000200, %rax # imm = 0x800100100000200
movq %rcx, %r13
movl %edx, %r12d
cmpq %rdi, %rcx
jbe 0x271cc
leaq -0x1(%r13), %rcx
movzbl -0x1(%r13), %esi
leal 0x1(%r12), %edx
cmpq $0x3b, %rsi
ja 0x271a7
btq %rsi, %rax
jae 0x271a7
movq %rdi, -0x58(%rbp)
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rbx
movaps %xmm0, (%rbx)
movq -0x48(%rbp), %rax
leaq 0x130(%rax), %r14
xorl %r15d, %r15d
cmpl (%r14), %r15d
jge 0x27269
movq %r14, %rdi
movl %r15d, %esi
callq 0x27508
movq (%rax), %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x274a6
testl %eax, %eax
jne 0x27220
movq %r14, %rdi
movl %r15d, %esi
callq 0x27508
movq %rbx, %rdi
movq %rax, %rsi
callq 0x26d0e
incl %r15d
jmp 0x271e8
movl 0x128(%rdi), %eax
movl 0x14(%r15), %ecx
cmpl $0x4, %ecx
je 0x272cb
cmpl $0x3, %ecx
jne 0x2747a
cmpl $-0x1, %eax
je 0x27416
testl %eax, %eax
jle 0x2747a
decl %eax
movl %eax, 0x128(%rdi)
movq 0x18(%r15), %rbx
movslq 0x20(%r15), %r14
movl %eax, %esi
jmp 0x27434
movl -0x40(%rbp), %eax
testl %eax, %eax
je 0x272e8
cmpl $0x1, %eax
jne 0x2730e
movq -0x58(%rbp), %rsi
addl -0x50(%rbp), %esi
movq -0x60(%rbp), %r14
subl 0x18(%r14), %esi
subl %r12d, %esi
movq %r14, %rdi
movl %r12d, %edx
callq 0x19aa4
movl 0x28(%r14), %ebx
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x27508
movq (%rax), %rdx
movq %r14, %rdi
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x19aec
movl 0x28(%r14), %esi
leaq 0x1bd90(%rip), %rdx     # 0x4304f
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x19aec
jmp 0x27300
cmpl $-0x1, %eax
je 0x2747a
leal 0x1(%rax), %ecx
cmpl 0x118(%rdi), %ecx
pushq $-0x1
popq %rsi
cmovll %ecx, %esi
jmp 0x2741e
leaq 0x142a6(%rip), %rsi     # 0x3b595
movq -0x48(%rbp), %rdi
movl %r12d, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x26e48
leaq -0x40(%rbp), %rdi
callq 0x26d60
jmp 0x2747a
movslq %r12d, %rdx
leaq -0x40(%rbp), %r13
movq %rdx, %r15
movb $0x1, %cl
xorl %r14d, %r14d
xorl %ebx, %ebx
cmpl %eax, %ebx
jge 0x2736b
testb $0x1, %cl
je 0x2736b
movq %r13, %rdi
testl %ebx, %ebx
je 0x2734b
movl %ebx, %esi
callq 0x27508
movq (%rax), %rax
movsbl (%rax,%r15), %edi
callq 0x7150
cmpl %eax, %r14d
sete %cl
jmp 0x27364
xorl %esi, %esi
callq 0x27508
movq (%rax), %rax
movsbl (%rax,%r15), %edi
callq 0x7150
movl %eax, %r14d
movb $0x1, %cl
incl %ebx
movl -0x40(%rbp), %eax
jmp 0x2731f
leaq 0x1(%r15), %rdx
testb $0x1, %cl
jne 0x27315
testq %r15, %r15
movq -0x60(%rbp), %r13
jle 0x273c8
movq -0x58(%rbp), %rsi
addl -0x50(%rbp), %esi
subl 0x18(%r13), %esi
subl %r12d, %esi
movq %r13, %rdi
movl %r12d, %edx
callq 0x19aa4
movl 0x28(%r13), %ebx
leaq -0x40(%rbp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x27508
movq (%rax), %r12
movq %r14, %rdi
xorl %esi, %esi
callq 0x27508
movl %r15d, %ecx
addq (%rax), %rcx
movq %r13, %rdi
movl %ebx, %esi
movq %r12, %rdx
callq 0x19aec
leaq 0x141dc(%rip), %rsi     # 0x3b5ab
movq -0x48(%rbp), %rdi
xorl %eax, %eax
callq 0x26e48
leaq -0x40(%rbp), %rbx
leaq 0x141d9(%rip), %r14     # 0x3b5be
xorl %r15d, %r15d
movq -0x48(%rbp), %r12
cmpl -0x40(%rbp), %r15d
jge 0x27300
movq %rbx, %rdi
movl %r15d, %esi
callq 0x27508
movq (%rax), %rdx
movq %r12, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x26e48
incl %r15d
jmp 0x273ec
movl 0x118(%rdi), %esi
decl %esi
movl %esi, 0x128(%rdi)
cmpl %esi, %eax
je 0x2747a
movq 0x18(%r15), %rbx
movslq 0x20(%r15), %r14
testl %esi, %esi
js 0x27445
addq $0x118, %rdi            # imm = 0x118
callq 0x26d98
movq (%rax), %rcx
jmp 0x2744c
leaq 0x131dd(%rip), %rcx     # 0x3a629
leaq 0x141ca(%rip), %rdx     # 0x3b61d
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x73d0
movb $0x1, 0x24(%r15)
movq 0x18(%r15), %rdi
callq 0x7300
movl %eax, 0x30(%r15)
movl %eax, 0x2c(%r15)
movl %eax, 0x28(%r15)
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x27491
jmp 0x27491
jmp 0x27491
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x26d60
movq %rbx, %rdi
callq 0x74b0
nop