// File: /workspace/github_cpp_makefile_star2_O3/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
movl 0x4(%rdi), %eax
movl %eax, -0x2c(%rbp)
testl %eax, %eax
jle 0xa719b
movss %xmm0, -0x34(%rbp)
xorps %xmm3, %xmm3
xorl %ebx, %ebx
movq %rdi, -0x40(%rbp)
movss %xmm1, -0x44(%rbp)
movss %xmm3, -0x30(%rbp)
movslq 0x4(%rdi), %rax
movq 0x18(%rdi), %r14
movq $0x0, -0x50(%rbp)
movslq %ebx, %rcx
leaq (%r14,%rcx,2), %r13
leaq (%r14,%rax,2), %rsi
movq %r13, %rdi
leaq -0x50(%rbp), %rdx
movl $0x1, %ecx
callq 0x9cb91
movq -0x50(%rbp), %r15
movq %r15, %r12
subq %r13, %r12
shrq %r12
testl %r12d, %r12d
jle 0xa719b
movss -0x44(%rbp), %xmm1
movss -0x30(%rbp), %xmm3
ucomiss %xmm1, %xmm3
jbe 0xa70ea
testl %ebx, %ebx
je 0xa710b
movaps %xmm0, %xmm2
shufps $0x55, %xmm0, %xmm2     # xmm2 = xmm2[1,1],xmm0[1,1]
addss %xmm2, %xmm3
ucomiss %xmm1, %xmm3
ja 0xa7117
addl %r12d, %ebx
cmpl -0x2c(%rbp), %ebx
movq -0x40(%rbp), %rdi
jl 0xa7090
jmp 0xa719b
movl $0x0, -0x2c(%rbp)
jmp 0xa719b
xorps %xmm1, %xmm1
movss -0x34(%rbp), %xmm2
ucomiss %xmm2, %xmm1
ja 0xa7198
ucomiss %xmm2, %xmm0
jbe 0xa717d
subq %r14, %r15
subq %rbx, %r15
subq %rbx, %r15
shrq %r15
negl %r15d
xorps %xmm0, %xmm0
xorl %r14d, %r14d
xorl %r13d, %r13d
xorps %xmm2, %xmm2
movss %xmm2, -0x30(%rbp)
movss %xmm0, -0x2c(%rbp)
movq -0x40(%rbp), %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0xa6d04
movss -0x30(%rbp), %xmm2
movss -0x34(%rbp), %xmm1
addss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0xa71ad
incl %r13d
decl %r14d
movaps %xmm2, %xmm0
cmpl %r14d, %r15d
jne 0xa7144
addl %r12d, %ebx
movq -0x40(%rbp), %rcx
cmpl %ebx, 0x10(%rcx)
jl 0xa71ca
leal -0x1(%rbx), %eax
movq 0x18(%rcx), %rcx
cmpw $0xa, (%rcx,%rax,2)
cmovel %eax, %ebx
movl %ebx, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
mulss 0xde4f(%rip), %xmm0     # 0xb5004
movss -0x2c(%rbp), %xmm2
addss %xmm0, %xmm2
subl %r14d, %ebx
ucomiss %xmm1, %xmm2
ja 0xa7198
incl %ebx
jmp 0xa7198
leaq 0x124a7(%rip), %rdi     # 0xb9678
leaq 0x124b3(%rip), %rsi     # 0xb968b
leaq 0x2be82(%rip), %rcx     # 0xd3061
movl $0x65d, %edx            # imm = 0x65D
callq 0xc140