#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*/ exit(int);
int /*<<< orphan*/ printf(char *, char);
int hdtoid(char c) {
  if (c >= '0' && c <= '9')
    return c - 48;
  if (c >= 'A' && c <= 'F')
    return c - 55;
  if (c >= 'a' && c <= 'f')
    return c - 87;
  printf("Invalid character specified (%c); terminating\n", c);
  exit(1);
}


x86 assembly (clang, -O0):
<hdtoid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     1157 <hdtoid+0x37>
movsbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     1157 <hdtoid+0x37>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11c3 <hdtoid+0xa3>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jl     1180 <hdtoid+0x60>
movsbl -0x5(%rbp),%eax
cmp    $0x46,%eax
jg     1180 <hdtoid+0x60>
movsbl -0x5(%rbp),%eax
sub    $0x37,%eax
mov    %eax,-0x4(%rbp)
jmp    11c3 <hdtoid+0xa3>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     11a9 <hdtoid+0x89>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     11a9 <hdtoid+0x89>
movsbl -0x5(%rbp),%eax
sub    $0x57,%eax
mov    %eax,-0x4(%rbp)
jmp    11c3 <hdtoid+0xa3>
lea    0xe50(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@.str = [47 x i8] c"Invalid character specified (%c); terminating\0A\00"
define i32 @hdtoid(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 %43
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 %27
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 %27
23: ; preds = %19
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = sub nsw i32 %25, 55
store i32 %26, i32* %2
br label %43
27: ; preds = %19, %15
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp sge i32 %29, 97
br i1 %30, label %31, label %39
31: ; preds = %27
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = icmp sle i32 %33, 102
br i1 %34, label %35, label %39
35: ; preds = %31
%36 = load i8, i8* %3
%37 = sext i8 %36 to i32
%38 = sub nsw i32 %37, 87
store i32 %38, i32* %2
br label %43
39: ; preds = %31, %27
%40 = load i8, i8* %3
%41 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8 signext %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %35, %23, %11
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.str = [47 x i8] c"Invalid character specified (%c); terminating\0A\00"
define i32 @hdtoid(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 ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8 signext %0)
%12 = tail call i32 @exit(i32 1)
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
}