#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(int /*<<< orphan*/);
unsigned int command2hash(const unsigned char *p) {
  unsigned int h = 0;
  while (*p) {
    h = (h << 6) + (h << 16) - h;
    h += (unsigned char)tolower(*p++);
  }
  return h % 127;
}


x86 assembly (clang, -O0):
<command2hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1169 <command2hash+0x59>
mov    -0xc(%rbp),%eax
shl    $0x6,%eax
mov    -0xc(%rbp),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%edi
call   1030 <tolower@plt>
movzbl %al,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <command2hash+0x13>
mov    -0xc(%rbp),%eax
mov    $0x7f,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<command2hash>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1171 <command2hash+0x61>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
imul   $0x1003f,%ecx,%ebp
movzbl %al,%edi
call   1030 <tolower@plt>
movzbl %al,%ecx
add    %ebp,%ecx
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <command2hash+0x20>
mov    %ecx,%eax
imul   $0x2040811,%rax,%rdx
shr    $0x20,%rdx
mov    %ecx,%eax
sub    %edx,%eax
shr    %eax
add    %edx,%eax
shr    $0x6,%eax
mov    %eax,%edx
shl    $0x7,%edx
sub    %edx,%eax
add    %ecx,%eax
jmp    1173 <command2hash+0x63>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @command2hash(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 %25
8: ; preds = %4
%9 = load i32, i32* %3
%10 = shl i32 %9, 6
%11 = load i32, i32* %3
%12 = shl i32 %11, 16
%13 = add i32 %10, %12
%14 = load i32, i32* %3
%15 = sub i32 %13, %14
store i32 %15, i32* %3
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %2
%18 = load i8, i8* %16
%19 = zext i8 %18 to i32
%20 = call i64 @tolower(i32 %19)
%21 = trunc i64 %20 to i8
%22 = zext i8 %21 to i32
%23 = load i32, i32* %3
%24 = add i32 %23, %22
store i32 %24, i32* %3
br label %4
25: ; preds = %4
%26 = load i32, i32* %3
%27 = urem i32 %26, 127
ret i32 %27
}

LLVM IR (-O2):
define i32 @command2hash(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 [ %14, %4 ], [ 0, %1 ]
%7 = phi i8* [ %9, %4 ], [ %0, %1 ]
%8 = mul i32 %6, 65599
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = zext i8 %5 to i32
%11 = tail call i64 @tolower(i32 %10)
%12 = trunc i64 %11 to i32
%13 = and i32 %12, 255
%14 = add i32 %13, %8
%15 = load i8, i8* %9
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %4
17: ; preds = %4
%18 = urem i32 %14, 127
br label %19
19: ; preds = %17, %1
%20 = phi i32 [ 0, %1 ], [ %18, %17 ]
ret i32 %20
}