#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(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ILibGetHashValue(void *key, int keylength) {
  int HashValue = 0;
  char TempValue[4];
  if (keylength <= 4) {
    memset(TempValue, 0, 4);
    memcpy(TempValue, key, keylength);
    HashValue = *((int *)TempValue);
  } else {
    memcpy(TempValue, key, 4);
    HashValue = *((int *)TempValue);
    memcpy(TempValue, (char *)key + (keylength - 4), 4);
    HashValue = HashValue ^ (*((int *)TempValue));
    if (keylength >= 10) {
      memcpy(TempValue, (char *)key + (keylength / 2), 4);
      HashValue = HashValue ^ (*((int *)TempValue));
    }
  }
  return (HashValue);
}


x86 assembly (clang, -O0):
<ILibGetHashValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0xc(%rbp)
jg     116b <ILibGetHashValue+0x4b>
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11e3 <ILibGetHashValue+0xc3>
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
cltq
add    %rax,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%eax
xor    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0xc(%rbp)
jl     11de <ILibGetHashValue+0xbe>
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
add    %rax,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%eax
xor    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11e3 <ILibGetHashValue+0xc3>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ILibGetHashValue>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
cmp    $0x4,%esi
jg     1158 <ILibGetHashValue+0x38>
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    0x4(%rsp),%ebp
jmp    11a8 <ILibGetHashValue+0x88>
lea    0x4(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    0x4(%rsp),%ebp
lea    -0x4(%rbx),%esi
add    %r14,%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
xor    0x4(%rsp),%ebp
cmp    $0xa,%ebx
jb     11a8 <ILibGetHashValue+0x88>
shr    %ebx
add    %rbx,%r14
lea    0x4(%rsp),%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
xor    0x4(%rsp),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ILibGetHashValue(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 4
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 4)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = call i32 @memcpy(i8* %12, i8* %13, i32 %14)
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
store i32 %18, i32* %5
br label %54
19: ; preds = %2
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = call i32 @memcpy(i8* %20, i8* %21, i32 4)
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%24 = bitcast i8* %23 to i32*
%25 = load i32, i32* %24
store i32 %25, i32* %5
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = call i32 @memcpy(i8* %26, i8* %31, i32 4)
%33 = load i32, i32* %5
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%35 = bitcast i8* %34 to i32*
%36 = load i32, i32* %35
%37 = xor i32 %33, %36
store i32 %37, i32* %5
%38 = load i32, i32* %4
%39 = icmp sge i32 %38, 10
br i1 %39, label %40, label %53
40: ; preds = %19
%41 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%42 = load i8*, i8** %3
%43 = load i32, i32* %4
%44 = sdiv i32 %43, 2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = call i32 @memcpy(i8* %41, i8* %46, i32 4)
%48 = load i32, i32* %5
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%50 = bitcast i8* %49 to i32*
%51 = load i32, i32* %50
%52 = xor i32 %48, %51
store i32 %52, i32* %5
br label %53
53: ; preds = %40, %19
br label %54
54: ; preds = %53, %9
%55 = load i32, i32* %5
ret i32 %55
}

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