#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 toupper(int /*<<< orphan*/);
unsigned int hash_string(const char *key) {
  unsigned int hash = 0;
  while (*key) {
    hash = ((hash << 5) ^ (hash >> 27)) ^ toupper(*key++);
  }
  hash = hash % 37;
  return hash;
}


x86 assembly (clang, -O0):
<hash_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1167 <hash_string+0x57>
mov    -0xc(%rbp),%eax
shl    $0x5,%eax
mov    -0xc(%rbp),%ecx
shr    $0x1b,%ecx
xor    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
xor    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <hash_string+0x13>
mov    -0xc(%rbp),%eax
mov    $0x25,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_string>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%cl
test   %cl,%cl
je     116e <hash_string+0x5e>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ebp
rol    $0x5,%ebp
movsbl %cl,%edi
call   1030 <toupper@plt>
xor    %ebp,%eax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1130 <hash_string+0x20>
mov    %eax,%ecx
mov    $0xbacf914d,%edx
imul   %rcx,%rdx
shr    $0x20,%rdx
mov    %eax,%ecx
sub    %edx,%ecx
shr    %ecx
add    %edx,%ecx
shr    $0x5,%ecx
lea    (%rcx,%rcx,8),%edx
lea    (%rcx,%rdx,4),%ecx
sub    %ecx,%eax
jmp    1170 <hash_string+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hash_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %8, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = load i32, i32* %3
%10 = shl i32 %9, 5
%11 = load i32, i32* %3
%12 = lshr i32 %11, 27
%13 = xor i32 %10, %12
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %2
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
%18 = call i32 @toupper(i32 %17)
%19 = xor i32 %13, %18
store i32 %19, i32* %3
br label %4
20: ; preds = %4
%21 = load i32, i32* %3
%22 = urem i32 %21, 37
store i32 %22, i32* %3
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
define i32 @hash_string(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %13, %4 ], [ %2, %1 ]
%6 = phi i32 [ %12, %4 ], [ 0, %1 ]
%7 = phi i8* [ %9, %4 ], [ %0, %1 ]
%8 = tail call i32 @llvm.fshl.i32(i32 %6, i32 %6, i32 5)
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = sext i8 %5 to i32
%11 = tail call i32 @toupper(i32 %10)
%12 = xor i32 %11, %8
%13 = load i8, i8* %9
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %4
15: ; preds = %4
%16 = urem i32 %12, 37
br label %17
17: ; preds = %15, %1
%18 = phi i32 [ 0, %1 ], [ %16, %15 ]
ret i32 %18
}