// File: attractivechaos[P]udb2/stb/./stb.h
// Function: malloc_base
static void * malloc_base(void *context, size_t size, stb__alloc_type t, int align)
{
   void *p;

   stb__alloc *src = stb__get_context(context);

   if (align <= 0) {
      // compute worst-case C packed alignment
      // e.g. a 24-byte struct is 8-aligned
      int align_proposed = 1 << stb_lowbit8(size);

      if (align_proposed < 0)
         align_proposed = 4;

      if (align_proposed == 0) {
         if (size == 0)
            align_proposed = 1;
         else
            align_proposed = 256;
      }

      // a negative alignment means 'don't align any larger
      // than this'; so -16 means we align 1,2,4,8, or 16

      if (align < 0) {
         if (align_proposed > -align)
            align_proposed = -align;
      }

      align = align_proposed;
   }

   assert(stb_is_pow2(align));

   // don't cause misalignment when allocating nochildren
   if (t == STB__nochildren && align > 8)
      t = STB__alloc;

   switch (t) {
      case STB__alloc: {
         stb__alloc *s = (stb__alloc *) malloc(size + sizeof(*s));
         if (s == NULL) return NULL;
         p = s+1;
         s->child = NULL;
         stb__insert_alloc(src, s);

         stb__setchunks(s,NULL);
         break;
      }

      case STB__nochildren: {
         stb__nochildren *s = (stb__nochildren *) malloc(size + sizeof(*s));
         if (s == NULL) return NULL;
         p = s+1;
         stb__insert_nochild(src, s);
         break;
      }

      case STB__chunk_raw: {
         p = stb__alloc_chunk(src, size, align, 0);
         if (p == NULL) return NULL;
         break;
      }

      case STB__chunked: {
         stb__chunked *s;
         if (align < sizeof(stb_uintptr)) align = sizeof(stb_uintptr);
         s = (stb__chunked *) stb__alloc_chunk(src, size, align, sizeof(*s));
         if (s == NULL) return NULL;
         stb__setparent(s, src);
         p = s+1;
         break;
      }

      default: p = NULL; assert(0); /* NOTREACHED */
   }

   ++stb_alloc_count_alloc;
   return p;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movl %edx, 0x3c(%rsp)
movl %ecx, 0x38(%rsp)
movq 0x48(%rsp), %rdi
callq 0x7a30
movq %rax, 0x28(%rsp)
cmpl $0x0, 0x38(%rsp)
jg 0x73a0
movq 0x40(%rsp), %rax
movl %eax, %edi
callq 0x4820
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jge 0x7354
movl $0x4, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jne 0x7377
cmpq $0x0, 0x40(%rsp)
jne 0x736d
movl $0x1, 0x24(%rsp)
jmp 0x7375
movl $0x100, 0x24(%rsp)      # imm = 0x100
jmp 0x7377
cmpl $0x0, 0x38(%rsp)
jge 0x7398
movl 0x24(%rsp), %eax
xorl %ecx, %ecx
subl 0x38(%rsp), %ecx
cmpl %ecx, %eax
jle 0x7396
xorl %eax, %eax
subl 0x38(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x7398
movl 0x24(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %edi
callq 0x4680
cmpl $0x0, %eax
je 0x73b0
jmp 0x73cf
leaq 0x18ade(%rip), %rdi     # 0x1fe95
leaq 0x17fcb(%rip), %rsi     # 0x1f389
movl $0xb05, %edx            # imm = 0xB05
leaq 0x18ade(%rip), %rcx     # 0x1fea8
callq 0x2140
cmpl $0x0, 0x3c(%rsp)
jne 0x73e5
cmpl $0x8, 0x38(%rsp)
jle 0x73e5
movl $0x2, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movq %rax, (%rsp)
subq $0x4, %rax
ja 0x7558
movq (%rsp), %rax
leaq 0x17cae(%rip), %rcx     # 0x1f0b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x40(%rsp), %rdi
addq $0x20, %rdi
callq 0x2260
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x7434
movq $0x0, 0x50(%rsp)
jmp 0x7599
movq 0x18(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x30(%rsp)
movq 0x18(%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x7aa0
movq 0x18(%rsp), %rax
movq $0x2, 0x18(%rax)
jmp 0x7580
movq 0x40(%rsp), %rdi
addq $0x10, %rdi
callq 0x2260
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x7499
movq $0x0, 0x50(%rsp)
jmp 0x7599
movq 0x10(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x7b20
jmp 0x7580
movq 0x28(%rsp), %rdi
movq 0x40(%rsp), %rax
movl %eax, %esi
movl 0x38(%rsp), %edx
xorl %ecx, %ecx
callq 0x1c840
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x74ed
movq $0x0, 0x50(%rsp)
jmp 0x7599
jmp 0x7580
movslq 0x38(%rsp), %rax
cmpq $0x8, %rax
jae 0x7505
movl $0x8, 0x38(%rsp)
movq 0x28(%rsp), %rdi
movq 0x40(%rsp), %rax
movl %eax, %esi
movl 0x38(%rsp), %edx
movl $0x8, %ecx
callq 0x1c840
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x7537
movq $0x0, 0x50(%rsp)
jmp 0x7599
movq 0x28(%rsp), %rcx
addq $0x1, %rcx
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x30(%rsp)
jmp 0x7580
movq $0x0, 0x30(%rsp)
leaq 0x18146(%rip), %rdi     # 0x1f6ae
leaq 0x17e1a(%rip), %rsi     # 0x1f389
movl $0xb2f, %edx            # imm = 0xB2F
leaq 0x1892d(%rip), %rcx     # 0x1fea8
callq 0x2140
movl 0x22afe(%rip), %eax     # 0x2a084
addl $0x1, %eax
movl %eax, 0x22af5(%rip)     # 0x2a084
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)