// File: twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::Predictor::find(libzpaq::Array<unsigned char>&, int, unsigned int)
size_t Predictor::find(Array<U8>& ht, int sizebits, U32 cxt) {
  assert(initTables);
  assert(ht.size()==size_t(16)<<sizebits);
  int chk=cxt>>sizebits&255;
  size_t h0=(cxt*16)&(ht.size()-16);
  if (ht[h0]==chk) return h0;
  size_t h1=h0^16;
  if (ht[h1]==chk) return h1;
  size_t h2=h0^32;
  if (ht[h2]==chk) return h2;
  if (ht[h0+1]<=ht[h1+1] && ht[h0+1]<=ht[h2+1])
    return memset(&ht[h0], 0, 16), ht[h0]=chk, h0;
  else if (ht[h1+1]<ht[h2+1])
    return memset(&ht[h1], 0, 16), ht[h1]=chk, h1;
  else
    return memset(&ht[h2], 0, 16), ht[h2]=chk, h2;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl -0x1c(%rbp), %ecx
shrl %cl, %eax
andl $0xff, %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
shll $0x4, %eax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
callq 0x30610
movq %rax, %rcx
movq -0x48(%rbp), %rax
subq $0x10, %rcx
andq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x30630
movzbl (%rax), %eax
cmpl -0x24(%rbp), %eax
jne 0x129bf
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x12b75
movq -0x30(%rbp), %rax
xorq $0x10, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x30630
movzbl (%rax), %eax
cmpl -0x24(%rbp), %eax
jne 0x129ed
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x12b75
movq -0x30(%rbp), %rax
xorq $0x20, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x30630
movzbl (%rax), %eax
cmpl -0x24(%rbp), %eax
jne 0x12a1b
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x12b75
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x1, %rsi
callq 0x30630
movzbl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x1, %rsi
callq 0x30630
movq %rax, %rcx
movl -0x4c(%rbp), %eax
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jg 0x12ac6
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x1, %rsi
callq 0x30630
movzbl (%rax), %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x1, %rsi
callq 0x30630
movq %rax, %rcx
movl -0x50(%rbp), %eax
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jg 0x12ac6
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x30630
movq %rax, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x5150
movl -0x24(%rbp), %eax
movb %al, -0x51(%rbp)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x30630
movb -0x51(%rbp), %cl
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x12b75
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x1, %rsi
callq 0x30630
movzbl (%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
addq $0x1, %rsi
callq 0x30630
movq %rax, %rcx
movl -0x58(%rbp), %eax
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x12b39
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x30630
movq %rax, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x5150
movl -0x24(%rbp), %eax
movb %al, -0x59(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x30630
movb -0x59(%rbp), %cl
movb %cl, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x12b75
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x30630
movq %rax, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x5150
movl -0x24(%rbp), %eax
movb %al, -0x5a(%rbp)
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x30630
movb -0x5a(%rbp), %cl
movb %cl, (%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nop