// File: Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: ImStb::STB_TEXTEDIT_INSERTCHARS(ImGuiInputTextState*, int, unsigned short const*, int)
static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const ImWchar* new_text, int new_text_len)
{
    const bool is_resizable = (obj->UserFlags & ImGuiInputTextFlags_CallbackResize) != 0;
    const int text_len = obj->CurLenW;
    IM_ASSERT(pos <= text_len);

    const int new_text_len_utf8 = ImTextCountUtf8BytesFromStr(new_text, new_text + new_text_len);
    if (!is_resizable && (new_text_len_utf8 + obj->CurLenA + 1 > obj->BufCapacityA))
        return false;

    // Grow internal buffer if needed
    if (new_text_len + text_len + 1 > obj->TextW.Size)
    {
        if (!is_resizable)
            return false;
        IM_ASSERT(text_len < obj->TextW.Size);
        obj->TextW.resize(text_len + ImClamp(new_text_len * 4, 32, ImMax(256, new_text_len)) + 1);
    }

    ImWchar* text = obj->TextW.Data;
    if (pos != text_len)
        memmove(text + pos + new_text_len, text + pos, (size_t)(text_len - pos) * sizeof(ImWchar));
    memcpy(text + pos, new_text, (size_t)new_text_len * sizeof(ImWchar));

    obj->Edited = true;
    obj->CurLenW += new_text_len;
    obj->CurLenA += new_text_len_utf8;
    obj->TextW[obj->CurLenW] = '\0';

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl 0xe80(%rax), %eax
andl $0x40000, %eax          # imm = 0x40000
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x25(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jg 0x158f14
jmp 0x158f33
leaq 0x376a5(%rip), %rdi     # 0x1905c0
leaq 0x354be(%rip), %rsi     # 0x18e3e0
movl $0xe00, %edx            # imm = 0xE00
leaq 0x376a2(%rip), %rcx     # 0x1905d0
callq 0xd180
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rsi
movslq -0x24(%rbp), %rax
shlq %rax
addq %rax, %rsi
callq 0xc5760
movl %eax, -0x30(%rbp)
testb $0x1, -0x25(%rbp)
jne 0x158f72
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
addl 0x8(%rcx), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jle 0x158f72
movb $0x0, -0x1(%rbp)
jmp 0x1590b7
movl -0x24(%rbp), %eax
addl -0x2c(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jle 0x15900c
testb $0x1, -0x25(%rbp)
jne 0x158f97
movb $0x0, -0x1(%rbp)
jmp 0x1590b7
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x158fa5
jmp 0x158fc4
leaq 0x3767b(%rip), %rdi     # 0x190627
leaq 0x3542d(%rip), %rsi     # 0x18e3e0
movl $0xe0b, %edx            # imm = 0xE0B
leaq 0x37611(%rip), %rcx     # 0x1905d0
callq 0xd180
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x40(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x24(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x48(%rbp)
movl -0x24(%rbp), %esi
movl $0x100, %edi            # imm = 0x100
callq 0x1437b0
movl -0x48(%rbp), %edi
movl %eax, %edx
movl $0x20, %esi
callq 0x140f50
movl -0x44(%rbp), %esi
movq -0x40(%rbp), %rdi
addl %eax, %esi
addl $0x1, %esi
callq 0xe7f00
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x2c(%rbp), %eax
je 0x159057
movq -0x38(%rbp), %rdi
movslq -0x14(%rbp), %rax
shlq %rax
addq %rax, %rdi
movslq -0x24(%rbp), %rax
shlq %rax
addq %rax, %rdi
movq -0x38(%rbp), %rsi
movslq -0x14(%rbp), %rax
shlq %rax
addq %rax, %rsi
movl -0x2c(%rbp), %eax
subl -0x14(%rbp), %eax
movslq %eax, %rdx
shlq %rdx
callq 0xd170
movq -0x38(%rbp), %rdi
movslq -0x14(%rbp), %rax
shlq %rax
addq %rax, %rdi
movq -0x20(%rbp), %rsi
movslq -0x24(%rbp), %rdx
shlq %rdx
callq 0xd0a0
movq -0x10(%rbp), %rax
movb $0x1, 0xe7e(%rax)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x1094a0
movw $0x0, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)