// File: kobanium[P]Ray/src/pattern/PatternHash.cpp
// Function: PatternHash(pattern_t const*, pattern_hash_t*)
void
PatternHash( const pattern_t *pat, pattern_hash_t *hash_pat )
{
  unsigned int md2_transp[16], md3_transp[16], md4_transp[16];
  unsigned long long md5_transp[16];
  unsigned int tmp2, min2, tmp3, min3;
  unsigned long long tmp4, min4, tmp5, min5;
  int index2, index3, index4, index5;

  MD2Transpose16(pat->list[MD_2], md2_transp);
  MD3Transpose16(pat->list[MD_3], md3_transp);
  MD4Transpose16(pat->list[MD_4], md4_transp);
  MD5Transpose16(pat->large_list[MD_5], md5_transp);

  index2 = index3 = index4 = index5 = 0;

  min2 = md2_transp[0];
  min3 = md3_transp[0] + md2_transp[0];
  min4 = static_cast<unsigned long long>(md4_transp[0]) + md3_transp[0] + md2_transp[0];
  min5 = md5_transp[0] + md4_transp[0] + md3_transp[0] + md2_transp[0];

  for (int i = 1; i < 16; i++) {
    tmp2 = md2_transp[i];
    if (min2 > tmp2){
      index2 = i;
      min2 = tmp2;
    }
    tmp3 = md3_transp[i] + md2_transp[i];
    if (min3 > tmp3){
      index3 = i;
      min3 = tmp3;
    }
    tmp4 = static_cast<unsigned long long>(md4_transp[i]) + md3_transp[i] + md2_transp[i];
    if (min4 > tmp4) {
      index4 = i;
      min4 = tmp4;
    }
    tmp5 = md5_transp[i] + md4_transp[i] + md3_transp[i] + md2_transp[i];
    if (min5 > tmp5){
      index5 = i;
      min5 = tmp5;
    }
  }

  hash_pat->list[MD_2] = MD2Hash(md2_transp[index2]);
  hash_pat->list[MD_3] = MD3Hash(md3_transp[index3]) ^ MD2Hash(md2_transp[index3]);
  hash_pat->list[MD_4] = MD4Hash(md4_transp[index4]) ^ MD3Hash(md3_transp[index4]) ^ MD2Hash(md2_transp[index4]);
  hash_pat->list[MD_5 + MD_MAX] = MD5Hash(md5_transp[index5]) ^ MD4Hash(md4_transp[index5]) ^ MD3Hash(md3_transp[index5]) ^ MD2Hash(md2_transp[index5]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %edi
leaq -0x50(%rbp), %rsi
callq 0x93060
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x90(%rbp), %rsi
callq 0x93360
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
leaq -0xd0(%rbp), %rsi
callq 0x93710
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x150(%rbp), %rsi
callq 0x93c90
movl $0x0, -0x190(%rbp)
movl $0x0, -0x18c(%rbp)
movl $0x0, -0x188(%rbp)
movl $0x0, -0x184(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x158(%rbp)
movl -0x90(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x160(%rbp)
movl -0xd0(%rbp), %eax
movl -0x90(%rbp), %ecx
addq %rcx, %rax
movl -0x50(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x170(%rbp)
movq -0x150(%rbp), %rax
movl -0xd0(%rbp), %ecx
addq %rcx, %rax
movl -0x90(%rbp), %ecx
addq %rcx, %rax
movl -0x50(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x180(%rbp)
movl $0x1, -0x194(%rbp)
cmpl $0x10, -0x194(%rbp)
jge 0x97f15
movslq -0x194(%rbp), %rax
movl -0x50(%rbp,%rax,4), %eax
movl %eax, -0x154(%rbp)
movl -0x158(%rbp), %eax
cmpl -0x154(%rbp), %eax
jbe 0x97dec
movl -0x194(%rbp), %eax
movl %eax, -0x184(%rbp)
movl -0x154(%rbp), %eax
movl %eax, -0x158(%rbp)
movslq -0x194(%rbp), %rax
movl -0x90(%rbp,%rax,4), %eax
movslq -0x194(%rbp), %rcx
addl -0x50(%rbp,%rcx,4), %eax
movl %eax, -0x15c(%rbp)
movl -0x160(%rbp), %eax
cmpl -0x15c(%rbp), %eax
jbe 0x97e31
movl -0x194(%rbp), %eax
movl %eax, -0x188(%rbp)
movl -0x15c(%rbp), %eax
movl %eax, -0x160(%rbp)
movslq -0x194(%rbp), %rax
movl -0xd0(%rbp,%rax,4), %eax
movslq -0x194(%rbp), %rcx
movl -0x90(%rbp,%rcx,4), %ecx
addq %rcx, %rax
movslq -0x194(%rbp), %rcx
movl -0x50(%rbp,%rcx,4), %ecx
addq %rcx, %rax
movq %rax, -0x168(%rbp)
movq -0x170(%rbp), %rax
cmpq -0x168(%rbp), %rax
jbe 0x97e8f
movl -0x194(%rbp), %eax
movl %eax, -0x18c(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x170(%rbp)
movslq -0x194(%rbp), %rax
movq -0x150(%rbp,%rax,8), %rax
movslq -0x194(%rbp), %rcx
movl -0xd0(%rbp,%rcx,4), %ecx
addq %rcx, %rax
movslq -0x194(%rbp), %rcx
movl -0x90(%rbp,%rcx,4), %ecx
addq %rcx, %rax
movslq -0x194(%rbp), %rcx
movl -0x50(%rbp,%rcx,4), %ecx
addq %rcx, %rax
movq %rax, -0x178(%rbp)
movq -0x180(%rbp), %rax
cmpq -0x178(%rbp), %rax
jbe 0x97eff
movl -0x194(%rbp), %eax
movl %eax, -0x190(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x180(%rbp)
jmp 0x97f01
movl -0x194(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x194(%rbp)
jmp 0x97da8
movslq -0x184(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x98070
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movslq -0x188(%rbp), %rax
movl -0x90(%rbp,%rax,4), %edi
callq 0x980d0
movq %rax, -0x1c8(%rbp)
movslq -0x188(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x98070
movq -0x1c8(%rbp), %rcx
xorq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movslq -0x18c(%rbp), %rax
movl -0xd0(%rbp,%rax,4), %edi
callq 0x98140
movq %rax, -0x1c0(%rbp)
movslq -0x18c(%rbp), %rax
movl -0x90(%rbp,%rax,4), %edi
callq 0x980d0
movq %rax, %rcx
movq -0x1c0(%rbp), %rax
xorq %rcx, %rax
movq %rax, -0x1b8(%rbp)
movslq -0x18c(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x98070
movq -0x1b8(%rbp), %rcx
xorq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movslq -0x190(%rbp), %rax
movq -0x150(%rbp,%rax,8), %rdi
callq 0x981b0
movq %rax, -0x1b0(%rbp)
movslq -0x190(%rbp), %rax
movl -0xd0(%rbp,%rax,4), %edi
callq 0x98140
movq %rax, %rcx
movq -0x1b0(%rbp), %rax
xorq %rcx, %rax
movq %rax, -0x1a8(%rbp)
movslq -0x190(%rbp), %rax
movl -0x90(%rbp,%rax,4), %edi
callq 0x980d0
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
xorq %rcx, %rax
movq %rax, -0x1a0(%rbp)
movslq -0x190(%rbp), %rax
movl -0x50(%rbp,%rax,4), %edi
callq 0x98070
movq -0x1a0(%rbp), %rcx
xorq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nopw %cs:(%rax,%rax)