#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__((hot)) __attribute__((optimize("-O3"))) uint32_t
hash_djb2a(const char *str) {
  register uint32_t hash = 5381;
  register int c;
  while ((c = *str++)) {
    hash = ((hash << 5) + hash) ^ c;
    hash = (hash * 33) ^ c;
  }
  return hash % (1009);
}


x86 assembly (clang, -O0):
<hash_djb2a>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x1505,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
je     114b <hash_djb2a+0x4b>
mov    -0xc(%rbp),%eax
shl    $0x5,%eax
add    -0xc(%rbp),%eax
xor    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
imul   $0x21,-0xc(%rbp),%eax
xor    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    110f <hash_djb2a+0xf>
mov    -0xc(%rbp),%eax
mov    $0x3f1,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_djb2a>:
mov    (%rdi),%cl
test   %cl,%cl
je     1092 <hash_djb2a+0x52>
add    $0x1,%rdi
mov    $0x1505,%eax
nop
movsbl %cl,%ecx
mov    %eax,%edx
shl    $0x5,%edx
add    %eax,%edx
xor    %ecx,%edx
mov    %edx,%eax
shl    $0x5,%eax
add    %edx,%eax
xor    %ecx,%eax
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
jne    1050 <hash_djb2a+0x10>
cltq
imul   $0xffffffff81e722c3,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x9,%ecx
add    %edx,%ecx
imul   $0x3f1,%ecx,%ecx
sub    %ecx,%eax
ret
mov    $0x150,%eax
ret
nopl   0x0(%rax,%rax,1)

LLVM IR (-O0):
define i32 @hash_djb2a(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 5381, i32* %3
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
%9 = sext i8 %8 to i32
store i32 %9, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %5
%12 = load i32, i32* %3
%13 = shl i32 %12, 5
%14 = load i32, i32* %3
%15 = add nsw i32 %13, %14
%16 = load i32, i32* %4
%17 = xor i32 %15, %16
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = mul nsw i32 %18, 33
%20 = load i32, i32* %4
%21 = xor i32 %19, %20
store i32 %21, i32* %3
br label %5
22: ; preds = %5
%23 = load i32, i32* %3
%24 = srem i32 %23, 1009
ret i32 %24
}

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