#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 tolower(unsigned char);
int filehash(const char *fname) {
  unsigned int hash = 0;
  while (*fname) {
    hash = (hash << 1) + (hash >> 7) * 9 + (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     116b <filehash+0x5b>
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    %eax,%ecx
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 %21
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 i32 @tolower(i8 zeroext %16)
%18 = add i32 %14, %17
store i32 %18, i32* %3
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
br label %4
21: ; preds = %4
%22 = load i32, i32* %3
%23 = and i32 %22, 255
ret i32 %23
}

LLVM IR (-O2):
define i32 @filehash(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %15, %4 ], [ %2, %1 ]
%6 = phi i32 [ %13, %4 ], [ 0, %1 ]
%7 = phi i8* [ %14, %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 i32 @tolower(i8 zeroext %5)
%13 = add i32 %11, %12
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %4
17: ; preds = %4
%18 = and i32 %13, 255
br label %19
19: ; preds = %17, %1
%20 = phi i32 [ 0, %1 ], [ %18, %17 ]
ret i32 %20
}