// File: Ciaxur[P]yagb-emu/include/imgui/imstb_rectpack.h
// Function: stbrp_pack_rects(stbrp_context*, stbrp_rect*, int)
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
{
   int i, all_rects_packed = 1;

   // we use the 'was_packed' field internally to allow sorting/unsorting
   for (i=0; i < num_rects; ++i) {
      rects[i].was_packed = i;
   }

   // sort according to heuristic
   STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);

   for (i=0; i < num_rects; ++i) {
      if (rects[i].w == 0 || rects[i].h == 0) {
         rects[i].x = rects[i].y = 0;  // empty rect needs no space
      } else {
         stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
         if (fr.prev_link) {
            rects[i].x = (stbrp_coord) fr.x;
            rects[i].y = (stbrp_coord) fr.y;
         } else {
            rects[i].x = rects[i].y = STBRP__MAXVAL;
         }
      }
   }

   // unsort
   STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);

   // set was_packed flags and all_rects_packed status
   for (i=0; i < num_rects; ++i) {
      rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
      if (!rects[i].was_packed)
         all_rects_packed = 0;
   }

   // return the all_rects_packed status
   return all_rects_packed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x119e09
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x119de1
movq -0x10(%rbp), %rdi
movslq -0x14(%rbp), %rsi
movl $0x10, %edx
leaq 0x78c3(%rip), %rcx      # 0x1216e0
callq 0xd6c0
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x119f42
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
cmpl $0x0, %eax
je 0x119e65
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x6(%rax), %eax
cmpl $0x0, %eax
jne 0x119e94
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movw $0x0, 0xa(%rax)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movw $0x0, 0x8(%rax)
jmp 0x119f32
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %esi
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x6(%rax), %edx
callq 0x121780
movq %rax, -0x30(%rbp)
movq %rdx, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x119f06
movl -0x30(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movw %cx, 0x8(%rax)
movl -0x2c(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movw %cx, 0xa(%rax)
jmp 0x119f30
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movw $0xffff, 0xa(%rax)      # imm = 0xFFFF
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movw $0xffff, 0x8(%rax)      # imm = 0xFFFF
jmp 0x119f32
jmp 0x119f34
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x119e29
movq -0x10(%rbp), %rdi
movslq -0x14(%rbp), %rsi
movl $0x10, %edx
leaq 0x79aa(%rip), %rcx      # 0x121900
callq 0xd6c0
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x119ff4
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x8(%rax), %ecx
xorl %eax, %eax
cmpl $0xffff, %ecx           # imm = 0xFFFF
movb %al, -0x31(%rbp)
jne 0x119fac
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0xa(%rax), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
sete %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %ecx
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, 0xc(%rax)
jne 0x119fe4
movl $0x0, -0x1c(%rbp)
jmp 0x119fe6
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x119f62
movl -0x1c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)