#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 const *);
unsigned int tdb_hash(const char *name) {
  unsigned value;
  unsigned i;
  for (value = 0x238F13AF * strlen(name), i = 0; name[i]; i++)
    value = (value + (((unsigned char *)name)[i] << (i * 5 % 24)));
  return (1103515243 * value + 12345);
}


x86 assembly (clang, -O0):
<tdb_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
imul   $0x238f13af,%eax,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
cmpb   $0x0,(%rax,%rcx,1)
je     1186 <tdb_hash+0x76>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x14(%rbp)
imul   $0x5,-0x10(%rbp),%eax
mov    $0x18,%ecx
xor    %edx,%edx
div    %ecx
mov    -0x18(%rbp),%eax
mov    %edx,%ecx
mov    -0x14(%rbp),%edx
shl    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1135 <tdb_hash+0x25>
imul   $0x41c64e6b,-0xc(%rbp),%eax
add    $0x3039,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tdb_hash>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
imul   $0x238f13af,%eax,%eax
mov    (%r14),%bl
test   %bl,%bl
je     116c <tdb_hash+0x5c>
xor    %edx,%edx
mov    $0x1,%esi
mov    $0xaaaaaaab,%r8d
cs nopw 0x0(%rax,%rax,1)
mov    %edx,%ecx
imul   %r8,%rcx
shr    $0x24,%rcx
shl    $0x3,%ecx
lea    (%rcx,%rcx,2),%edi
mov    %edx,%ecx
sub    %edi,%ecx
movzbl %bl,%edi
shl    %cl,%edi
add    %edi,%eax
mov    %esi,%ecx
movzbl (%r14,%rcx,1),%ebx
add    $0x5,%edx
add    $0x1,%esi
test   %bl,%bl
jne    1140 <tdb_hash+0x30>
imul   $0x41c64e6b,%eax,%eax
add    $0x3039,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @tdb_hash(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = mul nsw i32 %2, 596579247
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %1, %6
%7 = phi i8 [ %18, %6 ], [ %4, %1 ]
%8 = phi i32 [ %15, %6 ], [ 0, %1 ]
%9 = phi i32 [ %14, %6 ], [ %3, %1 ]
%10 = zext i8 %7 to i32
%11 = mul i32 %8, 5
%12 = urem i32 %11, 24
%13 = shl nuw nsw i32 %10, %12
%14 = add i32 %13, %9
%15 = add i32 %8, 1
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %6
20: ; preds = %6, %1
%21 = phi i32 [ %3, %1 ], [ %14, %6 ]
%22 = mul i32 %21, 1103515243
%23 = add i32 %22, 12345
ret i32 %23
}