// File: attractivechaos[P]udb2/stb/./stb.h
// Function: stb_ps_remove_any
stb_ps *stb_ps_remove_any(stb_ps *ps, void **value)
{
   assert(ps != NULL);
   switch (3 & (int) ps) {
      case STB_ps_direct:
         *value = ps;
         return NULL;
      case STB_ps_bucket: {
         stb_ps_bucket *b = GetBucket(ps);
         int count=0, slast=0, last=0;
         assert(STB_BUCKET_SIZE == 4);
         if (b->p[0]) { ++count;               last = 0; }
         if (b->p[1]) { ++count; slast = last; last = 1; }
         if (b->p[2]) { ++count; slast = last; last = 2; }
         if (b->p[3]) { ++count; slast = last; last = 3; }
         *value = b->p[last];
         b->p[last] = 0;
         if (count == 2) {
            void *leftover = b->p[slast]; // second to last
            stb_bucket_free(b);
            return (stb_ps *) leftover; 
         }
         return ps;
      }
      case STB_ps_array: {
         stb_ps_array *a = GetArray(ps);
         *value = a->p[a->count-1];
         if (a->count == 4)
            return stb_ps_remove(ps, *value);
         --a->count;
         return ps;
      }
      case STB_ps_hash: {
         stb_ps_hash *h = GetHash(ps);
         void **t = h->table;
         stb_uint32 n = h->any_offset;
         while (stb_ps_empty(t[n]))
            n = (n + 1) & h->mask;
         *value = t[n];
         h->any_offset = (n+1) & h->mask;
         // check if we need to skip down to the previous type
         if (h->count-1 < stb_ps_array_max || h->count-1 == h->shrink_threshhold)
            return stb_ps_remove(ps, *value);
         t[n] = STB_DEL;
         -- h->count;
         ++ h->count_deletes;
         return ps;
      }
   }
   return ps; /* NOTREACHED */
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x13b38
jmp 0x13b57
leaq 0xbfb1(%rip), %rdi      # 0x1faf0
leaq 0xb843(%rip), %rsi      # 0x1f389
movl $0x1ed0, %edx           # imm = 0x1ED0
leaq 0xbfa9(%rip), %rcx      # 0x1fafb
callq 0x2140
movl 0x58(%rsp), %eax
andl $0x3, %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0x3, %eax
ja 0x13e25
movq 0x8(%rsp), %rax
leaq 0xb59a(%rip), %rcx      # 0x1f114
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
movq $0x0, 0x60(%rsp)
jmp 0x13e2f
movq 0x58(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, (%rax)
je 0x13be2
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
movl $0x0, 0x3c(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x13c09
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0x40(%rsp)
movl $0x1, 0x3c(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x13c30
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0x40(%rsp)
movl $0x2, 0x3c(%rsp)
movq 0x48(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x13c57
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0x40(%rsp)
movl $0x3, 0x3c(%rsp)
movq 0x48(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
movq 0x48(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
cmpl $0x2, 0x44(%rsp)
jne 0x13cb2
movq 0x48(%rsp), %rax
movslq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rdi
callq 0x12a20
movq 0x30(%rsp), %rax
movq %rax, 0x60(%rsp)
jmp 0x13e2f
movq 0x58(%rsp), %rax
movq %rax, 0x60(%rsp)
jmp 0x13e2f
movq 0x58(%rsp), %rax
addq $-0x2, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq 0x28(%rsp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq 0x8(%rax,%rcx,8), %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
cmpl $0x4, (%rax)
jne 0x13d14
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rax
movq (%rax), %rsi
callq 0x134b0
movq %rax, 0x60(%rsp)
jmp 0x13e2f
movq 0x28(%rsp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq 0x58(%rsp), %rax
movq %rax, 0x60(%rsp)
jmp 0x13e2f
movq 0x58(%rsp), %rax
addq $-0x3, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movl 0x1c(%rax), %eax
movl %eax, 0x14(%rsp)
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x1, %eax
ja 0x13d7e
movl 0x14(%rsp), %eax
addl $0x1, %eax
movq 0x20(%rsp), %rcx
andl 0x4(%rcx), %eax
movl %eax, 0x14(%rsp)
jmp 0x13d57
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
movq (%rax,%rcx,8), %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movq 0x20(%rsp), %rax
andl 0x4(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq 0x20(%rsp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
cmpl 0x125c5(%rip), %eax     # 0x26380
jl 0x13dd2
movq 0x20(%rsp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movq 0x20(%rsp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x13deb
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rax
movq (%rax), %rsi
callq 0x134b0
movq %rax, 0x60(%rsp)
jmp 0x13e2f
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
movl $0x1, %edx
movq %rdx, (%rax,%rcx,8)
movq 0x20(%rsp), %rax
movl 0x8(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x8(%rax)
movq 0x20(%rsp), %rax
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
movq 0x58(%rsp), %rax
movq %rax, 0x60(%rsp)
jmp 0x13e2f
movq 0x58(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
nopl (%rax)