#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 */
char EOF;
char getchar();
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
void from_ascii(void) {
  char c;
  int d;
  while ((c = getchar()) != EOF) {
    if (c != '%' || (c = getchar()) == '%')
      putchar(c);
    else {
      ungetc(c, stdin);
      scanf("%2x", &d);
      *((unsigned char *)&c) = d;
      putchar(c);
    }
  }
}


x86 assembly (clang, -O0):
<from_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
mov    0x2e84(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d0 <from_ascii+0x90>
movsbl -0x1(%rbp),%eax
cmp    $0x25,%eax
jne    118a <from_ascii+0x4a>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
cmp    $0x25,%eax
jne    1198 <from_ascii+0x58>
movsbl -0x1(%rbp),%edi
call   1030 <putchar@plt>
jmp    11cb <from_ascii+0x8b>
mov    -0x1(%rbp),%al
mov    0x2e46(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <ungetc@plt>
lea    0xe4d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <putchar@plt>
jmp    1148 <from_ascii+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<from_ascii>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e85(%rip),%r12
cmp    (%r12),%al
jne    116f <from_ascii+0x2f>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %eax,%ebx
mov    0x2e70(%rip),%r13
lea    0xe81(%rip),%r14
lea    0xc(%rsp),%r15
jmp    11a7 <from_ascii+0x67>
cs nopw 0x0(%rax,%rax,1)
movsbl %bl,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
cmp    (%r12),%al
je     1161 <from_ascii+0x21>
cmp    $0x25,%bl
jne    1190 <from_ascii+0x50>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x25,%al
je     1190 <from_ascii+0x50>
mov    0x0(%r13),%esi
movsbl %al,%edi
call   1050 <ungetc@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
movzbl 0xc(%rsp),%ebx
jmp    1190 <from_ascii+0x50>

LLVM IR (-O0):
@EOF = global i8 0
@stdin = global i32 0
@.str = [4 x i8] c"%2x\00"
define void @from_ascii() {
%1 = alloca i8
%2 = alloca i32
br label %3
3: ; preds = %29, %0
%4 = call signext i8 (...) @getchar()
store i8 %4, i8* %1
%5 = sext i8 %4 to i32
%6 = load i8, i8* @EOF
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %5, %7
br i1 %8, label %9, label %30
9: ; preds = %3
%10 = load i8, i8* %1
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 37
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = call signext i8 (...) @getchar()
store i8 %14, i8* %1
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 37
br i1 %16, label %17, label %20
17: ; preds = %13, %9
%18 = load i8, i8* %1
%19 = call i32 @putchar(i8 signext %18)
br label %29
20: ; preds = %13
%21 = load i8, i8* %1
%22 = load i32, i32* @stdin
%23 = call i32 @ungetc(i8 signext %21, i32 %22)
%24 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
%26 = trunc i32 %25 to i8
store i8 %26, i8* %1
%27 = load i8, i8* %1
%28 = call i32 @putchar(i8 signext %27)
br label %29
29: ; preds = %20, %17
br label %3
30: ; preds = %3
ret void
}

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