#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 */
char toupper(char);
short hexChar2Dec(char ch) {
  ch = toupper(ch);
  if ('A' <= ch && 'F' >= ch) {
    return (ch - 'A' + 10);
  } else if ('0' <= ch && '9' >= ch) {
    return (ch - '0');
  }
  return (-1);
}


x86 assembly (clang, -O0):
<hexChar2Dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x3(%rbp)
movsbl -0x3(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0x3(%rbp)
movsbl -0x3(%rbp),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     115f <hexChar2Dec+0x4f>
movsbl -0x3(%rbp),%ecx
mov    $0x46,%eax
cmp    %ecx,%eax
jl     115f <hexChar2Dec+0x4f>
movsbl -0x3(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %ax,-0x2(%rbp)
jmp    119c <hexChar2Dec+0x8c>
movsbl -0x3(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     1191 <hexChar2Dec+0x81>
movsbl -0x3(%rbp),%ecx
mov    $0x39,%eax
cmp    %ecx,%eax
jl     1191 <hexChar2Dec+0x81>
movsbl -0x3(%rbp),%eax
sub    $0x30,%eax
mov    %ax,-0x2(%rbp)
jmp    119c <hexChar2Dec+0x8c>
jmp    1196 <hexChar2Dec+0x86>
movw   $0xffff,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexChar2Dec>:
push   %rax
call   1030 <toupper@plt>
lea    -0x41(%rax),%ecx
cmp    $0x5,%cl
ja     1126 <hexChar2Dec+0x16>
movzbl %al,%ecx
add    $0xffffffc9,%ecx
jmp    1138 <hexChar2Dec+0x28>
lea    -0x30(%rax),%edx
mov    $0xffff,%cx
cmp    $0x9,%dl
ja     1138 <hexChar2Dec+0x28>
movzbl %al,%ecx
add    $0xffffffd0,%ecx
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define signext i16 @hexChar2Dec(i8 signext %0) {
%2 = alloca i16
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = call signext i8 @toupper(i8 signext %4)
store i8 %5, i8* %3
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
%8 = icmp sle i32 65, %7
br i1 %8, label %9, label %19
9: ; preds = %1
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = icmp sge i32 70, %11
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = sub nsw i32 %15, 65
%17 = add nsw i32 %16, 10
%18 = trunc i32 %17 to i16
store i16 %18, i16* %2
br label %34
19: ; preds = %9, %1
%20 = load i8, i8* %3
%21 = sext i8 %20 to i32
%22 = icmp sle i32 48, %21
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = icmp sge i32 57, %25
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = sub nsw i32 %29, 48
%31 = trunc i32 %30 to i16
store i16 %31, i16* %2
br label %34
32: ; preds = %23, %19
br label %33
33: ; preds = %32
store i16 -1, i16* %2
br label %34
34: ; preds = %33, %27, %13
%35 = load i16, i16* %2
ret i16 %35
}

LLVM IR (-O2):
define signext i16 @hexChar2Dec(i8 signext %0) {
%2 = tail call signext i8 @toupper(i8 signext %0)
%3 = add i8 %2, -65
%4 = icmp ult i8 %3, 6
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = zext i8 %2 to i16
%7 = add nsw i16 %6, -55
br label %14
8: ; preds = %1
%9 = add i8 %2, -48
%10 = icmp ult i8 %9, 10
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = zext i8 %2 to i16
%13 = add nsw i16 %12, -48
br label %14
14: ; preds = %8, %11, %5
%15 = phi i16 [ %7, %5 ], [ %13, %11 ], [ -1, %8 ]
ret i16 %15
}