#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 */
typedef int uint32_t;

/* Variables and functions */
__attribute__((__unused__)) uint32_t hash_string(const char *str) {
  unsigned char c;
  uint32_t hash = (uint32_t)0x811c9dc5;
  while ((c = (unsigned char)*(str++)) != '\0')
    hash = ((hash * (uint32_t)0x01000193) ^ (uint32_t)c);
  return (hash ? hash : 1);
}


x86 assembly (clang, -O0):
<hash_string>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x811c9dc5,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x9(%rbp)
movzbl %al,%eax
cmp    $0x0,%eax
je     1144 <hash_string+0x44>
imul   $0x1000193,-0x10(%rbp),%eax
movzbl -0x9(%rbp),%ecx
xor    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    110f <hash_string+0xf>
cmpl   $0x0,-0x10(%rbp)
je     1159 <hash_string+0x59>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <hash_string+0x66>
mov    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <hash_string+0x66>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_string>:
mov    (%rdi),%al
test   %al,%al
je     1131 <hash_string+0x31>
add    $0x1,%rdi
mov    $0x811c9dc5,%ecx
nop
movzbl %al,%eax
imul   $0x1000193,%ecx,%ecx
xor    %eax,%ecx
movzbl (%rdi),%eax
add    $0x1,%rdi
test   %al,%al
jne    1110 <hash_string+0x10>
test   %ecx,%ecx
mov    $0x1,%eax
cmovne %ecx,%eax
ret
mov    $0x811c9dc5,%eax
ret

LLVM IR (-O0):
define i32 @hash_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
store i8* %0, i8** %2
store i32 -2128831035, i32* %4
br label %5
5: ; preds = %11, %1
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %2
%8 = load i8, i8* %6
store i8 %8, i8* %3
%9 = zext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %5
%12 = load i32, i32* %4
%13 = mul nsw i32 %12, 16777619
%14 = load i8, i8* %3
%15 = zext i8 %14 to i32
%16 = xor i32 %13, %15
store i32 %16, i32* %4
br label %5
17: ; preds = %5
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load i32, i32* %4
br label %23
22: ; preds = %17
br label %23
23: ; preds = %22, %20
%24 = phi i32 [ %21, %20 ], [ 1, %22 ]
ret i32 %24
}

LLVM IR (-O2):
define i32 @hash_string(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %12, %4 ], [ %2, %1 ]
%6 = phi i32 [ %11, %4 ], [ -2128831035, %1 ]
%7 = phi i8* [ %9, %4 ], [ %0, %1 ]
%8 = zext i8 %5 to i32
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = mul nsw i32 %6, 16777619
%11 = xor i32 %10, %8
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %4
%15 = icmp eq i32 %11, 0
%16 = select i1 %15, i32 1, i32 %11
br label %17
17: ; preds = %14, %1
%18 = phi i32 [ -2128831035, %1 ], [ %16, %14 ]
ret i32 %18
}