#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int u_int8_t;
typedef int /*<<< orphan*/ u_int32_t;
typedef int /*<<< orphan*/ tempkey;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
u_int32_t do_hash(const void *key, u_int8_t len) {
  int i;
  u_int32_t *p;
  u_int32_t index = 0;
  u_int32_t tempkey;
  for (i = 0, p = (u_int32_t *)key; i < len / sizeof(tempkey); i++, p++) {
    memcpy(&tempkey, p, sizeof(tempkey));
    index ^= tempkey;
  }
  memcpy(&tempkey, p, len % (sizeof(tempkey)));
  index ^= tempkey;
  return index;
}


x86 assembly (clang, -O0):
<do_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movslq -0x10(%rbp),%rax
movslq -0xc(%rbp),%rcx
shr    $0x2,%rcx
cmp    %rcx,%rax
jae    117f <do_hash+0x6f>
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1135 <do_hash+0x25>
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
and    $0x3,%rax
mov    %eax,%edx
lea    -0x20(%rbp),%rdi
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_hash>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
cmp    $0x4,%esi
jae    112c <do_hash+0x1c>
xor    %r12d,%r12d
jmp    116f <do_hash+0x5f>
movslq %r14d,%rax
shr    $0x2,%rax
cmp    $0x2,%rax
mov    $0x1,%ebp
cmovae %rax,%rbp
xor    %r12d,%r12d
lea    0xc(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
xor    0xc(%rsp),%r12d
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
jne    1150 <do_hash+0x40>
and    $0x3,%r14d
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <memcpy@plt>
xor    0xc(%rsp),%r12d
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @do_hash(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %7
store i32 0, i32* %5
%9 = load i8*, i8** %3
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %6
br label %11
11: ; preds = %24, %2
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = udiv i64 %15, 4
%17 = icmp ult i64 %13, %16
br i1 %17, label %18, label %29
18: ; preds = %11
%19 = load i32*, i32** %6
%20 = call i32 @memcpy(i32* %8, i32* %19, i32 4)
%21 = load i32, i32* %8
%22 = load i32, i32* %7
%23 = xor i32 %22, %21
store i32 %23, i32* %7
br label %24
24: ; preds = %18
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
%27 = load i32*, i32** %6
%28 = getelementptr inbounds i32, i32* %27, i32 1
store i32* %28, i32** %6
br label %11
29: ; preds = %11
%30 = load i32*, i32** %6
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = urem i64 %32, 4
%34 = trunc i64 %33 to i32
%35 = call i32 @memcpy(i32* %8, i32* %30, i32 %34)
%36 = load i32, i32* %8
%37 = load i32, i32* %7
%38 = xor i32 %37, %36
store i32 %38, i32* %7
%39 = load i32, i32* %7
ret i32 %39
}

LLVM IR (-O2):
define i32 @do_hash(i8* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = bitcast i8* %0 to i32*
%6 = icmp ult i32 %1, 4
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = sext i32 %1 to i64
%9 = lshr i64 %8, 2
%10 = call i64 @llvm.umax.i64(i64 %9, i64 1)
br label %11
11: ; preds = %7, %11
%12 = phi i64 [ 0, %7 ], [ %18, %11 ]
%13 = phi i32 [ 0, %7 ], [ %17, %11 ]
%14 = phi i32* [ %5, %7 ], [ %19, %11 ]
%15 = call i32 @memcpy(i32* %3, i32* %14, i32 4)
%16 = load i32, i32* %3
%17 = xor i32 %16, %13
%18 = add nuw nsw i64 %12, 1
%19 = getelementptr inbounds i32, i32* %14, i64 1
%20 = icmp eq i64 %18, %10
br i1 %20, label %21, label %11
21: ; preds = %11, %2
%22 = phi i32* [ %5, %2 ], [ %19, %11 ]
%23 = phi i32 [ 0, %2 ], [ %17, %11 ]
%24 = and i32 %1, 3
%25 = call i32 @memcpy(i32* %3, i32* %22, i32 %24)
%26 = load i32, i32* %3
%27 = xor i32 %26, %23
ret i32 %27
}