#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 *, int, unsigned long, ...);
int hash() {
  unsigned char *str = "Start";
  unsigned long hash = 5381;
  int c;
  printf("Before %lu, 0x%lx\n", hash, hash);
  while (c = *str++) {
    hash = ((hash << 5) + hash) + c;
    printf("%c, %lu, 0x%lx\n", c, hash, hash);
  }
  return hash;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xee1(%rip),%rax
mov    %rax,-0x8(%rbp)
movq   $0x1505,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1196 <hash+0x86>
mov    -0x10(%rbp),%rax
shl    $0x5,%rax
add    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1143 <hash+0x33>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbx
lea    0xee8(%rip),%rdi
mov    $0x1505,%edx
mov    $0x1505,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee3(%rip),%rbx
mov    $0x2b5f8,%edx
mov    $0x2b5f8,%ecx
mov    %rbx,%rdi
mov    $0x53,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x59756c,%edx
mov    $0x59756c,%ecx
mov    %rbx,%rdi
mov    $0x74,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xb88234d,%edx
mov    $0xb88234d,%ecx
mov    %rbx,%rdi
mov    $0x61,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movabs $0x17c8c8d5f,%rcx
mov    %rbx,%rdi
mov    $0x72,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
movabs $0x310e1e39b3,%rcx
mov    %rbx,%rdi
mov    $0x74,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xe1e39b3,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str.1 = [19 x i8] c"Before %lu, 0x%lx\0A\00"
@.str.2 = [16 x i8] c"%c, %lu, 0x%lx\0A\00"
define i32 @hash() {
%1 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 5381, i64 5381)
%2 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 83, i64 177656, i64 177656)
%3 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 116, i64 5862764, i64 5862764)
%4 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 97, i64 193471309, i64 193471309)
%5 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 114, i64 6384553311, i64 6384553311)
%6 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 116, i64 210690259379, i64 210690259379)
ret i32 236861875
}