#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 strlen(char *);
unsigned long long getHash(char *str) {
  unsigned long long hash = 17;
  int i;
  for (i = 0; i < strlen(str); i++) {
    hash = ((int)str[i] + (31 * hash)) % (unsigned long long)1e10;
  }
  return hash;
}


x86 assembly (clang, -O0):
<getHash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x11,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    117e <getHash+0x6e>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cltq
imul   $0x1f,-0x10(%rbp),%rcx
add    %rcx,%rax
movabs $0x2540be400,%rcx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112b <getHash+0x1b>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHash>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1189 <getHash+0x79>
mov    $0x11,%eax
xor    %r15d,%r15d
movabs $0xdbe6fecebdedd5bf,%r12
fe e6 db
movabs $0x2540be400,%r13
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbq (%r14,%r15,1),%rcx
shl    $0x5,%rbx
sub    %rax,%rbx
add    %rcx,%rbx
mov    %rbx,%rax
mul    %r12
shr    $0x21,%rdx
imul   %r13,%rdx
sub    %rdx,%rbx
add    $0x1,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
mov    %rbx,%rax
cmp    %rcx,%r15
jl     1150 <getHash+0x40>
jmp    118e <getHash+0x7e>
mov    $0x11,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @getHash(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i8* %0, i8** %2
store i64 17, i64* %3
store i32 0, i32* %4
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* %4
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = icmp slt i32 %6, %8
br i1 %9, label %10, label %25
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = sext i32 %16 to i64
%18 = load i64, i64* %3
%19 = mul i64 31, %18
%20 = add i64 %17, %19
%21 = urem i64 %20, 10000000000
store i64 %21, i64* %3
br label %22
22: ; preds = %10
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %5
25: ; preds = %5
%26 = load i64, i64* %3
ret i64 %26
}

LLVM IR (-O2):
define i64 @getHash(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %17
4: ; preds = %1, %4
%5 = phi i64 [ %13, %4 ], [ 0, %1 ]
%6 = phi i64 [ %12, %4 ], [ 17, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %5
%8 = load i8, i8* %7
%9 = sext i8 %8 to i64
%10 = mul nuw nsw i64 %6, 31
%11 = add nsw i64 %10, %9
%12 = urem i64 %11, 10000000000
%13 = add nuw nsw i64 %5, 1
%14 = tail call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %13, %15
br i1 %16, label %4, label %17
17: ; preds = %4, %1
%18 = phi i64 [ 17, %1 ], [ %12, %4 ]
ret i64 %18
}