// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl (%rsi), %eax
cmpl $0x80, %eax
je 0x2c591
cmpl $0x40, %eax
jne 0x2c7a6
movq 0x18(%rbx), %rax
movslq 0x28(%rbx), %r15
addq %rax, %r15
movabsq $0x800100100000200, %rcx # imm = 0x800100100000200
movq %r15, -0x48(%rbp)
cmpq %rax, %r15
jbe 0x2c433
movzbl -0x1(%r15), %edx
cmpq $0x3b, %rdx
ja 0x2c42c
btq %rdx, %rcx
jae 0x2c42c
xorl %edx, %edx
testb %dl, %dl
jne 0x2c40e
jmp 0x2c433
decq %r15
movb $0x1, %dl
jmp 0x2c426
movq %rbx, -0x50(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
cmpl $0x0, 0x130(%r14)
movq %r15, -0x60(%rbp)
movq %r14, -0x68(%rbp)
jle 0x2c52b
movq -0x48(%rbp), %rax
movl %eax, %r13d
subl %r15d, %r13d
xorl %ebx, %ebx
movq 0x138(%r14), %rax
movq (%rax,%rbx,8), %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x2c808
testl %eax, %eax
jne 0x2c518
movslq 0x130(%r14), %rax
cmpq %rax, %rbx
jge 0x2c7b7
movq 0x138(%r14), %r14
movl -0x40(%rbp), %r12d
movl -0x3c(%rbp), %eax
cmpl %eax, %r12d
jne 0x2c4fa
testl %eax, %eax
je 0x2c4b2
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
addl %eax, %ecx
jmp 0x2c4b7
movl $0x8, %ecx
incl %r12d
cmpl %r12d, %ecx
cmovgl %ecx, %r12d
cmpl %r12d, %eax
jge 0x2c4fa
movslq %r12d, %rdi
shlq $0x3, %rdi
callq 0x85d9
movq %rax, %r15
movq -0x38(%rbp), %rsi
movslq -0x40(%rbp), %rdx
shlq $0x3, %rdx
movq %rax, %rdi
callq 0x7080
movq -0x38(%rbp), %rdi
callq 0x9065
movq %r15, -0x38(%rbp)
movl %r12d, -0x3c(%rbp)
movq (%r14,%rbx,8), %rax
movq -0x38(%rbp), %rcx
movslq -0x40(%rbp), %rdx
leal 0x1(%rdx), %esi
movl %esi, -0x40(%rbp)
movq %rax, (%rcx,%rdx,8)
movq -0x68(%rbp), %r14
movq -0x60(%rbp), %r15
incq %rbx
movslq 0x130(%r14), %rax
cmpq %rax, %rbx
jl 0x2c460
movslq -0x40(%rbp), %rcx
testq %rcx, %rcx
je 0x2c5e9
cmpl $0x1, %ecx
jne 0x2c609
movl %r15d, %esi
movq -0x50(%rbp), %rbx
subl 0x18(%rbx), %esi
movq -0x48(%rbp), %rdx
subl %r15d, %edx
movq %rbx, %rdi
callq 0x1f094
cmpl $0x0, -0x40(%rbp)
jle 0x2c7b7
movl 0x28(%rbx), %esi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x1f0e4
movl 0x28(%rbx), %esi
leaq 0x1d895(%rip), %rdx     # 0x49e17
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x1f0e4
jmp 0x2c733
movl 0x128(%r14), %eax
movl 0x14(%rbx), %ecx
cmpl $0x4, %ecx
je 0x2c5c2
cmpl $0x3, %ecx
jne 0x2c74e
cmpl $-0x1, %eax
je 0x2c73e
testl %eax, %eax
jle 0x2c74e
leal -0x1(%rax), %ecx
jmp 0x2c747
cmpl $-0x1, %eax
je 0x2c74e
leal 0x1(%rax), %edx
movl %edx, 0x128(%r14)
cmpl 0x118(%r14), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovll %edx, %ecx
jmp 0x2c747
movq -0x48(%rbp), %rdx
subl %r15d, %edx
leaq 0x15e31(%rip), %rsi     # 0x42428
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2bfa2
jmp 0x2c733
movq -0x48(%rbp), %rax
subl %r15d, %eax
movq -0x38(%rbp), %rdx
movq %rdx, -0x70(%rbp)
movq %rax, -0x48(%rbp)
movl %eax, %r13d
movq -0x50(%rbp), %rbx
testl %ecx, %ecx
jle 0x2c69e
movl %r13d, -0x54(%rbp)
movslq %r13d, %r15
xorl %r13d, %r13d
movb $0x1, %r12b
movl $0x1, %ebx
movq %rcx, %r14
cmpq $0x1, %rbx
jne 0x2c658
movq -0x70(%rbp), %rax
movq (%rax), %rax
movsbl (%rax,%r15), %edi
callq 0x7150
movl %eax, %r13d
jmp 0x2c67b
movq -0x70(%rbp), %rax
movq -0x8(%rax,%rbx,8), %rax
movsbl (%rax,%r15), %edi
callq 0x7150
cmpl %eax, %r13d
movzbl %r12b, %r12d
movl $0x0, %eax
cmovnel %eax, %r12d
movq %r14, %rcx
cmpq %r14, %rbx
jge 0x2c68c
incq %rbx
testb $0x1, %r12b
jne 0x2c639
movl %r12d, %eax
andb $0x1, %al
movzbl %al, %eax
movq -0x50(%rbp), %rbx
movl -0x54(%rbp), %r13d
jmp 0x2c6a6
movb $0x1, %r12b
movl $0x1, %eax
addl %eax, %r13d
testb $0x1, %r12b
jne 0x2c623
testl %r13d, %r13d
movq -0x68(%rbp), %r15
jle 0x2c6f1
movq -0x60(%rbp), %rsi
subl 0x18(%rbx), %esi
movq %rbx, %rdi
movq -0x48(%rbp), %rdx
callq 0x1f094
cmpl $0x0, -0x40(%rbp)
jle 0x2c7b7
movl 0x28(%rbx), %esi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
movl %r13d, %ecx
addq %rdx, %rcx
movq %rbx, %rdi
callq 0x1f0e4
leaq 0x15d46(%rip), %rsi     # 0x4243e
movq %r15, %rdi
xorl %eax, %eax
callq 0x2bfa2
cmpl $0x0, -0x40(%rbp)
jle 0x2c733
leaq 0x15d42(%rip), %rbx     # 0x42451
xorl %r14d, %r14d
movq -0x38(%rbp), %rax
movq (%rax,%r14,8), %rdx
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2bfa2
incq %r14
movslq -0x40(%rbp), %rax
cmpq %rax, %r14
jl 0x2c712
leaq -0x40(%rbp), %rdi
callq 0x2bf6a
jmp 0x2c7a6
movl 0x118(%r14), %ecx
decl %ecx
movl %ecx, 0x128(%r14)
movl 0x128(%r14), %ecx
cmpl %ecx, %eax
je 0x2c7a6
movq 0x18(%rbx), %rdi
movslq 0x20(%rbx), %rsi
testl %ecx, %ecx
js 0x2c77b
cmpl %ecx, 0x118(%r14)
jle 0x2c7d6
movq 0x120(%r14), %rax
movq (%rax,%rcx,8), %rcx
jmp 0x2c782
leaq 0x14d37(%rip), %rcx     # 0x414b9
leaq 0x15d27(%rip), %rdx     # 0x424b0
xorl %eax, %eax
callq 0x73e0
movb $0x1, 0x24(%rbx)
movq 0x18(%rbx), %rdi
callq 0x72f0
movl %eax, 0x30(%rbx)
movl %eax, 0x2c(%rbx)
movl %eax, 0x28(%rbx)
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x125f2(%rip), %rdi     # 0x3edb0
leaq 0x122ce(%rip), %rsi     # 0x3ea93
leaq 0x15c8b(%rip), %rcx     # 0x42457
movl $0x31c, %edx            # imm = 0x31C
callq 0x7140
leaq 0x125d3(%rip), %rdi     # 0x3edb0
leaq 0x122af(%rip), %rsi     # 0x3ea93
leaq 0x15a51(%rip), %rcx     # 0x4223c
jmp 0x2c7cc
jmp 0x2c7f3
jmp 0x2c7f3
jmp 0x2c7f3
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x2bf6a
movq %rbx, %rdi
callq 0x74d0
nop