#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*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
char *xmalloc(int);
char *xstrcpyunprint(char *str) {
  char *cpy = xmalloc(strlen(str) + 1);
  int i;
  int esc = 0;
  *cpy = '\0';
  for (i = 0; i < strlen(str); i++) {
    if (esc) {
      switch (str[i]) {
      case 'r':
        strcat(cpy, "\r");
        break;
      case 'n':
        strcat(cpy, "\n");
        break;
      case '\\':
        strcat(cpy, "\\");
        break;
      default:
        strcat(cpy, "\\");
        strncat(cpy, &str[i], 1);
        break;
      }
      esc = 0;
    } else if (str[i] == '\\') {
      esc = 1;
    } else {
      strncat(cpy, &str[i], 1);
    }
  }
  return cpy;
}


x86 assembly (clang, -O0):
<xstrcpyunprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    12a3 <xstrcpyunprint+0x163>
cmpl   $0x0,-0x18(%rbp)
je     1251 <xstrcpyunprint+0x111>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
sub    $0x5c,%eax
je     1207 <xstrcpyunprint+0xc7>
jmp    11bb <xstrcpyunprint+0x7b>
mov    -0x20(%rbp),%eax
sub    $0x6e,%eax
je     11f2 <xstrcpyunprint+0xb2>
jmp    11cc <xstrcpyunprint+0x8c>
mov    -0x20(%rbp),%eax
sub    $0x72,%eax
jne    121c <xstrcpyunprint+0xdc>
jmp    11dd <xstrcpyunprint+0x9d>
mov    -0x10(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1060 <strcat@plt>
jmp    1245 <xstrcpyunprint+0x105>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1060 <strcat@plt>
jmp    1245 <xstrcpyunprint+0x105>
mov    -0x10(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   1060 <strcat@plt>
jmp    1245 <xstrcpyunprint+0x105>
mov    -0x10(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
movl   $0x0,-0x18(%rbp)
jmp    1290 <xstrcpyunprint+0x150>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    1272 <xstrcpyunprint+0x132>
movl   $0x1,-0x18(%rbp)
jmp    128b <xstrcpyunprint+0x14b>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
jmp    1290 <xstrcpyunprint+0x150>
jmp    1295 <xstrcpyunprint+0x155>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1178 <xstrcpyunprint+0x38>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrcpyunprint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1040 <xmalloc@plt>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1204 <xstrcpyunprint+0xc4>
xor    %r12d,%r12d
lea    0xe89(%rip),%r15
xor    %r13d,%r13d
jmp    11ae <xstrcpyunprint+0x6e>
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1050 <strncat@plt>
xor    %r13d,%r13d
add    $0x1,%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%r12
jge    1204 <xstrcpyunprint+0xc4>
lea    (%rbx,%r12,1),%rbp
movsbl (%rbx,%r12,1),%eax
test   %r13d,%r13d
je     11e0 <xstrcpyunprint+0xa0>
mov    %r14,%rdi
cmp    $0x5c,%eax
je     11ec <xstrcpyunprint+0xac>
cmp    $0x6e,%eax
je     11f6 <xstrcpyunprint+0xb6>
cmp    $0x72,%eax
jne    1180 <xstrcpyunprint+0x40>
lea    0xe2b(%rip),%rsi
call   1060 <strcat@plt>
jmp    1198 <xstrcpyunprint+0x58>
nopl   0x0(%rax)
mov    $0x1,%r13d
cmp    $0x5c,%al
jne    1188 <xstrcpyunprint+0x48>
jmp    119b <xstrcpyunprint+0x5b>
mov    %r15,%rsi
call   1060 <strcat@plt>
jmp    1198 <xstrcpyunprint+0x58>
lea    0xe05(%rip),%rsi
call   1060 <strcat@plt>
jmp    1198 <xstrcpyunprint+0x58>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0D\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c"\\\00"
define i8* @xstrcpyunprint(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = tail call i8* @xmalloc(i32 %3)
store i8 0, i8* %4
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %34
7: ; preds = %1, %28
%8 = phi i64 [ %30, %28 ], [ 0, %1 ]
%9 = phi i32 [ %29, %28 ], [ 0, %1 ]
%10 = icmp eq i32 %9, 0
%11 = getelementptr inbounds i8, i8* %0, i64 %8
%12 = load i8, i8* %11
br i1 %10, label %24, label %13
13: ; preds = %7
%14 = sext i8 %12 to i32
switch i32 %14, label %21 [
i32 114, label %15
i32 110, label %17
i32 92, label %19
]
15: ; preds = %13
%16 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %28
17: ; preds = %13
%18 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %28
19: ; preds = %13
%20 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %28
21: ; preds = %13
%22 = tail call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @strncat(i8* %4, i8* %11, i32 1)
br label %28
24: ; preds = %7
%25 = icmp eq i8 %12, 92
br i1 %25, label %28, label %26
26: ; preds = %24
%27 = tail call i32 @strncat(i8* %4, i8* %11, i32 1)
br label %28
28: ; preds = %24, %15, %17, %19, %21, %26
%29 = phi i32 [ 0, %26 ], [ 0, %21 ], [ 0, %19 ], [ 0, %17 ], [ 0, %15 ], [ 1, %24 ]
%30 = add nuw nsw i64 %8, 1
%31 = tail call i32 @strlen(i8* %0)
%32 = sext i32 %31 to i64
%33 = icmp slt i64 %30, %32
br i1 %33, label %7, label %34
34: ; preds = %28, %1
ret i8* %4
}