#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;
int /*<<< orphan*/ escape(char *, char *);
char getchar();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ unescape(char *, char *);
int main() {
  char string1[1000], string2[1000], c;
  int i;
  for (i = 0; (c = getchar()) != EOF && i < 1000 - 1; i++)
    string1[i] = c;
  string1[i] = '\0';
  escape(string1, string2);
  printf("%s\n", string2);
  unescape(string2, string1);
  printf("%s\n", string1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x7e8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x7e1(%rbp)
movsbl %al,%ecx
mov    0x2e75(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x7e9(%rbp)
je     1199 <main+0x59>
cmpl   $0x3e7,-0x7e8(%rbp)
setl   %al
mov    %al,-0x7e9(%rbp)
mov    -0x7e9(%rbp),%al
test   $0x1,%al
jne    11ac <main+0x6c>
jmp    11d4 <main+0x94>
mov    -0x7e1(%rbp),%cl
movslq -0x7e8(%rbp),%rax
mov    %cl,-0x3f0(%rbp,%rax,1)
mov    -0x7e8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7e8(%rbp)
jmp    115c <main+0x1c>
movslq -0x7e8(%rbp),%rax
movb   $0x0,-0x3f0(%rbp,%rax,1)
lea    -0x3f0(%rbp),%rdi
lea    -0x7e0(%rbp),%rsi
call   1060 <escape@plt>
lea    -0x7e0(%rbp),%rsi
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
lea    -0x7e0(%rbp),%rdi
lea    -0x3f0(%rbp),%rsi
call   1050 <unescape@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xdd6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x7e0,%rsp
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e8b(%rip),%r14
cmp    (%r14),%al
je     118f <main+0x4f>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %al,(%rsp,%rbx,1)
lea    0x1(%rbx),%r15
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r14),%al
je     118f <main+0x4f>
cmp    $0x3e6,%rbx
mov    %r15,%rbx
jb     1170 <main+0x30>
movb   $0x0,(%rsp,%r15,1)
mov    %rsp,%r14
lea    0x3f0(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <escape@plt>
lea    0xe4f(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <unescape@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x7e0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i8]
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
br label %6
6: ; preds = %22, %0
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %4
%8 = sext i8 %7 to i32
%9 = load i8, i8* @EOF
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %8, %10
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 999
br label %15
15: ; preds = %12, %6
%16 = phi i1 [ false, %6 ], [ %14, %12 ]
br i1 %16, label %17, label %25
17: ; preds = %15
%18 = load i8, i8* %4
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %20
store i8 %18, i8* %21
br label %22
22: ; preds = %17
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %6
25: ; preds = %15
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %27
store i8 0, i8* %28
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%31 = call i32 @escape(i8* %29, i8* %30)
%32 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%36 = call i32 @unescape(i8* %34, i8* %35)
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%5 = tail call signext i8 (...) @getchar()
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %18, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %12, %8 ], [ 0, %0 ]
%10 = phi i8 [ %13, %8 ], [ %5, %0 ]
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %9
store i8 %10, i8* %11
%12 = add nuw nsw i64 %9, 1
%13 = tail call signext i8 (...) @getchar()
%14 = load i8, i8* @EOF
%15 = icmp ne i8 %13, %14
%16 = icmp ult i64 %9, 998
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %8, label %18
18: ; preds = %8, %0
%19 = phi i64 [ 0, %0 ], [ %12, %8 ]
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 @escape(i8* %3, i8* %4)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%23 = call i32 @unescape(i8* %4, i8* %3)
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
ret i32 0
}