#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getchar();
scalar_t__ isalnum(int);
scalar_t__ printf(char *, unsigned char);
int putchar(int);
int /*<<< orphan*/ *strchr(char *, int);
int main() {
  for (;;) {
    int c;
    errno = 0;
    c = getchar();
    if (c == EOF) {
      exit(errno == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
    } else if (isalnum(c) || strchr("!$'()*+,-.:=@_~/\n", c) != NULL) {
      if (putchar(c) == EOF) {
        exit(EXIT_FAILURE);
      }
    } else if (printf("%%%02X", (unsigned char)(char)c) < 0) {
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e62(%rip),%rax
movq   $0x0,(%rax)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%eax
jne    11cf <main+0x6f>
mov    0x2e38(%rip),%rax
cmpq   $0x0,(%rax)
jne    11bb <main+0x5b>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    11c7 <main+0x67>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
call   1060 <isalnum@plt>
cmp    $0x0,%rax
jne    11fa <main+0x9a>
mov    -0x8(%rbp),%esi
lea    0xe15(%rip),%rdi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1224 <main+0xc4>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%eax
jne    121f <main+0xbf>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1253 <main+0xf3>
mov    -0x8(%rbp),%eax
lea    0xde4(%rip),%rdi
movzbl %al,%esi
call   1050 <printf@plt>
cmp    $0x0,%rax
jge    124e <main+0xee>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1253 <main+0xf3>
jmp    1258 <main+0xf8>
jmp    116f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e69(%rip),%r12
movq   $0x0,(%r12)
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2e63(%rip),%rbx
cmp    (%rbx),%eax
jne    119e <main+0x3e>
cmpq   $0x0,(%r12)
jne    11fc <main+0x9c>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %eax,%ebp
lea    0xe59(%rip),%r15
lea    0xe64(%rip),%r14
jmp    11d0 <main+0x70>
mov    %ebp,%edi
call   1030 <putchar@plt>
cmp    (%rbx),%eax
je     11fc <main+0x9c>
movq   $0x0,(%r12)
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebp
cmp    (%rbx),%eax
je     1189 <main+0x29>
mov    %ebp,%edi
call   1060 <isalnum@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
movzbl %bpl,%esi
mov    %r14,%rdi
call   1050 <printf@plt>
test   %rax,%rax
jns    11bb <main+0x5b>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EOF = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [18 x i8] c"!$'()*+,-.:=@_~/\0A\00"
@.str.1 = [7 x i8] c"%%%02X\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %45, %0
store i64 0, i64* @errno
%4 = call i32 (...) @getchar()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %18
8: ; preds = %3
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i32, i32* @EXIT_SUCCESS
br label %15
13: ; preds = %8
%14 = load i32, i32* @EXIT_FAILURE
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %12, %11 ], [ %14, %13 ]
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %3
%19 = load i32, i32* %2
%20 = call i64 @isalnum(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* %2
%24 = call i32* @strchr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %35
26: ; preds = %22, %18
%27 = load i32, i32* %2
%28 = call i32 @putchar(i32 %27)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %26
br label %44
35: ; preds = %22
%36 = load i32, i32* %2
%37 = trunc i32 %36 to i8
%38 = call i64 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %35
br label %44
44: ; preds = %43, %34
br label %45
45: ; preds = %44
br label %3
}

LLVM IR (-O2):
@errno = global i64 0
@EOF = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [18 x i8] c"!$'()*+,-.:=@_~/\0A\00"
@.str.1 = [7 x i8] c"%%%02X\00"
define i32 @main() {
store i64 0, i64* @errno
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %4, label %11
4: ; preds = %32, %0
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
%7 = load i32, i32* @EXIT_SUCCESS
%8 = load i32, i32* @EXIT_FAILURE
%9 = select i1 %6, i32 %7, i32 %8
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0, %32
%12 = phi i32 [ %33, %32 ], [ %1, %0 ]
%13 = tail call i64 @isalnum(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = tail call i32* @strchr(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %12)
%17 = icmp eq i32* %16, null
br i1 %17, label %25, label %18
18: ; preds = %15, %11
%19 = tail call i32 @putchar(i32 %12)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %15
%26 = trunc i32 %12 to i8
%27 = tail call i64 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %18, %25
store i64 0, i64* @errno
%33 = tail call i32 (...) @getchar()
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %4, label %11
}