#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;
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ putchar(unsigned int);
int scanf(char *, unsigned int *);
int /*<<< orphan*/ stdin;
int decode_hex(void) {
  int ret;
  unsigned int val;
  while ((ret = scanf("%2x", &val)) == 1)
    putchar(val);
  return ret != EOF || ferror(stdin);
}


x86 assembly (clang, -O0):
<decode_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x1,%eax
jne    1161 <decode_hex+0x31>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    1138 <decode_hex+0x8>
mov    -0x4(%rbp),%ecx
mov    $0x1,%al
mov    0x2e73(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x9(%rbp)
jne    1190 <decode_hex+0x60>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_hex>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1179 <decode_hex+0x49>
lea    0xeaf(%rip),%r14
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    0x4(%rsp),%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
je     1160 <decode_hex+0x30>
mov    0x2e60(%rip),%rdx
mov    $0x1,%ecx
cmp    (%rdx),%eax
jne    119f <decode_hex+0x6f>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%2x\00"
@EOF = global i32 0
@stdin = global i32 0
define i32 @decode_hex() {
%1 = alloca i32
%2 = alloca i32
br label %3
3: ; preds = %6, %0
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 %4, i32* %1
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* %2
%8 = call i32 @putchar(i32 %7)
br label %3
9: ; preds = %3
%10 = load i32, i32* %1
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i32, i32* @stdin
%15 = call i64 @ferror(i32 %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %13, %9
%18 = phi i1 [ true, %9 ], [ %16, %13 ]
%19 = zext i1 %18 to i32
ret i32 %19
}

LLVM IR (-O2):
@.str = [4 x i8] c"%2x\00"
@EOF = global i32 0
@stdin = global i32 0
define i32 @decode_hex() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %10
5: ; preds = %0, %5
%6 = load i32, i32* %1
%7 = call i32 @putchar(i32 %6)
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %5, label %10
10: ; preds = %5, %0
%11 = phi i32 [ %3, %0 ], [ %8, %5 ]
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* @stdin
%16 = call i64 @ferror(i32 %15)
%17 = icmp ne i64 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %14, %10
%20 = phi i32 [ 1, %10 ], [ %18, %14 ]
ret i32 %20
}