// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %rbx
movq %rdi, %r12
movq %rsp, %r13
leaq 0x40(%rsp), %rbp
leaq 0x80(%rsp), %r15
leaq 0xc0(%rsp), %r14
movl (%rdi), %edi
movq %r13, %rsi
callq 0x374d5
movl 0x4(%r12), %edi
movq %rbp, %rsi
callq 0x3769e
movl 0x8(%r12), %edi
movq %r15, %rsi
callq 0x37875
movq 0x10(%r12), %rdi
movq %r14, %rsi
callq 0x37b6b
movl (%r13), %eax
movl (%rbp), %ecx
leal (%rcx,%rax), %edx
movl (%r15), %esi
addq %rax, %rcx
addq %rsi, %rcx
movq (%r14), %rsi
addq %rcx, %rsi
xorl %edi, %edi
pushq $-0xf
popq %r8
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebp, %ebp
testq %r8, %r8
je 0x39120
movl 0x40(%rsp,%r8,4), %r10d
leal 0x10(%r8), %r9d
cmpl %r10d, %eax
cmovael %r10d, %eax
cmoval %r9d, %edi
movl 0x80(%rsp,%r8,4), %r11d
leal (%r11,%r10), %r12d
cmpl %r12d, %edx
cmovael %r12d, %edx
cmoval %r9d, %r14d
movl 0xc0(%rsp,%r8,4), %r12d
addq %r10, %r11
addq %r12, %r11
cmpq %r11, %rcx
cmoval %r9d, %r15d
cmovaeq %r11, %rcx
addq 0x140(%rsp,%r8,8), %r11
cmpq %r11, %rsi
cmovaeq %r11, %rsi
cmoval %r9d, %ebp
incq %r8
jmp 0x390bf
movslq %edi, %rax
movl (%rsp,%rax,4), %edi
callq 0x391fa
movq %rax, (%rbx)
movslq %r14d, %r12
movl 0x40(%rsp,%r12,4), %edi
callq 0x39221
movq %rax, %r14
movl (%rsp,%r12,4), %edi
callq 0x391fa
xorq %r14, %rax
movq %rax, 0x8(%rbx)
movslq %r15d, %r12
movl 0x80(%rsp,%r12,4), %edi
callq 0x39248
movq %rax, %r14
movl 0x40(%rsp,%r12,4), %edi
callq 0x39221
movq %rax, %r15
xorq %r14, %r15
movl (%rsp,%r12,4), %edi
callq 0x391fa
xorq %r15, %rax
movq %rax, 0x10(%rbx)
movslq %ebp, %r13
movq 0xc0(%rsp,%r13,8), %rax
leaq 0xe94d(%rip), %rdx      # 0x47ae0
xorl %ecx, %ecx
xorl %r12d, %r12d
cmpq $0x28, %rcx
je 0x391b5
movq %rax, %rsi
shrq %cl, %rsi
andl $0x3, %esi
xorq (%rdx,%rsi,8), %r12
addq $0x2, %rcx
addq $0x20, %rdx
jmp 0x39198
movl 0x80(%rsp,%r13,4), %edi
callq 0x39248
movq %rax, %r14
movl 0x40(%rsp,%r13,4), %edi
callq 0x39221
movq %rax, %r15
movl (%rsp,%r13,4), %edi
callq 0x391fa
xorq %r14, %r15
xorq %r12, %rax
xorq %r15, %rax
movq %rax, 0x18(%rbx)
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq