#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 uint64_t;
typedef int /*<<< orphan*/ hist;

/* Variables and functions */
int get_hashed_token(char const *, size_t);
scalar_t__ get_next_token(char const **, char const *, char const **, size_t *);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ update_hist(int *, int);
uint64_t charikar_hash64(const char *data, long data_length) {
  const char *data_end = data + data_length;
  int hist[64];
  memset(hist, 0, sizeof(hist));
  const char *token_start;
  size_t token_length;
  int tokens = 0;
  while ((get_next_token(&data, data_end, &token_start, &token_length))) {
    if (token_length > 3) {
      uint64_t token = get_hashed_token(token_start, token_length);
      ;
      update_hist(hist, token);
      tokens++;
    }
  }
  tokens /= 2;
  uint64_t simhash = 0;
  for (int c = 0; c < 64; c++)
    simhash |= (uint64_t)((hist[c] - tokens) >= 0) << c;
  return simhash;
}


x86 assembly (clang, -O0):
<charikar_hash64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
movl   $0x0,-0x134(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x8(%rbp),%rdi
lea    -0x128(%rbp),%rdx
lea    -0x130(%rbp),%rcx
call   1060 <get_next_token@plt>
cmp    $0x0,%rax
je     11ee <charikar_hash64+0xae>
cmpq   $0x3,-0x130(%rbp)
03
jbe    11e9 <charikar_hash64+0xa9>
mov    -0x128(%rbp),%rdi
mov    -0x130(%rbp),%rsi
call   1030 <get_hashed_token@plt>
mov    %eax,-0x138(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x138(%rbp),%esi
call   1050 <update_hist@plt>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    117c <charikar_hash64+0x3c>
mov    -0x134(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x134(%rbp)
movl   $0x0,-0x13c(%rbp)
movl   $0x0,-0x140(%rbp)
cmpl   $0x40,-0x140(%rbp)
jge    126a <charikar_hash64+0x12a>
movslq -0x140(%rbp),%rax
mov    -0x120(%rbp,%rax,4),%eax
sub    -0x134(%rbp),%eax
cmp    $0x0,%eax
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x140(%rbp),%ecx
shl    %cl,%eax
or     -0x13c(%rbp),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x140(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x140(%rbp)
jmp    1216 <charikar_hash64+0xd6>
mov    -0x13c(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charikar_hash64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbx
mov    %rdi,0x18(%rsp)
add    %rdi,%rbx
lea    0x20(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rsi
call   1060 <get_next_token@plt>
test   %rax,%rax
je     11ea <charikar_hash64+0xaa>
lea    0x20(%rsp),%r14
lea    0x18(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
jmp    11c6 <charikar_hash64+0x86>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1060 <get_next_token@plt>
test   %rax,%rax
je     11ea <charikar_hash64+0xaa>
mov    0x8(%rsp),%rsi
cmp    $0x4,%rsi
jb     11b0 <charikar_hash64+0x70>
mov    0x10(%rsp),%rdi
call   1030 <get_hashed_token@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <update_hist@plt>
add    $0x1,%ebp
jmp    11b0 <charikar_hash64+0x70>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @charikar_hash64(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca [64 x i32]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%13 = load i8*, i8** %3
%14 = load i64, i64* %4
%15 = getelementptr inbounds i8, i8* %13, i64 %14
store i8* %15, i8** %5
%16 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 0
%17 = call i32 @memset(i32* %16, i32 0, i32 256)
store i32 0, i32* %9
br label %18
18: ; preds = %34, %2
%19 = load i8*, i8** %5
%20 = call i64 @get_next_token(i8** %3, i8* %19, i8** %7, i64* %8)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %35
22: ; preds = %18
%23 = load i64, i64* %8
%24 = icmp ugt i64 %23, 3
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = load i64, i64* %8
%28 = call i32 @get_hashed_token(i8* %26, i64 %27)
store i32 %28, i32* %10
%29 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 0
%30 = load i32, i32* %10
%31 = call i32 @update_hist(i32* %29, i32 %30)
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %34
34: ; preds = %25, %22
br label %18
35: ; preds = %18
%36 = load i32, i32* %9
%37 = sdiv i32 %36, 2
store i32 %37, i32* %9
store i32 0, i32* %11
store i32 0, i32* %12
br label %38
38: ; preds = %54, %35
%39 = load i32, i32* %12
%40 = icmp slt i32 %39, 64
br i1 %40, label %41, label %57
41: ; preds = %38
%42 = load i32, i32* %12
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = load i32, i32* %9
%47 = sub nsw i32 %45, %46
%48 = icmp sge i32 %47, 0
%49 = zext i1 %48 to i32
%50 = load i32, i32* %12
%51 = shl i32 %49, %50
%52 = load i32, i32* %11
%53 = or i32 %52, %51
store i32 %53, i32* %11
br label %54
54: ; preds = %41
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %12
br label %38
57: ; preds = %38
%58 = load i32, i32* %11
ret i32 %58
}

LLVM IR (-O2):
define i32 @charikar_hash64(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca [64 x i32]
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
%7 = getelementptr inbounds i8, i8* %0, i64 %1
%8 = bitcast [64 x i32]* %4 to i8*
%9 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 0
%10 = call i32 @memset(i32* %9, i32 0, i32 256)
%11 = bitcast i8** %5 to i8*
%12 = bitcast i64* %6 to i8*
%13 = call i64 @get_next_token(i8** %3, i8* %7, i8** %5, i64* %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %2, %24
%16 = phi i32 [ %25, %24 ], [ 0, %2 ]
%17 = load i64, i64* %6
%18 = icmp ugt i64 %17, 3
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i32 @get_hashed_token(i8* %20, i64 %17)
%22 = call i32 @update_hist(i32* %9, i32 %21)
%23 = add nsw i32 %16, 1
br label %24
24: ; preds = %19, %15
%25 = phi i32 [ %23, %19 ], [ %16, %15 ]
%26 = call i64 @get_next_token(i8** %3, i8* %7, i8** %5, i64* %6)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %15
28: ; preds = %2, %24
ret i32 poison
}