// File: /workspace/github_cpp_makefile_star2_O1/attractivechaos[P]udb2/stb/./stb.h
// Function: stb__alloc_chunk
static void * stb__alloc_chunk(stb__alloc *src, int size, int align, int pre_align)
{
   void *p;
   stb__chunk *c = stb__chunks(src);

   if (c && size <= stb_alloc_chunk_size) {

      p = stb__try_chunk(c, size, align, pre_align);
      if (p) { ++c->alloc; return p; }

      // try a second chunk to reduce wastage
      if (c->next) {
         p = stb__try_chunk(c->next, size, align, pre_align);
         if (p) { ++c->alloc; return p; }
   
         // put the bigger chunk first, since the second will get buried
         // the upshot of this is that, until it gets allocated from, chunk #2
         // is always the largest remaining chunk. (could formalize
         // this with a heap!)
         stb__sort_chunks(src);
         c = stb__chunks(src);
      }
   }

   // allocate a new chunk
   {
      stb__chunk *n;

      int chunk_size = stb_alloc_chunk_size;
      // we're going to allocate a new chunk to put this in
      if (size > chunk_size)
         chunk_size = size;

      assert(sizeof(*n) + pre_align <= 16);

      // loop trying to allocate a large enough chunk
      // the loop is because the alignment may cause problems if it's big...
      // and we don't know what our chunk alignment is going to be
      while (1) {
         n = (stb__chunk *) malloc(16 + chunk_size);
         if (n == NULL) return NULL;

         n->data_left = chunk_size - sizeof(*n);

         p = stb__try_chunk(n, size, align, pre_align);
         if (p != NULL) {
            n->next = c;
            stb__setchunks(src, n);

            // if we just used up the whole block immediately,
            // move the following chunk up
            n->alloc = 1;
            if (size == chunk_size)
               stb__sort_chunks(src);

            return p;
         }

         free(n);
         chunk_size += 16+align;
      }
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %r14d
movl %edx, %r12d
movl %esi, %ebp
movq %rdi, %r15
movq 0x18(%rdi), %rbx
leaq -0x2(%rbx), %r13
cmpl %esi, 0x9795(%rip)      # 0x1a230
jge 0x10b34
movq %r13, 0x10(%rsp)
testl %r14d, %r14d
jne 0x10bfe
movl 0x977b(%rip), %ebx      # 0x1a230
cmpl %ebp, %ebx
movl %ebp, %eax
cmovgl %ebx, %eax
addl $0x10, %eax
movslq %eax, %rdi
callq 0x2250
testq %rax, %rax
je 0x10b30
movq %rax, %r13
movl %r14d, 0x4(%rsp)
movq %r15, 0x8(%rsp)
movq %r12, %r14
leal 0x10(%r12), %eax
cmpl %ebp, %ebx
cmovlel %ebp, %ebx
movslq %ebx, %rcx
movslq %eax, %r15
leal -0x10(%rcx), %r12d
leaq (%rcx,%r15), %rbx
addq $0x10, %rbx
movl %r12d, 0x8(%r13)
movq %r13, %rdi
movl %ebp, %esi
movl %r14d, %edx
movl 0x4(%rsp), %ecx
callq 0x10c1d
testq %rax, %rax
jne 0x10b4e
movq %r13, %rdi
callq 0x23d0
movq %rbx, %rdi
callq 0x2250
movq %rax, %r13
addl %r15d, %r12d
addq %r15, %rbx
testq %rax, %rax
jne 0x10af8
xorl %eax, %eax
jmp 0x10b99
movq %r13, %rdi
movl %ebp, %esi
movl %r12d, %edx
movl %r14d, %ecx
callq 0x10c1d
testq %rax, %rax
je 0x10ba8
incl 0xa(%rbx)
jmp 0x10b99
subl %ebp, %r12d
movq 0x10(%rsp), %rcx
movq %rcx, (%r13)
leaq 0x2(%r13), %rcx
movq 0x8(%rsp), %rsi
movq %rcx, 0x18(%rsi)
movl $0x1, 0xc(%r13)
cmpl $-0x10, %r12d
jne 0x10b99
movq (%r13), %rcx
testq %rcx, %rcx
je 0x10b99
movl 0x8(%r13), %edx
cmpl 0x8(%rcx), %edx
jg 0x10b99
movq (%rcx), %rdx
movq %rdx, (%r13)
movq %r13, (%rcx)
addq $0x2, %rcx
movq %rcx, 0x18(%rsi)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r13), %rdi
testq %rdi, %rdi
je 0x10aa1
movl %ebp, %esi
movl %r12d, %edx
movl %r14d, %ecx
callq 0x10c1d
testq %rax, %rax
jne 0x10b49
movq 0x18(%r15), %rcx
movq -0x2(%rcx), %rax
testq %rax, %rax
je 0x10bf1
movl 0x6(%rcx), %edx
cmpl 0x8(%rax), %edx
jg 0x10bf1
addq $-0x2, %rcx
movq (%rax), %rdx
movq %rdx, (%rcx)
movq %rcx, (%rax)
addq $0x2, %rax
movq %rax, 0x18(%r15)
movq 0x18(%r15), %r13
addq $-0x2, %r13
jmp 0x10aa1
leaq 0x2424(%rip), %rdi      # 0x13029
leaq 0x18f5(%rip), %rsi      # 0x12501
leaq 0x2433(%rip), %rcx      # 0x13046
movl $0xaa4, %edx            # imm = 0xAA4
callq 0x2140