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

/* Variables and functions */
int fread(char *, int, int, int /*<<< orphan*/ *);
uint8_t read_hexuint8_t(FILE *fp) {
  static char buf[2];
  static uint32_t bytes_read;
  uint8_t res = 0;
  bytes_read = fread(buf, 1, 2, fp);
  if (bytes_read == 2) {
    if ((buf[0] >= '0') && (buf[0] <= '9'))
      res = (buf[0] & 0x0F) << 4;
    else if ((buf[0] >= 'A') && (buf[0] <= 'F'))
      res = (buf[0] - 55) << 4;
    if ((buf[1] >= '0') && (buf[1] <= '9'))
      res |= (buf[1] & 0x0F);
    else if ((buf[1] >= 'A') && (buf[1] <= 'F'))
      res |= (buf[1] - 55);
  }
  return res;
}


x86 assembly (clang, -O0):
<read_hexuint8_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%rcx
lea    0x2f01(%rip),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
mov    %eax,0x2ef0(%rip)
cmpl   $0x2,0x2ee9(%rip)
jne    122c <read_hexuint8_t+0x11c>
movsbl 0x2ed8(%rip),%eax
cmp    $0x30,%eax
jl     1182 <read_hexuint8_t+0x72>
movsbl 0x2ec8(%rip),%eax
cmp    $0x39,%eax
jg     1182 <read_hexuint8_t+0x72>
movsbl 0x2eb8(%rip),%eax
and    $0xf,%eax
shl    $0x4,%eax
mov    %al,-0x9(%rbp)
jmp    11b7 <read_hexuint8_t+0xa7>
movsbl 0x2ea3(%rip),%eax
cmp    $0x41,%eax
jl     11b2 <read_hexuint8_t+0xa2>
movsbl 0x2e93(%rip),%eax
cmp    $0x46,%eax
jg     11b2 <read_hexuint8_t+0xa2>
movsbl 0x2e83(%rip),%eax
sub    $0x37,%eax
shl    $0x4,%eax
mov    %al,-0x9(%rbp)
jmp    11b7 <read_hexuint8_t+0xa7>
movsbl 0x2e6f(%rip),%eax
cmp    $0x30,%eax
jl     11ef <read_hexuint8_t+0xdf>
movsbl 0x2e5f(%rip),%eax
cmp    $0x39,%eax
jg     11ef <read_hexuint8_t+0xdf>
movsbl 0x2e4f(%rip),%ecx
and    $0xf,%ecx
movsbl -0x9(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x9(%rbp)
jmp    1227 <read_hexuint8_t+0x117>
movsbl 0x2e37(%rip),%eax
cmp    $0x41,%eax
jl     1222 <read_hexuint8_t+0x112>
movsbl 0x2e27(%rip),%eax
cmp    $0x46,%eax
jg     1222 <read_hexuint8_t+0x112>
movsbl 0x2e17(%rip),%ecx
sub    $0x37,%ecx
movsbl -0x9(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x9(%rbp)
jmp    1227 <read_hexuint8_t+0x117>
jmp    122c <read_hexuint8_t+0x11c>
movsbl -0x9(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hexuint8_t>:
push   %rax
mov    %rdi,%rcx
lea    0x2f0e(%rip),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
cmp    $0x2,%eax
jne    1142 <read_hexuint8_t+0x32>
mov    0x2ef4(%rip),%al
lea    -0x30(%rax),%ecx
cmp    $0x9,%cl
ja     1146 <read_hexuint8_t+0x36>
shl    $0x4,%al
jmp    1157 <read_hexuint8_t+0x47>
xor    %eax,%eax
pop    %rcx
ret
lea    -0x41(%rax),%ecx
cmp    $0x5,%cl
ja     1155 <read_hexuint8_t+0x45>
shl    $0x4,%al
add    $0x90,%al
jmp    1157 <read_hexuint8_t+0x47>
xor    %eax,%eax
mov    0x2ecd(%rip),%cl
lea    -0x30(%rcx),%edx
cmp    $0x9,%dl
ja     116a <read_hexuint8_t+0x5a>
and    $0xf,%cl
jmp    1175 <read_hexuint8_t+0x65>
lea    -0x41(%rcx),%edx
cmp    $0x5,%dl
ja     1144 <read_hexuint8_t+0x34>
add    $0xc9,%cl
or     %al,%cl
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
@read_hexuint8_t.buf = internal global [2 x i8] zeroinitializer
@read_hexuint8_t.bytes_read = internal global i32 0
define signext i8 @read_hexuint8_t(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
store i32* %0, i32** %2
store i8 0, i8* %3
%4 = load i32*, i32** %2
%5 = call i32 @fread(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 0), i32 1, i32 2, i32* %4)
store i32 %5, i32* @read_hexuint8_t.bytes_read
%6 = load i32, i32* @read_hexuint8_t.bytes_read
%7 = icmp eq i32 %6, 2
br i1 %7, label %8, label %71
8: ; preds = %1
%9 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 0)
%10 = sext i8 %9 to i32
%11 = icmp sge i32 %10, 48
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 0)
%14 = sext i8 %13 to i32
%15 = icmp sle i32 %14, 57
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 0)
%18 = sext i8 %17 to i32
%19 = and i32 %18, 15
%20 = shl i32 %19, 4
%21 = trunc i32 %20 to i8
store i8 %21, i8* %3
br label %37
22: ; preds = %12, %8
%23 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 0)
%24 = sext i8 %23 to i32
%25 = icmp sge i32 %24, 65
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 0)
%28 = sext i8 %27 to i32
%29 = icmp sle i32 %28, 70
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 0)
%32 = sext i8 %31 to i32
%33 = sub nsw i32 %32, 55
%34 = shl i32 %33, 4
%35 = trunc i32 %34 to i8
store i8 %35, i8* %3
br label %36
36: ; preds = %30, %26, %22
br label %37
37: ; preds = %36, %16
%38 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 1)
%39 = sext i8 %38 to i32
%40 = icmp sge i32 %39, 48
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 1)
%43 = sext i8 %42 to i32
%44 = icmp sle i32 %43, 57
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 1)
%47 = sext i8 %46 to i32
%48 = and i32 %47, 15
%49 = load i8, i8* %3
%50 = sext i8 %49 to i32
%51 = or i32 %50, %48
%52 = trunc i32 %51 to i8
store i8 %52, i8* %3
br label %70
53: ; preds = %41, %37
%54 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 1)
%55 = sext i8 %54 to i32
%56 = icmp sge i32 %55, 65
br i1 %56, label %57, label %69
57: ; preds = %53
%58 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 1)
%59 = sext i8 %58 to i32
%60 = icmp sle i32 %59, 70
br i1 %60, label %61, label %69
61: ; preds = %57
%62 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 1)
%63 = sext i8 %62 to i32
%64 = sub nsw i32 %63, 55
%65 = load i8, i8* %3
%66 = sext i8 %65 to i32
%67 = or i32 %66, %64
%68 = trunc i32 %67 to i8
store i8 %68, i8* %3
br label %69
69: ; preds = %61, %57, %53
br label %70
70: ; preds = %69, %45
br label %71
71: ; preds = %70, %1
%72 = load i8, i8* %3
ret i8 %72
}

LLVM IR (-O2):
@read_hexuint8_t.buf = internal global [2 x i8] zeroinitializer
define signext i8 @read_hexuint8_t(i32* nocapture %0) {
%2 = tail call i32 @fread(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 0), i32 1, i32 2, i32* %0)
%3 = icmp eq i32 %2, 2
br i1 %3, label %4, label %30
4: ; preds = %1
%5 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 0)
%6 = add i8 %5, -48
%7 = icmp ult i8 %6, 10
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = shl i8 %5, 4
br label %16
10: ; preds = %4
%11 = add i8 %5, -65
%12 = icmp ult i8 %11, 6
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = shl i8 %5, 4
%15 = add nuw nsw i8 %14, -112
br label %16
16: ; preds = %10, %13, %8
%17 = phi i8 [ %9, %8 ], [ %15, %13 ], [ 0, %10 ]
%18 = load i8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @read_hexuint8_t.buf, i64 0, i64 1)
%19 = add i8 %18, -48
%20 = icmp ult i8 %19, 10
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = and i8 %18, 15
%23 = or i8 %22, %17
br label %30
24: ; preds = %16
%25 = add i8 %18, -65
%26 = icmp ult i8 %25, 6
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = add nsw i8 %18, -55
%29 = or i8 %28, %17
br label %30
30: ; preds = %21, %27, %24, %1
%31 = phi i8 [ %23, %21 ], [ %29, %27 ], [ %17, %24 ], [ 0, %1 ]
ret i8 %31
}