// File: /workspace/github_cpp_makefile_star2_O1/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 $0x508, %rsp            # imm = 0x508
movl %edx, %ebx
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
movslq %edx, %rax
movq %rax, 0x58(%rsp)
leaq (,%rax,4), %rdi
cmpl $0x101, %edi            # imm = 0x101
movq %rdi, 0x28(%rsp)
jl 0x5bf9
andl $0x7ffffffc, %edi       # imm = 0x7FFFFFFC
callq 0x2250
movq %rax, %rbp
movq 0x28(%rsp), %rdi
jmp 0x5c01
leaq 0x400(%rsp), %rbp
cmpl $0x101, %edi            # imm = 0x101
jl 0x5c19
andl $0x7ffffffc, %edi       # imm = 0x7FFFFFFC
callq 0x2250
movq %rax, %r12
jmp 0x5c21
leaq 0x300(%rsp), %r12
leal (%rbx,%rbx), %eax
cmpl $0x101, %eax            # imm = 0x101
jl 0x5c34
movl %eax, %edi
callq 0x2250
jmp 0x5c3c
leaq 0x200(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpl $0x8001, %ebx           # imm = 0x8001
jge 0x637e
movl %ebx, %edi
callq 0x3ad1
movl $0x1, %r15d
movl %eax, %ecx
shll %cl, %r15d
movq $0x0, 0x20(%r14)
leal (,%rbx,4), %eax
movl %eax, 0x4c(%rsp)
movq 0x28(%rsp), %rax
andl $0x7ffffffc, %eax       # imm = 0x7FFFFFFC
movq %rax, 0x50(%rsp)
movq %rbx, 0x10(%rsp)
movl %ebx, %r9d
movl $0x8, %r13d
movq $0x0, 0x30(%rsp)
movq %r14, (%rsp)
movq %r9, 0x8(%rsp)
movl %r13d, %eax
shll $0x4, %eax
leaq 0x80(%rsp), %rbx
cmpl $0x101, %eax            # imm = 0x101
jl 0x5cc0
movl %eax, %edi
callq 0x2250
movq %rax, %rbx
movq %r13, 0x20(%rsp)
movslq %r13d, %rax
movq %rax, 0x70(%rsp)
leaq (%rax,%rax), %r13
leaq 0x180(%rsp), %rax
cmpl $0x81, %r13d
jl 0x5cf0
movl %r13d, %edi
andl $0x7ffffffe, %edi       # imm = 0x7FFFFFFE
callq 0x2250
movq %rax, 0x78(%rsp)
movq %r13, 0x60(%rsp)
imulq $0x7ff8a3ed, 0x1a6cb(%rip), %rax # imm = 0x7FF8A3ED
movl $0x2aa01d31, %esi       # imm = 0x2AA01D31
addq %rsi, %rax
movq %rax, 0x1a6bc(%rip)     # 0x203d0
movl %eax, %ecx
imulq $0x7ff8a3ed, %rax, %rdx # imm = 0x7FF8A3ED
shrq $0x10, %rax
shll $0x10, %ecx
addl %ecx, %eax
xorl $0x31415926, %eax       # imm = 0x31415926
movl %eax, (%r14)
addq %rsi, %rdx
movq %rdx, 0x1a698(%rip)     # 0x203d0
movq %rdx, %r13
shrq $0x10, %r13
shll $0x10, %edx
addl %edx, %r13d
andl $-0x2, %r13d
xorl $0x31415927, %r13d      # imm = 0x31415927
movl %r13d, 0x4(%r14)
movq %r15, %rax
decl %r15d
movl %r15d, 0x28(%r14)
movq %r14, %rdx
movq 0x20(%rsp), %rcx
leal -0x1(%rcx), %r14d
movl %r14d, 0x8(%rdx)
movq %rax, 0x40(%rsp)
movslq %eax, %rdi
shlq $0x2, %rdi
movq %rdi, 0x68(%rsp)
callq 0x2250
movq (%rsp), %rcx
movq %rax, 0x30(%rcx)
cmpl $0x0, 0x20(%rsp)
movl $0x0, %esi
jle 0x5db9
movl 0x20(%rsp), %eax
leaq 0x4(%rbx), %rcx
xorl %edx, %edx
movw %dx, -0x2(%rcx)
movw %si, -0x4(%rcx)
movw %si, (%rcx)
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %rax
jne 0x5da2
cmpl $0x0, 0x10(%rsp)
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r8
jle 0x5e06
xorl %eax, %eax
movl (%rdi,%rax,4), %ecx
movl %ecx, %edx
imull %r13d, %edx
shrl $0x10, %ecx
movl %edx, %esi
shrl $0x18, %esi
addl %ecx, %esi
addl %edx, %ecx
shrl $0xc, %ecx
andl %r14d, %esi
andl %r15d, %ecx
movzwl %si, %edx
shll $0x4, %edx
incw (%rbx,%rdx)
movw %si, (%r12,%rax,2)
movw %cx, (%rbp,%rax,2)
incq %rax
cmpq %rax, %r8
jne 0x5dcc
movl $0x10, %edx
movq %rbx, %rdi
movq 0x70(%rsp), %rsi
leaq 0x583(%rip), %rcx       # 0x639d
callq 0x20a0
movq 0x20(%rsp), %r13
testl %r13d, %r13d
movq 0x78(%rsp), %rdi
jle 0x5e62
movl %r13d, %eax
movq %rbx, %rcx
xorl %edx, %edx
movq 0x38(%rsp), %rsi
movq %rsi, 0x8(%rcx)
movzwl (%rcx), %r8d
leaq (%rsi,%r8,2), %rsi
movw $0x0, (%rcx)
movzwl 0x2(%rcx), %r8d
movw %dx, (%rdi,%r8,2)
incq %rdx
addq $0x10, %rcx
cmpq %rdx, %rax
jne 0x5e3b
cmpl $0x0, 0x10(%rsp)
movq (%rsp), %r14
movq 0x40(%rsp), %r15
movq 0x8(%rsp), %r8
jle 0x5ea3
xorl %eax, %eax
movzwl (%r12,%rax,2), %ecx
movzwl (%rdi,%rcx,2), %ecx
shll $0x4, %ecx
movq 0x8(%rbx,%rcx), %rdx
movzwl (%rbx,%rcx), %esi
leal 0x1(%rsi), %r9d
movw %r9w, (%rbx,%rcx)
movw %ax, (%rdx,%rsi,2)
incq %rax
cmpq %rax, %r8
jne 0x5e79
leaq 0x180(%rsp), %rax
cmpq %rax, %rdi
je 0x5eb5
callq 0x23d0
testl %r13d, %r13d
jle 0x5efd
movl %r13d, %eax
xorl %ecx, %ecx
movq %rcx, %rdi
shlq $0x4, %rdi
movzwl (%rbx,%rdi), %edx
testq %rdx, %rdx
je 0x5ef5
addq %rbx, %rdi
movq 0x8(%rdi), %rsi
movzwl 0x2(%rdi), %edi
xorl %r8d, %r8d
movzwl (%rsi,%r8,2), %r9d
cmpw %di, (%r12,%r9,2)
jne 0x6340
incq %r8
cmpq %r8, %rdx
jne 0x5edd
incq %rcx
cmpq %rax, %rcx
jne 0x5ebf
movq 0x30(%r14), %rdi
xorl %esi, %esi
movq 0x68(%rsp), %rdx
callq 0x2160
testl %r13d, %r13d
jle 0x5fa5
movl %r13d, %eax
xorl %ecx, %ecx
movq %rcx, %rdi
shlq $0x4, %rdi
movzwl (%rbx,%rdi), %edx
cmpq $0x2, %rdx
jb 0x5f99
addq %rbx, %rdi
movq 0x30(%r14), %r8
movq 0x8(%rdi), %r9
xorl %r10d, %r10d
xorl %esi, %esi
movl $0x1, %r13d
movzwl (%r9,%r10,2), %r11d
movzwl (%rbp,%r11,2), %r11d
cmpl $0x0, (%r8,%r11,4)
cmovnel %r13d, %esi
movl $0x1, (%r8,%r11,4)
incq %r10
cmpq %r10, %rdx
jne 0x5f42
movq 0x30(%r14), %r8
movq 0x8(%rdi), %rdi
xorl %r9d, %r9d
movzwl (%rdi,%r9,2), %r10d
movzwl (%rbp,%r10,2), %r10d
movl $0x0, (%r8,%r10,4)
incq %r9
cmpq %r9, %rdx
jne 0x5f71
testl %esi, %esi
movq 0x20(%rsp), %r13
jne 0x60ce
incq %rcx
cmpq %rax, %rcx
jne 0x5f1b
testl %r13d, %r13d
jle 0x6070
movl %r13d, %ecx
xorl %eax, %eax
movq %rax, %rdi
shlq $0x4, %rdi
movzwl (%rbx,%rdi), %r8d
testl %r8d, %r8d
je 0x605f
testl %r15d, %r15d
jle 0x6021
addq %rbx, %rdi
movq 0x8(%rdi), %r9
movq 0x30(%r14), %r10
movl 0x28(%r14), %r11d
movl %r8d, %esi
xorl %edx, %edx
xorl %r14d, %r14d
movzwl (%r9,%r14,2), %r15d
movzwl (%rbp,%r15,2), %r15d
xorl %edx, %r15d
andl %r11d, %r15d
cmpl $0x0, (%r10,%r15,4)
jne 0x6007
incq %r14
cmpq %r14, %rsi
jne 0x5fe4
movl %r8d, %r14d
movq 0x40(%rsp), %r15
cmpl %r8d, %r14d
je 0x6025
incl %edx
cmpl %r15d, %edx
jne 0x5fe1
movl %r15d, %edx
movq (%rsp), %r14
jmp 0x605a
xorl %edx, %edx
jmp 0x605a
movw %dx, 0x4(%rdi)
movq 0x8(%rdi), %rdi
movq (%rsp), %r14
movq 0x30(%r14), %r8
xorl %r9d, %r9d
movzwl (%rdi,%r9,2), %r10d
movzwl (%rbp,%r10,2), %r10d
xorl %edx, %r10d
andl 0x28(%r14), %r10d
movl $0x1, (%r8,%r10,4)
incq %r9
cmpq %r9, %rsi
jne 0x6038
cmpl %r15d, %edx
je 0x6072
incq %rax
cmpq %rcx, %rax
jne 0x5fb3
movl %r13d, %eax
jmp 0x6072
xorl %eax, %eax
cmpl %r13d, %eax
jne 0x60ce
cmpl $0x10, %r13d
jg 0x61e7
cmpl $0x100, %r15d           # imm = 0x100
jg 0x61e7
movq $0x0, 0x20(%r14)
testl %r13d, %r13d
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
jle 0x6224
movl %r13d, %eax
shlq $0x4, %rax
xorl %ecx, %ecx
movb 0x4(%rbx,%rcx), %dl
movzwl 0x2(%rbx,%rcx), %esi
movb %dl, 0xc(%r14,%rsi)
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x60b2
jmp 0x6224
movq 0x30(%r14), %rdi
callq 0x23d0
movq $0x0, 0x30(%r14)
leaq 0x80(%rsp), %rax
cmpq %rax, %rbx
je 0x60f4
movq %rbx, %rdi
callq 0x23d0
movq 0x30(%rsp), %rdx
leal 0x1(%rdx), %r14d
cmpl $0x3, %edx
setge %al
cmpl %r15d, %r13d
setl %cl
andb %al, %cl
shll %cl, %r13d
cmpl $0x7, %edx
setge %al
testb $0x3, %r14b
sete %dl
cmpl 0x4c(%rsp), %r15d
setl %cl
andb %al, %cl
andb %dl, %cl
shll %cl, %r13d
shll %cl, %r15d
movb $0x1, %al
cmpl $0x6, %r14d
jne 0x61da
leaq 0x80(%rsp), %rbx
movq 0x28(%rsp), %rdx
cmpl $0x101, %edx            # imm = 0x101
jl 0x6160
movq 0x50(%rsp), %rdi
callq 0x2250
movq %rax, %rbx
movq 0x28(%rsp), %rdx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x2230
movl $0x0, 0x17995(%rip)     # 0x1db0c
movl $0x4, %edx
movq %rbx, %rdi
movq 0x58(%rsp), %rsi
leaq -0x2671(%rip), %rcx     # 0x3b1a
callq 0x20a0
cmpl $0x2, 0x10(%rsp)
jl 0x61b6
movl $0x1, %eax
movq 0x8(%rsp), %r9
xorl %edx, %edx
movl (%rbx,%rax,4), %ecx
cmpl -0x4(%rbx,%rax,4), %ecx
cmovel %edx, %r15d
incq %rax
cmpq %rax, %r9
jne 0x61a3
leaq 0x80(%rsp), %rax
cmpq %rax, %rbx
je 0x61cb
movq %rbx, %rdi
callq 0x23d0
testl %r15d, %r15d
setne %al
movl $0x6, %ecx
cmovel %ecx, %r14d
movl %r14d, %ecx
movq %rcx, 0x30(%rsp)
jmp 0x62c8
movq 0x60(%rsp), %rdi
callq 0x2250
movq %rax, 0x20(%r14)
testl %r13d, %r13d
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %r9
jle 0x6224
movl %r13d, %ecx
shlq $0x4, %rcx
xorl %edx, %edx
movzwl 0x4(%rbx,%rdx), %esi
movzwl 0x2(%rbx,%rdx), %edi
movw %si, (%rax,%rdi,2)
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x620d
testl %r15d, %r15d
jle 0x6240
movq 0x30(%r14), %rax
movl %r15d, %ecx
xorl %edx, %edx
movl (%r8), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x6232
cmpl $0x0, 0x10(%rsp)
jle 0x6280
movq 0x20(%r14), %rax
movq 0x30(%r14), %rcx
xorl %edx, %edx
movzwl (%rbp,%rdx,2), %esi
movzwl (%r12,%rdx,2), %edi
testq %rax, %rax
je 0x6266
xorw (%rax,%rdi,2), %si
jmp 0x626e
movzbl 0xc(%r14,%rdi), %edi
xorl %edi, %esi
movl (%r8,%rdx,4), %edi
movzwl %si, %esi
movl %edi, (%rcx,%rsi,4)
incq %rdx
cmpq %rdx, %r9
jne 0x6251
cmpl $0x0, 0x10(%rsp)
jle 0x62b1
xorl %r14d, %r14d
movl (%r8,%r14,4), %esi
movq (%rsp), %rdi
callq 0x5b58
testl %eax, %eax
js 0x635f
incq %r14
movq 0x8(%rsp), %r9
cmpq %r14, %r9
movq 0x18(%rsp), %r8
jne 0x628a
leaq 0x80(%rsp), %rax
cmpq %rax, %rbx
je 0x62c6
movq %rbx, %rdi
callq 0x23d0
xorl %eax, %eax
movq (%rsp), %r14
testb %al, %al
jne 0x5ca1
movq 0x30(%rsp), %rax
cmpl 0x17c51(%rip), %eax     # 0x1df30
jle 0x62e7
movl %eax, 0x17c49(%rip)     # 0x1df30
leaq 0x400(%rsp), %rax
cmpq %rax, %rbp
movq 0x38(%rsp), %rbx
je 0x6301
movq %rbp, %rdi
callq 0x23d0
leaq 0x300(%rsp), %rax
cmpq %rax, %r12
je 0x6316
movq %r12, %rdi
callq 0x23d0
leaq 0x200(%rsp), %rax
cmpq %rax, %rbx
je 0x632b
movq %rbx, %rdi
callq 0x23d0
movl %r15d, %eax
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc493(%rip), %rdi      # 0x127da
leaq 0xc1b3(%rip), %rsi      # 0x12501
leaq 0xc44a(%rip), %rcx      # 0x1279f
movl $0xe15, %edx            # imm = 0xE15
callq 0x2140
leaq 0xc49c(%rip), %rdi      # 0x12802
leaq 0xc194(%rip), %rsi      # 0x12501
leaq 0xc42b(%rip), %rcx      # 0x1279f
movl $0xe5a, %edx            # imm = 0xE5A
callq 0x2140
leaq 0xc40f(%rip), %rdi      # 0x12794
leaq 0xc175(%rip), %rsi      # 0x12501
leaq 0xc40c(%rip), %rcx      # 0x1279f
movl $0xdeb, %edx            # imm = 0xDEB
callq 0x2140