// File: /workspace/github_cpp_makefile_star2_O3/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 0x4f4d8
movl 0x4(%r12), %edi
movq %rbp, %rsi
callq 0x4f6bd
movl 0x8(%r12), %edi
movq %r15, %rsi
callq 0x4f8b0
movq 0x10(%r12), %rdi
movq %r14, %rsi
callq 0x4fbbf
movl (%r13), %ecx
movl (%rbp), %edi
leal (%rdi,%rcx), %r8d
movl (%r15), %eax
addq %rcx, %rdi
addq %rax, %rdi
movq (%r14), %r9
addq %rdi, %r9
xorl %r11d, %r11d
xorl %eax, %eax
xorl %edx, %edx
xorl %esi, %esi
xorl %r10d, %r10d
movl 0x4(%rsp,%r11,4), %r15d
leaq 0x1(%r11), %r14
cmpl %r15d, %ecx
cmovael %r15d, %ecx
cmoval %r14d, %r10d
movl 0x44(%rsp,%r11,4), %r12d
leal (%r12,%r15), %ebp
cmpl %ebp, %r8d
cmovael %ebp, %r8d
cmoval %r14d, %esi
movl 0x84(%rsp,%r11,4), %r13d
addq %r15, %r12
addq %r13, %r12
cmpq %r12, %rdi
cmoval %r14d, %edx
cmovaeq %r12, %rdi
addq 0xc8(%rsp,%r11,8), %r12
cmpq %r12, %r9
cmoval %r14d, %eax
cmovaeq %r12, %r9
movq %r14, %r11
cmpq $0xf, %r14
jne 0x51ab6
movslq %r10d, %rcx
movl (%rsp,%rcx,4), %edi
leaq 0xeba0(%rip), %r8       # 0x606c0
xorl %ecx, %ecx
xorl %r9d, %r9d
movl %edi, %r10d
shrl %cl, %r10d
andl $0x3, %r10d
xorq (%r8,%r10,8), %r9
addq $0x2, %rcx
addq $0x20, %r8
cmpq $0x18, %rcx
jne 0x51b25
movq %r9, (%rbx)
movslq %esi, %rdi
movl 0x40(%rsp,%rdi,4), %r8d
leaq 0xeced(%rip), %r9       # 0x60840
xorl %ecx, %ecx
xorl %esi, %esi
movl %r8d, %r10d
shrl %cl, %r10d
andl $0x3, %r10d
xorq (%r9,%r10,8), %rsi
addq $0x2, %rcx
addq $0x20, %r9
cmpq $0x18, %rcx
jne 0x51b57
movl (%rsp,%rdi,4), %edi
leaq 0xeb43(%rip), %r8       # 0x606c0
xorl %ecx, %ecx
xorl %r9d, %r9d
movl %edi, %r10d
shrl %cl, %r10d
andl $0x3, %r10d
xorq (%r8,%r10,8), %r9
addq $0x2, %rcx
addq $0x20, %r8
cmpq $0x18, %rcx
jne 0x51b82
xorq %rsi, %r9
movq %r9, 0x8(%rbx)
movslq %edx, %rsi
movl 0x80(%rsp,%rsi,4), %edi
leaq 0xee0a(%rip), %r8       # 0x609c0
xorl %ecx, %ecx
xorl %edx, %edx
movl %edi, %r9d
shrl %cl, %r9d
andl $0x3, %r9d
xorq (%r8,%r9,8), %rdx
addq $0x2, %rcx
addq $0x20, %r8
cmpq $0x20, %rcx
jne 0x51bba
movl 0x40(%rsp,%rsi,4), %r8d
leaq 0xec5e(%rip), %r9       # 0x60840
xorl %ecx, %ecx
xorl %edi, %edi
movl %r8d, %r10d
shrl %cl, %r10d
andl $0x3, %r10d
xorq (%r9,%r10,8), %rdi
addq $0x2, %rcx
addq $0x20, %r9
cmpq $0x18, %rcx
jne 0x51be6
movl (%rsp,%rsi,4), %esi
leaq 0xeab4(%rip), %r8       # 0x606c0
xorl %ecx, %ecx
xorl %r9d, %r9d
movl %esi, %r10d
shrl %cl, %r10d
andl $0x3, %r10d
xorq (%r8,%r10,8), %r9
addq $0x2, %rcx
addq $0x20, %r8
cmpq $0x18, %rcx
jne 0x51c11
xorq %rdx, %rdi
xorq %r9, %rdi
movq %rdi, 0x10(%rbx)
movslq %eax, %rdx
movq 0xc0(%rsp,%rdx,8), %rsi
leaq 0xef77(%rip), %rdi      # 0x60bc0
xorl %ecx, %ecx
xorl %eax, %eax
movq %rsi, %r8
shrq %cl, %r8
andl $0x3, %r8d
xorq (%rdi,%r8,8), %rax
addq $0x2, %rcx
addq $0x20, %rdi
cmpq $0x28, %rcx
jne 0x51c4d
movl 0x80(%rsp,%rdx,4), %edi
leaq 0xed49(%rip), %r8       # 0x609c0
xorl %ecx, %ecx
xorl %esi, %esi
movl %edi, %r9d
shrl %cl, %r9d
andl $0x3, %r9d
xorq (%r8,%r9,8), %rsi
addq $0x2, %rcx
addq $0x20, %r8
cmpq $0x20, %rcx
jne 0x51c7b
movl 0x40(%rsp,%rdx,4), %r8d
leaq 0xeb9d(%rip), %r9       # 0x60840
xorl %ecx, %ecx
xorl %edi, %edi
movl %r8d, %r10d
shrl %cl, %r10d
andl $0x3, %r10d
xorq (%r9,%r10,8), %rdi
addq $0x2, %rcx
addq $0x20, %r9
cmpq $0x18, %rcx
jne 0x51ca7
movl (%rsp,%rdx,4), %r8d
leaq 0xe9f2(%rip), %r9       # 0x606c0
xorl %ecx, %ecx
xorl %edx, %edx
movl %r8d, %r10d
shrl %cl, %r10d
andl $0x3, %r10d
xorq (%r9,%r10,8), %rdx
addq $0x2, %rcx
addq $0x20, %r9
cmpq $0x18, %rcx
jne 0x51cd2
xorq %rax, %rsi
xorq %rdi, %rsi
xorq %rdx, %rsi
movq %rsi, 0x18(%rbx)
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq