// File: /workspace/github_cpp_makefile_star2_O2/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, %r12d
movl %edx, %ebp
movl %esi, %r13d
movq %rdi, %r14
movq 0x18(%rdi), %rbx
leaq -0x2(%rbx), %r15
cmpl %esi, 0x94d2(%rip)      # 0x18220
jge 0xedcf
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
testl %r12d, %r12d
jne 0xee67
movl 0x94b8(%rip), %eax      # 0x18220
leal 0x10(%rbp), %ecx
cmpl %r13d, %eax
cmovlel %r13d, %eax
movslq %eax, %r12
movslq %ecx, %rax
movq %rax, 0x10(%rsp)
leal -0x10(%r12), %r15d
addq $0x10, %r12
movq %r12, %rdi
callq 0x2250
testq %rax, %rax
je 0xedec
movq %rax, %rbx
movl %r15d, 0x8(%rax)
movq %rax, %rdi
movl %r13d, %r14d
movl %r13d, %esi
movq %rbp, %r13
movl %ebp, %edx
xorl %ecx, %ecx
callq 0xee86
testq %rax, %rax
jne 0xedf0
movq %rbx, %rdi
callq 0x23c0
movq 0x10(%rsp), %rax
addl %eax, %r15d
addq %rax, %r12
movq %r13, %rbp
movl %r14d, %r13d
jmp 0xed86
movq %r15, %rdi
movl %r13d, %esi
movl %ebp, %edx
movl %r12d, %ecx
callq 0xee86
testq %rax, %rax
je 0xee31
movq %rax, %rbp
incl 0xa(%rbx)
jmp 0xee1f
xorl %ebp, %ebp
jmp 0xee1f
movq %rax, %rbp
movq (%rsp), %rax
movq %rax, (%rbx)
movq %rbx, %rax
addq $0x2, %rax
movq 0x8(%rsp), %rdi
movq %rax, 0x18(%rdi)
movl $0x1, 0xc(%rbx)
subl %r14d, %r15d
cmpl $-0x10, %r15d
jne 0xee1f
callq 0xeee1
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %rdi
testq %rdi, %rdi
je 0xed50
movl %r13d, %esi
movl %ebp, %edx
movl %r12d, %ecx
callq 0xee86
testq %rax, %rax
jne 0xede4
movq %r14, %rdi
callq 0xeee1
movq 0x18(%r14), %rax
addq $-0x2, %rax
movq %rax, %r15
jmp 0xed50
leaq 0x20d1(%rip), %rdi      # 0x10f3f
leaq 0x15ac(%rip), %rsi      # 0x10421
leaq 0x20e0(%rip), %rcx      # 0x10f5c
movl $0xaa4, %edx            # imm = 0xAA4
callq 0x2140