#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__ isalpha(char);
scalar_t__ isdigit(char);
int toupper(char);
unsigned hash(char *label, char *phase) {
  unsigned hashval;
  if (isdigit(label[0]))
    hashval = label[0] - '0';
  else if (isalpha(label[0]))
    hashval = 10 + toupper(label[0]) - 'A';
  else
    hashval = 36 + label[0] % 10;
  hashval = hashval % 46;
  return hashval;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1168 <hash+0x38>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <hash+0x82>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     1198 <hash+0x68>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
add    $0xa,%eax
sub    $0x41,%eax
mov    %eax,-0x14(%rbp)
jmp    11ad <hash+0x7d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x24,%edx
mov    %edx,-0x14(%rbp)
jmp    11b2 <hash+0x82>
mov    -0x14(%rbp),%eax
mov    $0x2e,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbx
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
movsbl (%rbx),%eax
test   %rcx,%rcx
je     114c <hash+0x1c>
add    $0xffffffd0,%eax
jmp    1188 <hash+0x58>
mov    %eax,%edi
call   1050 <isalpha@plt>
mov    (%rbx),%cl
test   %rax,%rax
je     1167 <hash+0x37>
movsbl %cl,%edi
call   1040 <toupper@plt>
add    $0xffffffc9,%eax
jmp    1188 <hash+0x58>
movsbl %cl,%eax
imul   $0x67,%eax,%eax
movzwl %ax,%edx
shr    $0xa,%eax
shr    $0xf,%edx
add    %al,%dl
movzbl %dl,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %al,%cl
add    $0x24,%cl
movzbl %cl,%eax
mov    %eax,%ecx
mov    $0xb21642c9,%edx
imul   %rcx,%rdx
shr    $0x25,%rdx
imul   $0x2e,%edx,%ecx
sub    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @hash(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = call i64 @isdigit(i8 signext %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = sub nsw i32 %15, 48
store i32 %16, i32* %5
br label %38
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = call i64 @isalpha(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = call i32 @toupper(i8 signext %26)
%28 = add nsw i32 10, %27
%29 = sub nsw i32 %28, 65
store i32 %29, i32* %5
br label %37
30: ; preds = %17
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = srem i32 %34, 10
%36 = add nsw i32 36, %35
store i32 %36, i32* %5
br label %37
37: ; preds = %30, %23
br label %38
38: ; preds = %37, %11
%39 = load i32, i32* %5
%40 = urem i32 %39, 46
store i32 %40, i32* %5
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
define i32 @hash(i8* nocapture %0, i8* nocapture readnone %1) {
%3 = load i8, i8* %0
%4 = tail call i64 @isdigit(i8 signext %3)
%5 = icmp eq i64 %4, 0
%6 = load i8, i8* %0
br i1 %5, label %10, label %7
7: ; preds = %2
%8 = sext i8 %6 to i32
%9 = add nsw i32 %8, -48
br label %21
10: ; preds = %2
%11 = tail call i64 @isalpha(i8 signext %6)
%12 = icmp eq i64 %11, 0
%13 = load i8, i8* %0
br i1 %12, label %17, label %14
14: ; preds = %10
%15 = tail call i32 @toupper(i8 signext %13)
%16 = add nsw i32 %15, -55
br label %21
17: ; preds = %10
%18 = srem i8 %13, 10
%19 = add nsw i8 %18, 36
%20 = zext i8 %19 to i32
br label %21
21: ; preds = %14, %17, %7
%22 = phi i32 [ %9, %7 ], [ %16, %14 ], [ %20, %17 ]
%23 = urem i32 %22, 46
ret i32 %23
}