// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
notl %edx
leaq 0x2df2(%rip), %rcx      # 0x2a750
cmpq $0x40, %rsi
jb 0x27a9a
movl $0x3fc, %eax            # imm = 0x3FC
movl $0xff, %r8d
xorl %r9d, %r9d
xorl (%rdi,%r9), %edx
movl 0xc(%rdi,%r9), %r10d
movl %r10d, %r11d
shrl $0x18, %r11d
movl %r10d, %ebx
shrl $0xe, %ebx
andl %eax, %ebx
movl %edx, %r14d
movl %edx, %r15d
movl %edx, %r12d
movl 0x400(%rbx,%rcx), %ebx
xorl (%rcx,%r11,4), %ebx
movl %r10d, %r11d
shrl $0x8, %r11d
andl %r8d, %r11d
xorl 0x800(%rcx,%r11,4), %ebx
movl 0x8(%rdi,%r9), %r11d
andl %r8d, %r10d
xorl 0xc00(%rcx,%r10,4), %ebx
movl %r11d, %r10d
shrl $0x18, %r10d
xorl 0x1000(%rcx,%r10,4), %ebx
movl %r11d, %r10d
shrl $0xe, %r10d
andl %eax, %r10d
xorl 0x1400(%r10,%rcx), %ebx
movl %r11d, %r10d
shrl $0x8, %r10d
andl %r8d, %r10d
xorl 0x1800(%rcx,%r10,4), %ebx
movl 0x4(%rdi,%r9), %r10d
andl %r8d, %r11d
xorl 0x1c00(%rcx,%r11,4), %ebx
movl %r10d, %r11d
shrl $0x18, %r11d
xorl 0x2000(%rcx,%r11,4), %ebx
movl %r10d, %r11d
shrl $0xe, %r11d
andl %eax, %r11d
xorl 0x2400(%r11,%rcx), %ebx
movl %r10d, %r11d
shrl $0x8, %r11d
andl %r8d, %r11d
xorl 0x2800(%rcx,%r11,4), %ebx
andl %r8d, %r10d
xorl 0x2c00(%rcx,%r10,4), %ebx
shrl $0x18, %edx
xorl 0x3000(%rcx,%rdx,4), %ebx
shrl $0xe, %r14d
andl %eax, %r14d
xorl 0x3400(%r14,%rcx), %ebx
shrl $0x8, %r15d
andl %r8d, %r15d
xorl 0x3800(%rcx,%r15,4), %ebx
andl %r8d, %r12d
movl %ebx, %edx
xorl 0x3c00(%rcx,%r12,4), %edx
addq $0x10, %r9
cmpq $0x40, %r9
jne 0x27976
addq $0x40, %rdi
addq $-0x40, %rsi
cmpq $0x3f, %rsi
ja 0x27973
testq %rsi, %rsi
je 0x27ac2
xorl %r8d, %r8d
movl %edx, %eax
shrl $0x8, %eax
movzbl %dl, %edx
movzbl (%rdi,%r8), %r9d
xorl %edx, %r9d
xorl (%rcx,%r9,4), %eax
incq %r8
movl %eax, %edx
cmpq %r8, %rsi
jne 0x27aa4
jmp 0x27ac4
movl %edx, %eax
notl %eax
popq %rbx
popq %r12
popq %r14
popq %r15
retq