#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned char fgetc(int /*<<< orphan*/ *);
unsigned char finhn(FILE *f) {
  unsigned char c;
  do {
    c = fgetc(f);
  } while (!(c >= '0' && c <= '9') && !(c >= 'A' && c <= 'F'));
  if (c <= '9') {
    return c - '0';
  } else {
    return c + 0x0A - 'A';
  }
}


x86 assembly (clang, -O0):
<finhn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x30,%eax
jl     1147 <finhn+0x37>
movzbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x39,%ecx
mov    %al,-0x12(%rbp)
jle    116e <finhn+0x5e>
movzbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x41,%ecx
mov    %al,-0x13(%rbp)
jl     1166 <finhn+0x56>
movzbl -0x11(%rbp),%eax
cmp    $0x46,%eax
setle  %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
xor    $0xff,%al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    111c <finhn+0xc>
movzbl -0x11(%rbp),%eax
cmp    $0x39,%eax
jg     1195 <finhn+0x85>
movzbl -0x11(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x1(%rbp)
jmp    11a2 <finhn+0x92>
movzbl -0x11(%rbp),%eax
add    $0xa,%eax
sub    $0x41,%eax
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finhn>:
push   %rbx
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <fgetc@plt>
lea    -0x30(%rax),%ecx
cmp    $0xa,%cl
jb     1138 <finhn+0x28>
lea    -0x47(%rax),%edx
cmp    $0xfa,%dl
jb     1120 <finhn+0x10>
lea    -0x37(%rax),%edx
cmp    $0x3a,%al
movzbl %cl,%ecx
movzbl %dl,%eax
cmovb  %ecx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define zeroext i8 @finhn(i32* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call zeroext i8 @fgetc(i32* %0)
%4 = add i8 %3, -48
%5 = icmp ugt i8 %4, 9
%6 = add i8 %3, -71
%7 = icmp ult i8 %6, -6
%8 = and i1 %5, %7
br i1 %8, label %2, label %9
9: ; preds = %2
%10 = icmp ult i8 %3, 58
%11 = add nsw i8 %3, -55
%12 = select i1 %10, i8 %4, i8 %11
ret i8 %12
}