#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 */
unsigned char getchr();
unsigned char get_nibble() {
  unsigned char c = getchr();
  if (c < '0')
    return 0xFF;
  if (c <= '9')
    return c - '0';
  if (c < 'A')
    return 0xFF;
  if (c <= 'F')
    return c - 0x37;
  if (c < 'a')
    return 0xFF;
  if (c <= 'f')
    return c - 0x57;
  return 0xFF;
}


x86 assembly (clang, -O0):
<get_nibble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <getchr@plt>
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x30,%eax
jge    1138 <get_nibble+0x28>
movb   $0xff,-0x1(%rbp)
jmp    11bc <get_nibble+0xac>
movzbl -0x2(%rbp),%eax
cmp    $0x39,%eax
jg     1154 <get_nibble+0x44>
movzbl -0x2(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x1(%rbp)
jmp    11bc <get_nibble+0xac>
movzbl -0x2(%rbp),%eax
cmp    $0x41,%eax
jge    116a <get_nibble+0x5a>
movb   $0xff,-0x1(%rbp)
jmp    11bc <get_nibble+0xac>
movzbl -0x2(%rbp),%eax
cmp    $0x46,%eax
jg     1186 <get_nibble+0x76>
movzbl -0x2(%rbp),%eax
sub    $0x37,%eax
mov    %al,-0x1(%rbp)
jmp    11bc <get_nibble+0xac>
movzbl -0x2(%rbp),%eax
cmp    $0x61,%eax
jge    119c <get_nibble+0x8c>
movb   $0xff,-0x1(%rbp)
jmp    11bc <get_nibble+0xac>
movzbl -0x2(%rbp),%eax
cmp    $0x66,%eax
jg     11b8 <get_nibble+0xa8>
movzbl -0x2(%rbp),%eax
sub    $0x57,%eax
mov    %al,-0x1(%rbp)
jmp    11bc <get_nibble+0xac>
movb   $0xff,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_nibble>:
push   %rax
xor    %eax,%eax
call   1030 <getchr@plt>
mov    $0xff,%cl
cmp    $0x30,%al
jb     1149 <get_nibble+0x39>
cmp    $0x39,%al
ja     1128 <get_nibble+0x18>
add    $0xd0,%al
mov    %eax,%ecx
jmp    1149 <get_nibble+0x39>
cmp    $0x41,%al
jb     1149 <get_nibble+0x39>
cmp    $0x46,%al
ja     1136 <get_nibble+0x26>
add    $0xc9,%al
mov    %eax,%ecx
jmp    1149 <get_nibble+0x39>
lea    -0x61(%rax),%ecx
add    $0xa9,%al
cmp    $0x6,%cl
movzbl %al,%eax
mov    $0xff,%ecx
cmovb  %eax,%ecx
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define zeroext i8 @get_nibble() {
%1 = alloca i8
%2 = alloca i8
%3 = call zeroext i8 (...) @getchr()
store i8 %3, i8* %2
%4 = load i8, i8* %2
%5 = zext i8 %4 to i32
%6 = icmp slt i32 %5, 48
br i1 %6, label %7, label %8
7: ; preds = %0
store i8 -1, i8* %1
br label %46
8: ; preds = %0
%9 = load i8, i8* %2
%10 = zext i8 %9 to i32
%11 = icmp sle i32 %10, 57
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i8, i8* %2
%14 = zext i8 %13 to i32
%15 = sub nsw i32 %14, 48
%16 = trunc i32 %15 to i8
store i8 %16, i8* %1
br label %46
17: ; preds = %8
%18 = load i8, i8* %2
%19 = zext i8 %18 to i32
%20 = icmp slt i32 %19, 65
br i1 %20, label %21, label %22
21: ; preds = %17
store i8 -1, i8* %1
br label %46
22: ; preds = %17
%23 = load i8, i8* %2
%24 = zext i8 %23 to i32
%25 = icmp sle i32 %24, 70
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8, i8* %2
%28 = zext i8 %27 to i32
%29 = sub nsw i32 %28, 55
%30 = trunc i32 %29 to i8
store i8 %30, i8* %1
br label %46
31: ; preds = %22
%32 = load i8, i8* %2
%33 = zext i8 %32 to i32
%34 = icmp slt i32 %33, 97
br i1 %34, label %35, label %36
35: ; preds = %31
store i8 -1, i8* %1
br label %46
36: ; preds = %31
%37 = load i8, i8* %2
%38 = zext i8 %37 to i32
%39 = icmp sle i32 %38, 102
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i8, i8* %2
%42 = zext i8 %41 to i32
%43 = sub nsw i32 %42, 87
%44 = trunc i32 %43 to i8
store i8 %44, i8* %1
br label %46
45: ; preds = %36
store i8 -1, i8* %1
br label %46
46: ; preds = %45, %40, %35, %26, %21, %12, %7
%47 = load i8, i8* %1
ret i8 %47
}

LLVM IR (-O2):
define zeroext i8 @get_nibble() {
%1 = tail call zeroext i8 (...) @getchr()
%2 = icmp ult i8 %1, 48
br i1 %2, label %18, label %3
3: ; preds = %0
%4 = icmp ult i8 %1, 58
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = add nsw i8 %1, -48
br label %18
7: ; preds = %3
%8 = icmp ult i8 %1, 65
br i1 %8, label %18, label %9
9: ; preds = %7
%10 = icmp ult i8 %1, 71
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = add nsw i8 %1, -55
br label %18
13: ; preds = %9
%14 = add i8 %1, -97
%15 = icmp ult i8 %14, 6
%16 = add i8 %1, -87
%17 = select i1 %15, i8 %16, i8 -1
br label %18
18: ; preds = %13, %7, %0, %11, %5
%19 = phi i8 [ %6, %5 ], [ %12, %11 ], [ -1, %0 ], [ -1, %7 ], [ %17, %13 ]
ret i8 %19
}