#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 int ihex_getc();
unsigned int ihex_getchex(void) {
  unsigned int c = ihex_getc();
  if (c < '0')
    return 0;
  if (c <= '9')
    return c - '0';
  if (c < 'A')
    return 0;
  if (c <= 'F')
    return c - 'A' + 10U;
  if (c < 'a')
    return 0;
  if (c <= 'f')
    return c - 'a' + 10U;
  return 0;
}


x86 assembly (clang, -O0):
<ihex_getchex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <ihex_getc@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x30,-0x8(%rbp)
jae    1138 <ihex_getchex+0x28>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <ihex_getchex+0xa9>
cmpl   $0x39,-0x8(%rbp)
ja     1150 <ihex_getchex+0x40>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <ihex_getchex+0xa9>
cmpl   $0x41,-0x8(%rbp)
jae    1166 <ihex_getchex+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <ihex_getchex+0xa9>
cmpl   $0x46,-0x8(%rbp)
ja     1181 <ihex_getchex+0x71>
mov    -0x8(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <ihex_getchex+0xa9>
cmpl   $0x61,-0x8(%rbp)
jae    1197 <ihex_getchex+0x87>
movl   $0x0,-0x4(%rbp)
jmp    11b9 <ihex_getchex+0xa9>
cmpl   $0x66,-0x8(%rbp)
ja     11b2 <ihex_getchex+0xa2>
mov    -0x8(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11b9 <ihex_getchex+0xa9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ihex_getchex>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <ihex_getc@plt>
cmp    $0x30,%eax
jb     114a <ihex_getchex+0x3a>
cmp    $0x39,%eax
ja     112b <ihex_getchex+0x1b>
add    $0xffffffd0,%eax
mov    %eax,%ebx
jmp    114a <ihex_getchex+0x3a>
cmp    $0x41,%eax
jb     114a <ihex_getchex+0x3a>
cmp    $0x46,%eax
ja     113c <ihex_getchex+0x2c>
add    $0xffffffc9,%eax
mov    %eax,%ebx
jmp    114a <ihex_getchex+0x3a>
lea    -0x61(%rax),%ecx
add    $0xffffffa9,%eax
xor    %ebx,%ebx
cmp    $0x6,%ecx
cmovb  %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @ihex_getchex() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @ihex_getc()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ult i32 %4, 48
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 0, i32* %1
br label %36
7: ; preds = %0
%8 = load i32, i32* %2
%9 = icmp ule i32 %8, 57
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* %2
%12 = sub i32 %11, 48
store i32 %12, i32* %1
br label %36
13: ; preds = %7
%14 = load i32, i32* %2
%15 = icmp ult i32 %14, 65
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 0, i32* %1
br label %36
17: ; preds = %13
%18 = load i32, i32* %2
%19 = icmp ule i32 %18, 70
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %2
%22 = sub i32 %21, 65
%23 = add i32 %22, 10
store i32 %23, i32* %1
br label %36
24: ; preds = %17
%25 = load i32, i32* %2
%26 = icmp ult i32 %25, 97
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 0, i32* %1
br label %36
28: ; preds = %24
%29 = load i32, i32* %2
%30 = icmp ule i32 %29, 102
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* %2
%33 = sub i32 %32, 97
%34 = add i32 %33, 10
store i32 %34, i32* %1
br label %36
35: ; preds = %28
store i32 0, i32* %1
br label %36
36: ; preds = %35, %31, %27, %20, %16, %10, %6
%37 = load i32, i32* %1
ret i32 %37
}

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