#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 unsigned long uint32_t;
typedef unsigned long uint16_t;

/* Variables and functions */
int /*<<< orphan*/ crc16(int /*<<< orphan*/, unsigned long *);
uint32_t hash(const char *text) {
  uint16_t crc = 0xFFFF;
  char *p = (char *)text;
  if (p != NULL) {
    while (*p != 0)
      crc16(*p++, &crc);
    return crc & ((4096UL * 4) - 1);
  } else
    return 0xFFFFFFFF;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0xffff,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117f <hash+0x6f>
jmp    113c <hash+0x2c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     116c <hash+0x5c>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <crc16@plt>
jmp    113c <hash+0x2c>
mov    -0x18(%rbp),%rax
and    $0x3fff,%rax
mov    %rax,-0x8(%rbp)
jmp    1188 <hash+0x78>
mov    $0xffffffff,%eax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %r14
push   %rbx
push   %rax
movq   $0xffff,(%rsp)
test   %rdi,%rdi
je     1161 <hash+0x51>
mov    %rdi,%rbx
mov    (%rdi),%al
test   %al,%al
je     1168 <hash+0x58>
add    $0x1,%rbx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r14,%rsi
call   1030 <crc16@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <hash+0x30>
mov    (%rsp),%rax
and    $0x3fff,%eax
jmp    116d <hash+0x5d>
mov    $0xffffffff,%eax
jmp    116d <hash+0x5d>
mov    $0x3fff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @hash(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %3
store i64 65535, i64* %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %24
9: ; preds = %1
br label %10
10: ; preds = %15, %9
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %5
%18 = load i8, i8* %16
%19 = sext i8 %18 to i32
%20 = call i32 @crc16(i32 %19, i64* %4)
br label %10
21: ; preds = %10
%22 = load i64, i64* %4
%23 = and i64 %22, 16383
store i64 %23, i64* %2
br label %25
24: ; preds = %1
store i64 4294967295, i64* %2
br label %25
25: ; preds = %24, %21
%26 = load i64, i64* %2
ret i64 %26
}

LLVM IR (-O2):
define i64 @hash(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 65535, i64* %2
%4 = icmp eq i8* %0, null
br i1 %4, label %19, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %5, %8
%9 = phi i8 [ %14, %8 ], [ %6, %5 ]
%10 = phi i8* [ %12, %8 ], [ %0, %5 ]
%11 = sext i8 %9 to i32
%12 = getelementptr inbounds i8, i8* %10, i64 1
%13 = call i32 @crc16(i32 %11, i64* %2)
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = load i64, i64* %2
%18 = and i64 %17, 16383
br label %19
19: ; preds = %5, %16, %1
%20 = phi i64 [ 4294967295, %1 ], [ %18, %16 ], [ 16383, %5 ]
ret i64 %20
}