#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 */
scalar_t__ tolower(unsigned char);
int filehash(char *fname) {
  unsigned int hash = 0;
  while (*fname) {
    hash = ((hash << 1) + (hash >> 7) * 9 +
            (unsigned int)tolower((unsigned char)(*fname)));
    fname++;
  }
  return hash & 255;
}


x86 assembly (clang, -O0):
<filehash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     116c <filehash+0x5c>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    -0xc(%rbp),%ecx
shr    $0x7,%ecx
imul   $0x9,%ecx,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <filehash+0x13>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filehash>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%cl
test   %cl,%cl
je     1155 <filehash+0x45>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%edx
shr    $0x7,%edx
lea    (%rdx,%rdx,8),%edx
lea    (%rdx,%rax,2),%ebp
movzbl %cl,%edi
call   1030 <tolower@plt>
add    %ebp,%eax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1130 <filehash+0x20>
movzbl %al,%eax
jmp    1157 <filehash+0x47>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @filehash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %8, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = load i32, i32* %3
%10 = shl i32 %9, 1
%11 = load i32, i32* %3
%12 = lshr i32 %11, 7
%13 = mul i32 %12, 9
%14 = add i32 %10, %13
%15 = load i8*, i8** %2
%16 = load i8, i8* %15
%17 = call i64 @tolower(i8 zeroext %16)
%18 = trunc i64 %17 to i32
%19 = add i32 %14, %18
store i32 %19, i32* %3
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %2
br label %4
22: ; preds = %4
%23 = load i32, i32* %3
%24 = and i32 %23, 255
ret i32 %24
}

LLVM IR (-O2):
define i32 @filehash(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %16, %4 ], [ %2, %1 ]
%6 = phi i32 [ %14, %4 ], [ 0, %1 ]
%7 = phi i8* [ %15, %4 ], [ %0, %1 ]
%8 = shl i32 %6, 1
%9 = lshr i32 %6, 7
%10 = mul nuw nsw i32 %9, 9
%11 = add i32 %10, %8
%12 = tail call i64 @tolower(i8 zeroext %5)
%13 = trunc i64 %12 to i32
%14 = add i32 %11, %13
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %4
18: ; preds = %4
%19 = and i32 %14, 255
br label %20
20: ; preds = %18, %1
%21 = phi i32 [ 0, %1 ], [ %19, %18 ]
ret i32 %21
}