#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 */
short EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, short);
short getchar();
int /*<<< orphan*/ stderr;
short getValidHexCharacter(char *const ch, const bool ignoreInputErrors) {
  short input;
  while (EOF != (input = getchar())) {
    if ('A' <= input && 'F' >= input) {
      *ch = input;
      return (0);
    } else if ('a' <= input && 'f' >= input) {
      *ch = input;
      return (0);
    } else if ('0' <= input && '9' >= input) {
      *ch = input;
      return (0);
    } else if (false == ignoreInputErrors) {
      fprintf(stderr, "Invalid hexadecimal character '%c'.\n", input);
      exit(EXIT_FAILURE);
    }
  }
  return (-1);
}


x86 assembly (clang, -O0):
<getValidHexCharacter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2ea2(%rip),%rax
movswl (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %ax,%cx
mov    -0x1c(%rbp),%eax
mov    %cx,-0x16(%rbp)
movswl %cx,%ecx
cmp    %ecx,%eax
je     1259 <getValidHexCharacter+0x129>
movswl -0x16(%rbp),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     11a1 <getValidHexCharacter+0x71>
movswl -0x16(%rbp),%ecx
mov    $0x46,%eax
cmp    %ecx,%eax
jl     11a1 <getValidHexCharacter+0x71>
mov    -0x16(%rbp),%ax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movw   $0x0,-0x2(%rbp)
jmp    125f <getValidHexCharacter+0x12f>
movswl -0x16(%rbp),%ecx
mov    $0x61,%eax
cmp    %ecx,%eax
jg     11da <getValidHexCharacter+0xaa>
movswl -0x16(%rbp),%ecx
mov    $0x66,%eax
cmp    %ecx,%eax
jl     11da <getValidHexCharacter+0xaa>
mov    -0x16(%rbp),%ax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movw   $0x0,-0x2(%rbp)
jmp    125f <getValidHexCharacter+0x12f>
movswl -0x16(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     1213 <getValidHexCharacter+0xe3>
movswl -0x16(%rbp),%ecx
mov    $0x39,%eax
cmp    %ecx,%eax
jl     1213 <getValidHexCharacter+0xe3>
mov    -0x16(%rbp),%ax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movw   $0x0,-0x2(%rbp)
jmp    125f <getValidHexCharacter+0x12f>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    1245 <getValidHexCharacter+0x115>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
movswl -0x16(%rbp),%edx
call   1040 <fprintf@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    124a <getValidHexCharacter+0x11a>
jmp    124f <getValidHexCharacter+0x11f>
jmp    1254 <getValidHexCharacter+0x124>
jmp    113f <getValidHexCharacter+0xf>
movw   $0xffff,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getValidHexCharacter>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2ea4(%rip),%r12
movabs $0x3f0000003f,%r15
jmp    1154 <getValidHexCharacter+0x24>
test   %ebp,%ebp
je     1194 <getValidHexCharacter+0x64>
movzwl (%r12),%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    %ax,%bx
je     118e <getValidHexCharacter+0x5e>
lea    -0x30(%rax),%ecx
cmp    $0xa,%cx
jb     1180 <getValidHexCharacter+0x50>
lea    -0x41(%rax),%ecx
cmp    $0x25,%cx
ja     1150 <getValidHexCharacter+0x20>
movzwl %cx,%ecx
bt     %rcx,%r15
jae    1150 <getValidHexCharacter+0x20>
mov    %al,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffff,%ax
jmp    1185 <getValidHexCharacter+0x55>
mov    0x2e3d(%rip),%rcx
mov    (%rcx),%edi
movswl %ax,%edx
lea    0xe59(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@EOF = global i16 0
@stderr = global i32 0
@.str = [37 x i8] c"Invalid hexadecimal character '%c'.\0A\00"
@EXIT_FAILURE = global i32 0
define signext i16 @getValidHexCharacter(i8* %0, i32 %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i16
store i8* %0, i8** %4
store i32 %1, i32* %5
br label %7
7: ; preds = %61, %2
%8 = load i16, i16* @EOF
%9 = sext i16 %8 to i32
%10 = call signext i16 (...) @getchar()
store i16 %10, i16* %6
%11 = sext i16 %10 to i32
%12 = icmp ne i32 %9, %11
br i1 %12, label %13, label %62
13: ; preds = %7
%14 = load i16, i16* %6
%15 = sext i16 %14 to i32
%16 = icmp sle i32 65, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i16, i16* %6
%19 = sext i16 %18 to i32
%20 = icmp sge i32 70, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i16, i16* %6
%23 = trunc i16 %22 to i8
%24 = load i8*, i8** %4
store i8 %23, i8* %24
store i16 0, i16* %3
br label %63
25: ; preds = %17, %13
%26 = load i16, i16* %6
%27 = sext i16 %26 to i32
%28 = icmp sle i32 97, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load i16, i16* %6
%31 = sext i16 %30 to i32
%32 = icmp sge i32 102, %31
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i16, i16* %6
%35 = trunc i16 %34 to i8
%36 = load i8*, i8** %4
store i8 %35, i8* %36
store i16 0, i16* %3
br label %63
37: ; preds = %29, %25
%38 = load i16, i16* %6
%39 = sext i16 %38 to i32
%40 = icmp sle i32 48, %39
br i1 %40, label %41, label %49
41: ; preds = %37
%42 = load i16, i16* %6
%43 = sext i16 %42 to i32
%44 = icmp sge i32 57, %43
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i16, i16* %6
%47 = trunc i16 %46 to i8
%48 = load i8*, i8** %4
store i8 %47, i8* %48
store i16 0, i16* %3
br label %63
49: ; preds = %41, %37
%50 = load i32, i32* %5
%51 = icmp eq i32 0, %50
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = load i16, i16* %6
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i16 signext %54)
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %49
br label %59
59: ; preds = %58
br label %60
60: ; preds = %59
br label %61
61: ; preds = %60
br label %7
62: ; preds = %7
store i16 -1, i16* %3
br label %63
63: ; preds = %62, %45, %33, %21
%64 = load i16, i16* %3
ret i16 %64
}

LLVM IR (-O2):
@EOF = global i16 0
@stderr = global i32 0
@.str = [37 x i8] c"Invalid hexadecimal character '%c'.\0A\00"
@EXIT_FAILURE = global i32 0
define signext i16 @getValidHexCharacter(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br label %4
4: ; preds = %12, %2
%5 = load i16, i16* @EOF
%6 = tail call signext i16 (...) @getchar()
%7 = icmp eq i16 %5, %6
br i1 %7, label %20, label %8
8: ; preds = %4
%9 = add i16 %6, -48
%10 = icmp ult i16 %9, 10
br i1 %10, label %18, label %11
11: ; preds = %8
switch i16 %6, label %12 [
i16 102, label %18
i16 101, label %18
i16 100, label %18
i16 99, label %18
i16 98, label %18
i16 97, label %18
i16 70, label %18
i16 69, label %18
i16 68, label %18
i16 67, label %18
i16 66, label %18
i16 65, label %18
]
12: ; preds = %11
br i1 %3, label %13, label %4
13: ; preds = %12
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i16 signext %6)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %11, %11, %11, %11, %11, %11, %11, %11, %11, %11, %11, %11, %8
%19 = trunc i16 %6 to i8
store i8 %19, i8* %0
br label %20
20: ; preds = %4, %18
%21 = phi i16 [ 0, %18 ], [ -1, %4 ]
ret i16 %21
}