// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rdi, %r14
movl 0x4(%rdi), %r15d
leaq -0x4c(%rbp), %r12
andq $0x0, (%r12)
andq $0x0, 0xc(%r12)
andl $0x0, 0x14(%r12)
movss %xmm1, -0x2c(%rbp)
xorl %ebx, %ebx
xorps %xmm2, %xmm2
movss %xmm0, -0x34(%rbp)
cmpl %r15d, %ebx
jge 0x8e6f8
movss %xmm2, -0x30(%rbp)
movq %r12, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x8e293
movl -0x38(%rbp), %r13d
testl %r13d, %r13d
jle 0x8e6f8
testl %ebx, %ebx
movss -0x34(%rbp), %xmm0
movss -0x30(%rbp), %xmm2
jne 0x8e65d
movss -0x40(%rbp), %xmm1
addss %xmm2, %xmm1
ucomiss -0x2c(%rbp), %xmm1
ja 0x8e6d8
movss -0x3c(%rbp), %xmm1
addss %xmm2, %xmm1
ucomiss -0x2c(%rbp), %xmm1
ja 0x8e676
addl %r13d, %ebx
addss -0x44(%rbp), %xmm2
jmp 0x8e618
movss -0x4c(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x8e685
movl %ebx, %r15d
jmp 0x8e6f8
movss %xmm1, -0x30(%rbp)
movss -0x48(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x8e6dd
movl %r13d, %eax
negl %eax
movl %eax, -0x2c(%rbp)
xorl %r12d, %r12d
xorl %r15d, %r15d
cmpl %r12d, -0x2c(%rbp)
je 0x8e6dd
movq %r14, %rdi
movl %ebx, %esi
movl %r15d, %edx
callq 0x8e2fa
movss -0x30(%rbp), %xmm3
movaps %xmm3, %xmm1
addss %xmm0, %xmm1
movss -0x34(%rbp), %xmm2
ucomiss %xmm2, %xmm1
ja 0x8e70a
incl %r15d
decl %r12d
movss %xmm1, -0x30(%rbp)
jmp 0x8e6a2
xorl %r15d, %r15d
jmp 0x8e6f8
leal (%rbx,%r13), %r15d
addl %r13d, %ebx
decl %ebx
movq %r14, %rdi
movl %ebx, %esi
callq 0x8e281
cmpw $0xa, %ax
cmovel %ebx, %r15d
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
mulss 0xd906(%rip), %xmm0     # 0x9c018
addss %xmm0, %xmm3
subl %r12d, %ebx
ucomiss %xmm2, %xmm3
ja 0x8e680
incl %ebx
jmp 0x8e680