#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*/ abort();
int /*<<< orphan*/ printf(char *, char);
int hex_to_num(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  } else if (c >= 'A' && c <= 'F') {
    return c - 'A' + 10;
  } else if (c >= 'a' && c <= 'f') {
    return c - 'a' + 10;
  } else {
    printf("error: invalid hex digit '%c'\n", c);
    abort();
  }
}


x86 assembly (clang, -O0):
<hex_to_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     1157 <hex_to_num+0x37>
movsbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     1157 <hex_to_num+0x37>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <hex_to_num+0xa6>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jl     1183 <hex_to_num+0x63>
movsbl -0x5(%rbp),%eax
cmp    $0x46,%eax
jg     1183 <hex_to_num+0x63>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <hex_to_num+0xa6>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     11af <hex_to_num+0x8f>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     11af <hex_to_num+0x8f>
movsbl -0x5(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <hex_to_num+0xa6>
lea    0xe4a(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_num>:
lea    -0x30(%rdi),%eax
mov    $0xffffffd0,%ecx
cmp    $0xa,%al
jb     1144 <hex_to_num+0x24>
lea    -0x41(%rdi),%eax
mov    $0xffffffc9,%ecx
cmp    $0x6,%al
jb     1144 <hex_to_num+0x24>
lea    -0x61(%rdi),%eax
mov    $0xffffffa9,%ecx
cmp    $0x6,%al
jae    114b <hex_to_num+0x2b>
movsbl %dil,%eax
add    %ecx,%eax
ret
push   %rax
movsbl %dil,%esi
lea    0xea9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

LLVM IR (-O2):
@.str = [31 x i8] c"error: invalid hex digit '%c'\0A\00"
define i32 @hex_to_num(i8 signext %0) {
%2 = add i8 %0, -48
%3 = icmp ult i8 %2, 10
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = add i8 %0, -65
%6 = icmp ult i8 %5, 6
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = add i8 %0, -97
%9 = icmp ult i8 %8, 6
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8 signext %0)
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %7, %4, %1
%14 = phi i32 [ -48, %1 ], [ -55, %4 ], [ -87, %7 ]
%15 = sext i8 %0 to i32
%16 = add nsw i32 %14, %15
ret i32 %16
}