#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 tolower(char const);
unsigned int hash(const char *key) {
  unsigned int h = 0;
  for (unsigned int i = 0; i < 45; ++i) {
    if (key[i] == '\0') {
      break;
    }
    h = 101 * h + tolower(key[i]);
  }
  return (h ^ (h >> 16)) % 100000;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x2d,-0x10(%rbp)
jae    117c <hash+0x6c>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    114d <hash+0x3d>
jmp    117c <hash+0x6c>
imul   $0x65,-0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <hash+0x1a>
mov    -0xc(%rbp),%eax
mov    -0xc(%rbp),%ecx
shr    $0x10,%ecx
xor    %ecx,%eax
mov    $0x186a0,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%ecx
test   %cl,%cl
je     1140 <hash+0x30>
imul   $0x65,%eax,%ebp
movsbl %cl,%edi
call   1030 <tolower@plt>
add    %ebp,%eax
add    $0x1,%rbx
cmp    $0x2d,%rbx
jne    1120 <hash+0x10>
mov    %eax,%ecx
shr    $0x10,%ecx
xor    %eax,%ecx
mov    %ecx,%eax
shr    $0x5,%eax
imul   $0xa7c5ac5,%rax,%rax
shr    $0x27,%rax
imul   $0x186a0,%eax,%eax
sub    %eax,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %27, %1
%6 = load i32, i32* %4
%7 = icmp ult i32 %6, 45
br i1 %7, label %8, label %30
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load i32, i32* %4
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %8
br label %30
17: ; preds = %8
%18 = load i32, i32* %3
%19 = mul i32 101, %18
%20 = load i8*, i8** %2
%21 = load i32, i32* %4
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @tolower(i8 signext %24)
%26 = add i32 %19, %25
store i32 %26, i32* %3
br label %27
27: ; preds = %17
%28 = load i32, i32* %4
%29 = add i32 %28, 1
store i32 %29, i32* %4
br label %5
30: ; preds = %16, %5
%31 = load i32, i32* %3
%32 = load i32, i32* %3
%33 = lshr i32 %32, 16
%34 = xor i32 %31, %33
%35 = urem i32 %34, 100000
ret i32 %35
}

LLVM IR (-O2):
define i32 @hash(i8* nocapture %0) {
br label %2
2: ; preds = %1, %8
%3 = phi i64 [ 0, %1 ], [ %12, %8 ]
%4 = phi i32 [ 0, %1 ], [ %11, %8 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = mul i32 %4, 101
%10 = tail call i32 @tolower(i8 signext %6)
%11 = add i32 %10, %9
%12 = add nuw nsw i64 %3, 1
%13 = icmp eq i64 %12, 45
br i1 %13, label %14, label %2
14: ; preds = %2, %8
%15 = phi i32 [ %4, %2 ], [ %11, %8 ]
%16 = lshr i32 %15, 16
%17 = xor i32 %16, %15
%18 = urem i32 %17, 100000
ret i32 %18
}