#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 const *);
unsigned int hash(const char *string) {
  unsigned int l = strlen(string);
  unsigned int h = l;
  size_t step = (l >> 5) + 1;
  size_t ll;
  for (ll = 1; ll >= step; ll -= step) {
    h = h ^ ((h << 5) + (h >> 2) + (unsigned char)(string[ll - 1]));
  }
  return h;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x5,%eax
add    $0x1,%eax
mov    %eax,%eax
mov    %rax,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     118f <hash+0x7f>
mov    -0x10(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x5,%ecx
mov    -0x10(%rbp),%edx
shr    $0x2,%edx
add    %edx,%ecx
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rsi
sub    $0x1,%rsi
movzbl (%rdx,%rsi,1),%edx
add    %edx,%ecx
xor    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1145 <hash+0x35>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x1f,%eax
ja     1131 <hash+0x21>
movzbl (%rbx),%ecx
mov    %eax,%edx
shl    $0x5,%edx
mov    %eax,%esi
shr    $0x2,%esi
add    %edx,%esi
add    %ecx,%esi
xor    %esi,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
store i32 %9, i32* %4
%10 = load i32, i32* %3
%11 = lshr i32 %10, 5
%12 = add i32 %11, 1
%13 = zext i32 %12 to i64
store i64 %13, i64* %5
store i64 1, i64* %6
br label %14
14: ; preds = %33, %1
%15 = load i64, i64* %6
%16 = load i64, i64* %5
%17 = icmp uge i64 %15, %16
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = load i32, i32* %4
%20 = load i32, i32* %4
%21 = shl i32 %20, 5
%22 = load i32, i32* %4
%23 = lshr i32 %22, 2
%24 = add i32 %21, %23
%25 = load i8*, i8** %2
%26 = load i64, i64* %6
%27 = sub i64 %26, 1
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = add i32 %24, %30
%32 = xor i32 %19, %31
store i32 %32, i32* %4
br label %33
33: ; preds = %18
%34 = load i64, i64* %5
%35 = load i64, i64* %6
%36 = sub i64 %35, %34
store i64 %36, i64* %6
br label %14
37: ; preds = %14
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
define i32 @hash(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp ult i32 %2, 32
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i8, i8* %0
%6 = zext i8 %5 to i32
%7 = shl nuw nsw i32 %2, 5
%8 = lshr i32 %2, 2
%9 = add nuw nsw i32 %7, %8
%10 = add nuw nsw i32 %9, %6
%11 = xor i32 %10, %2
br label %12
12: ; preds = %4, %1
%13 = phi i32 [ %2, %1 ], [ %11, %4 ]
ret i32 %13
}