#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 */
scalar_t__ isdigit(int);
scalar_t__ islower(int);
int /*<<< orphan*/ isxdigit(int);
int scanc();
int /*<<< orphan*/ yyerror(char *);
int scan_hex_byte(void) {
  int c1, c2;
  int v;
  c1 = scanc();
  if (!isxdigit(c1)) {
    yyerror("malformed hex digit");
    return (0);
  }
  c2 = scanc();
  if (!isxdigit(c2)) {
    yyerror("malformed hex digit");
    return (0);
  }
  v = (((isdigit(c1) ? (c1 - '0')
                     : ((islower(c1) ? (c1 - 'a') : (c1 - 'A')) + 10))
        << 4) |
       (isdigit(c2) ? (c2 - '0')
                    : ((islower(c2) ? (c2 - 'a') : (c2 - 'A')) + 10)));
  return (v);
}


x86 assembly (clang, -O0):
<scan_hex_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1070 <scanc@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%eax
jne    118b <scan_hex_byte+0x3b>
lea    0xe86(%rip),%rdi
call   1050 <yyerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    127c <scan_hex_byte+0x12c>
mov    $0x0,%al
call   1070 <scanc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%eax
jne    11be <scan_hex_byte+0x6e>
lea    0xe53(%rip),%rdi
call   1050 <yyerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    127c <scan_hex_byte+0x12c>
mov    -0x8(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11de <scan_hex_byte+0x8e>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    1210 <scan_hex_byte+0xc0>
mov    -0x8(%rbp),%edi
call   1040 <islower@plt>
cmp    $0x0,%rax
je     11fe <scan_hex_byte+0xae>
mov    -0x8(%rbp),%eax
sub    $0x61,%eax
mov    %eax,-0x18(%rbp)
jmp    1207 <scan_hex_byte+0xb7>
mov    -0x8(%rbp),%eax
sub    $0x41,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1239 <scan_hex_byte+0xe9>
mov    -0xc(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x20(%rbp)
jmp    126b <scan_hex_byte+0x11b>
mov    -0xc(%rbp),%edi
call   1040 <islower@plt>
cmp    $0x0,%rax
je     1259 <scan_hex_byte+0x109>
mov    -0xc(%rbp),%eax
sub    $0x61,%eax
mov    %eax,-0x24(%rbp)
jmp    1262 <scan_hex_byte+0x112>
mov    -0xc(%rbp),%eax
sub    $0x41,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_hex_byte>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <scanc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <isxdigit@plt>
test   %eax,%eax
je     1192 <scan_hex_byte+0x42>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <scanc@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1060 <isxdigit@plt>
test   %eax,%eax
je     1192 <scan_hex_byte+0x42>
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11a0 <scan_hex_byte+0x50>
add    $0xffffffd0,%ebx
jmp    11b7 <scan_hex_byte+0x67>
lea    0xe67(%rip),%rdi
call   1050 <yyerror@plt>
jmp    11ec <scan_hex_byte+0x9c>
mov    %ebx,%edi
call   1040 <islower@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
shl    $0x5,%ecx
add    %ecx,%ebx
add    $0xffffffa9,%ebx
shl    $0x4,%ebx
mov    %r14d,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11d0 <scan_hex_byte+0x80>
add    $0xffffffd0,%r14d
mov    %r14d,%ebp
jmp    11ea <scan_hex_byte+0x9a>
mov    %r14d,%edi
call   1040 <islower@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
shl    $0x5,%ecx
lea    (%rcx,%r14,1),%ebp
add    $0xffffffa9,%ebp
or     %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"malformed hex digit\00"
define i32 @scan_hex_byte() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @scanc()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @isxdigit(i32 %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @yyerror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %64
11: ; preds = %0
%12 = call i32 (...) @scanc()
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 @isxdigit(i32 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 @yyerror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %64
18: ; preds = %11
%19 = load i32, i32* %2
%20 = call i64 @isdigit(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %2
%24 = sub nsw i32 %23, 48
br label %38
25: ; preds = %18
%26 = load i32, i32* %2
%27 = call i64 @islower(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* %2
%31 = sub nsw i32 %30, 97
br label %35
32: ; preds = %25
%33 = load i32, i32* %2
%34 = sub nsw i32 %33, 65
br label %35
35: ; preds = %32, %29
%36 = phi i32 [ %31, %29 ], [ %34, %32 ]
%37 = add nsw i32 %36, 10
br label %38
38: ; preds = %35, %22
%39 = phi i32 [ %24, %22 ], [ %37, %35 ]
%40 = shl i32 %39, 4
%41 = load i32, i32* %3
%42 = call i64 @isdigit(i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i32, i32* %3
%46 = sub nsw i32 %45, 48
br label %60
47: ; preds = %38
%48 = load i32, i32* %3
%49 = call i64 @islower(i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i32, i32* %3
%53 = sub nsw i32 %52, 97
br label %57
54: ; preds = %47
%55 = load i32, i32* %3
%56 = sub nsw i32 %55, 65
br label %57
57: ; preds = %54, %51
%58 = phi i32 [ %53, %51 ], [ %56, %54 ]
%59 = add nsw i32 %58, 10
br label %60
60: ; preds = %57, %44
%61 = phi i32 [ %46, %44 ], [ %59, %57 ]
%62 = or i32 %40, %61
store i32 %62, i32* %4
%63 = load i32, i32* %4
store i32 %63, i32* %1
br label %64
64: ; preds = %60, %16, %9
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
@.str = [20 x i8] c"malformed hex digit\00"
define i32 @scan_hex_byte() {
%1 = tail call i32 (...) @scanc()
%2 = tail call i32 @isxdigit(i32 %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @yyerror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %39
6: ; preds = %0
%7 = tail call i32 (...) @scanc()
%8 = tail call i32 @isxdigit(i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @yyerror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %39
12: ; preds = %6
%13 = tail call i64 @isdigit(i32 %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = add nsw i32 %1, -48
br label %23
17: ; preds = %12
%18 = tail call i64 @islower(i32 %1)
%19 = icmp eq i64 %18, 0
%20 = select i1 %19, i32 -65, i32 -97
%21 = add i32 %1, 10
%22 = add i32 %21, %20
br label %23
23: ; preds = %17, %15
%24 = phi i32 [ %16, %15 ], [ %22, %17 ]
%25 = shl i32 %24, 4
%26 = tail call i64 @isdigit(i32 %7)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = add nsw i32 %7, -48
br label %36
30: ; preds = %23
%31 = tail call i64 @islower(i32 %7)
%32 = icmp eq i64 %31, 0
%33 = select i1 %32, i32 -65, i32 -97
%34 = add i32 %7, 10
%35 = add i32 %34, %33
br label %36
36: ; preds = %30, %28
%37 = phi i32 [ %29, %28 ], [ %35, %30 ]
%38 = or i32 %37, %25
br label %39
39: ; preds = %36, %10, %4
%40 = phi i32 [ %38, %36 ], [ 0, %10 ], [ 0, %4 ]
ret i32 %40
}