#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 uint16_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
uint16_t hash_function_filename(void *key) {
  unsigned long hash = 5381;
  int c;
  int ret;
  char *real_string;
  real_string = (char *)key;
  while (c = *real_string++)
    hash = ((hash << 5) + hash) + c;
  ret = (int)(hash & 0xFFFF);
  assert(ret >= 0 && ret <= 65535);
  return ret;
}


x86 assembly (clang, -O0):
<hash_function_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1505,-0x10(%rbp)
mov    -0x8(%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,-0x14(%rbp)
cmp    $0x0,%eax
je     1166 <hash_function_filename+0x56>
mov    -0x10(%rbp),%rax
shl    $0x5,%rax
add    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    112c <hash_function_filename+0x1c>
mov    -0x10(%rbp),%rax
and    $0xffff,%rax
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x21(%rbp)
jl     118f <hash_function_filename+0x7f>
cmpl   $0xffff,-0x18(%rbp)
setle  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_function_filename>:
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1141 <hash_function_filename+0x31>
add    $0x1,%rdi
mov    $0x1505,%ecx
mov    %rcx,%rdx
shl    $0x5,%rdx
add    %rcx,%rdx
movsbq %al,%rcx
add    %rdx,%rcx
movzbl (%rdi),%eax
add    $0x1,%rdi
test   %al,%al
jne    1120 <hash_function_filename+0x10>
movzwl %cx,%ebx
jmp    1146 <hash_function_filename+0x36>
mov    $0x1505,%ebx
mov    $0x1,%edi
call   1030 <assert@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @hash_function_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
store i64 5381, i64* %3
%7 = load i8*, i8** %2
store i8* %7, i8** %6
br label %8
8: ; preds = %14, %1
%9 = load i8*, i8** %6
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %6
%11 = load i8, i8* %9
%12 = sext i8 %11 to i32
store i32 %12, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = load i64, i64* %3
%16 = shl i64 %15, 5
%17 = load i64, i64* %3
%18 = add i64 %16, %17
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = add i64 %18, %20
store i64 %21, i64* %3
br label %8
22: ; preds = %8
%23 = load i64, i64* %3
%24 = and i64 %23, 65535
%25 = trunc i64 %24 to i32
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %5
%30 = icmp sle i32 %29, 65535
br label %31
31: ; preds = %28, %22
%32 = phi i1 [ false, %22 ], [ %30, %28 ]
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* %5
ret i32 %35
}

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