#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 *);
unsigned int hb_pjw_hash(char *value) {
  unsigned int hash = 0;
  unsigned int test = 0;
  unsigned int i = 0;
  const unsigned int bits_in_u = (unsigned int)(sizeof(unsigned int) * 8);
  const unsigned int three_quarters = (unsigned int)((bits_in_u * 3) / 4);
  const unsigned int one_eight = (unsigned int)(bits_in_u / 8);
  const unsigned int high_bits = (unsigned int)(0xffffffff)
                                 << (bits_in_u - one_eight);
  for (i = 0; i < strlen(value); i++, value++) {
    hash = (hash << one_eight) + *value;
    if ((test = hash & high_bits)) {
      hash = ((hash ^ (test >> three_quarters)) & (~high_bits));
    }
  }
  return hash;
}


x86 assembly (clang, -O0):
<hb_pjw_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x20,-0x18(%rbp)
movl   $0x18,-0x1c(%rbp)
movl   $0x4,-0x20(%rbp)
movl   $0xf0000000,-0x24(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jae    11c8 <hb_pjw_hash+0xb8>
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xf0000000,%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     11a9 <hb_pjw_hash+0x99>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
shr    $0x18,%ecx
xor    %ecx,%eax
and    $0xfffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11ae <hb_pjw_hash+0x9e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1154 <hb_pjw_hash+0x44>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hb_pjw_hash>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
je     116b <hb_pjw_hash+0x5b>
add    $0x1,%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
shl    $0x4,%ebp
movsbl -0x1(%r14),%eax
add    %ebp,%eax
mov    %eax,%ecx
and    $0xf0000000,%ecx
mov    %ecx,%edx
shr    $0x18,%edx
mov    %eax,%ebp
and    $0xfffffff,%ebp
xor    %edx,%ebp
test   %ecx,%ecx
cmove  %eax,%ebp
add    $0x1,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0x1,%r14
cmp    %eax,%ebx
jb     1130 <hb_pjw_hash+0x20>
jmp    116d <hb_pjw_hash+0x5d>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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