#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*/ escape(char *, char *);
int getchar();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ unescape(char *, char *);
int main(void) {
  int i = 0;
  int c;
  char str1[100];
  char str2[100];
  while ((c = getchar()) != EOF && i < 100)
    str2[i++] = c;
  str2[i] = '\0';
  printf("\n\nstr2 = \'%s\'\n", str2);
  escape(str1, str2);
  printf("str1 = \'%s\'\n", str1);
  unescape(str2, str1);
  printf("str2 = \'%s\'\n", str2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
mov    0x2e7a(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0xe1(%rbp)
je     1189 <main+0x49>
cmpl   $0x64,-0x8(%rbp)
setl   %al
mov    %al,-0xe1(%rbp)
mov    -0xe1(%rbp),%al
test   $0x1,%al
jne    119c <main+0x5c>
jmp    11ba <main+0x7a>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
cltq
mov    %cl,-0xe0(%rbp,%rax,1)
jmp    1159 <main+0x19>
movslq -0x8(%rbp),%rax
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    -0xe0(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1060 <escape@plt>
lea    -0x70(%rbp),%rsi
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
lea    -0xe0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1050 <unescape@plt>
lea    -0xe0(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

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

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

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