// File: Ciaxur[P]yagb-emu/include/imgui/imstb_rectpack.h
// Function: stbrp__skyline_find_min_y(stbrp_context*, stbrp_node*, int, int, int*)
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
{
   stbrp_node *node = first;
   int x1 = x0 + width;
   int min_y, visited_width, waste_area;

   STBRP__NOTUSED(c);

   STBRP_ASSERT(first->x <= x0);

   #if 0
   // skip in case we're past the node
   while (node->next->x <= x0)
      ++node;
   #else
   STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
   #endif

   STBRP_ASSERT(node->x <= x0);

   min_y = 0;
   waste_area = 0;
   visited_width = 0;
   while (node->x < x1) {
      if (node->y > min_y) {
         // raise min_y higher.
         // we've accounted for all waste up to min_y,
         // but we'll now add more waste for everything we've visted
         waste_area += visited_width * (node->y - min_y);
         min_y = node->y;
         // the first time through, visited_width might be reduced
         if (node->x < x0)
            visited_width += node->next->x - x0;
         else
            visited_width += node->next->x - node->x;
      } else {
         // add waste area
         int under_width = node->next->x - node->x;
         if (under_width + visited_width > width)
            under_width = width - visited_width;
         waste_area += under_width * (min_y - node->y);
         visited_width += under_width;
      }
      node = node->next;
   }

   *pwaste = waste_area;
   return min_y;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movzwl (%rax), %eax
cmpl -0x14(%rbp), %eax
jg 0x121d19
jmp 0x121d38
leaq 0x696bc(%rip), %rdi     # 0x18b3dc
leaq 0x695b3(%rip), %rsi     # 0x18b2da
movl $0x12f, %edx            # imm = 0x12F
leaq 0x696b8(%rip), %rcx     # 0x18b3eb
callq 0xd180
jmp 0x121d3a
jmp 0x121d3c
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movzwl (%rax), %eax
cmpl -0x14(%rbp), %eax
jle 0x121d4e
jmp 0x121d6d
leaq 0x696e4(%rip), %rdi     # 0x18b439
leaq 0x6957e(%rip), %rsi     # 0x18b2da
movl $0x136, %edx            # imm = 0x136
leaq 0x69683(%rip), %rcx     # 0x18b3eb
callq 0xd180
jmp 0x121d6f
jmp 0x121d71
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
cmpl -0x14(%rbp), %eax
jg 0x121d7f
jmp 0x121d9e
leaq 0x696c6(%rip), %rdi     # 0x18b44c
leaq 0x6954d(%rip), %rsi     # 0x18b2da
movl $0x139, %edx            # imm = 0x139
leaq 0x69652(%rip), %rcx     # 0x18b3eb
callq 0xd180
jmp 0x121da0
movl $0x0, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
cmpl -0x2c(%rbp), %eax
jge 0x121e90
movq -0x28(%rbp), %rax
movzwl 0x2(%rax), %eax
cmpl -0x30(%rbp), %eax
jle 0x121e32
movl -0x34(%rbp), %eax
movq -0x28(%rbp), %rcx
movzwl 0x2(%rcx), %ecx
subl -0x30(%rbp), %ecx
imull %ecx, %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movzwl 0x2(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
cmpl -0x14(%rbp), %eax
jge 0x121e16
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movzwl (%rax), %eax
subl -0x14(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x121e30
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movzwl (%rax), %eax
movq -0x28(%rbp), %rcx
movzwl (%rcx), %ecx
subl %ecx, %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x121e7f
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movzwl (%rax), %eax
movq -0x28(%rbp), %rcx
movzwl (%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
addl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x121e5d
movl -0x18(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rdx
movzwl 0x2(%rdx), %edx
subl %edx, %ecx
imull %ecx, %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x121db5
movl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x30(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)