#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;
typedef int pid_t;

/* Variables and functions */
uint32_t __attribute__((optimize("-O3"))) __attribute__((hot))
hash_djb2a(const pid_t pid, const char *str) {
  register uint32_t hash = 5381 + pid;
  register int c;
  while ((c = *str++)) {
    hash = ((hash << 5) + hash) ^ c;
  }
  return hash % (2411);
}


x86 assembly (clang, -O0):
<hash_djb2a>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1505,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1148 <hash_djb2a+0x48>
mov    -0x14(%rbp),%eax
shl    $0x5,%eax
add    -0x14(%rbp),%eax
xor    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1116 <hash_djb2a+0x16>
mov    -0x14(%rbp),%eax
mov    $0x96b,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_djb2a>:
add    $0x1505,%edi
mov    (%rsi),%cl
test   %cl,%cl
je     1079 <hash_djb2a+0x39>
add    $0x1,%rsi
mov    %edi,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %cl,%ecx
shl    $0x5,%eax
add    %edi,%eax
xor    %ecx,%eax
movzbl (%rsi),%ecx
add    $0x1,%rsi
mov    %eax,%edi
test   %cl,%cl
jne    1060 <hash_djb2a+0x20>
jmp    107b <hash_djb2a+0x3b>
mov    %edi,%eax
cltq
imul   $0x6cba73bd,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2a,%rcx
add    %edx,%ecx
imul   $0x96b,%ecx,%ecx
sub    %ecx,%eax
ret
nopw   0x0(%rax,%rax,1)

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

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