#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 */
unsigned int tolower(int /*<<< orphan*/);
unsigned int hash_function(const char *input, unsigned int logsize) {
  unsigned int hash = 0x811C9DC5;
  while (*input != '\0') {
    hash ^= tolower(*(input++));
    hash *= 0x01000193;
  }
  return ((hash >> logsize) ^ hash) & ((1 << logsize) - 1);
}


x86 assembly (clang, -O0):
<hash_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x811c9dc5,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1162 <hash_function+0x52>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
xor    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
imul   $0x1000193,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <hash_function+0x16>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
shr    %cl,%eax
xor    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    $0x1,%ecx
and    %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_function>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    (%rdi),%al
test   %al,%al
je     114d <hash_function+0x3d>
mov    %rdi,%rbx
add    $0x1,%rbx
mov    $0x811c9dc5,%ebp
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <tolower@plt>
xor    %ebp,%eax
imul   $0x1000193,%eax,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <hash_function+0x20>
jmp    1152 <hash_function+0x42>
mov    $0x811c9dc5,%ebp
mov    %ebp,%edx
mov    %r14d,%ecx
shr    %cl,%edx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    %ebp,%edx
not    %eax
and    %edx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hash_function(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -2128831035, i32* %5
br label %6
6: ; preds = %11, %2
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
%14 = load i8, i8* %12
%15 = sext i8 %14 to i32
%16 = call i32 @tolower(i32 %15)
%17 = load i32, i32* %5
%18 = xor i32 %17, %16
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = mul i32 %19, 16777619
store i32 %20, i32* %5
br label %6
21: ; preds = %6
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = lshr i32 %22, %23
%25 = load i32, i32* %5
%26 = xor i32 %24, %25
%27 = load i32, i32* %4
%28 = shl i32 1, %27
%29 = sub nsw i32 %28, 1
%30 = and i32 %26, %29
ret i32 %30
}

LLVM IR (-O2):
define i32 @hash_function(i8* nocapture %0, i32 %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %2, %5
%6 = phi i8 [ %14, %5 ], [ %3, %2 ]
%7 = phi i32 [ %13, %5 ], [ -2128831035, %2 ]
%8 = phi i8* [ %10, %5 ], [ %0, %2 ]
%9 = sext i8 %6 to i32
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = tail call i32 @tolower(i32 %9)
%12 = xor i32 %11, %7
%13 = mul i32 %12, 16777619
%14 = load i8, i8* %10
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %5
16: ; preds = %5, %2
%17 = phi i32 [ -2128831035, %2 ], [ %13, %5 ]
%18 = lshr i32 %17, %1
%19 = xor i32 %18, %17
%20 = shl nsw i32 -1, %1
%21 = xor i32 %20, -1
%22 = and i32 %19, %21
ret i32 %22
}