#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 *calloc(int, scalar_t__);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
scalar_t__ strlen(char *);
char *escstr(char *string) {
  char *new, *p, *retval;
  int pos;
  if (string == NULL)
    return NULL;
  if ((new = calloc(2, strlen(string) + 1)) == NULL) {
    fprintf(stderr, "error in calloc\n");
    exit(1);
  }
  for (pos = 0, p = string; *p != '\0'; p++) {
    if (*p == '\\' || *p == '\t')
      new[pos++] = '\\';
    new[pos++] = *p;
  }
  new[pos] = '\0';
  retval = strdup(new);
  free(new);
  return retval;
}


x86 assembly (clang, -O0):
<escstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1184 <escstr+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1276 <escstr+0x116>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rsi
add    $0x1,%rsi
mov    $0x2,%edi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cb <escstr+0x6b>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124c <escstr+0xec>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
je     120a <escstr+0xaa>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
jne    1220 <escstr+0xc0>
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x5c,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    (%rax),%dl
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11da <escstr+0x7a>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escstr>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11dc <escstr+0x7c>
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%rsi
mov    $0x2,%edi
call   1050 <calloc@plt>
test   %rax,%rax
je     11e6 <escstr+0x86>
mov    %rax,%r14
xor    %eax,%eax
jmp    11ac <escstr+0x4c>
nopl   0x0(%rax,%rax,1)
movslq %eax,%rcx
add    $0x1,%eax
movb   $0x5c,(%r14,%rcx,1)
movzbl (%rbx),%ecx
movslq %eax,%rdx
add    $0x1,%eax
mov    %cl,(%r14,%rdx,1)
add    $0x1,%rbx
movzbl (%rbx),%ecx
cmp    $0x9,%cl
je     1190 <escstr+0x30>
cmp    $0x5c,%cl
je     1190 <escstr+0x30>
test   %cl,%cl
jne    119e <escstr+0x3e>
cltq
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
call   1080 <strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    11de <escstr+0x7e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"error in calloc\0A\00"
define i8* @escstr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %65
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %13, 1
%15 = call i8* @calloc(i32 2, i64 %14)
store i8* %15, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %11
store i32 0, i32* %7
%22 = load i8*, i8** %3
store i8* %22, i8** %5
br label %23
23: ; preds = %52, %21
%24 = load i8*, i8** %5
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %55
28: ; preds = %23
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 92
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 9
br i1 %37, label %38, label %44
38: ; preds = %33, %28
%39 = load i8*, i8** %4
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 92, i8* %43
br label %44
44: ; preds = %38, %33
%45 = load i8*, i8** %5
%46 = load i8, i8* %45
%47 = load i8*, i8** %4
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
store i8 %46, i8* %51
br label %52
52: ; preds = %44
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %5
br label %23
55: ; preds = %23
%56 = load i8*, i8** %4
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 0, i8* %59
%60 = load i8*, i8** %4
%61 = call i8* @strdup(i8* %60)
store i8* %61, i8** %6
%62 = load i8*, i8** %4
%63 = call i32 @free(i8* %62)
%64 = load i8*, i8** %6
store i8* %64, i8** %2
br label %65
65: ; preds = %55, %10
%66 = load i8*, i8** %2
ret i8* %66
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"error in calloc\0A\00"
define noalias i8* @escstr(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %33, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = add nsw i64 %4, 1
%6 = tail call i8* @calloc(i32 2, i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %3, %21
%13 = phi i8* [ %27, %21 ], [ %0, %3 ]
%14 = phi i32 [ %24, %21 ], [ 0, %3 ]
%15 = load i8, i8* %13
switch i8 %15, label %21 [
i8 0, label %28
i8 92, label %16
i8 9, label %16
]
16: ; preds = %12, %12
%17 = add nsw i32 %14, 1
%18 = sext i32 %14 to i64
%19 = getelementptr inbounds i8, i8* %6, i64 %18
store i8 92, i8* %19
%20 = load i8, i8* %13
br label %21
21: ; preds = %12, %16
%22 = phi i8 [ %20, %16 ], [ %15, %12 ]
%23 = phi i32 [ %17, %16 ], [ %14, %12 ]
%24 = add nsw i32 %23, 1
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %6, i64 %25
store i8 %22, i8* %26
%27 = getelementptr inbounds i8, i8* %13, i64 1
br label %12
28: ; preds = %12
%29 = sext i32 %14 to i64
%30 = getelementptr inbounds i8, i8* %6, i64 %29
store i8 0, i8* %30
%31 = tail call i8* @strdup(i8* %6)
%32 = tail call i32 @free(i8* %6)
br label %33
33: ; preds = %1, %28
%34 = phi i8* [ %31, %28 ], [ null, %1 ]
ret i8* %34
}