#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 /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ unescape(char *, char *);
int main() {
  const int ARRAY_SIZE = 1000;
  char result[ARRAY_SIZE];
  char input[] = "Hello, world!\nMy\tname is Kirill!\n";
  printf("String before escaping: \n%s\n", input);
  escape(result, input);
  printf("Escaped string:\n%s\n", result);
  unescape(input, result);
  printf("Unescaped string:\n%s\n", input);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x22,%edx
call   1040 <memcpy@plt>
lea    -0x40(%rbp),%rsi
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    -0x430(%rbp),%rdi
call   1060 <escape@plt>
lea    0xea3(%rip),%rdi
lea    -0x430(%rbp),%rsi
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   1050 <unescape@plt>
lea    -0x40(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x418,%rsp
movaps 0xecf(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,(%rsp)
movw   $0xa,0x20(%rsp)
lea    0xec3(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1030 <printf@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <escape@plt>
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <unescape@plt>
lea    0xeb8(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.input = [34 x i8] c"Hello, world!\0AMy\09name is Kirill!\0A\00"
@.str = [29 x i8] c"String before escaping: \0A%s\0A\00"
@.str.1 = [20 x i8] c"Escaped string:\0A%s\0A\00"
@.str.2 = [22 x i8] c"Unescaped string:\0A%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [34 x i8]
store i32 0, i32* %1
store i32 1000, i32* %2
%5 = call i8* @llvm.stacksave()
store i8* %5, i8** %3
%6 = alloca i8, i64 1000
%7 = bitcast [34 x i8]* %4 to i8*
%8 = getelementptr inbounds [34 x i8], [34 x i8]* %4, i64 0, i64 0
%9 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [34 x i8], [34 x i8]* %4, i64 0, i64 0
%11 = call i32 @escape(i8* %6, i8* %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%13 = getelementptr inbounds [34 x i8], [34 x i8]* %4, i64 0, i64 0
%14 = call i32 @unescape(i8* %13, i8* %6)
%15 = getelementptr inbounds [34 x i8], [34 x i8]* %4, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %15)
store i32 0, i32* %1
%17 = load i8*, i8** %3
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@__const.main.input = [34 x i8] c"Hello, world!\0AMy\09name is Kirill!\0A\00"
@.str = [29 x i8] c"String before escaping: \0A%s\0A\00"
@.str.1 = [20 x i8] c"Escaped string:\0A%s\0A\00"
@.str.2 = [22 x i8] c"Unescaped string:\0A%s\0A\00"
define i32 @main() {
%1 = alloca [34 x i8]
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [34 x i8], [34 x i8]* %1, i64 0, i64 0
%5 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i32 @escape(i8* %3, i8* %4)
%7 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%8 = call i32 @unescape(i8* %4, i8* %3)
%9 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %4)
ret i32 0
}