#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 */

/* Variables and functions */
unsigned int toupper(unsigned int);
int hashfunc(const char *str) {
  unsigned hash = 987654321;
  unsigned c;
  while (*str) {
    c = *str++;
    c = toupper(c);
    hash = hash * 65537;
    hash = hash ^ c;
  }
  return hash % 128;
}


x86 assembly (clang, -O0):
<hashfunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x3ade68b1,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1168 <hashfunc+0x58>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <toupper@plt>
mov    %eax,-0x10(%rbp)
imul   $0x10001,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
xor    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <hashfunc+0x13>
mov    -0xc(%rbp),%eax
and    $0x7f,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashfunc>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1152 <hashfunc+0x42>
mov    %rdi,%r14
add    $0x1,%r14
mov    $0x3ade68b1,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %ebx,%ecx
shl    $0x10,%ecx
add    %ecx,%ebx
xor    %eax,%ebx
movzbl (%r14),%eax
add    $0x1,%r14
test   %al,%al
jne    1130 <hashfunc+0x20>
and    $0x7f,%ebx
jmp    1157 <hashfunc+0x47>
mov    $0x31,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @hashfunc(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 987654321, i32* %3
br label %5
5: ; preds = %9, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %2
%12 = load i8, i8* %10
%13 = sext i8 %12 to i32
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = call i32 @toupper(i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = mul i32 %16, 65537
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = xor i32 %18, %19
store i32 %20, i32* %3
br label %5
21: ; preds = %5
%22 = load i32, i32* %3
%23 = urem i32 %22, 128
ret i32 %23
}

LLVM IR (-O2):
define i32 @hashfunc(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 [ %13, %4 ], [ %2, %1 ]
%6 = phi i8* [ %8, %4 ], [ %0, %1 ]
%7 = phi i32 [ %12, %4 ], [ 987654321, %1 ]
%8 = getelementptr inbounds i8, i8* %6, i64 1
%9 = sext i8 %5 to i32
%10 = tail call i32 @toupper(i32 %9)
%11 = mul i32 %7, 65537
%12 = xor i32 %10, %11
%13 = load i8, i8* %8
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %4
15: ; preds = %4
%16 = and i32 %12, 127
br label %17
17: ; preds = %15, %1
%18 = phi i32 [ 49, %1 ], [ %16, %15 ]
ret i32 %18
}