// File: /workspace/github_cpp_makefile_star2_O2/BU-DiSC[P]BF-Shared-Hashing/hash/Crc32.cpp
// Function: crc32_16bytes(void const*, unsigned long, unsigned int)
uint32_t crc32_16bytes(const void* data, size_t length, uint32_t previousCrc32)
{
  uint32_t crc = ~previousCrc32; // same as previousCrc32 ^ 0xFFFFFFFF
  const uint32_t* current = (const uint32_t*) data;

  // enabling optimization (at least -O2) automatically unrolls the inner for-loop
  const size_t Unroll = 4;
  const size_t BytesAtOnce = 16 * Unroll;

  while (length >= BytesAtOnce)
  {
    for (size_t unrolling = 0; unrolling < Unroll; unrolling++)
    {
#if __BYTE_ORDER == __BIG_ENDIAN
    uint32_t one   = *current++ ^ swap(crc);
    uint32_t two   = *current++;
    uint32_t three = *current++;
    uint32_t four  = *current++;
    crc  = Crc32Lookup[ 0][ four         & 0xFF] ^
           Crc32Lookup[ 1][(four  >>  8) & 0xFF] ^
           Crc32Lookup[ 2][(four  >> 16) & 0xFF] ^
           Crc32Lookup[ 3][(four  >> 24) & 0xFF] ^
           Crc32Lookup[ 4][ three        & 0xFF] ^
           Crc32Lookup[ 5][(three >>  8) & 0xFF] ^
           Crc32Lookup[ 6][(three >> 16) & 0xFF] ^
           Crc32Lookup[ 7][(three >> 24) & 0xFF] ^
           Crc32Lookup[ 8][ two          & 0xFF] ^
           Crc32Lookup[ 9][(two   >>  8) & 0xFF] ^
           Crc32Lookup[10][(two   >> 16) & 0xFF] ^
           Crc32Lookup[11][(two   >> 24) & 0xFF] ^
           Crc32Lookup[12][ one          & 0xFF] ^
           Crc32Lookup[13][(one   >>  8) & 0xFF] ^
           Crc32Lookup[14][(one   >> 16) & 0xFF] ^
           Crc32Lookup[15][(one   >> 24) & 0xFF];
#else
    uint32_t one   = *current++ ^ crc;
    uint32_t two   = *current++;
    uint32_t three = *current++;
    uint32_t four  = *current++;
    crc  = Crc32Lookup[ 0][(four  >> 24) & 0xFF] ^
           Crc32Lookup[ 1][(four  >> 16) & 0xFF] ^
           Crc32Lookup[ 2][(four  >>  8) & 0xFF] ^
           Crc32Lookup[ 3][ four         & 0xFF] ^
           Crc32Lookup[ 4][(three >> 24) & 0xFF] ^
           Crc32Lookup[ 5][(three >> 16) & 0xFF] ^
           Crc32Lookup[ 6][(three >>  8) & 0xFF] ^
           Crc32Lookup[ 7][ three        & 0xFF] ^
           Crc32Lookup[ 8][(two   >> 24) & 0xFF] ^
           Crc32Lookup[ 9][(two   >> 16) & 0xFF] ^
           Crc32Lookup[10][(two   >>  8) & 0xFF] ^
           Crc32Lookup[11][ two          & 0xFF] ^
           Crc32Lookup[12][(one   >> 24) & 0xFF] ^
           Crc32Lookup[13][(one   >> 16) & 0xFF] ^
           Crc32Lookup[14][(one   >>  8) & 0xFF] ^
           Crc32Lookup[15][ one          & 0xFF];
#endif
    }

    length -= BytesAtOnce;
  }

  const uint8_t* currentChar = (const uint8_t*) current;
  // remaining 1 to 63 bytes (standard algorithm)
  while (length-- != 0)
    crc = (crc >> 8) ^ Crc32Lookup[0][(crc & 0xFF) ^ *currentChar++];

  return ~crc; // same as crc ^ 0xFFFFFFFF
}

// Assembly:
pushq %r14
pushq %rbx
movl %edx, %eax
notl %eax
leaq 0x275d(%rip), %rcx      # 0x23700
movl $0x3fc, %edx            # imm = 0x3FC
movl $0xff, %r8d
cmpq $0x40, %rsi
jb 0x210df
xorl %r9d, %r9d
cmpq $0x40, %r9
je 0x210d2
xorl (%rdi,%r9), %eax
movl 0xc(%rdi,%r9), %r11d
movl %r11d, %ebx
shrl $0x18, %ebx
movl %r11d, %r10d
shrl $0xe, %r10d
andl %edx, %r10d
movl 0x400(%r10,%rcx), %r10d
xorl (%rcx,%rbx,4), %r10d
movl %r11d, %ebx
shrl $0x8, %ebx
andl %r8d, %ebx
xorl 0x800(%rcx,%rbx,4), %r10d
movl 0x8(%rdi,%r9), %ebx
andl %r8d, %r11d
xorl 0xc00(%rcx,%r11,4), %r10d
movl %ebx, %r11d
shrl $0x18, %r11d
xorl 0x1000(%rcx,%r11,4), %r10d
movl 0x4(%rdi,%r9), %r11d
movl %ebx, %r14d
shrl $0xe, %r14d
andl %edx, %r14d
xorl 0x1400(%r14,%rcx), %r10d
movl %ebx, %r14d
shrl $0x8, %r14d
andl %r8d, %r14d
xorl 0x1800(%rcx,%r14,4), %r10d
andl %r8d, %ebx
xorl 0x1c00(%rcx,%rbx,4), %r10d
movl %r11d, %ebx
shrl $0x18, %ebx
xorl 0x2000(%rcx,%rbx,4), %r10d
movl %r11d, %ebx
shrl $0xe, %ebx
andl %edx, %ebx
xorl 0x2400(%rbx,%rcx), %r10d
movl %r11d, %ebx
shrl $0x8, %ebx
andl %r8d, %ebx
xorl 0x2800(%rcx,%rbx,4), %r10d
andl %r8d, %r11d
xorl 0x2c00(%rcx,%r11,4), %r10d
movl %eax, %r11d
shrl $0x18, %r11d
xorl 0x3000(%rcx,%r11,4), %r10d
movl %eax, %r11d
shrl $0xe, %r11d
andl %edx, %r11d
xorl 0x3400(%r11,%rcx), %r10d
movl %eax, %r11d
shrl $0x8, %r11d
andl %r8d, %r11d
xorl 0x3800(%rcx,%r11,4), %r10d
andl %r8d, %eax
xorl 0x3c00(%rcx,%rax,4), %r10d
addq $0x10, %r9
movl %r10d, %eax
jmp 0x20fbb
addq $0x40, %rdi
addq $-0x40, %rsi
jmp 0x20fae
xorl %edx, %edx
cmpq %rdx, %rsi
je 0x210fe
movzbl %al, %r8d
shrl $0x8, %eax
movzbl (%rdi,%rdx), %r9d
xorl %r8d, %r9d
xorl (%rcx,%r9,4), %eax
incq %rdx
jmp 0x210e1
notl %eax
popq %rbx
popq %r14
retq