// File: /workspace/github_cpp_makefile_star2_O2/Ciaxur[P]yagb-emu/include/imgui/imstb_textedit.h
// Function: ImStb::stb_textedit_find_charpos(ImStb::StbFindState*, ImGuiInputTextState*, int, int)
static void stb_textedit_find_charpos(StbFindState *find, STB_TEXTEDIT_STRING *str, int n, int single_line)
{
   StbTexteditRow r;
   int prev_start = 0;
   int z = STB_TEXTEDIT_STRINGLEN(str);
   int i=0, first;

   if (n == z) {
      // if it's at the end, then find the last line -- simpler than trying to
      // explicitly handle this case in the regular code
      if (single_line) {
         STB_TEXTEDIT_LAYOUTROW(&r, str, 0);
         find->y = 0;
         find->first_char = 0;
         find->length = z;
         find->height = r.ymax - r.ymin;
         find->x = r.x1;
      } else {
         find->y = 0;
         find->x = 0;
         find->height = 1;
         while (i < z) {
            STB_TEXTEDIT_LAYOUTROW(&r, str, i);
            prev_start = i;
            i += r.num_chars;
         }
         find->first_char = i;
         find->length = 0;
         find->prev_first = prev_start;
      }
      return;
   }

   // search rows to find the one that straddles character n
   find->y = 0;

   for(;;) {
      STB_TEXTEDIT_LAYOUTROW(&r, str, i);
      if (n < i + r.num_chars)
         break;
      prev_start = i;
      i += r.num_chars;
      find->y += r.baseline_y_delta;
   }

   find->first_char = first = i;
   find->length = r.num_chars;
   find->height = r.ymax - r.ymin;
   find->prev_first = prev_start;

   // now scan to find xpos
   find->x = r.x0;
   for (i=0; first+i < n; ++i)
      find->x += STB_TEXTEDIT_GETWIDTH(str, first, i);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
cmpl %edx, 0x4(%rsi)
jne 0x8e1b0
testl %ecx, %ecx
je 0x8e233
leaq -0x40(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x8e293
andl $0x0, 0x4(%rbx)
andl $0x0, 0xc(%rbx)
movl %r14d, 0x10(%rbx)
movss 0x10(%r12), %xmm0
subss 0xc(%r12), %xmm0
movss %xmm0, 0x8(%rbx)
movss 0x4(%r12), %xmm0
movss %xmm0, (%rbx)
jmp 0x8e272
xorl %eax, %eax
xorps %xmm0, %xmm0
xorl %r13d, %r13d
movl %eax, %r12d
movss %xmm0, 0x4(%rbx)
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x8e293
movl -0x2c(%rbp), %ecx
leal (%rcx,%r12), %eax
cmpl %r14d, %eax
jg 0x8e1e9
movss -0x38(%rbp), %xmm0
addss 0x4(%rbx), %xmm0
movl %r12d, %r13d
jmp 0x8e1b8
movl %r12d, 0xc(%rbx)
movl %ecx, 0x10(%rbx)
movss -0x30(%rbp), %xmm0
subss -0x34(%rbp), %xmm0
movss %xmm0, 0x8(%rbx)
movl %r13d, 0x14(%rbx)
movss -0x40(%rbp), %xmm0
movss %xmm0, (%rbx)
xorl %r13d, %r13d
leal (%r12,%r13), %eax
cmpl %r14d, %eax
jge 0x8e272
movq %r15, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0x8e2fa
addss (%rbx), %xmm0
movss %xmm0, (%rbx)
incl %r13d
jmp 0x8e20f
andq $0x0, (%rbx)
movl $0x3f800000, 0x8(%rbx)  # imm = 0x3F800000
xorl %eax, %eax
leaq -0x40(%rbp), %r12
xorl %ecx, %ecx
movl %eax, %r13d
cmpl %r14d, %eax
jge 0x8e267
movq %r12, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x8e293
movl -0x2c(%rbp), %eax
addl %r13d, %eax
movl %r13d, %ecx
jmp 0x8e246
movl %r13d, 0xc(%rbx)
andl $0x0, 0x10(%rbx)
movl %ecx, 0x14(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq