// File: prakhar2808[P]DBEngine/dbengine/MurmurHash3.cc
// Function: MurmurHash3_x86_32(void const*, int, unsigned int, void*)
void MurmurHash3_x86_32 ( const void * key, int len,
                          uint32_t seed, void * out )
{
  const uint8_t * data = (const uint8_t*)key;
  const int nblocks = len / 4;

  uint32_t h1 = seed;

  const uint32_t c1 = 0xcc9e2d51;
  const uint32_t c2 = 0x1b873593;

  //----------
  // body

  const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);

  for(int i = -nblocks; i; i++)
  {
    uint32_t k1 = getblock32(blocks,i);

    k1 *= c1;
    k1 = ROTL32(k1,15);
    k1 *= c2;
    
    h1 ^= k1;
    h1 = ROTL32(h1,13); 
    h1 = h1*5+0xe6546b64;
  }

  //----------
  // tail

  const uint8_t * tail = (const uint8_t*)(data + nblocks*4);

  uint32_t k1 = 0;

  switch(len & 3)
  {
  case 3: k1 ^= tail[2] << 16;
  case 2: k1 ^= tail[1] << 8;
  case 1: k1 ^= tail[0];
          k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
  };

  //----------
  // finalization

  h1 ^= len;

  h1 = fmix32(h1);

  *(uint32_t*)out = h1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x20(%rbp)
movl %esi, -0x24(%rbp)
movl %edx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x24(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0xcc9e2d51, -0x44(%rbp) # imm = 0xCC9E2D51
movl $0x1b873593, -0x48(%rbp) # imm = 0x1B873593
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0x6e52
movq -0x50(%rbp), %rcx
movl -0x54(%rbp), %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x58(%rbp)
imull $0xcc9e2d51, -0x58(%rbp), %eax # imm = 0xCC9E2D51
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %edi
movl $0xf, %esi
callq 0x7d50
movl %eax, -0x58(%rbp)
imull $0x1b873593, -0x58(%rbp), %eax # imm = 0x1B873593
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
xorl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %edi
movl $0xd, %esi
callq 0x7d50
movl %eax, -0x40(%rbp)
imull $0x5, -0x40(%rbp), %eax
addl $0xe6546b64, %eax       # imm = 0xE6546B64
movl %eax, -0x40(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x6ddc
movq -0x38(%rbp), %rax
movl -0x3c(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x24(%rbp), %eax
andl $0x3, %eax
movl %eax, -0x68(%rbp)
subl $0x1, %eax
je 0x6eb3
jmp 0x6e7d
movl -0x68(%rbp), %eax
subl $0x2, %eax
je 0x6ea2
jmp 0x6e87
movl -0x68(%rbp), %eax
subl $0x3, %eax
jne 0x6eed
jmp 0x6e91
movq -0x60(%rbp), %rax
movzbl 0x2(%rax), %eax
shll $0x10, %eax
xorl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x60(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0x8, %eax
xorl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x60(%rbp), %rax
movzbl (%rax), %eax
xorl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
imull $0xcc9e2d51, -0x64(%rbp), %eax # imm = 0xCC9E2D51
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %edi
movl $0xf, %esi
callq 0x7d50
movl %eax, -0x64(%rbp)
imull $0x1b873593, -0x64(%rbp), %eax # imm = 0x1B873593
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
xorl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x24(%rbp), %eax
xorl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
shrl $0x10, %eax
xorl -0x4(%rbp), %eax
movl %eax, -0x4(%rbp)
imull $0x85ebca6b, -0x4(%rbp), %eax # imm = 0x85EBCA6B
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
shrl $0xd, %eax
xorl -0x4(%rbp), %eax
movl %eax, -0x4(%rbp)
imull $0xc2b2ae35, -0x4(%rbp), %eax # imm = 0xC2B2AE35
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
shrl $0x10, %eax
xorl -0x4(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)