#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 */
uint32_t pjw_hash(const char *str) {
  uint32_t hash = 0;
  uint32_t test = 0;
  for (; *str; str++) {
    hash = (hash << 4) + (unsigned char)(*str);
    if ((test = hash & 0xf0000000) != 0) {
      hash = ((hash ^ (test >> 24)) & (0xfffffff));
    }
  }
  return hash;
}


x86 assembly (clang, -O0):
<pjw_hash>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1172 <pjw_hash+0x72>
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    -0x8(%rbp),%rcx
movzbl (%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xf0000000,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     115c <pjw_hash+0x5c>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    $0x18,%ecx
xor    %ecx,%eax
and    $0xfffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <pjw_hash+0x61>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1116 <pjw_hash+0x16>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<pjw_hash>:
mov    (%rdi),%cl
test   %cl,%cl
je     113d <pjw_hash+0x3d>
add    $0x1,%rdi
xor    %eax,%eax
nopl   0x0(%rax)
shl    $0x4,%eax
movzbl %cl,%ecx
add    %eax,%ecx
mov    %ecx,%edx
and    $0xf0000000,%edx
mov    %edx,%eax
sar    $0x18,%eax
xor    %ecx,%eax
and    $0xfffffff,%eax
test   %edx,%edx
cmove  %ecx,%eax
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
jne    1110 <pjw_hash+0x10>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @pjw_hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %26, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %5
%10 = load i32, i32* %3
%11 = shl i32 %10, 4
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = add nsw i32 %11, %14
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = and i32 %16, -268435456
store i32 %17, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %9
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = ashr i32 %21, 24
%23 = xor i32 %20, %22
%24 = and i32 %23, 268435455
store i32 %24, i32* %3
br label %25
25: ; preds = %19, %9
br label %26
26: ; preds = %25
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
br label %5
29: ; preds = %5
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @pjw_hash(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %18, %4 ], [ %2, %1 ]
%6 = phi i32 [ %16, %4 ], [ 0, %1 ]
%7 = phi i8* [ %17, %4 ], [ %0, %1 ]
%8 = shl i32 %6, 4
%9 = zext i8 %5 to i32
%10 = add nsw i32 %8, %9
%11 = and i32 %10, -268435456
%12 = icmp eq i32 %11, 0
%13 = ashr exact i32 %11, 24
%14 = xor i32 %13, %10
%15 = and i32 %14, 268435455
%16 = select i1 %12, i32 %10, i32 %15
%17 = getelementptr inbounds i8, i8* %7, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %4
20: ; preds = %4, %1
%21 = phi i32 [ 0, %1 ], [ %16, %4 ]
ret i32 %21
}