#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 /*<<< orphan*/ escape(char *, char *);
int getline(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ unescape(char *, char *);
main() {
  int len;
  char line[1000];
  char s[1000 + 1];
  char t[1000 + 1];
  while ((len = getline(line, 1000)) > 0) {
    if (line[len - 1] != '\n')
      putchar('\n');
    escape(s, line);
    printf("escaped: %s\n", s);
    unescape(t, s);
    printf("unescape: %s\n", t);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rdi
mov    $0x3e8,%esi
call   1060 <getline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11f3 <main+0xa3>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x3f0(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     11a2 <main+0x52>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    -0x7e0(%rbp),%rdi
lea    -0x3f0(%rbp),%rsi
call   1070 <escape@plt>
lea    -0x7e0(%rbp),%rsi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
lea    -0xbd0(%rbp),%rdi
lea    -0x7e0(%rbp),%rsi
call   1050 <unescape@plt>
lea    -0xbd0(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
jmp    1162 <main+0x12>
xor    %eax,%eax
add    $0xbd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xbd0,%rsp
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1060 <getline@plt>
test   %eax,%eax
jle    11f2 <main+0xa2>
lea    0x7e0(%rsp),%rbx
mov    %rsp,%r14
lea    0xe79(%rip),%r15
lea    0x3f0(%rsp),%r12
lea    0xe77(%rip),%r13
jmp    11dd <main+0x8d>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <escape@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <unescape@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x3e8,%esi
call   1060 <getline@plt>
test   %eax,%eax
jle    11f2 <main+0xa2>
add    $0xffffffff,%eax
cmpb   $0xa,(%rsp,%rax,1)
je     11a0 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11a0 <main+0x50>
xor    %eax,%eax
add    $0xbd0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"escaped: %s\0A\00"
@.str.1 = [14 x i8] c"unescape: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x i8]
%4 = alloca [1001 x i8]
%5 = alloca [1001 x i8]
store i32 0, i32* %1
br label %6
6: ; preds = %20, %0
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%8 = call i32 @getline(i8* %7, i32 1000)
store i32 %8, i32* %2
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %31
10: ; preds = %6
%11 = load i32, i32* %2
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @putchar(i8 signext 10)
br label %20
20: ; preds = %18, %10
%21 = getelementptr inbounds [1001 x i8], [1001 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%23 = call i32 @escape(i8* %21, i8* %22)
%24 = getelementptr inbounds [1001 x i8], [1001 x i8]* %4, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%27 = getelementptr inbounds [1001 x i8], [1001 x i8]* %4, i64 0, i64 0
%28 = call i32 @unescape(i8* %26, i8* %27)
%29 = getelementptr inbounds [1001 x i8], [1001 x i8]* %5, i64 0, i64 0
%30 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %6
31: ; preds = %6
ret i32 0
}

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