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


x86 assembly (clang, -O0):
<to_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
mov    0x2e8c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11a3 <to_ascii+0x63>
movsbl -0x1(%rbp),%edi
call   1060 <isascii@plt>
cmp    $0x0,%rax
je     1188 <to_ascii+0x48>
movsbl -0x1(%rbp),%edi
call   1030 <putchar@plt>
jmp    119e <to_ascii+0x5e>
movzbl -0x1(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
jmp    1148 <to_ascii+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_ascii>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e93(%rip),%r15
cmp    (%r15),%al
jne    1165 <to_ascii+0x25>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
lea    0xe92(%rip),%r14
jmp    1189 <to_ascii+0x49>
movzbl %bl,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
cmp    (%r15),%al
je     115a <to_ascii+0x1a>
movsbl %bl,%ebp
mov    %ebp,%edi
call   1060 <isascii@plt>
test   %rax,%rax
je     1170 <to_ascii+0x30>
mov    %ebp,%edi
call   1030 <putchar@plt>
jmp    117b <to_ascii+0x3b>

LLVM IR (-O0):
@EOF = global i8 0
@.str = [6 x i8] c"%%%2x\00"
define void @to_ascii() {
%1 = alloca i8
%2 = alloca i32
br label %3
3: ; preds = %21, %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 %22
9: ; preds = %3
%10 = load i8, i8* %1
%11 = call i64 @isascii(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i8, i8* %1
%15 = call i32 @putchar(i8 signext %14)
br label %21
16: ; preds = %9
%17 = load i8, i8* %1
%18 = zext i8 %17 to i32
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %16, %13
br label %3
22: ; preds = %3
ret void
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [6 x i8] c"%%%2x\00"
define void @to_ascii() {
%1 = tail call signext i8 (...) @getchar()
%2 = load i8, i8* @EOF
%3 = icmp eq i8 %1, %2
br i1 %3, label %17, label %4
4: ; preds = %0, %13
%5 = phi i8 [ %14, %13 ], [ %1, %0 ]
%6 = tail call i64 @isascii(i8 signext %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @putchar(i8 signext %5)
br label %13
10: ; preds = %4
%11 = zext i8 %5 to i32
%12 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10, %8
%14 = tail call signext i8 (...) @getchar()
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %17, label %4
17: ; preds = %13, %0
ret void
}