// File: /workspace/github_cpp_makefile_star2_O3/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, %r14d
movl %esi, %ebp
movq %rdi, %r15
movq 0x18(%rdi), %rbx
leaq -0x2(%rbx), %r13
cmpl %esi, 0x9a74(%rip)      # 0x1a220
jge 0x1083a
testl %r12d, %r12d
jne 0x108fd
movl 0x9a5f(%rip), %ebx      # 0x1a220
cmpl %ebp, %ebx
movl %ebp, %eax
cmovgl %ebx, %eax
addl $0x10, %eax
movslq %eax, %rdi
callq 0x2250
testq %rax, %rax
je 0x10836
movq %rax, %r12
movq %r13, 0x8(%rsp)
movq %r15, 0x10(%rsp)
leal 0x10(%r14), %eax
cmpl %ebp, %ebx
cmovlel %ebp, %ebx
movslq %ebx, %rcx
movslq %eax, %r15
leal -0x10(%rcx), %ebx
leaq (%rcx,%r15), %r13
addq $0x10, %r13
movl %ebx, 0x8(%r12)
movq %r12, %rdi
movl %ebp, %esi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x1091c
testq %rax, %rax
jne 0x10854
movq %r12, %rdi
callq 0x23c0
movq %r13, %rdi
callq 0x2250
movq %rax, %r12
addl %r15d, %ebx
addq %r15, %r13
testq %rax, %rax
jne 0x107ff
xorl %eax, %eax
jmp 0x10897
movq %r13, %rdi
movl %ebp, %esi
movl %r14d, %edx
movl %r12d, %ecx
callq 0x1091c
testq %rax, %rax
je 0x108a6
incl 0xa(%rbx)
jmp 0x10897
movq 0x8(%rsp), %rsi
movq %rsi, (%r12)
leaq 0x2(%r12), %rcx
movq 0x10(%rsp), %rdx
movq %rcx, 0x18(%rdx)
movl $0x1, 0xc(%r12)
subl %ebp, %ebx
cmpl $-0x10, %ebx
jne 0x10897
movl 0x8(%r12), %ecx
cmpl 0x8(%rsi), %ecx
jg 0x10897
movq (%rsi), %rcx
movq %rcx, (%r12)
movq %r12, (%rsi)
addq $0x2, %rsi
movq %rsi, 0x18(%rdx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r13), %rdi
testq %rdi, %rdi
je 0x107b2
movl %ebp, %esi
movl %r14d, %edx
movl %r12d, %ecx
callq 0x1091c
testq %rax, %rax
jne 0x1084f
movq 0x18(%r15), %r13
movq -0x2(%r13), %rax
testq %rax, %rax
je 0x108f4
movl 0x6(%r13), %ecx
cmpl 0x8(%rax), %ecx
jg 0x108f4
addq $-0x2, %r13
movq (%rax), %rcx
movq %rcx, (%r13)
movq %r13, (%rax)
addq $0x2, %rax
movq %rax, 0x18(%r15)
movq %rax, %r13
addq $-0x2, %r13
jmp 0x107b2
leaq 0x26cb(%rip), %rdi      # 0x12fcf
leaq 0x1ba6(%rip), %rsi      # 0x124b1
leaq 0x26da(%rip), %rcx      # 0x12fec
movl $0xaa4, %edx            # imm = 0xAA4
callq 0x2140