#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*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ stderr;
short hex_digit(char c) {
  if ('a' <= c && c <= 'f')
    return 10 + c - 'a';
  if ('A' <= c && c <= 'F')
    return 10 + c - 'A';
  if ('0' <= c && c <= '9')
    return c - '0';
  fprintf(stderr, "hex_digit: character '%c' is not a hex digit\n", c);
  return -1;
}


x86 assembly (clang, -O0):
<hex_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x3(%rbp)
movsbl -0x3(%rbp),%ecx
mov    $0x61,%eax
cmp    %ecx,%eax
jg     114f <hex_digit+0x3f>
movsbl -0x3(%rbp),%eax
cmp    $0x66,%eax
jg     114f <hex_digit+0x3f>
movsbl -0x3(%rbp),%eax
add    $0xa,%eax
sub    $0x61,%eax
mov    %ax,-0x2(%rbp)
jmp    11cd <hex_digit+0xbd>
movsbl -0x3(%rbp),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     1180 <hex_digit+0x70>
movsbl -0x3(%rbp),%eax
cmp    $0x46,%eax
jg     1180 <hex_digit+0x70>
movsbl -0x3(%rbp),%eax
add    $0xa,%eax
sub    $0x41,%eax
mov    %ax,-0x2(%rbp)
jmp    11cd <hex_digit+0xbd>
movsbl -0x3(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     11ae <hex_digit+0x9e>
movsbl -0x3(%rbp),%eax
cmp    $0x39,%eax
jg     11ae <hex_digit+0x9e>
movsbl -0x3(%rbp),%eax
sub    $0x30,%eax
mov    %ax,-0x2(%rbp)
jmp    11cd <hex_digit+0xbd>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
movsbl -0x3(%rbp),%edx
call   1030 <fprintf@plt>
movw   $0xffff,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_digit>:
lea    -0x61(%rdi),%eax
cmp    $0x5,%al
ja     111f <hex_digit+0xf>
movzbl %dil,%eax
add    $0xffffffa9,%eax
ret
lea    -0x41(%rdi),%eax
cmp    $0x5,%al
ja     112e <hex_digit+0x1e>
movzbl %dil,%eax
add    $0xffffffc9,%eax
ret
lea    -0x30(%rdi),%eax
cmp    $0x9,%al
ja     113d <hex_digit+0x2d>
movzbl %dil,%eax
add    $0xffffffd0,%eax
ret
push   %rax
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
movsbl %dil,%edx
lea    0xeae(%rip),%rsi
mov    %eax,%edi
call   1030 <fprintf@plt>
mov    $0xffff,%ax
add    $0x8,%rsp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"hex_digit: character '%c' is not a hex digit\0A\00"
define signext i16 @hex_digit(i8 signext %0) {
%2 = add i8 %0, -97
%3 = icmp ult i8 %2, 6
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = zext i8 %0 to i16
%6 = add nsw i16 %5, -87
br label %22
7: ; preds = %1
%8 = add i8 %0, -65
%9 = icmp ult i8 %8, 6
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = zext i8 %0 to i16
%12 = add nsw i16 %11, -55
br label %22
13: ; preds = %7
%14 = add i8 %0, -48
%15 = icmp ult i8 %14, 10
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = zext i8 %0 to i16
%18 = add nsw i16 %17, -48
br label %22
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8 signext %0)
br label %22
22: ; preds = %19, %16, %10, %4
%23 = phi i16 [ %6, %4 ], [ %12, %10 ], [ %18, %16 ], [ -1, %19 ]
ret i16 %23
}