#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 */
int EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int gethexnibble(FILE *fp) {
  int ch;
  ch = getc(fp);
  if (ch >= '0' && ch <= '9')
    return (ch - '0');
  if (ch >= 'a' && ch <= 'f')
    return (ch - 'a' + 10);
  if (ch >= 'A' && ch <= 'F')
    return (ch - 'A' + 10);
  if (ch == EOF)
    fprintf(stderr, "Unexpected EOF\n");
  else
    fprintf(stderr, "Bad hex char\n");
  return -1;
}


x86 assembly (clang, -O0):
<gethexnibble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x30,-0x14(%rbp)
jl     115a <gethexnibble+0x3a>
cmpl   $0x39,-0x14(%rbp)
jg     115a <gethexnibble+0x3a>
mov    -0x14(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <gethexnibble+0xcc>
cmpl   $0x61,-0x14(%rbp)
jl     117f <gethexnibble+0x5f>
cmpl   $0x66,-0x14(%rbp)
jg     117f <gethexnibble+0x5f>
mov    -0x14(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <gethexnibble+0xcc>
cmpl   $0x41,-0x14(%rbp)
jl     11a4 <gethexnibble+0x84>
cmpl   $0x46,-0x14(%rbp)
jg     11a4 <gethexnibble+0x84>
mov    -0x14(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <gethexnibble+0xcc>
mov    -0x14(%rbp),%eax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%eax
jne    11d0 <gethexnibble+0xb0>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11e5 <gethexnibble+0xc5>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gethexnibble>:
push   %rax
call   1040 <getc@plt>
lea    -0x30(%rax),%ecx
cmp    $0xa,%ecx
jb     117a <gethexnibble+0x5a>
lea    -0x61(%rax),%ecx
cmp    $0x5,%ecx
ja     113d <gethexnibble+0x1d>
add    $0xffffffa9,%eax
mov    %eax,%ecx
jmp    117a <gethexnibble+0x5a>
lea    -0x41(%rax),%ecx
cmp    $0x5,%ecx
ja     114c <gethexnibble+0x2c>
add    $0xffffffc9,%eax
mov    %eax,%ecx
jmp    117a <gethexnibble+0x5a>
mov    0x2e95(%rip),%rcx
mov    0x2e7e(%rip),%rdx
mov    (%rdx),%edi
cmp    (%rcx),%eax
jne    1169 <gethexnibble+0x49>
lea    0xe99(%rip),%rsi
jmp    1170 <gethexnibble+0x50>
lea    0xea0(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [16 x i8] c"Unexpected EOF\0A\00"
@.str.1 = [14 x i8] c"Bad hex char\0A\00"
define i32 @gethexnibble(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = add i32 %2, -48
%4 = icmp ult i32 %3, 10
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = add i32 %2, -97
%7 = icmp ult i32 %6, 6
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = add nsw i32 %2, -87
br label %23
10: ; preds = %5
%11 = add i32 %2, -65
%12 = icmp ult i32 %11, 6
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = add nsw i32 %2, -55
br label %23
15: ; preds = %10
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %2, %16
%18 = load i32, i32* @stderr
br i1 %17, label %19, label %21
19: ; preds = %15
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %23
21: ; preds = %15
%22 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %1, %19, %21, %13, %8
%24 = phi i32 [ %9, %8 ], [ %14, %13 ], [ -1, %21 ], [ -1, %19 ], [ %3, %1 ]
ret i32 %24
}