#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 */
typedef char int8_t;

/* Variables and functions */
char ascii_hex_to_bin(int8_t hex_digit) {
  if (('A' <= hex_digit) && ('F' >= hex_digit)) {
    return hex_digit - 'A' + 10;
  } else if (('a' <= hex_digit) && ('f' >= hex_digit)) {
    return hex_digit - 'a' + 10;
  } else if (('0' <= hex_digit) && ('9' >= hex_digit)) {
    return hex_digit - '0';
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<ascii_hex_to_bin>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     113e <ascii_hex_to_bin+0x3e>
movsbl -0x2(%rbp),%ecx
mov    $0x46,%eax
cmp    %ecx,%eax
jl     113e <ascii_hex_to_bin+0x3e>
movsbl -0x2(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %al,-0x1(%rbp)
jmp    11a7 <ascii_hex_to_bin+0xa7>
movsbl -0x2(%rbp),%ecx
mov    $0x61,%eax
cmp    %ecx,%eax
jg     1172 <ascii_hex_to_bin+0x72>
movsbl -0x2(%rbp),%ecx
mov    $0x66,%eax
cmp    %ecx,%eax
jl     1172 <ascii_hex_to_bin+0x72>
movsbl -0x2(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %al,-0x1(%rbp)
jmp    11a7 <ascii_hex_to_bin+0xa7>
movsbl -0x2(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     11a3 <ascii_hex_to_bin+0xa3>
movsbl -0x2(%rbp),%ecx
mov    $0x39,%eax
cmp    %ecx,%eax
jl     11a3 <ascii_hex_to_bin+0xa3>
movsbl -0x2(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x1(%rbp)
jmp    11a7 <ascii_hex_to_bin+0xa7>
movb   $0xff,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ascii_hex_to_bin>:
mov    %edi,%eax
lea    -0x41(%rax),%ecx
cmp    $0x5,%cl
ja     110d <ascii_hex_to_bin+0xd>
add    $0xc9,%al
ret
lea    -0x61(%rax),%ecx
cmp    $0x5,%cl
ja     1118 <ascii_hex_to_bin+0x18>
add    $0xa9,%al
ret
add    $0xd0,%al
cmp    $0xa,%al
movzbl %al,%ecx
mov    $0xff,%eax
cmovb  %ecx,%eax
ret

LLVM IR (-O0):
define signext i8 @ascii_hex_to_bin(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = icmp sle i32 65, %5
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp sge i32 70, %9
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = sub nsw i32 %13, 65
%15 = add nsw i32 %14, 10
%16 = trunc i32 %15 to i8
store i8 %16, i8* %2
br label %45
17: ; preds = %7, %1
%18 = load i8, i8* %3
%19 = sext i8 %18 to i32
%20 = icmp sle i32 97, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = icmp sge i32 102, %23
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = sub nsw i32 %27, 97
%29 = add nsw i32 %28, 10
%30 = trunc i32 %29 to i8
store i8 %30, i8* %2
br label %45
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 sge i32 57, %37
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 i8
store i8 %43, i8* %2
br label %45
44: ; preds = %35, %31
store i8 -1, i8* %2
br label %45
45: ; preds = %44, %39, %25, %11
%46 = load i8, i8* %2
ret i8 %46
}

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