// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imstb_textedit.h
// Function: ImStb::stb_text_locate_coord(ImGuiInputTextState*, float, float)
static int stb_text_locate_coord(STB_TEXTEDIT_STRING *str, float x, float y)
{
   StbTexteditRow r;
   int n = STB_TEXTEDIT_STRINGLEN(str);
   float base_y = 0, prev_x;
   int i=0, k;

   r.x0 = r.x1 = 0;
   r.ymin = r.ymax = 0;
   r.num_chars = 0;

   // search rows to find one that straddles 'y'
   while (i < n) {
      STB_TEXTEDIT_LAYOUTROW(&r, str, i);
      if (r.num_chars <= 0)
         return n;

      if (i==0 && y < base_y + r.ymin)
         return 0;

      if (y < base_y + r.ymax)
         break;

      i += r.num_chars;
      base_y += r.baseline_y_delta;
   }

   // below all text, return 'after' last character
   if (i >= n)
      return n;

   // check if it's before the beginning of the line
   if (x < r.x0)
      return i;

   // check if it's before the end of the line
   if (x < r.x1) {
      // search characters in row for one that straddles 'x'
      prev_x = r.x0;
      for (k=0; k < r.num_chars; ++k) {
         float w = STB_TEXTEDIT_GETWIDTH(str, i, k);
         if (x < prev_x+w) {
            if (x < prev_x+w/2)
               return k+i;
            else
               return k+i+1;
         }
         prev_x += w;
      }
      // shouldn't happen, but if it does, fall through to end-of-line case
   }

   // if the last character is a newline, return that. otherwise return 'after' the last character
   if (STB_TEXTEDIT_GETCHAR(str, i+r.num_chars-1) == STB_TEXTEDIT_NEWLINE)
      return i+r.num_chars-1;
   else
      return i+r.num_chars;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movaps %xmm0, %xmm3
movq %rdi, %rbx
movl 0x4(%rdi), %eax
movl %eax, -0x2c(%rbp)
testl %eax, %eax
setg %r12b
jle 0xa8c16
movss %xmm3, -0x30(%rbp)
xorps %xmm3, %xmm3
xorl %r14d, %r14d
movss %xmm1, -0x38(%rbp)
movss %xmm3, -0x34(%rbp)
movq 0x18(%rbx), %rax
movq $0x0, -0x40(%rbp)
movslq %r14d, %rcx
leaq (%rax,%rcx,2), %r13
movslq 0x4(%rbx), %rcx
leaq (%rax,%rcx,2), %rsi
movq %r13, %rdi
leaq -0x40(%rbp), %rdx
movl $0x1, %ecx
callq 0x9e5cc
movq -0x40(%rbp), %r15
subq %r13, %r15
shrq %r15
testl %r15d, %r15d
jle 0xa8cd6
movss -0x38(%rbp), %xmm1
movss -0x34(%rbp), %xmm3
ucomiss %xmm1, %xmm3
jbe 0xa8bf2
testl %r14d, %r14d
je 0xa8ccf
movaps %xmm0, %xmm2
shufps $0x55, %xmm0, %xmm2     # xmm2 = xmm2[1,1],xmm0[1,1]
addss %xmm2, %xmm3
ucomiss %xmm1, %xmm3
ja 0xa8c0f
addl %r15d, %r14d
cmpl -0x2c(%rbp), %r14d
setl %r12b
jl 0xa8b96
movss -0x30(%rbp), %xmm3
jmp 0xa8c1f
xorl %r14d, %r14d
xorps %xmm0, %xmm0
xorl %r15d, %r15d
testb $0x1, %r12b
je 0xa8cd6
xorps %xmm1, %xmm1
ucomiss %xmm3, %xmm1
jbe 0xa8c3a
movl %r14d, -0x2c(%rbp)
jmp 0xa8cd6
ucomiss %xmm3, %xmm0
jbe 0xa8cad
testl %r15d, %r15d
jle 0xa8cad
leal 0x1(%r14), %r13d
xorps %xmm2, %xmm2
xorl %r12d, %r12d
movss %xmm3, -0x30(%rbp)
movss %xmm2, -0x34(%rbp)
movq %rbx, %rdi
movl %r14d, %esi
movl %r12d, %edx
callq 0xa87ff
movss -0x34(%rbp), %xmm4
movss -0x30(%rbp), %xmm3
movaps %xmm4, %xmm1
addss %xmm0, %xmm1
ucomiss %xmm3, %xmm1
movaps %xmm1, %xmm2
jbe 0xa8ca0
mulss 0xe37d(%rip), %xmm0     # 0xb7004
addss %xmm4, %xmm0
ucomiss %xmm3, %xmm0
jbe 0xa8c96
leal (%r14,%r12), %eax
jmp 0xa8c9a
leal (%r12,%r13), %eax
movl %eax, -0x2c(%rbp)
movaps %xmm4, %xmm2
ucomiss %xmm3, %xmm1
ja 0xa8cd6
incl %r12d
cmpl %r12d, %r15d
jne 0xa8c53
addl %r14d, %r15d
jle 0xa8ce8
cmpl %r15d, 0x10(%rbx)
jl 0xa8ce8
leal -0x1(%r15), %eax
movq 0x18(%rbx), %rcx
cmpw $0xa, (%rcx,%rax,2)
cmovel %eax, %r15d
movl %r15d, -0x2c(%rbp)
jmp 0xa8cd6
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12989(%rip), %rdi     # 0xbb678
leaq 0x12995(%rip), %rsi     # 0xbb68b
leaq 0x2c4b7(%rip), %rcx     # 0xd51b4
movl $0x65d, %edx            # imm = 0x65D
callq 0xc140