#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 uint8_t;

/* Variables and functions */
uint8_t gdbstub_from_hex_digit(char ch) {
  if (ch >= '0' && ch <= '9')
    return ch - '0';
  else if (ch >= 'A' && ch <= 'F')
    return ch - 'A' + 0xa;
  else
    return (ch - 'a' + 0xa) & 0xf;
}


x86 assembly (clang, -O0):
<gdbstub_from_hex_digit>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0x30,%eax
jl     1133 <gdbstub_from_hex_digit+0x33>
movsbl -0x2(%rbp),%eax
cmp    $0x39,%eax
jg     1133 <gdbstub_from_hex_digit+0x33>
movsbl -0x2(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x1(%rbp)
jmp    116f <gdbstub_from_hex_digit+0x6f>
movsbl -0x2(%rbp),%eax
cmp    $0x41,%eax
jl     115f <gdbstub_from_hex_digit+0x5f>
movsbl -0x2(%rbp),%eax
cmp    $0x46,%eax
jg     115f <gdbstub_from_hex_digit+0x5f>
movsbl -0x2(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %al,-0x1(%rbp)
jmp    116f <gdbstub_from_hex_digit+0x6f>
movsbl -0x2(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
and    $0xf,%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdbstub_from_hex_digit>:
lea    -0x30(%rdi),%eax
cmp    $0xa,%al
jb     111e <gdbstub_from_hex_digit+0x1e>
lea    -0x41(%rdi),%eax
cmp    $0x5,%al
ja     1114 <gdbstub_from_hex_digit+0x14>
add    $0xc9,%dil
jmp    111c <gdbstub_from_hex_digit+0x1c>
add    $0x9,%dil
and    $0xf,%dil
mov    %edi,%eax
ret

LLVM IR (-O0):
define signext i8 @gdbstub_from_hex_digit(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 sge i32 %5, 48
br i1 %6, label %7, label %16
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 %16
11: ; preds = %7
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = sub nsw i32 %13, 48
%15 = trunc i32 %14 to i8
store i8 %15, i8* %2
br label %37
16: ; preds = %7, %1
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = icmp sge i32 %18, 65
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = icmp sle i32 %22, 70
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8, i8* %3
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 65
%28 = add nsw i32 %27, 10
%29 = trunc i32 %28 to i8
store i8 %29, i8* %2
br label %37
30: ; preds = %20, %16
%31 = load i8, i8* %3
%32 = sext i8 %31 to i32
%33 = sub nsw i32 %32, 97
%34 = add nsw i32 %33, 10
%35 = and i32 %34, 15
%36 = trunc i32 %35 to i8
store i8 %36, i8* %2
br label %37
37: ; preds = %30, %24, %11
%38 = load i8, i8* %2
ret i8 %38
}

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