// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rsi, %r14
movq %rdi, %rbx
movl 0x4(%rsi), %r12d
cmpl %edx, %r12d
jne 0xa86d7
testl %ecx, %ecx
je 0xa877d
movslq %r12d, %rax
movq 0x18(%r14), %rdi
leaq -0x38(%rbp), %rdx
movq $0x0, (%rdx)
leaq (%rdi,%rax,2), %rsi
movl $0x1, %ecx
callq 0x9e5cc
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
xorl %eax, %eax
movl %eax, 0x4(%rbx)
movl %eax, 0xc(%rbx)
movl %r12d, 0x10(%rbx)
movss %xmm1, 0x8(%rbx)
movss %xmm0, (%rbx)
jmp 0xa87f0
movl %edx, -0x2c(%rbp)
xorl %eax, %eax
xorps %xmm0, %xmm0
xorl %r15d, %r15d
movl %eax, %r12d
movss %xmm0, 0x4(%rbx)
movq 0x18(%r14), %rax
movq $0x0, -0x38(%rbp)
movslq %r12d, %rcx
leaq (%rax,%rcx,2), %r13
movslq 0x4(%r14), %rcx
leaq (%rax,%rcx,2), %rsi
movq %r13, %rdi
leaq -0x38(%rbp), %rdx
movl $0x1, %ecx
callq 0x9e5cc
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movq -0x38(%rbp), %rcx
subq %r13, %rcx
shrq %rcx
leal (%r12,%rcx), %eax
cmpl -0x2c(%rbp), %eax
jg 0xa8737
addss 0x4(%rbx), %xmm0
movl %r12d, %r15d
jmp 0xa86e2
movl %r12d, 0xc(%rbx)
movl %ecx, 0x10(%rbx)
movss %xmm0, 0x8(%rbx)
movl %r15d, 0x14(%rbx)
movl $0x0, (%rbx)
movl -0x2c(%rbp), %r15d
subl %r12d, %r15d
jle 0xa87f0
xorl %r13d, %r13d
movq %r14, %rdi
movl %r12d, %esi
movl %r13d, %edx
callq 0xa87ff
addss (%rbx), %xmm0
movss %xmm0, (%rbx)
incl %r13d
cmpl %r13d, %r15d
jne 0xa875d
jmp 0xa87f0
movq $0x0, (%rbx)
movl $0x3f800000, 0x8(%rbx)  # imm = 0x3F800000
xorl %r15d, %r15d
testl %r12d, %r12d
jle 0xa87de
movl %r12d, -0x2c(%rbp)
movl %r15d, %r13d
movq 0x18(%r14), %rax
movq $0x0, -0x38(%rbp)
movslq %r15d, %r15
leaq (%rax,%r15,2), %r12
movslq 0x4(%r14), %rcx
leaq (%rax,%rcx,2), %rsi
movq %r12, %rdi
leaq -0x38(%rbp), %rdx
movl $0x1, %ecx
callq 0x9e5cc
movq -0x38(%rbp), %rax
subq %r12, %rax
movl -0x2c(%rbp), %r12d
shrq %rax
addl %eax, %r15d
cmpl %r12d, %r15d
jl 0xa8797
jmp 0xa87e1
xorl %r13d, %r13d
movl %r15d, 0xc(%rbx)
movl $0x0, 0x10(%rbx)
movl %r13d, 0x14(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq