#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 *, unsigned int);
unsigned int strlen(char const *);
unsigned int hash_keyval(const char *key) {
  unsigned int hash = 0;
  unsigned i;
  unsigned int len = strlen(key);
  for (i = 0; i < len / sizeof(unsigned int); ++i) {
    unsigned int val;
    memcpy(&val, key, sizeof(unsigned int));
    hash = hash * 2147059363 + val;
    key += sizeof(unsigned int);
  }
  {
    unsigned int val = 0;
    memcpy(&val, key, len % sizeof(unsigned int));
    hash = hash * 2147059363 + val;
  }
  hash += (hash >> 17);
  return hash;
}


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

x86 assembly (clang, -O2):
<hash_keyval>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r14d
xor    %ebp,%ebp
cmp    $0x4,%eax
jb     1173 <hash_keyval+0x53>
mov    %r14d,%ebx
shr    $0x2,%ebx
xor    %ebp,%ebp
lea    0xc(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    0xc(%rsp),%ebp
add    $0x4,%r12
imul   $0x7ff986a3,%ebp,%ebp
add    $0xffffffff,%ebx
jne    1150 <hash_keyval+0x30>
movl   $0x0,0x8(%rsp)
and    $0x3,%r14d
lea    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
add    0x8(%rsp),%ebp
mov    %ebp,%eax
shr    $0x11,%eax
add    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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