#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 gfarm_hash_casefold(const void *key, int keylen) {
  int i;
  unsigned int hash = 0, g;
  for (i = 0; i < keylen; i++) {
    hash = (hash << 4) + tolower(((unsigned char *)key)[i]);
    if ((g = hash & 0xf0000000) != 0) {
      hash ^= g >> 24;
      hash ^= g;
    }
  }
  return (hash);
}


x86 assembly (clang, -O0):
<gfarm_hash_casefold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1199 <gfarm_hash_casefold+0x89>
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <tolower@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xf0000000,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1186 <gfarm_hash_casefold+0x76>
mov    -0x18(%rbp),%eax
shr    $0x18,%eax
xor    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
xor    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    118b <gfarm_hash_casefold+0x7b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <gfarm_hash_casefold+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gfarm_hash_casefold>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1166 <gfarm_hash_casefold+0x56>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
shl    $0x4,%ebp
movzbl (%r14,%rbx,1),%edi
call   1030 <tolower@plt>
add    %ebp,%eax
mov    %eax,%ecx
and    $0xf0000000,%ecx
mov    %ecx,%edx
shr    $0x18,%edx
mov    %eax,%ebp
and    $0xfffffff,%ebp
xor    %edx,%ebp
test   %ecx,%ecx
cmove  %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <gfarm_hash_casefold+0x20>
jmp    1168 <gfarm_hash_casefold+0x58>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gfarm_hash_casefold(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %8
8: ; preds = %34, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %37
12: ; preds = %8
%13 = load i32, i32* %6
%14 = shl i32 %13, 4
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @tolower(i8 zeroext %19)
%21 = add i32 %14, %20
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = and i32 %22, -268435456
store i32 %23, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %12
%26 = load i32, i32* %7
%27 = lshr i32 %26, 24
%28 = load i32, i32* %6
%29 = xor i32 %28, %27
store i32 %29, i32* %6
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = xor i32 %31, %30
store i32 %32, i32* %6
br label %33
33: ; preds = %25, %12
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %8
37: ; preds = %8
%38 = load i32, i32* %6
ret i32 %38
}

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