#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 */
unsigned char getc(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
unsigned char read_hex() {
  unsigned char c1 = getc(stdin);
  unsigned char c2 = getc(stdin);
  if (c1 >= '0' && c1 <= '9') {
    c1 -= '0';
  } else if (c1 >= 'a' && c1 <= 'f') {
    c1 -= 'a';
    c1 += 0xa;
  } else {
    return 0;
  }
  if (c2 >= '0' && c2 <= '9') {
    c2 -= '0';
  } else if (c2 >= 'a' && c2 <= 'f') {
    c2 -= 'a';
    c2 += 0xa;
  } else {
    return 0;
  }
  return (c1 * 0x10) + (c2);
}


x86 assembly (clang, -O0):
<read_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
call   1030 <getc@plt>
mov    %al,-0x2(%rbp)
mov    0x2eb8(%rip),%rax
mov    (%rax),%edi
call   1030 <getc@plt>
mov    %al,-0x3(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x30,%eax
jl     1163 <read_hex+0x53>
movzbl -0x2(%rbp),%eax
cmp    $0x39,%eax
jg     1163 <read_hex+0x53>
movzbl -0x2(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x2(%rbp)
jmp    11a4 <read_hex+0x94>
movzbl -0x2(%rbp),%eax
cmp    $0x61,%eax
jl     1196 <read_hex+0x86>
movzbl -0x2(%rbp),%eax
cmp    $0x66,%eax
jg     1196 <read_hex+0x86>
movzbl -0x2(%rbp),%eax
sub    $0x61,%eax
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
add    $0xa,%eax
mov    %al,-0x2(%rbp)
jmp    119f <read_hex+0x8f>
movb   $0x0,-0x1(%rbp)
jmp    121e <read_hex+0x10e>
jmp    11a4 <read_hex+0x94>
movzbl -0x3(%rbp),%eax
cmp    $0x30,%eax
jl     11cd <read_hex+0xbd>
movzbl -0x3(%rbp),%eax
cmp    $0x39,%eax
jg     11cd <read_hex+0xbd>
movzbl -0x3(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0x3(%rbp)
jmp    120e <read_hex+0xfe>
movzbl -0x3(%rbp),%eax
cmp    $0x61,%eax
jl     1200 <read_hex+0xf0>
movzbl -0x3(%rbp),%eax
cmp    $0x66,%eax
jg     1200 <read_hex+0xf0>
movzbl -0x3(%rbp),%eax
sub    $0x61,%eax
mov    %al,-0x3(%rbp)
movzbl -0x3(%rbp),%eax
add    $0xa,%eax
mov    %al,-0x3(%rbp)
jmp    1209 <read_hex+0xf9>
movb   $0x0,-0x1(%rbp)
jmp    121e <read_hex+0x10e>
jmp    120e <read_hex+0xfe>
movzbl -0x2(%rbp),%eax
shl    $0x4,%eax
movzbl -0x3(%rbp),%ecx
add    %ecx,%eax
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hex>:
push   %r14
push   %rbx
push   %rax
mov    0x2ecd(%rip),%r14
mov    (%r14),%edi
call   1030 <getc@plt>
mov    %eax,%ebx
mov    (%r14),%edi
call   1030 <getc@plt>
mov    %eax,%ecx
lea    -0x30(%rbx),%eax
cmp    $0xa,%al
jb     1142 <read_hex+0x32>
lea    -0x61(%rbx),%eax
cmp    $0x5,%al
ja     115e <read_hex+0x4e>
add    $0xa9,%bl
mov    %ebx,%eax
lea    -0x30(%rcx),%edx
cmp    $0xa,%dl
jb     1157 <read_hex+0x47>
lea    -0x61(%rcx),%edx
cmp    $0x5,%dl
ja     115e <read_hex+0x4e>
add    $0xa9,%cl
mov    %ecx,%edx
shl    $0x4,%al
add    %dl,%al
jmp    1160 <read_hex+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
define zeroext i8 @read_hex() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = load i32, i32* @stdin
%5 = call zeroext i8 @getc(i32 %4)
store i8 %5, i8* %2
%6 = load i32, i32* @stdin
%7 = call zeroext i8 @getc(i32 %6)
store i8 %7, i8* %3
%8 = load i8, i8* %2
%9 = zext i8 %8 to i32
%10 = icmp sge i32 %9, 48
br i1 %10, label %11, label %20
11: ; preds = %0
%12 = load i8, i8* %2
%13 = zext i8 %12 to i32
%14 = icmp sle i32 %13, 57
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8, i8* %2
%17 = zext i8 %16 to i32
%18 = sub nsw i32 %17, 48
%19 = trunc i32 %18 to i8
store i8 %19, i8* %2
br label %39
20: ; preds = %11, %0
%21 = load i8, i8* %2
%22 = zext i8 %21 to i32
%23 = icmp sge i32 %22, 97
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = load i8, i8* %2
%26 = zext i8 %25 to i32
%27 = icmp sle i32 %26, 102
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load i8, i8* %2
%30 = zext i8 %29 to i32
%31 = sub nsw i32 %30, 97
%32 = trunc i32 %31 to i8
store i8 %32, i8* %2
%33 = load i8, i8* %2
%34 = zext i8 %33 to i32
%35 = add nsw i32 %34, 10
%36 = trunc i32 %35 to i8
store i8 %36, i8* %2
br label %38
37: ; preds = %24, %20
store i8 0, i8* %1
br label %79
38: ; preds = %28
br label %39
39: ; preds = %38, %15
%40 = load i8, i8* %3
%41 = zext i8 %40 to i32
%42 = icmp sge i32 %41, 48
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = load i8, i8* %3
%45 = zext i8 %44 to i32
%46 = icmp sle i32 %45, 57
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i8, i8* %3
%49 = zext i8 %48 to i32
%50 = sub nsw i32 %49, 48
%51 = trunc i32 %50 to i8
store i8 %51, i8* %3
br label %71
52: ; preds = %43, %39
%53 = load i8, i8* %3
%54 = zext i8 %53 to i32
%55 = icmp sge i32 %54, 97
br i1 %55, label %56, label %69
56: ; preds = %52
%57 = load i8, i8* %3
%58 = zext i8 %57 to i32
%59 = icmp sle i32 %58, 102
br i1 %59, label %60, label %69
60: ; preds = %56
%61 = load i8, i8* %3
%62 = zext i8 %61 to i32
%63 = sub nsw i32 %62, 97
%64 = trunc i32 %63 to i8
store i8 %64, i8* %3
%65 = load i8, i8* %3
%66 = zext i8 %65 to i32
%67 = add nsw i32 %66, 10
%68 = trunc i32 %67 to i8
store i8 %68, i8* %3
br label %70
69: ; preds = %56, %52
store i8 0, i8* %1
br label %79
70: ; preds = %60
br label %71
71: ; preds = %70, %47
%72 = load i8, i8* %2
%73 = zext i8 %72 to i32
%74 = mul nsw i32 %73, 16
%75 = load i8, i8* %3
%76 = zext i8 %75 to i32
%77 = add nsw i32 %74, %76
%78 = trunc i32 %77 to i8
store i8 %78, i8* %1
br label %79
79: ; preds = %71, %69, %37
%80 = load i8, i8* %1
ret i8 %80
}

LLVM IR (-O2):
@stdin = global i32 0
define zeroext i8 @read_hex() {
%1 = load i32, i32* @stdin
%2 = tail call zeroext i8 @getc(i32 %1)
%3 = load i32, i32* @stdin
%4 = tail call zeroext i8 @getc(i32 %3)
%5 = add i8 %2, -48
%6 = icmp ult i8 %5, 10
br i1 %6, label %12, label %7
7: ; preds = %0
%8 = add i8 %2, -97
%9 = icmp ult i8 %8, 6
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = add nsw i8 %2, -87
br label %12
12: ; preds = %0, %10
%13 = phi i8 [ %11, %10 ], [ %5, %0 ]
%14 = add i8 %4, -48
%15 = icmp ult i8 %14, 10
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = add i8 %4, -97
%18 = icmp ult i8 %17, 6
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = add nsw i8 %4, -87
br label %21
21: ; preds = %12, %19
%22 = phi i8 [ %20, %19 ], [ %14, %12 ]
%23 = shl nuw i8 %13, 4
%24 = add nuw i8 %22, %23
br label %25
25: ; preds = %16, %7, %21
%26 = phi i8 [ %24, %21 ], [ 0, %7 ], [ 0, %16 ]
ret i8 %26
}