#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 */
int /*<<< orphan*/ printf(char *);
int CalculateIndex(char index_char) {
  int index_int;
  if (index_char >= '0' && index_char <= '9') {
    index_int = index_char - '0';
    return index_int;
  } else if (index_char >= 'A' && index_char <= 'Z') {
    index_int = index_char - 'A';
    return index_int;
  } else if (index_char >= 'a' && index_char <= 'z') {
    index_int = index_char - 'a';
    return index_int;
  } else {
    printf("Error");
    return -1;
  }
}


x86 assembly (clang, -O0):
<CalculateIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     114d <CalculateIndex+0x3d>
movsbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     114d <CalculateIndex+0x3d>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <CalculateIndex+0xae>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jl     117c <CalculateIndex+0x6c>
movsbl -0x5(%rbp),%eax
cmp    $0x5a,%eax
jg     117c <CalculateIndex+0x6c>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <CalculateIndex+0xae>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     11ab <CalculateIndex+0x9b>
movsbl -0x5(%rbp),%eax
cmp    $0x7a,%eax
jg     11ab <CalculateIndex+0x9b>
movsbl -0x5(%rbp),%eax
sub    $0x61,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <CalculateIndex+0xae>
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateIndex>:
mov    %edi,%eax
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     111e <CalculateIndex+0xe>
add    $0xffffffd0,%eax
ret
lea    -0x41(%rax),%ecx
cmp    $0x19,%cl
ja     112a <CalculateIndex+0x1a>
add    $0xffffffbf,%eax
ret
lea    -0x61(%rax),%ecx
cmp    $0x19,%cl
ja     1136 <CalculateIndex+0x26>
add    $0xffffff9f,%eax
ret
push   %rax
lea    0xec2(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"Error\00"
define i32 @CalculateIndex(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
store i8 %0, i8* %3
%5 = load i8, i8* %3
%6 = sext i8 %5 to i32
%7 = icmp sge i32 %6, 48
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i8, i8* %3
%10 = sext i8 %9 to i32
%11 = icmp sle i32 %10, 57
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = sub nsw i32 %14, 48
store i32 %15, i32* %4
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %45
17: ; preds = %8, %1
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp sge i32 %19, 65
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = icmp sle i32 %23, 90
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = sub nsw i32 %27, 65
store i32 %28, i32* %4
%29 = load i32, i32* %4
store i32 %29, i32* %2
br label %45
30: ; preds = %21, %17
%31 = load i8, i8* %3
%32 = sext i8 %31 to i32
%33 = icmp sge i32 %32, 97
br i1 %33, label %34, label %43
34: ; preds = %30
%35 = load i8, i8* %3
%36 = sext i8 %35 to i32
%37 = icmp sle i32 %36, 122
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8, i8* %3
%40 = sext i8 %39 to i32
%41 = sub nsw i32 %40, 97
store i32 %41, i32* %4
%42 = load i32, i32* %4
store i32 %42, i32* %2
br label %45
43: ; preds = %34, %30
%44 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %45
45: ; preds = %43, %38, %25, %12
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str = [6 x i8] c"Error\00"
define i32 @CalculateIndex(i8 signext %0) {
%2 = sext i8 %0 to i32
%3 = add i8 %0, -48
%4 = icmp ult i8 %3, 10
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = add nsw i32 %2, -48
br label %19
7: ; preds = %1
%8 = add i8 %0, -65
%9 = icmp ult i8 %8, 26
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = add nsw i32 %2, -65
br label %19
12: ; preds = %7
%13 = add i8 %0, -97
%14 = icmp ult i8 %13, 26
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = add nsw i32 %2, -97
br label %19
17: ; preds = %12
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %15, %10, %5
%20 = phi i32 [ %6, %5 ], [ %11, %10 ], [ %16, %15 ], [ -1, %17 ]
ret i32 %20
}