#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*/ fprintf(int /*<<< orphan*/, char *, unsigned char,
                           unsigned char);
int /*<<< orphan*/ stderr;
int fromhex(unsigned char c) {
  if (c >= 'a' && c <= 'f')
    return 10 + (c - 'a');
  if (c >= '0' && c <= '9')
    return (c - '0');
  fprintf(stderr, "bad char: '%c' 0x%02x\n", c, c);
  exit(-1);
}


x86 assembly (clang, -O0):
<fromhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     115a <fromhex+0x3a>
movzbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     115a <fromhex+0x3a>
movzbl -0x5(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <fromhex+0x8c>
movzbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     1183 <fromhex+0x63>
movzbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     1183 <fromhex+0x63>
movzbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11ac <fromhex+0x8c>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    -0x5(%rbp),%al
lea    0xe6a(%rip),%rsi
movzbl %al,%edx
movzbl -0x5(%rbp),%ecx
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fromhex>:
lea    -0x61(%rdi),%eax
mov    $0xffffffa9,%ecx
cmp    $0x6,%al
jb     1138 <fromhex+0x18>
lea    -0x30(%rdi),%eax
mov    $0xffffffd0,%ecx
cmp    $0xa,%al
jae    113f <fromhex+0x1f>
movzbl %dil,%eax
add    %ecx,%eax
ret
push   %rax
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
movzbl %dil,%ecx
lea    0xeac(%rip),%rsi
mov    %eax,%edi
mov    %ecx,%edx
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"bad char: '%c' 0x%02x\0A\00"
define i32 @fromhex(i8 zeroext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = zext i8 %4 to i32
%6 = icmp sge i32 %5, 97
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = load i8, i8* %3
%9 = zext i8 %8 to i32
%10 = icmp sle i32 %9, 102
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i8, i8* %3
%13 = zext i8 %12 to i32
%14 = sub nsw i32 %13, 97
%15 = add nsw i32 10, %14
store i32 %15, i32* %2
br label %34
16: ; preds = %7, %1
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
%19 = icmp sge i32 %18, 48
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i8, i8* %3
%22 = zext i8 %21 to i32
%23 = icmp sle i32 %22, 57
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i8, i8* %3
%26 = zext i8 %25 to i32
%27 = sub nsw i32 %26, 48
store i32 %27, i32* %2
br label %34
28: ; preds = %20, %16
%29 = load i32, i32* @stderr
%30 = load i8, i8* %3
%31 = load i8, i8* %3
%32 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8 zeroext %30, i8 zeroext %31)
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %24, %11
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"bad char: '%c' 0x%02x\0A\00"
define i32 @fromhex(i8 zeroext %0) {
%2 = add i8 %0, -97
%3 = icmp ult i8 %2, 6
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = add i8 %0, -48
%6 = icmp ult i8 %5, 10
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8 zeroext %0, i8 zeroext %0)
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %4, %1
%12 = phi i32 [ -87, %1 ], [ -48, %4 ]
%13 = zext i8 %0 to i32
%14 = add nsw i32 %12, %13
ret i32 %14
}