#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 */
int digitValue(char);
int /*<<< orphan*/ error(char *, ...);
char input();
int /*<<< orphan*/ isDigit(char, int);
int /*<<< orphan*/ skipToEol();
int /*<<< orphan*/ unput(char);
int getHexByte() {
  char c1, c2;
  while ((c1 = input()) == '\\' || c1 == ' ')
    if (c1 == '\\')
      c1 = input();
  if (c1 == '\n' || c1 == 0) {
    unput(c1);
    return (-1);
  } else if (!isDigit(c1, 16)) {
    error("illegal hex digit '%c'\n", c1);
    skipToEol();
    return (-2);
  }
  c2 = input();
  if (c2 == '\n' || c2 == 0) {
    unput(c1);
    error("bad hex digit parity\n");
    return (-2);
  } else if (!isDigit(c2, 16)) {
    error("illegal hex digit '%c'\n", c2);
    skipToEol();
    return (-2);
  }
  return (digitValue(c1) * 16 + digitValue(c2));
}


x86 assembly (clang, -O0):
<getHexByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <input@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%ecx
mov    $0x1,%al
cmp    $0x5c,%ecx
mov    %al,-0x7(%rbp)
je     1190 <getHexByte+0x30>
movsbl -0x5(%rbp),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x7(%rbp)
mov    -0x7(%rbp),%al
test   $0x1,%al
jne    11a0 <getHexByte+0x40>
jmp    11bc <getHexByte+0x5c>
movsbl -0x5(%rbp),%eax
cmp    $0x5c,%eax
jne    11b7 <getHexByte+0x57>
mov    $0x0,%al
call   1030 <input@plt>
mov    %al,-0x5(%rbp)
jmp    1168 <getHexByte+0x8>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
je     11d6 <getHexByte+0x76>
movsbl -0x5(%rbp),%eax
cmp    $0x0,%eax
jne    11eb <getHexByte+0x8b>
movsbl -0x5(%rbp),%edi
call   1040 <unput@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <getHexByte+0x176>
mov    $0x10,%esi
movsbl -0x5(%rbp),%edi
call   1050 <isDigit@plt>
cmp    $0x0,%eax
jne    1227 <getHexByte+0xc7>
movsbl -0x5(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1060 <error@plt>
mov    $0x0,%al
call   1070 <skipToEol@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12d6 <getHexByte+0x176>
jmp    122c <getHexByte+0xcc>
mov    $0x0,%al
call   1030 <input@plt>
mov    %al,-0x6(%rbp)
movsbl -0x6(%rbp),%eax
cmp    $0xa,%eax
je     1250 <getHexByte+0xf0>
movsbl -0x6(%rbp),%eax
cmp    $0x0,%eax
jne    1273 <getHexByte+0x113>
movsbl -0x5(%rbp),%edi
call   1040 <unput@plt>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1060 <error@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12d6 <getHexByte+0x176>
mov    $0x10,%esi
movsbl -0x6(%rbp),%edi
call   1050 <isDigit@plt>
cmp    $0x0,%eax
jne    12af <getHexByte+0x14f>
movsbl -0x6(%rbp),%esi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1060 <error@plt>
mov    $0x0,%al
call   1070 <skipToEol@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12d6 <getHexByte+0x176>
jmp    12b4 <getHexByte+0x154>
movsbl -0x5(%rbp),%edi
call   1080 <digitValue@plt>
shl    $0x4,%eax
mov    %eax,-0xc(%rbp)
movsbl -0x6(%rbp),%edi
call   1080 <digitValue@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHexByte>:
push   %rbp
push   %rbx
push   %rax
jmp    1174 <getHexByte+0x14>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x20,%al
jne    118c <getHexByte+0x2c>
xor    %eax,%eax
call   1030 <input@plt>
cmp    $0x5b,%al
jle    1170 <getHexByte+0x10>
cmp    $0x5c,%al
jne    11a8 <getHexByte+0x48>
xor    %eax,%eax
call   1030 <input@plt>
jmp    1174 <getHexByte+0x14>
test   %al,%al
je     1194 <getHexByte+0x34>
cmp    $0xa,%al
jne    11a8 <getHexByte+0x48>
movsbl %al,%edi
call   1040 <unput@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
movsbl %al,%ebx
mov    %ebx,%edi
mov    $0x10,%esi
call   1050 <isDigit@plt>
test   %eax,%eax
je     11e6 <getHexByte+0x86>
xor    %eax,%eax
call   1030 <input@plt>
cmp    $0xa,%al
je     11ca <getHexByte+0x6a>
test   %al,%al
jne    1204 <getHexByte+0xa4>
mov    %ebx,%edi
call   1040 <unput@plt>
lea    0xe40(%rip),%rdi
xor    %eax,%eax
call   1060 <error@plt>
mov    $0xfffffffe,%eax
jmp    11a1 <getHexByte+0x41>
lea    0xe13(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <error@plt>
xor    %eax,%eax
call   1070 <skipToEol@plt>
mov    $0xfffffffe,%eax
jmp    11a1 <getHexByte+0x41>
movsbl %al,%ebp
mov    %ebp,%edi
mov    $0x10,%esi
call   1050 <isDigit@plt>
test   %eax,%eax
je     1231 <getHexByte+0xd1>
mov    %ebx,%edi
call   1080 <digitValue@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
mov    %ebp,%edi
call   1080 <digitValue@plt>
add    %ebx,%eax
jmp    11a1 <getHexByte+0x41>
lea    0xdc8(%rip),%rdi
mov    %ebp,%esi
jmp    11ef <getHexByte+0x8f>

LLVM IR (-O0):
@.str = [24 x i8] c"illegal hex digit '%c'\0A\00"
@.str.1 = [22 x i8] c"bad hex digit parity\0A\00"
define i32 @getHexByte() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i8
br label %4
4: ; preds = %20, %0
%5 = call signext i8 (...) @input()
store i8 %5, i8* %2
%6 = sext i8 %5 to i32
%7 = icmp eq i32 %6, 92
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 32
br label %12
12: ; preds = %8, %4
%13 = phi i1 [ true, %4 ], [ %11, %8 ]
br i1 %13, label %14, label %21
14: ; preds = %12
%15 = load i8, i8* %2
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 92
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call signext i8 (...) @input()
store i8 %19, i8* %2
br label %20
20: ; preds = %18, %14
br label %4
21: ; preds = %12
%22 = load i8, i8* %2
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = load i8, i8* %2
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25, %21
%30 = load i8, i8* %2
%31 = call i32 @unput(i8 signext %30)
store i32 -1, i32* %1
br label %72
32: ; preds = %25
%33 = load i8, i8* %2
%34 = call i32 @isDigit(i8 signext %33, i32 16)
%35 = icmp ne i32 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %32
%37 = load i8, i8* %2
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = call i32 (...) @skipToEol()
store i32 -2, i32* %1
br label %72
41: ; preds = %32
br label %42
42: ; preds = %41
%43 = call signext i8 (...) @input()
store i8 %43, i8* %3
%44 = load i8, i8* %3
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 10
br i1 %46, label %51, label %47
47: ; preds = %42
%48 = load i8, i8* %3
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47, %42
%52 = load i8, i8* %2
%53 = call i32 @unput(i8 signext %52)
%54 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %1
br label %72
55: ; preds = %47
%56 = load i8, i8* %3
%57 = call i32 @isDigit(i8 signext %56, i32 16)
%58 = icmp ne i32 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %55
%60 = load i8, i8* %3
%61 = sext i8 %60 to i32
%62 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %61)
%63 = call i32 (...) @skipToEol()
store i32 -2, i32* %1
br label %72
64: ; preds = %55
br label %65
65: ; preds = %64
%66 = load i8, i8* %2
%67 = call i32 @digitValue(i8 signext %66)
%68 = mul nsw i32 %67, 16
%69 = load i8, i8* %3
%70 = call i32 @digitValue(i8 signext %69)
%71 = add nsw i32 %68, %70
store i32 %71, i32* %1
br label %72
72: ; preds = %65, %59, %51, %36, %29
%73 = load i32, i32* %1
ret i32 %73
}

LLVM IR (-O2):
@.str = [24 x i8] c"illegal hex digit '%c'\0A\00"
@.str.1 = [22 x i8] c"bad hex digit parity\0A\00"
define i32 @getHexByte() {
br label %1
1: ; preds = %3, %0
%2 = tail call signext i8 (...) @input()
switch i8 %2, label %8 [
i8 92, label %4
i8 32, label %3
i8 10, label %6
i8 0, label %6
]
3: ; preds = %1, %4
br label %1
4: ; preds = %1
%5 = tail call signext i8 (...) @input()
br label %3
6: ; preds = %1, %1
%7 = tail call i32 @unput(i8 signext %2)
br label %32
8: ; preds = %1
%9 = tail call i32 @isDigit(i8 signext %2, i32 16)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = sext i8 %2 to i32
%13 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = tail call i32 (...) @skipToEol()
br label %32
15: ; preds = %8
%16 = tail call signext i8 (...) @input()
%17 = sext i8 %16 to i32
switch i8 %16, label %21 [
i8 10, label %18
i8 0, label %18
]
18: ; preds = %15, %15
%19 = tail call i32 @unput(i8 signext %2)
%20 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %32
21: ; preds = %15
%22 = tail call i32 @isDigit(i8 signext %16, i32 16)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %17)
%26 = tail call i32 (...) @skipToEol()
br label %32
27: ; preds = %21
%28 = tail call i32 @digitValue(i8 signext %2)
%29 = shl nsw i32 %28, 4
%30 = tail call i32 @digitValue(i8 signext %16)
%31 = add nsw i32 %29, %30
br label %32
32: ; preds = %27, %24, %18, %11, %6
%33 = phi i32 [ -1, %6 ], [ -2, %18 ], [ %31, %27 ], [ -2, %24 ], [ -2, %11 ]
ret i32 %33
}