#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 */

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned int *, char const *, int const);
unsigned int hash_keyval(char const *key, int const size) {
  unsigned int const magic = 2147059363;
  unsigned int hash = 0;
  unsigned int i;
  for (i = 0; i < size / sizeof(unsigned int); ++i) {
    unsigned int val;
    memcpy(&val, key, sizeof(unsigned int));
    hash = hash * magic + val;
    key += sizeof(unsigned int);
  }
  {
    unsigned int val = 0;
    memcpy(&val, key, size % sizeof(unsigned int));
    hash = hash * magic + val;
  }
  return hash + (hash >> 17);
}


x86 assembly (clang, -O0):
<hash_keyval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x7ff986a3,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movslq -0xc(%rbp),%rcx
shr    $0x2,%rcx
cmp    %rcx,%rax
jae    1181 <hash_keyval+0x71>
mov    -0x8(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
mov    $0x4,%edx
call   1030 <memcpy@plt>
imul   $0x7ff986a3,-0x14(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1134 <hash_keyval+0x24>
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
and    $0x3,%rax
mov    %eax,%edx
lea    -0x20(%rbp),%rdi
call   1030 <memcpy@plt>
imul   $0x7ff986a3,-0x14(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
shr    $0x11,%ecx
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_keyval>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r13
xor    %ebp,%ebp
cmp    $0x4,%esi
jb     1168 <hash_keyval+0x58>
movslq %r14d,%r12
shr    $0x2,%r12
xor    %ebp,%ebp
mov    $0x1,%ebx
lea    0x4(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
add    0x4(%rsp),%ebp
add    $0x4,%r13
imul   $0x7ff986a3,%ebp,%ebp
mov    %ebx,%eax
add    $0x1,%ebx
cmp    %rax,%r12
ja     1140 <hash_keyval+0x30>
movl   $0x0,(%rsp)
and    $0x3,%r14d
mov    %rsp,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   1030 <memcpy@plt>
add    (%rsp),%ebp
mov    %ebp,%eax
shr    $0x11,%eax
add    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hash_keyval(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 2147059363, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %10
10: ; preds = %26, %2
%11 = load i32, i32* %7
%12 = zext i32 %11 to i64
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = udiv i64 %14, 4
%16 = icmp ult i64 %12, %15
br i1 %16, label %17, label %29
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = call i32 @memcpy(i32* %8, i8* %18, i32 4)
%20 = load i32, i32* %6
%21 = mul i32 %20, 2147059363
%22 = load i32, i32* %8
%23 = add i32 %21, %22
store i32 %23, i32* %6
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 4
store i8* %25, i8** %3
br label %26
26: ; preds = %17
%27 = load i32, i32* %7
%28 = add i32 %27, 1
store i32 %28, i32* %7
br label %10
29: ; preds = %10
store i32 0, i32* %9
%30 = load i8*, i8** %3
%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* %9, i8* %30, i32 %34)
%36 = load i32, i32* %6
%37 = mul i32 %36, 2147059363
%38 = load i32, i32* %9
%39 = add i32 %37, %38
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = load i32, i32* %6
%42 = lshr i32 %41, 17
%43 = add i32 %40, %42
ret i32 %43
}

LLVM IR (-O2):
define i32 @hash_keyval(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = sext i32 %1 to i64
%6 = lshr i64 %5, 2
%7 = icmp ult i32 %1, 4
br i1 %7, label %22, label %8
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
br label %10
10: ; preds = %8, %10
%11 = phi i32 [ 0, %8 ], [ %18, %10 ]
%12 = phi i32 [ 0, %8 ], [ %19, %10 ]
%13 = phi i8* [ %0, %8 ], [ %17, %10 ]
%14 = call i32 @memcpy(i32* %3, i8* %13, i32 4)
%15 = load i32, i32* %3
%16 = add i32 %15, %12
%17 = getelementptr inbounds i8, i8* %13, i64 4
%18 = add i32 %11, 1
%19 = mul i32 %16, 2147059363
%20 = zext i32 %18 to i64
%21 = icmp ugt i64 %6, %20
br i1 %21, label %10, label %22
22: ; preds = %10, %2
%23 = phi i8* [ %0, %2 ], [ %17, %10 ]
%24 = phi i32 [ 0, %2 ], [ %19, %10 ]
%25 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%26 = and i32 %1, 3
%27 = call i32 @memcpy(i32* %4, i8* %23, i32 %26)
%28 = load i32, i32* %4
%29 = add i32 %28, %24
%30 = lshr i32 %29, 17
%31 = add i32 %30, %29
ret i32 %31
}