#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 EOF;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getchar();
int hexchar_to_int(int);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stdout;
int main(void) {
  int n;
  int c;
  int state;
  int acc;
  c = getchar();
  state = 0;
  while (c != EOF) {
    n = hexchar_to_int(c);
    if (-1 != n) {
      if (!state) {
        acc = n * 16;
        state = 1;
      } else {
        acc += n;
        putchar(acc);
        fflush(stdout);
        state = 0;
      }
    } else {
      state = 0;
    }
    c = getchar();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
je     11eb <main+0xab>
mov    -0xc(%rbp),%edi
call   1050 <hexchar_to_int@plt>
mov    %eax,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
je     11d5 <main+0x95>
cmpl   $0x0,-0x10(%rbp)
jne    11aa <main+0x6a>
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
jmp    11d0 <main+0x90>
mov    -0x8(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
movl   $0x0,-0x10(%rbp)
jmp    11dc <main+0x9c>
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
jmp    1160 <main+0x20>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e92(%rip),%r14
cmp    (%r14),%eax
jne    1166 <main+0x26>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e6b(%rip),%r15
xor    %ebp,%ebp
jmp    11a1 <main+0x61>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %eax,%r12d
mov    %r12d,%edi
call   1030 <putchar@plt>
mov    (%r15),%edi
call   1060 <fflush@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %ebx,%ebp
cmp    (%r14),%eax
je     115b <main+0x1b>
mov    %eax,%edi
call   1050 <hexchar_to_int@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     1193 <main+0x53>
test   %ebp,%ebp
jne    1180 <main+0x40>
shl    $0x4,%eax
mov    $0x1,%ebx
mov    %eax,%r12d
jmp    1193 <main+0x53>

LLVM IR (-O0):
@EOF = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (...) @getchar()
store i32 %6, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %32, %0
%8 = load i32, i32* %3
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i32, i32* %3
%13 = call i32 @hexchar_to_int(i32 %12)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp ne i32 -1, %14
br i1 %15, label %16, label %31
16: ; preds = %11
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* %2
%21 = mul nsw i32 %20, 16
store i32 %21, i32* %5
store i32 1, i32* %4
br label %30
22: ; preds = %16
%23 = load i32, i32* %2
%24 = load i32, i32* %5
%25 = add nsw i32 %24, %23
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = call i32 @putchar(i32 %26)
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
store i32 0, i32* %4
br label %30
30: ; preds = %22, %19
br label %32
31: ; preds = %11
store i32 0, i32* %4
br label %32
32: ; preds = %31, %30
%33 = call i32 (...) @getchar()
store i32 %33, i32* %3
br label %7
34: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@stdout = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %25, label %4
4: ; preds = %0, %19
%5 = phi i32 [ %21, %19 ], [ undef, %0 ]
%6 = phi i32 [ %20, %19 ], [ 0, %0 ]
%7 = phi i32 [ %22, %19 ], [ %1, %0 ]
%8 = tail call i32 @hexchar_to_int(i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %19, label %10
10: ; preds = %4
%11 = icmp eq i32 %6, 0
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = shl nsw i32 %8, 4
br label %19
14: ; preds = %10
%15 = add nsw i32 %8, %5
%16 = tail call i32 @putchar(i32 %15)
%17 = load i32, i32* @stdout
%18 = tail call i32 @fflush(i32 %17)
br label %19
19: ; preds = %4, %12, %14
%20 = phi i32 [ 0, %14 ], [ 1, %12 ], [ 0, %4 ]
%21 = phi i32 [ %15, %14 ], [ %13, %12 ], [ %5, %4 ]
%22 = tail call i32 (...) @getchar()
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %4
25: ; preds = %19, %0
ret i32 0
}