// File: 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
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movss %xmm1, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x158d60
movl %eax, -0x34(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x24(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x15a4b7
movq -0x10(%rbp), %rsi
movl -0x40(%rbp), %edx
leaq -0x30(%rbp), %rdi
callq 0x159a60
cmpl $0x0, -0x1c(%rbp)
jg 0x15a461
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x15a5cf
cmpl $0x0, -0x40(%rbp)
jne 0x15a487
movss -0x18(%rbp), %xmm1
movss -0x38(%rbp), %xmm0
addss -0x24(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x15a487
movl $0x0, -0x4(%rbp)
jmp 0x15a5cf
movss -0x18(%rbp), %xmm1
movss -0x38(%rbp), %xmm0
addss -0x20(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x15a49d
jmp 0x15a4b7
movl -0x1c(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movss -0x28(%rbp), %xmm0
addss -0x38(%rbp), %xmm0
movss %xmm0, -0x38(%rbp)
jmp 0x15a438
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
jl 0x15a4ca
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x15a5cf
movss -0x14(%rbp), %xmm1
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x15a4e4
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x15a5cf
movss -0x14(%rbp), %xmm1
movss -0x2c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x15a598
movss -0x30(%rbp), %xmm0
movss %xmm0, -0x3c(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x15a596
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0x159b20
movss %xmm0, -0x48(%rbp)
movss -0x14(%rbp), %xmm1
movss -0x3c(%rbp), %xmm0
addss -0x48(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x15a579
movss -0x14(%rbp), %xmm1
movss -0x3c(%rbp), %xmm0
movss -0x48(%rbp), %xmm2
movss 0x17a79(%rip), %xmm3    # 0x171fcc
divss %xmm3, %xmm2
addss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x15a56b
movl -0x44(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x15a5cf
movl -0x44(%rbp), %eax
addl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x15a5cf
movss -0x48(%rbp), %xmm0
addss -0x3c(%rbp), %xmm0
movss %xmm0, -0x3c(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x15a508
jmp 0x15a598
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
addl -0x1c(%rbp), %esi
subl $0x1, %esi
callq 0x159a30
movzwl %ax, %eax
movzwl 0xb87ec(%rip), %ecx     # 0x212da0
cmpl %ecx, %eax
jne 0x15a5c6
movl -0x40(%rbp), %eax
addl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x15a5cf
movl -0x40(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)