#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);
scalar_t__ isupper(char);
int c2i(char ch) {
  int num;
  if (isdigit(ch)) {
    num = ch - 48;
  } else if (isalpha(ch)) {
    if (ch < 'A' || (ch > 'F' && ch < 'a') || ch > 'z')
      num = -1;
    else
      num = (isupper(ch) ? ch - 55 : ch - 87);
  } else {
    num = -1;
  }
  return num;
}


x86 assembly (clang, -O0):
<c2i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1160 <c2i+0x30>
movsbl -0x1(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
jmp    11f6 <c2i+0xc6>
movsbl -0x1(%rbp),%edi
call   1040 <isalpha@plt>
cmp    $0x0,%rax
je     11ea <c2i+0xba>
movsbl -0x1(%rbp),%eax
cmp    $0x41,%eax
jl     11a7 <c2i+0x77>
movsbl -0x1(%rbp),%eax
cmp    $0x46,%eax
jle    119a <c2i+0x6a>
movsbl -0x1(%rbp),%eax
cmp    $0x61,%eax
jl     11a7 <c2i+0x77>
movsbl -0x1(%rbp),%eax
cmp    $0x7a,%eax
jle    11b3 <c2i+0x83>
movl   $0xffffffff,-0x8(%rbp)
jmp    11e5 <c2i+0xb5>
movsbl -0x1(%rbp),%edi
call   1050 <isupper@plt>
cmp    $0x0,%rax
je     11d5 <c2i+0xa5>
movsbl -0x1(%rbp),%eax
sub    $0x37,%eax
mov    %eax,-0xc(%rbp)
jmp    11df <c2i+0xaf>
movsbl -0x1(%rbp),%eax
sub    $0x57,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11f1 <c2i+0xc1>
movl   $0xffffffff,-0x8(%rbp)
jmp    11f6 <c2i+0xc6>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c2i>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1030 <isdigit@plt>
test   %rax,%rax
je     114e <c2i+0x1e>
movsbl %bl,%eax
add    $0xffffffd0,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movsbl %bl,%r14d
mov    %r14d,%edi
call   1040 <isalpha@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     1146 <c2i+0x16>
cmp    $0x41,%bl
jl     1146 <c2i+0x16>
cmp    $0x7a,%bl
ja     1146 <c2i+0x16>
lea    -0x47(%rbx),%ecx
cmp    $0x1a,%cl
jb     1146 <c2i+0x16>
mov    %r14d,%edi
call   1050 <isupper@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
shl    $0x5,%ecx
lea    (%rcx,%r14,1),%eax
add    $0xffffffa9,%eax
jmp    1146 <c2i+0x16>

LLVM IR (-O0):
define i32 @c2i(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
%4 = load i8, i8* %2
%5 = call i64 @isdigit(i8 signext %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = sub nsw i32 %9, 48
store i32 %10, i32* %3
br label %49
11: ; preds = %1
%12 = load i8, i8* %2
%13 = call i64 @isalpha(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %47
15: ; preds = %11
%16 = load i8, i8* %2
%17 = sext i8 %16 to i32
%18 = icmp slt i32 %17, 65
br i1 %18, label %31, label %19
19: ; preds = %15
%20 = load i8, i8* %2
%21 = sext i8 %20 to i32
%22 = icmp sgt i32 %21, 70
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i8, i8* %2
%25 = sext i8 %24 to i32
%26 = icmp slt i32 %25, 97
br i1 %26, label %31, label %27
27: ; preds = %23, %19
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
%30 = icmp sgt i32 %29, 122
br i1 %30, label %31, label %32
31: ; preds = %27, %23, %15
store i32 -1, i32* %3
br label %46
32: ; preds = %27
%33 = load i8, i8* %2
%34 = call i64 @isupper(i8 signext %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i8, i8* %2
%38 = sext i8 %37 to i32
%39 = sub nsw i32 %38, 55
br label %44
40: ; preds = %32
%41 = load i8, i8* %2
%42 = sext i8 %41 to i32
%43 = sub nsw i32 %42, 87
br label %44
44: ; preds = %40, %36
%45 = phi i32 [ %39, %36 ], [ %43, %40 ]
store i32 %45, i32* %3
br label %46
46: ; preds = %44, %31
br label %48
47: ; preds = %11
store i32 -1, i32* %3
br label %48
48: ; preds = %47, %46
br label %49
49: ; preds = %48, %7
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
define i32 @c2i(i8 signext %0) {
%2 = tail call i64 @isdigit(i8 signext %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = sext i8 %0 to i32
%6 = add nsw i32 %5, -48
br label %23
7: ; preds = %1
%8 = tail call i64 @isalpha(i8 signext %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %7
%11 = sext i8 %0 to i32
%12 = icmp slt i8 %0, 65
br i1 %12, label %23, label %13
13: ; preds = %10
%14 = add nsw i8 %0, -71
%15 = icmp ult i8 %14, 26
%16 = icmp ugt i8 %0, 122
%17 = or i1 %16, %15
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = tail call i64 @isupper(i8 signext %0)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i32 -87, i32 -55
%22 = add nsw i32 %21, %11
br label %23
23: ; preds = %7, %10, %13, %18, %4
%24 = phi i32 [ %6, %4 ], [ %22, %18 ], [ -1, %13 ], [ -1, %10 ], [ -1, %7 ]
ret i32 %24
}