#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 long tolower(int);
unsigned long hasher(const char *str) {
  unsigned long hash = 5381;
  int c;
  for (c = *str; *str != '\0'; str++) {
    hash = (((hash << 3) + hash) + tolower(c)) / 5;
  }
  return (hash % 143091);
}


x86 assembly (clang, -O0):
<hasher>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1505,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     117f <hasher+0x6f>
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <tolower@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    $0x5,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112e <hasher+0x1e>
mov    -0x10(%rbp),%rax
mov    $0x22ef3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hasher>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movsbl (%rdi),%r15d
test   %r15d,%r15d
je     1182 <hasher+0x72>
mov    %rdi,%rbx
add    $0x1,%rbx
mov    $0x1505,%ecx
movabs $0xcccccccccccccccd,%r14
cc cc cc
cs nopw 0x0(%rax,%rax,1)
lea    (%rcx,%rcx,8),%rbp
mov    %r15d,%edi
call   1030 <tolower@plt>
add    %rbp,%rax
mul    %r14
mov    %rdx,%rcx
shr    $0x2,%rcx
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1140 <hasher+0x30>
movabs $0xea7f455d348b116f,%rdx
45 7f ea
mov    %rcx,%rax
mul    %rdx
shr    $0x11,%rdx
imul   $0x22ef3,%rdx,%rax
sub    %rax,%rcx
jmp    1187 <hasher+0x77>
mov    $0x1505,%ecx
mov    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @hasher(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = sext i8 %2 to i32
%4 = icmp eq i8 %2, 0
br i1 %4, label %17, label %5
5: ; preds = %1, %5
%6 = phi i8* [ %12, %5 ], [ %0, %1 ]
%7 = phi i64 [ %11, %5 ], [ 5381, %1 ]
%8 = mul i64 %7, 9
%9 = tail call i64 @tolower(i32 %3)
%10 = add i64 %9, %8
%11 = udiv i64 %10, 5
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %5
%16 = urem i64 %11, 143091
br label %17
17: ; preds = %15, %1
%18 = phi i64 [ 5381, %1 ], [ %16, %15 ]
ret i64 %18
}