#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__ isdigit(char);
scalar_t__ islower(char);
scalar_t__ isupper(char);
int c2h(char c) {
  if (isdigit(c))
    return c - '0';
  if (islower(c))
    return 10 + c - 'a';
  if (isupper(c))
    return 10 + c - 'A';
  return -1;
}


x86 assembly (clang, -O0):
<c2h>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1160 <c2h+0x30>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <c2h+0x81>
movsbl -0x5(%rbp),%edi
call   1040 <islower@plt>
cmp    $0x0,%rax
je     1185 <c2h+0x55>
movsbl -0x5(%rbp),%eax
add    $0xa,%eax
sub    $0x61,%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <c2h+0x81>
movsbl -0x5(%rbp),%edi
call   1050 <isupper@plt>
cmp    $0x0,%rax
je     11aa <c2h+0x7a>
movsbl -0x5(%rbp),%eax
add    $0xa,%eax
sub    $0x41,%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <c2h+0x81>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c2h>:
push   %rbx
mov    %edi,%ebx
call   1030 <isdigit@plt>
movsbl %bl,%ebx
test   %rax,%rax
je     1145 <c2h+0x15>
add    $0xffffffd0,%ebx
jmp    116c <c2h+0x3c>
mov    %ebx,%edi
call   1040 <islower@plt>
test   %rax,%rax
je     1156 <c2h+0x26>
add    $0xffffffa9,%ebx
jmp    116c <c2h+0x3c>
mov    %ebx,%edi
call   1050 <isupper@plt>
test   %rax,%rax
je     1167 <c2h+0x37>
add    $0xffffffc9,%ebx
jmp    116c <c2h+0x3c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @c2h(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%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* %3
%9 = sext i8 %8 to i32
%10 = sub nsw i32 %9, 48
store i32 %10, i32* %2
br label %30
11: ; preds = %1
%12 = load i8, i8* %3
%13 = call i64 @islower(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = add nsw i32 10, %17
%19 = sub nsw i32 %18, 97
store i32 %19, i32* %2
br label %30
20: ; preds = %11
%21 = load i8, i8* %3
%22 = call i64 @isupper(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8, i8* %3
%26 = sext i8 %25 to i32
%27 = add nsw i32 10, %26
%28 = sub nsw i32 %27, 65
store i32 %28, i32* %2
br label %30
29: ; preds = %20
store i32 -1, i32* %2
br label %30
30: ; preds = %29, %24, %15, %7
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @c2h(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 %19
7: ; preds = %1
%8 = tail call i64 @islower(i8 signext %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = sext i8 %0 to i32
%12 = add nsw i32 %11, -87
br label %19
13: ; preds = %7
%14 = tail call i64 @isupper(i8 signext %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = sext i8 %0 to i32
%18 = add nsw i32 %17, -55
br label %19
19: ; preds = %13, %16, %10, %4
%20 = phi i32 [ %6, %4 ], [ %12, %10 ], [ %18, %16 ], [ -1, %13 ]
ret i32 %20
}