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

/* Variables and functions */
int tolower(char);
uint8_t hash(char *str) {
  uint8_t c;
  int i = 1;
  c = tolower(str[0]);
  while (tolower(str[i])) {
    c = c ^ tolower(str[i++]);
  };
  return (c % 256);
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
cmp    $0x0,%eax
je     117c <hash+0x6c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
xor    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    1132 <hash+0x22>
mov    -0xc(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <tolower@plt>
mov    %eax,%r14d
movsbl 0x1(%rbx),%edi
call   1030 <tolower@plt>
test   %eax,%eax
je     115c <hash+0x4c>
add    $0x2,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl -0x1(%rbx),%edi
call   1030 <tolower@plt>
xor    %eax,%r14d
movsbl (%rbx),%edi
call   1030 <tolower@plt>
add    $0x1,%rbx
test   %eax,%eax
jne    1140 <hash+0x30>
lea    0xff(%r14),%eax
test   %r14d,%r14d
cmovns %r14d,%eax
and    $0xffffff00,%eax
sub    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %4
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = call i32 @tolower(i8 signext %7)
store i32 %8, i32* %3
br label %9
9: ; preds = %17, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = call i32 @tolower(i8 signext %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %9
%18 = load i32, i32* %3
%19 = load i8*, i8** %2
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @tolower(i8 signext %24)
%26 = xor i32 %18, %25
store i32 %26, i32* %3
br label %9
27: ; preds = %9
%28 = load i32, i32* %3
%29 = srem i32 %28, 256
ret i32 %29
}

LLVM IR (-O2):
define i32 @hash(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @tolower(i8 signext %2)
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = tail call i32 @tolower(i8 signext %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %12, %8 ], [ 1, %1 ]
%10 = phi i8* [ %16, %8 ], [ %4, %1 ]
%11 = phi i32 [ %15, %8 ], [ %3, %1 ]
%12 = add nuw i64 %9, 1
%13 = load i8, i8* %10
%14 = tail call i32 @tolower(i8 signext %13)
%15 = xor i32 %14, %11
%16 = getelementptr inbounds i8, i8* %0, i64 %12
%17 = load i8, i8* %16
%18 = tail call i32 @tolower(i8 signext %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %8
20: ; preds = %8, %1
%21 = phi i32 [ %3, %1 ], [ %15, %8 ]
%22 = srem i32 %21, 256
ret i32 %22
}