#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*/ printf(char *, unsigned int);
unsigned hash(char *s) {
  unsigned hashval;
  unsigned result;
  for (hashval = 0; *s != '\0'; s++) {
    hashval = *s + 31 * hashval;
  }
  result = hashval % 101;
  printf("hash result: %d\n", result);
  return result;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1154 <hash+0x44>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
imul   $0x1f,-0xc(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <hash+0x13>
mov    -0xc(%rbp),%eax
mov    $0x65,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1158 <hash+0x48>
add    $0x1,%rdi
xor    %ebx,%ebx
nopl   (%rax)
movsbl %al,%eax
mov    %ebx,%ecx
shl    $0x5,%ecx
sub    %ebx,%ecx
mov    %ecx,%ebx
add    %eax,%ebx
movzbl (%rdi),%eax
add    $0x1,%rdi
test   %al,%al
jne    1120 <hash+0x10>
mov    %ebx,%eax
imul   $0x446f8657,%rax,%rax
shr    $0x20,%rax
mov    %ebx,%ecx
sub    %eax,%ecx
shr    %ecx
add    %eax,%ecx
shr    $0x6,%ecx
imul   $0x65,%ecx,%eax
sub    %eax,%ebx
jmp    115a <hash+0x4a>
xor    %ebx,%ebx
lea    0xe9f(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"hash result: %d\0A\00"
define i32 @hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %5
5: ; preds = %17, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = load i32, i32* %3
%15 = mul i32 31, %14
%16 = add i32 %13, %15
store i32 %16, i32* %3
br label %17
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %2
br label %5
20: ; preds = %5
%21 = load i32, i32* %3
%22 = urem i32 %21, 101
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@.str = [17 x i8] c"hash result: %d\0A\00"
define i32 @hash(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %12, %4 ], [ %2, %1 ]
%6 = phi i8* [ %11, %4 ], [ %0, %1 ]
%7 = phi i32 [ %10, %4 ], [ 0, %1 ]
%8 = sext i8 %5 to i32
%9 = mul i32 %7, 31
%10 = add i32 %9, %8
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = urem i32 %10, 101
br label %16
16: ; preds = %14, %1
%17 = phi i32 [ 0, %1 ], [ %15, %14 ]
%18 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %17)
ret i32 %17
}