#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 strtohex(uint8_t x) {
  if (x <= '9')
    return x - '0';
  else if (x <= 'F')
    return x - 'A' + 10;
  else if (x <= 'f')
    return x - 'a' + 10;
  return 0xFF;
}


x86 assembly (clang, -O0):
<strtohex>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0x39,%eax
jg     1126 <strtohex+0x26>
movsbl -0x2(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x1(%rbp)
jmp    1172 <strtohex+0x72>
movsbl -0x2(%rbp),%eax
cmp    $0x46,%eax
jg     1145 <strtohex+0x45>
movsbl -0x2(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %al,-0x1(%rbp)
jmp    1172 <strtohex+0x72>
movsbl -0x2(%rbp),%eax
cmp    $0x66,%eax
jg     1164 <strtohex+0x64>
movsbl -0x2(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %al,-0x1(%rbp)
jmp    1172 <strtohex+0x72>
jmp    1169 <strtohex+0x69>
jmp    116e <strtohex+0x6e>
movb   $0xff,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtohex>:
mov    %edi,%eax
cmp    $0x39,%al
jg     1109 <strtohex+0x9>
add    $0xd0,%al
ret
cmp    $0x46,%al
ja     1110 <strtohex+0x10>
add    $0xc9,%al
ret
lea    -0x57(%rax),%ecx
cmp    $0x67,%al
movzbl %cl,%ecx
mov    $0xff,%eax
cmovb  %ecx,%eax
ret

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

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