#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 /*<<< orphan*/ number;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int wordPointerSum(char *);
int wordSum(char *);
int hashWord(char *word) {
  int hash = wordSum(word);
  hash -= wordPointerSum(word);
  char number[100];
  snprintf(number, sizeof(number) / sizeof(char), "%d", hash);
  hash *= wordPointerSum(number);
  hash = hash % 661;
  return hash;
}


x86 assembly (clang, -O0):
<hashWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <wordSum@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <wordPointerSum@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    $0x64,%esi
lea    0xe92(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x70(%rbp),%rdi
call   1050 <wordPointerSum@plt>
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x295,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashWord>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rbx
call   1030 <wordSum@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <wordPointerSum@plt>
sub    %eax,%ebp
lea    0xeaf(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %ebp,%ecx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <wordPointerSum@plt>
imul   %ebp,%eax
cltq
imul   $0xffffffffc64b2279,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x9,%ecx
add    %edx,%ecx
imul   $0x295,%ecx,%ecx
sub    %ecx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @hashWord(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [100 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @wordSum(i8* %5)
store i32 %6, i32* %3
%7 = load i8*, i8** %2
%8 = call i32 @wordPointerSum(i8* %7)
%9 = load i32, i32* %3
%10 = sub nsw i32 %9, %8
store i32 %10, i32* %3
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = load i32, i32* %3
%13 = call i32 @snprintf(i8* %11, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%15 = call i32 @wordPointerSum(i8* %14)
%16 = load i32, i32* %3
%17 = mul nsw i32 %16, %15
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = srem i32 %18, 661
store i32 %19, i32* %3
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @hashWord(i8* %0) {
%2 = alloca [100 x i8]
%3 = tail call i32 @wordSum(i8* %0)
%4 = tail call i32 @wordPointerSum(i8* %0)
%5 = sub nsw i32 %3, %4
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 100, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
%8 = call i32 @wordPointerSum(i8* %6)
%9 = mul nsw i32 %8, %5
%10 = srem i32 %9, 661
ret i32 %10
}