#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 hash_filename(const pid_t pid, const char *filename) {
  register uint32_t hash = 5381 ^ pid;
  register int c;
  register const char *str = filename;
  while ((c = *str++)) {
    hash = ((hash << 5) + hash) ^ c;
  }
  return hash % (1997);
}


x86 assembly (clang, -O0):
<hash_filename>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
xor    $0x1505,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1150 <hash_filename+0x50>
mov    -0x14(%rbp),%eax
shl    $0x5,%eax
add    -0x14(%rbp),%eax
xor    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    111e <hash_filename+0x1e>
mov    -0x14(%rbp),%eax
mov    $0x7cd,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_filename>:
xor    $0x1505,%edi
mov    (%rsi),%cl
test   %cl,%cl
je     1139 <hash_filename+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    1120 <hash_filename+0x20>
jmp    113b <hash_filename+0x3b>
mov    %edi,%eax
cltq
imul   $0x41a26b6d,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x29,%rcx
add    %edx,%ecx
imul   $0x7cd,%ecx,%ecx
sub    %ecx,%eax
ret

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

LLVM IR (-O2):
define i32 @hash_filename(i32 %0, i8* nocapture %1) {
%3 = xor 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, 1997
ret i32 %18
}