// File: Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImGuiInputTextCallbackData::InsertChars(int, char const*, char const*)
void ImGuiInputTextCallbackData::InsertChars(int pos, const char* new_text, const char* new_text_end)
{
    const bool is_resizable = (Flags & ImGuiInputTextFlags_CallbackResize) != 0;
    const int new_text_len = new_text_end ? (int)(new_text_end - new_text) : (int)strlen(new_text);
    if (new_text_len + BufTextLen >= BufSize)
    {
        if (!is_resizable)
            return;

        // Contrary to STB_TEXTEDIT_INSERTCHARS() this is working in the UTF8 buffer, hence the mildly similar code (until we remove the U16 buffer altogether!)
        ImGuiContext& g = *GImGui;
        ImGuiInputTextState* edit_state = &g.InputTextState;
        IM_ASSERT(edit_state->ID != 0 && g.ActiveId == edit_state->ID);
        IM_ASSERT(Buf == edit_state->TextA.Data);
        int new_buf_size = BufTextLen + ImClamp(new_text_len * 4, 32, ImMax(256, new_text_len)) + 1;
        edit_state->TextA.reserve(new_buf_size + 1);
        Buf = edit_state->TextA.Data;
        BufSize = edit_state->BufCapacityA = new_buf_size;
    }

    if (BufTextLen != pos)
        memmove(Buf + pos + new_text_len, Buf + pos, (size_t)(BufTextLen - pos));
    memcpy(Buf + pos, new_text, (size_t)new_text_len * sizeof(char));
    Buf[BufTextLen + new_text_len] = '\0';

    if (CursorPos >= pos)
        CursorPos += new_text_len;
    SelectionStart = SelectionEnd = CursorPos;
    BufDirty = true;
    BufTextLen += new_text_len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl 0x4(%rax), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x21(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x14b529
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x4c(%rbp)
jmp 0x14b535
movq -0x18(%rbp), %rdi
callq 0xd410
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rcx
movl -0x4c(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
addl 0x20(%rcx), %eax
cmpl 0x24(%rcx), %eax
jl 0x14b662
testb $0x1, -0x21(%rbp)
jne 0x14b559
jmp 0x14b701
leaq 0xc79e0(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x2160, %rax           # imm = 0x2160
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, (%rcx)
movb %al, -0x4d(%rbp)
je 0x14b599
movq -0x30(%rbp), %rax
movl 0x1b30(%rax), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
sete %al
movb %al, -0x4d(%rbp)
movb -0x4d(%rbp), %al
testb $0x1, %al
jne 0x14b5a2
jmp 0x14b5a4
jmp 0x14b5c3
leaq 0x43fb1(%rip), %rdi     # 0x18f55c
leaq 0x42e2e(%rip), %rsi     # 0x18e3e0
movl $0xe72, %edx            # imm = 0xE72
leaq 0x43fd2(%rip), %rcx     # 0x18f590
callq 0xd180
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jne 0x14b5d7
jmp 0x14b5f6
leaq 0x44000(%rip), %rdi     # 0x18f5de
leaq 0x42dfb(%rip), %rsi     # 0x18e3e0
movl $0xe73, %edx            # imm = 0xE73
leaq 0x43f9f(%rip), %rcx     # 0x18f590
callq 0xd180
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x58(%rbp)
movl -0x28(%rbp), %esi
movl $0x100, %edi            # imm = 0x100
callq 0x1437b0
movl -0x58(%rbp), %edi
movl %eax, %edx
movl $0x20, %esi
callq 0x140f50
movl %eax, %ecx
movl -0x54(%rbp), %eax
addl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rdi
addq $0x20, %rdi
movl -0x3c(%rbp), %esi
addl $0x1, %esi
callq 0xe8470
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq %rcx, 0x18(%rax)
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rdx
movl %ecx, 0x44(%rdx)
movl %ecx, 0x24(%rax)
movq -0x48(%rbp), %rax
movl 0x20(%rax), %eax
cmpl -0xc(%rbp), %eax
je 0x14b69d
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdi
movslq -0xc(%rbp), %rcx
addq %rcx, %rdi
movslq -0x28(%rbp), %rcx
addq %rcx, %rdi
movq 0x18(%rax), %rsi
movslq -0xc(%rbp), %rcx
addq %rcx, %rsi
movl 0x20(%rax), %eax
subl -0xc(%rbp), %eax
movslq %eax, %rdx
callq 0xd170
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdi
movslq -0xc(%rbp), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x28(%rbp), %rdx
shlq $0x0, %rdx
callq 0xd0a0
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rcx
movl 0x20(%rax), %edx
addl -0x28(%rbp), %edx
movslq %edx, %rdx
movb $0x0, (%rcx,%rdx)
movl 0x2c(%rax), %eax
cmpl -0xc(%rbp), %eax
jl 0x14b6e7
movq -0x48(%rbp), %rax
movl -0x28(%rbp), %ecx
addl 0x2c(%rax), %ecx
movl %ecx, 0x2c(%rax)
movq -0x48(%rbp), %rax
movl 0x2c(%rax), %ecx
movl %ecx, 0x34(%rax)
movl %ecx, 0x30(%rax)
movb $0x1, 0x28(%rax)
movl -0x28(%rbp), %ecx
addl 0x20(%rax), %ecx
movl %ecx, 0x20(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)