// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r15
movl (%rsi), %eax
cmpl $0x80, %eax
je 0x2c184
cmpl $0x40, %eax
jne 0x2c361
movq 0x18(%rbx), %rdi
movq %rbx, -0x60(%rbp)
movslq 0x28(%rbx), %rcx
movq %rcx, -0x50(%rbp)
addq %rdi, %rcx
xorl %edx, %edx
movabsq $0x800100100000200, %rax # imm = 0x800100100000200
movq %rcx, %r13
movl %edx, %ebx
cmpq %rdi, %rcx
jbe 0x2c018
leaq -0x1(%r13), %rcx
movzbl -0x1(%r13), %esi
leal 0x1(%rbx), %edx
cmpq $0x3b, %rsi
ja 0x2bff6
btq %rsi, %rax
jae 0x2bff6
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
cmpl $0x0, 0x130(%r15)
jle 0x2c1c5
movq %rdi, -0x58(%rbp)
xorl %r14d, %r14d
movq $0x0, -0x48(%rbp)
xorl %r12d, %r12d
movq %r15, -0x68(%rbp)
movq %rbx, -0x70(%rbp)
movq 0x138(%r15), %rax
movq (%rax,%r12,8), %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x2c3c2
testl %eax, %eax
jne 0x2c10d
movslq 0x130(%r15), %rax
cmpq %rax, %r12
jge 0x2c372
movq 0x138(%r15), %rax
movq -0x48(%rbp), %rdx
cmpl %r14d, %edx
jne 0x2c09d
testl %r14d, %r14d
movq %rax, -0x78(%rbp)
je 0x2c0a3
movl %r14d, %eax
shrl $0x1f, %eax
addl %r14d, %eax
sarl %eax
addl %r14d, %eax
jmp 0x2c0a8
movq -0x38(%rbp), %rbx
jmp 0x2c0f3
movl $0x8, %eax
incl %r14d
cmpl %r14d, %eax
cmovgl %eax, %r14d
movslq %r14d, %rdi
shlq $0x3, %rdi
callq 0x8589
movq %rax, %rbx
movq -0x38(%rbp), %r15
movslq -0x40(%rbp), %rdx
shlq $0x3, %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x7080
movq %r15, %rdi
callq 0x9019
movq %rbx, -0x38(%rbp)
movl %r14d, -0x3c(%rbp)
movl -0x40(%rbp), %edx
movq -0x68(%rbp), %r15
movq -0x78(%rbp), %rax
movq (%rax,%r12,8), %rax
movslq %edx, %rcx
incl %edx
movl %edx, -0x40(%rbp)
movq %rax, (%rbx,%rcx,8)
movl %edx, %eax
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rbx
incq %r12
movslq 0x130(%r15), %rax
cmpq %rax, %r12
jl 0x2c047
movq -0x48(%rbp), %rax
testl %eax, %eax
movq -0x58(%rbp), %rsi
je 0x2c1c5
cmpl $0x1, %eax
jne 0x2c209
addl -0x50(%rbp), %esi
movq %rbx, %rdx
movq -0x60(%rbp), %rbx
subl 0x18(%rbx), %esi
subl %edx, %esi
movq %rbx, %rdi
callq 0x1eda4
cmpl $0x0, -0x40(%rbp)
jle 0x2c372
movl 0x28(%rbx), %esi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x1edfe
movl 0x28(%rbx), %esi
leaq 0x1dc47(%rip), %rdx     # 0x49dbf
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x1edfe
jmp 0x2c1db
movl 0x128(%r15), %eax
movl 0x14(%rbx), %ecx
cmpl $0x4, %ecx
je 0x2c1e9
cmpl $0x3, %ecx
jne 0x2c361
cmpl $-0x1, %eax
je 0x2c2fe
testl %eax, %eax
jle 0x2c361
decl %eax
movl %eax, 0x128(%r15)
movq 0x18(%rbx), %rdi
movslq 0x20(%rbx), %rsi
movl %eax, %ecx
jmp 0x2c31e
leaq 0x161d9(%rip), %rsi     # 0x423a5
movq %r15, %rdi
movl %ebx, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2bb82
leaq -0x40(%rbp), %rdi
callq 0x2bb4a
jmp 0x2c361
cmpl $-0x1, %eax
je 0x2c361
leal 0x1(%rax), %edx
cmpl 0x118(%r15), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovll %edx, %ecx
jmp 0x2c307
movq -0x38(%rbp), %r12
movslq %eax, %r13
movslq %ebx, %rcx
movq %rcx, %r14
testl %eax, %eax
jle 0x2c25e
xorl %ebx, %ebx
movl $0x1, %r15d
cmpq $0x1, %r15
jne 0x2c23c
movq (%r12), %rax
movsbl (%rax,%r14), %edi
callq 0x7150
movl %eax, %ebx
movb $0x1, %al
jmp 0x2c250
movq -0x8(%r12,%r15,8), %rax
movsbl (%rax,%r14), %edi
callq 0x7150
cmpl %eax, %ebx
sete %al
cmpq %r13, %r15
jge 0x2c260
incq %r15
testb %al, %al
jne 0x2c222
jmp 0x2c260
movb $0x1, %al
leaq 0x1(%r14), %rcx
testb %al, %al
movq -0x48(%rbp), %rax
jne 0x2c213
testq %r14, %r14
movq -0x60(%rbp), %rbx
movq -0x68(%rbp), %r15
jle 0x2c2b3
movq -0x58(%rbp), %rsi
addl -0x50(%rbp), %esi
subl 0x18(%rbx), %esi
movq -0x70(%rbp), %rdx
subl %edx, %esi
movq %rbx, %rdi
callq 0x1eda4
cmpl $0x0, -0x40(%rbp)
jle 0x2c372
movl 0x28(%rbx), %esi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movl %r14d, %ecx
addq %rdx, %rcx
movq %rbx, %rdi
callq 0x1edfe
leaq 0x16101(%rip), %rsi     # 0x423bb
movq %r15, %rdi
xorl %eax, %eax
callq 0x2bb82
cmpl $0x0, -0x40(%rbp)
jle 0x2c1db
leaq 0x160f9(%rip), %rbx     # 0x423ce
xorl %r14d, %r14d
movq -0x38(%rbp), %rax
movq (%rax,%r14,8), %rdx
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2bb82
incq %r14
movslq -0x40(%rbp), %rax
cmpq %rax, %r14
jl 0x2c2d8
jmp 0x2c1db
movl 0x118(%r15), %ecx
decl %ecx
movl %ecx, 0x128(%r15)
cmpl %ecx, %eax
je 0x2c361
movq 0x18(%rbx), %rdi
movslq 0x20(%rbx), %rsi
testl %ecx, %ecx
js 0x2c336
cmpl %ecx, 0x118(%r15)
jle 0x2c391
movq 0x120(%r15), %rax
movl %ecx, %ecx
movq (%rax,%rcx,8), %rcx
jmp 0x2c33d
leaq 0x150fc(%rip), %rcx     # 0x41439
leaq 0x160e9(%rip), %rdx     # 0x4242d
xorl %eax, %eax
callq 0x73d0
movb $0x1, 0x24(%rbx)
movq 0x18(%rbx), %rdi
callq 0x72e0
movl %eax, 0x30(%rbx)
movl %eax, 0x2c(%rbx)
movl %eax, 0x28(%rbx)
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12a67(%rip), %rdi     # 0x3ede0
leaq 0x12743(%rip), %rsi     # 0x3eac3
leaq 0x1604d(%rip), %rcx     # 0x423d4
movl $0x31c, %edx            # imm = 0x31C
callq 0x7140
leaq 0x12a48(%rip), %rdi     # 0x3ede0
leaq 0x12724(%rip), %rsi     # 0x3eac3
leaq 0x15e16(%rip), %rcx     # 0x421bc
jmp 0x2c387
jmp 0x2c3ae
jmp 0x2c3ae
jmp 0x2c3ae
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x2bb4a
movq %rbx, %rdi
callq 0x74c0