// File: Ciaxur[P]yagb-emu/include/imgui/imstb_truetype.h
// Function: stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context*, stbtt_fontinfo const*, stbtt_pack_range*, int, stbrp_rect*)
STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects)
{
   int i,j,k, return_value = 1;

   // save current values
   int old_h_over = spc->h_oversample;
   int old_v_over = spc->v_oversample;

   k = 0;
   for (i=0; i < num_ranges; ++i) {
      float fh = ranges[i].font_size;
      float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh);
      float recip_h,recip_v,sub_x,sub_y;
      spc->h_oversample = ranges[i].h_oversample;
      spc->v_oversample = ranges[i].v_oversample;
      recip_h = 1.0f / spc->h_oversample;
      recip_v = 1.0f / spc->v_oversample;
      sub_x = stbtt__oversample_shift(spc->h_oversample);
      sub_y = stbtt__oversample_shift(spc->v_oversample);
      for (j=0; j < ranges[i].num_chars; ++j) {
         stbrp_rect *r = &rects[k];
         if (r->was_packed && r->w != 0 && r->h != 0) {
            stbtt_packedchar *bc = &ranges[i].chardata_for_range[j];
            int advance, lsb, x0,y0,x1,y1;
            int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j];
            int glyph = stbtt_FindGlyphIndex(info, codepoint);
            stbrp_coord pad = (stbrp_coord) spc->padding;

            // pad on left and top
            r->x += pad;
            r->y += pad;
            r->w -= pad;
            r->h -= pad;
            stbtt_GetGlyphHMetrics(info, glyph, &advance, &lsb);
            stbtt_GetGlyphBitmapBox(info, glyph,
                                    scale * spc->h_oversample,
                                    scale * spc->v_oversample,
                                    &x0,&y0,&x1,&y1);
            stbtt_MakeGlyphBitmapSubpixel(info,
                                          spc->pixels + r->x + r->y*spc->stride_in_bytes,
                                          r->w - spc->h_oversample+1,
                                          r->h - spc->v_oversample+1,
                                          spc->stride_in_bytes,
                                          scale * spc->h_oversample,
                                          scale * spc->v_oversample,
                                          0,0,
                                          glyph);

            if (spc->h_oversample > 1)
               stbtt__h_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes,
                                  r->w, r->h, spc->stride_in_bytes,
                                  spc->h_oversample);

            if (spc->v_oversample > 1)
               stbtt__v_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes,
                                  r->w, r->h, spc->stride_in_bytes,
                                  spc->v_oversample);

            bc->x0       = (stbtt_int16)  r->x;
            bc->y0       = (stbtt_int16)  r->y;
            bc->x1       = (stbtt_int16) (r->x + r->w);
            bc->y1       = (stbtt_int16) (r->y + r->h);
            bc->xadvance =                scale * advance;
            bc->xoff     =       (float)  x0 * recip_h + sub_x;
            bc->yoff     =       (float)  y0 * recip_v + sub_y;
            bc->xoff2    =                (x0 + r->w) * recip_h + sub_x;
            bc->yoff2    =                (y0 + r->h) * recip_v + sub_y;
         } else {
            return_value = 0; // if any fail, report failure
         }

         ++k;
      }
   }

   // restore original values
   spc->h_oversample = old_h_over;
   spc->v_oversample = old_v_over;

   return return_value;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x11a5be
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movss (%rax), %xmm0
movss %xmm0, -0x44(%rbp)
movss -0x44(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x11a0f0
movq -0x10(%rbp), %rdi
movss -0x44(%rbp), %xmm0
callq 0x119620
movss %xmm0, -0x90(%rbp)
jmp 0x11a113
movq -0x10(%rbp), %rdi
movss -0x44(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
callq 0x119690
movss %xmm0, -0x90(%rbp)
movss -0x90(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movzbl 0x20(%rax,%rcx,8), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
movzbl 0x21(%rax,%rcx,8), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %eax
cvtsi2ss %rax, %xmm1
movss 0x56ad8(%rip), %xmm0    # 0x170c3c
divss %xmm1, %xmm0
movss %xmm0, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
cvtsi2ss %rax, %xmm1
movss 0x56abb(%rip), %xmm0    # 0x170c3c
divss %xmm1, %xmm0
movss %xmm0, -0x50(%rbp)
movq -0x8(%rbp), %rax
movl 0x24(%rax), %edi
callq 0x121eb0
movss %xmm0, -0x54(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %edi
callq 0x121eb0
movss %xmm0, -0x58(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jge 0x11a5ae
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x11a590
movq -0x60(%rbp), %rax
movzwl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0x11a590
movq -0x60(%rbp), %rax
movzwl 0x6(%rax), %eax
cmpl $0x0, %eax
je 0x11a590
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movslq -0x30(%rbp), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0x11a266
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x94(%rbp)
jmp 0x11a286
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x10(%rbp), %rdi
movl -0x84(%rbp), %esi
callq 0x119020
movl %eax, -0x88(%rbp)
movq -0x8(%rbp), %rax
movw 0x1c(%rax), %ax
movw %ax, -0x8a(%rbp)
movzwl -0x8a(%rbp), %edx
movq -0x60(%rbp), %rax
movl 0x8(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x8(%rax)
movzwl -0x8a(%rbp), %edx
movq -0x60(%rbp), %rax
movzwl 0xa(%rax), %ecx
addl %edx, %ecx
movw %cx, 0xa(%rax)
movzwl -0x8a(%rbp), %edx
movq -0x60(%rbp), %rax
movl 0x4(%rax), %ecx
subl %edx, %ecx
movw %cx, 0x4(%rax)
movzwl -0x8a(%rbp), %edx
movq -0x60(%rbp), %rax
movzwl 0x6(%rax), %ecx
subl %edx, %ecx
movw %cx, 0x6(%rax)
movq -0x10(%rbp), %rdi
movl -0x88(%rbp), %esi
leaq -0x6c(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x121f00
movq -0x10(%rbp), %rdi
movl -0x88(%rbp), %esi
movss -0x48(%rbp), %xmm1
movq -0x8(%rbp), %rax
movl 0x24(%rax), %ecx
movl 0x28(%rax), %eax
cvtsi2ss %rcx, %xmm2
movaps %xmm1, %xmm0
mulss %xmm2, %xmm0
cvtsi2ss %rax, %xmm2
mulss %xmm2, %xmm1
leaq -0x74(%rbp), %rdx
leaq -0x78(%rbp), %rcx
leaq -0x7c(%rbp), %r8
leaq -0x80(%rbp), %r9
callq 0x122040
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x60(%rbp), %rcx
movzwl 0x8(%rcx), %edx
addq %rdx, %rsi
movzwl 0xa(%rcx), %edx
movl 0x18(%rax), %r8d
movl 0x24(%rax), %r9d
imull %r8d, %edx
movslq %edx, %rdx
addq %rdx, %rsi
movzwl 0x4(%rcx), %edx
movl %r9d, %r10d
subl %r10d, %edx
incl %edx
movzwl 0x6(%rcx), %ecx
movl 0x28(%rax), %eax
movl %eax, %r10d
subl %r10d, %ecx
incl %ecx
movss -0x48(%rbp), %xmm1
cvtsi2ss %r9, %xmm2
movaps %xmm1, %xmm0
mulss %xmm2, %xmm0
cvtsi2ss %rax, %xmm2
mulss %xmm2, %xmm1
movl -0x88(%rbp), %r9d
xorps %xmm3, %xmm3
movaps %xmm3, %xmm2
callq 0x1220a0
movq -0x8(%rbp), %rax
cmpl $0x1, 0x24(%rax)
jbe 0x11a42e
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x60(%rbp), %rax
movzwl 0x8(%rax), %eax
cltq
addq %rax, %rdi
movq -0x60(%rbp), %rax
movzwl 0xa(%rax), %eax
movq -0x8(%rbp), %rcx
imull 0x18(%rcx), %eax
cltq
addq %rax, %rdi
movq -0x60(%rbp), %rax
movzwl 0x4(%rax), %esi
movq -0x60(%rbp), %rax
movzwl 0x6(%rax), %edx
movq -0x8(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x8(%rbp), %rax
movl 0x24(%rax), %r8d
callq 0x122190
movq -0x8(%rbp), %rax
cmpl $0x1, 0x28(%rax)
jbe 0x11a486
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x60(%rbp), %rax
movzwl 0x8(%rax), %eax
cltq
addq %rax, %rdi
movq -0x60(%rbp), %rax
movzwl 0xa(%rax), %eax
movq -0x8(%rbp), %rcx
imull 0x18(%rcx), %eax
cltq
addq %rax, %rdi
movq -0x60(%rbp), %rax
movzwl 0x4(%rax), %esi
movq -0x60(%rbp), %rax
movzwl 0x6(%rax), %edx
movq -0x8(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x8(%rbp), %rax
movl 0x28(%rax), %r8d
callq 0x1224e0
movq -0x60(%rbp), %rax
movw 0x8(%rax), %cx
movq -0x68(%rbp), %rax
movw %cx, (%rax)
movq -0x60(%rbp), %rax
movw 0xa(%rax), %cx
movq -0x68(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x60(%rbp), %rax
movzwl 0x8(%rax), %eax
movq -0x60(%rbp), %rcx
movzwl 0x4(%rcx), %ecx
addl %ecx, %eax
movw %ax, %cx
movq -0x68(%rbp), %rax
movw %cx, 0x4(%rax)
movq -0x60(%rbp), %rax
movzwl 0xa(%rax), %eax
movq -0x60(%rbp), %rcx
movzwl 0x6(%rcx), %ecx
addl %ecx, %eax
movw %ax, %cx
movq -0x68(%rbp), %rax
movw %cx, 0x6(%rax)
movss -0x48(%rbp), %xmm0
cvtsi2ssl -0x6c(%rbp), %xmm1
mulss %xmm1, %xmm0
movq -0x68(%rbp), %rax
movss %xmm0, 0x10(%rax)
cvtsi2ssl -0x74(%rbp), %xmm0
movss -0x4c(%rbp), %xmm2
movss -0x54(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x68(%rbp), %rax
movss %xmm0, 0x8(%rax)
cvtsi2ssl -0x78(%rbp), %xmm0
movss -0x50(%rbp), %xmm2
movss -0x58(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x68(%rbp), %rax
movss %xmm0, 0xc(%rax)
movl -0x74(%rbp), %eax
movq -0x60(%rbp), %rcx
movzwl 0x4(%rcx), %ecx
addl %ecx, %eax
cvtsi2ss %eax, %xmm0
movss -0x4c(%rbp), %xmm2
movss -0x54(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x68(%rbp), %rax
movss %xmm0, 0x14(%rax)
movl -0x78(%rbp), %eax
movq -0x60(%rbp), %rcx
movzwl 0x6(%rcx), %ecx
addl %ecx, %eax
cvtsi2ss %eax, %xmm0
movss -0x50(%rbp), %xmm2
movss -0x58(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x68(%rbp), %rax
movss %xmm0, 0x18(%rax)
jmp 0x11a597
movl $0x0, -0x38(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x11a1b3
jmp 0x11a5b0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11a0a7
movl -0x3c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0x40(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
movl -0x38(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nop