#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 long tolower(unsigned char);
unsigned long string_nocase_hash(void *string) {
  unsigned long result = 5381;
  unsigned char *p;
  p = (unsigned char *)string;
  while (*p != '\0') {
    result = ((result << 5) ^ result) ^ tolower(*p);
    ++p;
  }
  return result;
}


x86 assembly (clang, -O0):
<string_nocase_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1505,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     1177 <string_nocase_hash+0x67>
mov    -0x10(%rbp),%rax
shl    $0x5,%rax
xor    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <tolower@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
xor    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <string_nocase_hash+0x1c>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_nocase_hash>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%cl
test   %cl,%cl
je     1153 <string_nocase_hash+0x43>
mov    %rdi,%r14
add    $0x1,%r14
mov    $0x1505,%eax
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rbx
shl    $0x5,%rbx
xor    %rax,%rbx
movzbl %cl,%edi
call   1030 <tolower@plt>
xor    %rbx,%rax
movzbl (%r14),%ecx
add    $0x1,%r14
test   %cl,%cl
jne    1130 <string_nocase_hash+0x20>
jmp    1158 <string_nocase_hash+0x48>
mov    $0x1505,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i64 @string_nocase_hash(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %15, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %13, %4 ], [ %2, %1 ]
%6 = phi i8* [ %12, %4 ], [ %0, %1 ]
%7 = phi i64 [ %11, %4 ], [ 5381, %1 ]
%8 = shl i64 %7, 5
%9 = xor i64 %8, %7
%10 = tail call i64 @tolower(i8 zeroext %5)
%11 = xor i64 %9, %10
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %4
15: ; preds = %4, %1
%16 = phi i64 [ 5381, %1 ], [ %11, %4 ]
ret i64 %16
}