#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 *, char *, int, int);
size_t simple_hash(void *_key) {
  const char *key = (const char *)_key;
  size_t hash = 0;
  while (*key) {
    hash += *key++;
  }
  printf("hash for '%s' is %i, bucket=%i\n", (char *)_key, (int)hash,
         (int)hash % 10);
  return hash;
}


x86 assembly (clang, -O0):
<simple_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1159 <simple_hash+0x49>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbq (%rax),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    112c <simple_hash+0x1c>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x1c(%rbp),%edx
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simple_hash>:
push   %rbx
mov    %rdi,%rsi
mov    (%rdi),%al
test   %al,%al
je     1134 <simple_hash+0x24>
lea    0x1(%rsi),%rcx
xor    %ebx,%ebx
movsbq %al,%rax
add    %rax,%rbx
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    1120 <simple_hash+0x10>
jmp    1136 <simple_hash+0x26>
xor    %ebx,%ebx
movslq %ebx,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %edx,%ecx
sub    %eax,%ecx
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [32 x i8] c"hash for '%s' is %i, bucket=%i\0A\00"
define i64 @simple_hash(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %11, %4 ], [ %2, %1 ]
%6 = phi i64 [ %10, %4 ], [ 0, %1 ]
%7 = phi i8* [ %8, %4 ], [ %0, %1 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = sext i8 %5 to i64
%10 = add i64 %6, %9
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %4, %1
%14 = phi i64 [ 0, %1 ], [ %10, %4 ]
%15 = trunc i64 %14 to i32
%16 = srem i32 %15, 10
%17 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %15, i32 %16)
ret i64 %14
}