#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 strlen(char *);
unsigned int gethash(char *str) {
  static unsigned int primes[10] = {3, 5, 7, 11, 13, 17, 19, 23, 27, 31};
  unsigned int i = 0;
  unsigned int hash = strlen(str);
  while (*str) {
    hash *= 13;
    hash += (*str++) * primes[(++i) % 10];
  }
  return hash % 255;
}


x86 assembly (clang, -O0):
<gethash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1187 <gethash+0x77>
imul   $0xd,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    -0x14(%rbp),%eax
mov    %edx,%ecx
mov    %ecx,%edx
lea    0x2eb8(%rip),%rcx
imul   (%rcx,%rdx,4),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    112f <gethash+0x1f>
mov    -0x10(%rbp),%eax
mov    $0xff,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethash>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    (%rbx),%dl
test   %dl,%dl
je     1171 <gethash+0x61>
add    $0x1,%rbx
mov    $0x1,%ecx
mov    $0xcccccccd,%r8d
lea    0xecb(%rip),%r9
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%esi
imul   %r8,%rsi
shr    $0x23,%rsi
add    %esi,%esi
lea    (%rsi,%rsi,4),%esi
mov    %ecx,%edi
sub    %esi,%edi
lea    (%rax,%rax,2),%esi
lea    (%rax,%rsi,4),%esi
movsbl %dl,%eax
imul   (%r9,%rdi,4),%eax
add    %esi,%eax
movzbl (%rbx),%edx
add    $0x1,%ecx
add    $0x1,%rbx
test   %dl,%dl
jne    1140 <gethash+0x30>
mov    %eax,%edx
mov    $0x80808081,%ecx
imul   %rdx,%rcx
shr    $0x27,%rcx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %edx,%ecx
add    %eax,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@gethash.primes = internal global [10 x i32] [i32 3, i32 5, i32 7, i32 11, i32 13, i32 17, i32 19, i32 23, i32 27, i32 31]
define i32 @gethash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
br label %7
7: ; preds = %11, %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = load i32, i32* %4
%13 = mul i32 %12, 13
store i32 %13, i32* %4
%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 = load i32, i32* %3
%19 = add i32 %18, 1
store i32 %19, i32* %3
%20 = urem i32 %19, 10
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [10 x i32], [10 x i32]* @gethash.primes, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = mul i32 %17, %23
%25 = load i32, i32* %4
%26 = add i32 %25, %24
store i32 %26, i32* %4
br label %7
27: ; preds = %7
%28 = load i32, i32* %4
%29 = urem i32 %28, 255
ret i32 %29
}

LLVM IR (-O2):
@gethash.primes = internal unnamed_addr constant [10 x i32] [i32 3, i32 5, i32 7, i32 11, i32 13, i32 17, i32 19, i32 23, i32 27, i32 31]
define i32 @gethash(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %1, %5
%6 = phi i8 [ %20, %5 ], [ %3, %1 ]
%7 = phi i32 [ %19, %5 ], [ %2, %1 ]
%8 = phi i32 [ %13, %5 ], [ 0, %1 ]
%9 = phi i8* [ %11, %5 ], [ %0, %1 ]
%10 = mul i32 %7, 13
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = sext i8 %6 to i32
%13 = add i32 %8, 1
%14 = urem i32 %13, 10
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds [10 x i32], [10 x i32]* @gethash.primes, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = mul i32 %17, %12
%19 = add i32 %18, %10
%20 = load i8, i8* %11
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %5
22: ; preds = %5, %1
%23 = phi i32 [ %2, %1 ], [ %19, %5 ]
%24 = urem i32 %23, 255
ret i32 %24
}