// File: /workspace/github_cpp_makefile_star2_O2/attractivechaos[P]udb2/stb/./stb.h
// Function: stb_perfect_create
int stb_perfect_create(stb_perfect *p, unsigned int *v, int n)
{
   unsigned int buffer1[64], buffer2[64], buffer3[64], buffer4[64], buffer5[32];
   unsigned short *as = (unsigned short *) stb_temp(buffer1, sizeof(*v)*n);
   unsigned short *bs = (unsigned short *) stb_temp(buffer2, sizeof(*v)*n);
   unsigned short *entries = (unsigned short *) stb_temp(buffer4, sizeof(*entries) * n);
   int size = 1 << stb_log2_ceil(n), bsize=8;
   int failure = 0,i,j,k;

   assert(n <= 32768);
   p->large_bmap = NULL;

   for(;;) {
      stb__slot *bcount = (stb__slot *) stb_temp(buffer3, sizeof(*bcount) * bsize);
      unsigned short *bloc = (unsigned short *) stb_temp(buffer5, sizeof(*bloc) * bsize);
      unsigned short *e;
      int bad=0;

      p->addend = stb__perfect_rand();
      p->multiplicand = stb__perfect_rand() | 1;
      p->table_mask = size-1;
      p->b_mask = bsize-1;
      p->table = (stb_uint32 *) malloc(size * sizeof(*p->table));

      for (i=0; i < bsize; ++i) {
         bcount[i].b     = i;
         bcount[i].count = 0;
         bcount[i].map   = 0;
      }
      for (i=0; i < n; ++i) {
         stb__perfect_prehash(p, v[i], as+i, bs+i);
         ++bcount[bs[i]].count;
      }
      qsort(bcount, bsize, sizeof(*bcount), stb__slot_compare);
      e = entries; // now setup up their entries index
      for (i=0; i < bsize; ++i) {
         bcount[i].entries = e;
         e += bcount[i].count;
         bcount[i].count = 0;
         bloc[bcount[i].b] = i;
      }
      // now fill them out
      for (i=0; i < n; ++i) {
         int b = bs[i];
         int w = bloc[b];
         bcount[w].entries[bcount[w].count++] = i;
      }
      stb_tempfree(buffer5,bloc);
      // verify
      for (i=0; i < bsize; ++i)
         for (j=0; j < bcount[i].count; ++j)
            assert(bs[bcount[i].entries[j]] == bcount[i].b);
      memset(p->table, 0, size*sizeof(*p->table));

      // check if any b has duplicate a
      for (i=0; i < bsize; ++i) {
         if (bcount[i].count > 1) {
            for (j=0; j < bcount[i].count; ++j) {
               if (p->table[as[bcount[i].entries[j]]])
                  bad = 1;
               p->table[as[bcount[i].entries[j]]] = 1;
            }
            for (j=0; j < bcount[i].count; ++j) {
               p->table[as[bcount[i].entries[j]]] = 0;
            }
            if (bad) break;
         }
      }

      if (!bad) {
         // go through the bs and populate the table, first fit
         for (i=0; i < bsize; ++i) {
            if (bcount[i].count) {
               // go through the candidate table[b] values
               for (j=0; j < size; ++j) {
                  // go through the a values and see if they fit
                  for (k=0; k < bcount[i].count; ++k) {
                     int a = as[bcount[i].entries[k]];
                     if (p->table[(a^j)&p->table_mask]) {
                        break; // fails
                     }
                  }
                  // if succeeded, accept
                  if (k == bcount[i].count) {
                     bcount[i].map = j;
                     for (k=0; k < bcount[i].count; ++k) {
                        int a = as[bcount[i].entries[k]];
                        p->table[(a^j)&p->table_mask] = 1;
                     }
                     break;
                  }
               }
               if (j == size)
                  break; // no match for i'th entry, so break out in failure
            }
         }
         if (i == bsize) {
            // success... fill out map
            if (bsize <= 16 && size <= 256) {
               p->large_bmap = NULL;
               for (i=0; i < bsize; ++i)
                  p->small_bmap[bcount[i].b] = (stb_uint8) bcount[i].map;
            } else {
               p->large_bmap = (unsigned short *) malloc(sizeof(*p->large_bmap) * bsize);
               for (i=0; i < bsize; ++i)
                  p->large_bmap[bcount[i].b] = bcount[i].map;
            }

            // initialize table to v[0], so empty slots will fail
            for (i=0; i < size; ++i)
               p->table[i] = v[0];

            for (i=0; i < n; ++i)
               if (p->large_bmap)
                  p->table[as[i] ^ p->large_bmap[bs[i]]] = v[i];
               else
                  p->table[as[i] ^ p->small_bmap[bs[i]]] = v[i];

            // and now validate that none of them collided
            for (i=0; i < n; ++i)
               assert(stb_perfect_hash(p, v[i]) >= 0);

            stb_tempfree(buffer3, bcount);
            break;
         }
      }
      free(p->table);
      p->table = NULL;
      stb_tempfree(buffer3, bcount);

      ++failure;
      if (failure >= 4 && bsize < size) bsize *= 2;
      if (failure >= 8 && (failure & 3) == 0 && size < 4*n) {
         size *= 2;
         bsize *= 2;
      }
      if (failure == 6) {
         // make sure the input data is unique, so we don't infinite loop
         unsigned int *data = (unsigned int *) stb_temp(buffer3, n * sizeof(*data));
         memcpy(data, v, sizeof(*data) * n);
         qsort(data, n, sizeof(*data), stb_intcmp(0));
         for (i=1; i < n; ++i) {
            if (data[i] == data[i-1])
               size = 0; // size is return value, so 0 it
         }
         stb_tempfree(buffer3, data);
         if (!size) break;
      }
   }

   if (failure > stb_perfect_hash_max_failures)
      stb_perfect_hash_max_failures = failure;

   stb_tempfree(buffer1, as);
   stb_tempfree(buffer2, bs);
   stb_tempfree(buffer4, entries);

   return size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
movl %edx, %r15d
movq %rsi, (%rsp)
movq %rdi, %rbp
movslq %edx, %r12
leaq (,%r12,4), %r14
leaq 0x3f0(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movl %r14d, %edx
callq 0x32ac
movq %rax, %rbx
leaq 0x2f0(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, 0x30(%rsp)
movl %r14d, %edx
callq 0x32ac
movq %rax, %r14
leal (%r12,%r12), %edx
leaq 0x1f0(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x32ac
movq %rax, 0x40(%rsp)
movq %r12, 0x38(%rsp)
cmpl $0x8001, %r12d          # imm = 0x8001
jge 0x5c00
movl %r15d, %edi
callq 0x37b7
pushq $0x1
popq %rcx
movl %ecx, %r12d
movl %eax, %ecx
shll %cl, %r12d
andq $0x0, 0x20(%rbp)
leal (,%r15,4), %eax
movl %eax, 0x24(%rsp)
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
movq %r15, 0x10(%rsp)
pushq $0x8
popq %r13
leaq 0xf0(%rsp), %r15
xorl %ecx, %ecx
movq %rcx, 0x48(%rsp)
movq %r13, 0x8(%rsp)
movslq %r13d, %rax
movl %eax, %edx
movq %r15, %rdi
movq %rax, %r15
movq %rax, 0x50(%rsp)
shll $0x4, %edx
movl $0x100, %esi            # imm = 0x100
callq 0x32ac
movq %rax, %r13
leaq (%r15,%r15), %rdx
leaq 0x70(%rsp), %rdi
movl $0x80, %esi
movq %rdx, 0x58(%rsp)
callq 0x32ac
movq %rax, %r15
callq 0x5c1f
movl %eax, (%rbp)
callq 0x5c1f
orl $0x1, %eax
movq %rax, 0x68(%rsp)
movl %eax, 0x4(%rbp)
leal -0x1(%r12), %eax
movl %eax, 0x28(%rsp)
movl %eax, 0x28(%rbp)
movq 0x50(%rsp), %rax
decl %eax
movl %eax, 0x2c(%rsp)
movl %eax, 0x8(%rbp)
movq %r12, 0x18(%rsp)
movslq %r12d, %rdi
shlq $0x2, %rdi
movq %rdi, 0x60(%rsp)
callq 0x2250
movq 0x50(%rsp), %rsi
movq %rax, 0x30(%rbp)
testl %esi, %esi
movl $0x0, %r12d
cmovgl %esi, %r12d
leaq 0x4(%r13), %rax
xorl %ecx, %ecx
movq (%rsp), %r8
cmpq %rcx, %r12
je 0x56ed
movw %cx, -0x2(%rax)
andw $0x0, -0x4(%rax)
andw $0x0, (%rax)
incq %rcx
addq $0x10, %rax
jmp 0x56d2
xorl %eax, %eax
movq 0x10(%rsp), %rdi
movq 0x68(%rsp), %r10
movl 0x28(%rsp), %r11d
cmpq %rax, %rdi
je 0x5743
movl (%r8,%rax,4), %ecx
movl %ecx, %edx
imull %r10d, %edx
shrl $0x10, %ecx
movl %edx, %r9d
shrl $0x18, %r9d
addl %ecx, %r9d
addl %edx, %ecx
shrl $0xc, %ecx
andl 0x2c(%rsp), %r9d
andl %r11d, %ecx
movw %r9w, (%r14,%rax,2)
movw %cx, (%rbx,%rax,2)
movzwl (%r14,%rax,2), %ecx
shll $0x4, %ecx
incw (%r13,%rcx)
incq %rax
jmp 0x56fe
movq %r13, %rdi
pushq $0x10
popq %rdx
leaq 0x4fc(%rip), %rcx       # 0x5c4c
callq 0x20a0
movq %r13, %rax
xorl %ecx, %ecx
movq 0x40(%rsp), %rdx
cmpq %rcx, %r12
je 0x5785
movq %rdx, 0x8(%rax)
movzwl (%rax), %esi
leaq (%rdx,%rsi,2), %rdx
andw $0x0, (%rax)
movzwl 0x2(%rax), %esi
movw %cx, (%r15,%rsi,2)
incq %rcx
addq $0x10, %rax
jmp 0x575f
xorl %eax, %eax
movq 0x10(%rsp), %r8
cmpq %rax, %r8
je 0x57bb
movzwl (%r14,%rax,2), %ecx
movzwl (%r15,%rcx,2), %ecx
shll $0x4, %ecx
movq 0x8(%r13,%rcx), %rdx
movzwl (%r13,%rcx), %esi
leal 0x1(%rsi), %edi
movw %di, (%r13,%rcx)
movw %ax, (%rdx,%rsi,2)
incq %rax
jmp 0x578c
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x32bc
xorl %eax, %eax
pushq $0x1
popq %r15
cmpq %r12, %rax
je 0x580b
movq %rax, %rdx
shlq $0x4, %rdx
leaq (%rdx,%r13), %rcx
movzwl (%r13,%rdx), %edx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x5806
movq 0x8(%rcx), %rdi
movzwl (%rdi,%rsi,2), %edi
movzwl (%r14,%rdi,2), %edi
incq %rsi
cmpw 0x2(%rcx), %di
je 0x57e6
jmp 0x5be1
incq %rax
jmp 0x57ce
movq 0x30(%rbp), %rdi
xorl %esi, %esi
movq 0x60(%rsp), %rdx
callq 0x2160
xorl %eax, %eax
cmpq %r12, %rax
je 0x5893
movq %rax, %rdx
shlq $0x4, %rdx
movzwl (%r13,%rdx), %ecx
cmpq $0x2, %rcx
jb 0x588e
addq %r13, %rdx
movq 0x30(%rbp), %rdi
movq 0x8(%rdx), %rdx
xorl %r8d, %r8d
xorl %esi, %esi
cmpq %r8, %rcx
je 0x586a
movzwl (%rdx,%r8,2), %r9d
movzwl (%rbx,%r9,2), %r9d
cmpl $0x0, (%rdi,%r9,4)
cmovnel %r15d, %esi
movl $0x1, (%rdi,%r9,4)
incq %r8
jmp 0x5845
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x5886
movzwl (%rdx,%r8,2), %r9d
movzwl (%rbx,%r9,2), %r9d
andl $0x0, (%rdi,%r9,4)
incq %r8
jmp 0x586d
testl %esi, %esi
jne 0x5959
incq %rax
jmp 0x581d
movq 0x18(%rsp), %rax
testl %eax, %eax
movl $0x0, %r15d
cmovgl %eax, %r15d
xorl %eax, %eax
cmpq %r12, %rax
je 0x594a
movq %rax, %rsi
shlq $0x4, %rsi
movzwl (%r13,%rsi), %ecx
testq %rcx, %rcx
je 0x593f
addq %r13, %rsi
xorl %edx, %edx
cmpl %r15d, %edx
je 0x5936
movq 0x8(%rsi), %rdi
movq 0x30(%rbp), %r8
movl 0x28(%rbp), %r9d
xorl %r10d, %r10d
cmpq %r10, %rcx
je 0x5904
movzwl (%rdi,%r10,2), %r11d
movzwl (%rbx,%r11,2), %r11d
xorl %edx, %r11d
andl %r9d, %r11d
cmpl $0x0, (%r8,%r11,4)
jne 0x58fb
incq %r10
jmp 0x58da
cmpq %r10, %rcx
je 0x5904
incl %edx
jmp 0x58c6
movw %dx, 0x4(%rsi)
movq 0x8(%rsi), %rsi
movq 0x30(%rbp), %rdi
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x5939
movzwl (%rsi,%r8,2), %r9d
movzwl (%rbx,%r9,2), %r9d
xorl %edx, %r9d
andl 0x28(%rbp), %r9d
movl $0x1, (%rdi,%r9,4)
incq %r8
jmp 0x5913
movl %r15d, %edx
cmpl 0x18(%rsp), %edx
je 0x5947
incq %rax
jmp 0x58a6
movl %eax, %r12d
cmpl 0x8(%rsp), %r12d
je 0x5a51
movq 0x30(%rbp), %rdi
callq 0x23c0
andq $0x0, 0x30(%rbp)
leaq 0xf0(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x32bc
movq 0x48(%rsp), %rdx
cmpl $0x3, %edx
setge %al
movq 0x18(%rsp), %r12
movq 0x8(%rsp), %r13
cmpl %r12d, %r13d
setl %cl
andb %al, %cl
shll %cl, %r13d
cmpl $0x7, %edx
leal 0x1(%rdx), %eax
setge %dl
testb $0x3, %al
sete %sil
cmpl 0x24(%rsp), %r12d
setl %cl
andb %dl, %cl
andb %sil, %cl
shll %cl, %r13d
shll %cl, %r12d
movl %eax, %ecx
cmpl $0x6, %eax
jne 0x5626
movq %r15, %rdi
movl $0x100, %esi            # imm = 0x100
movq 0x30(%rsp), %rdx
callq 0x32ac
movq %rax, %r15
movq %rax, %rdi
movq (%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x2230
andl $0x0, 0x1610c(%rip)     # 0x1bafc
movq %r15, %rdi
movq 0x38(%rsp), %rsi
pushq $0x4
popq %rdx
leaq -0x2202(%rip), %rcx     # 0x3800
callq 0x20a0
movq 0x38(%rsp), %rdx
pushq $0x1
popq %rax
xorl %esi, %esi
cmpq %rdx, %rax
jge 0x5a28
movl (%r15,%rax,4), %ecx
cmpl -0x4(%r15,%rax,4), %ecx
cmovel %esi, %r12d
incq %rax
jmp 0x5a11
leaq 0xf0(%rsp), %rdi
movq %r15, %rsi
movq %rdi, %r15
callq 0x32bc
pushq $0x6
popq %rax
movl %eax, %ecx
testl %r12d, %r12d
jne 0x5626
xorl %r12d, %r12d
jmp 0x5b8c
cmpl $0x10, 0x8(%rsp)
movq 0x18(%rsp), %r12
jg 0x5a9e
cmpl $0x100, %r12d           # imm = 0x100
jg 0x5a9e
andq $0x0, 0x20(%rbp)
xorl %eax, %eax
movq 0x8(%rsp), %rsi
testl %esi, %esi
cmovlel %eax, %esi
shlq $0x4, %rsi
movq 0x10(%rsp), %rdi
movq (%rsp), %r8
cmpq %rax, %rsi
je 0x5ae2
movb 0x4(%r13,%rax), %cl
movzwl 0x2(%r13,%rax), %edx
movb %cl, 0xc(%rbp,%rdx)
addq $0x10, %rax
jmp 0x5a84
movq 0x58(%rsp), %rdi
callq 0x2250
movq %rax, 0x20(%rbp)
xorl %ecx, %ecx
movq 0x8(%rsp), %r9
testl %r9d, %r9d
cmovlel %ecx, %r9d
shlq $0x4, %r9
movq 0x10(%rsp), %rdi
movq (%rsp), %r8
cmpq %rcx, %r9
je 0x5ae2
movzwl 0x4(%r13,%rcx), %edx
movzwl 0x2(%r13,%rcx), %esi
movw %dx, (%rax,%rsi,2)
addq $0x10, %rcx
jmp 0x5ac7
movl %r15d, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x5afb
movl (%r8), %edx
movq 0x30(%rbp), %rsi
movl %edx, (%rsi,%rcx,4)
incq %rcx
jmp 0x5ae7
xorl %eax, %eax
cmpq %rax, %rdi
je 0x5b34
movq 0x20(%rbp), %rdx
movzwl (%rbx,%rax,2), %ecx
movzwl (%r14,%rax,2), %esi
testq %rdx, %rdx
je 0x5b1a
xorw (%rdx,%rsi,2), %cx
jmp 0x5b21
movzbl 0xc(%rbp,%rsi), %edx
xorl %edx, %ecx
movq 0x30(%rbp), %rdx
movl (%r8,%rax,4), %esi
movzwl %cx, %ecx
movl %esi, (%rdx,%rcx,4)
incq %rax
jmp 0x5afd
xorl %r15d, %r15d
cmpq %r15, %rdi
je 0x5b77
movl (%r8,%r15,4), %esi
movq %rbp, %rdi
callq 0x550e
movq (%rsp), %r8
movq 0x10(%rsp), %rdi
incq %r15
testl %eax, %eax
jns 0x5b37
leaq 0xabc3(%rip), %rdi      # 0x10722
leaq 0xa8bb(%rip), %rsi      # 0x10421
leaq 0xab52(%rip), %rcx      # 0x106bf
movl $0xe5a, %edx            # imm = 0xE5A
callq 0x2140
leaq 0xf0(%rsp), %rdi
movq %r13, %rsi
callq 0x32bc
movq 0x48(%rsp), %rax
cmpl 0x1638e(%rip), %eax     # 0x1bf20
jle 0x5b9a
movl %eax, 0x16386(%rip)     # 0x1bf20
leaq 0x3f0(%rsp), %rdi
movq %rbx, %rsi
callq 0x32bc
leaq 0x2f0(%rsp), %rdi
movq %r14, %rsi
callq 0x32bc
leaq 0x1f0(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x32bc
movl %r12d, %eax
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xab12(%rip), %rdi      # 0x106fa
leaq 0xa832(%rip), %rsi      # 0x10421
leaq 0xaac9(%rip), %rcx      # 0x106bf
movl $0xe15, %edx            # imm = 0xE15
callq 0x2140
leaq 0xaaad(%rip), %rdi      # 0x106b4
leaq 0xa813(%rip), %rsi      # 0x10421
leaq 0xaaaa(%rip), %rcx      # 0x106bf
movl $0xdeb, %edx            # imm = 0xDEB
callq 0x2140