#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 */
char EOF;
int /*<<< orphan*/ gli_display_error(char *);
int parse_hex_digit(char ch) {
  if (ch == EOF)
    (gli_display_error("data: Unexpected end of input"));
  if (ch >= '0' && ch <= '9')
    return ch - '0';
  if (ch >= 'A' && ch <= 'F')
    return ch + 10 - 'A';
  if (ch >= 'a' && ch <= 'f')
    return ch + 10 - 'a';
  (gli_display_error("data: Not a hex digit"));
  return 0;
}


x86 assembly (clang, -O0):
<parse_hex_digit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
mov    0x2ebf(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1140 <parse_hex_digit+0x30>
lea    0xec5(%rip),%rdi
call   1030 <gli_display_error@plt>
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jl     1169 <parse_hex_digit+0x59>
movsbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     1169 <parse_hex_digit+0x59>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <parse_hex_digit+0xc4>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jl     1195 <parse_hex_digit+0x85>
movsbl -0x5(%rbp),%eax
cmp    $0x46,%eax
jg     1195 <parse_hex_digit+0x85>
movsbl -0x5(%rbp),%eax
add    $0xa,%eax
sub    $0x41,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <parse_hex_digit+0xc4>
movsbl -0x5(%rbp),%eax
cmp    $0x61,%eax
jl     11c1 <parse_hex_digit+0xb1>
movsbl -0x5(%rbp),%eax
cmp    $0x66,%eax
jg     11c1 <parse_hex_digit+0xb1>
movsbl -0x5(%rbp),%eax
add    $0xa,%eax
sub    $0x61,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <parse_hex_digit+0xc4>
lea    0xe56(%rip),%rdi
call   1030 <gli_display_error@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_hex_digit>:
push   %rbx
mov    %edi,%ebx
mov    0x2ece(%rip),%rax
cmp    %bl,(%rax)
jne    112a <parse_hex_digit+0x1a>
lea    0xedb(%rip),%rdi
call   1030 <gli_display_error@plt>
lea    -0x30(%rbx),%eax
cmp    $0x9,%al
ja     1136 <parse_hex_digit+0x26>
add    $0xffffffd0,%ebx
jmp    115c <parse_hex_digit+0x4c>
lea    -0x41(%rbx),%eax
cmp    $0x5,%al
ja     1142 <parse_hex_digit+0x32>
add    $0xffffffc9,%ebx
jmp    115c <parse_hex_digit+0x4c>
lea    -0x61(%rbx),%eax
cmp    $0x5,%al
ja     114e <parse_hex_digit+0x3e>
add    $0xffffffa9,%ebx
jmp    115c <parse_hex_digit+0x4c>
lea    0xec9(%rip),%rdi
call   1030 <gli_display_error@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [30 x i8] c"data: Unexpected end of input\00"
@.str.1 = [22 x i8] c"data: Not a hex digit\00"
define i32 @parse_hex_digit(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = load i8, i8* @EOF
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %5, %7
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @gli_display_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = icmp sge i32 %13, 48
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = icmp sle i32 %17, 57
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i8, i8* %3
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, 48
store i32 %22, i32* %2
br label %51
23: ; preds = %15, %11
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = icmp sge i32 %25, 65
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp sle i32 %29, 70
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = add nsw i32 %33, 10
%35 = sub nsw i32 %34, 65
store i32 %35, i32* %2
br label %51
36: ; preds = %27, %23
%37 = load i8, i8* %3
%38 = sext i8 %37 to i32
%39 = icmp sge i32 %38, 97
br i1 %39, label %40, label %49
40: ; preds = %36
%41 = load i8, i8* %3
%42 = sext i8 %41 to i32
%43 = icmp sle i32 %42, 102
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = load i8, i8* %3
%46 = sext i8 %45 to i32
%47 = add nsw i32 %46, 10
%48 = sub nsw i32 %47, 97
store i32 %48, i32* %2
br label %51
49: ; preds = %40, %36
%50 = call i32 @gli_display_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %51
51: ; preds = %49, %44, %31, %19
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [30 x i8] c"data: Unexpected end of input\00"
@.str.1 = [22 x i8] c"data: Not a hex digit\00"
define i32 @parse_hex_digit(i8 signext %0) {
%2 = sext i8 %0 to i32
%3 = load i8, i8* @EOF
%4 = icmp eq i8 %3, %0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @gli_display_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = add i8 %0, -48
%9 = icmp ult i8 %8, 10
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = add nsw i32 %2, -48
br label %24
12: ; preds = %7
%13 = add i8 %0, -65
%14 = icmp ult i8 %13, 6
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = add nsw i32 %2, -55
br label %24
17: ; preds = %12
%18 = add i8 %0, -97
%19 = icmp ult i8 %18, 6
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = add nsw i32 %2, -87
br label %24
22: ; preds = %17
%23 = tail call i32 @gli_display_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %20, %15, %10
%25 = phi i32 [ %11, %10 ], [ %16, %15 ], [ %21, %20 ], [ 0, %22 ]
ret i32 %25
}