#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*/ memmove(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
void str_escape(char *arg) {
  char *s;
  for (s = arg; *s; s++)
    if (*s == '\\') {
      int ch = '\0';
      switch (s[1]) {
      case 'n':
        ch = '\n';
        break;
      case 'e':
        ch = '\x1b';
        break;
      }
      if (ch) {
        *s = ch;
        memmove(s + 1, s + 2, strlen(s + 1));
      }
    }
}


x86 assembly (clang, -O0):
<str_escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f9 <str_escape+0xd9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11e3 <str_escape+0xc3>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x18(%rbp)
sub    $0x65,%eax
je     118e <str_escape+0x6e>
jmp    1171 <str_escape+0x51>
mov    -0x18(%rbp),%eax
sub    $0x6e,%eax
jne    1195 <str_escape+0x75>
jmp    1182 <str_escape+0x62>
movl   $0xa,-0x14(%rbp)
jmp    1195 <str_escape+0x75>
movl   $0x1b,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11de <str_escape+0xbe>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <memmove@plt>
jmp    11e3 <str_escape+0xc3>
jmp    11e8 <str_escape+0xc8>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <str_escape+0x14>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_escape>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
jmp    1134 <str_escape+0x14>
nopl   0x0(%rax)
test   %al,%al
je     1171 <str_escape+0x51>
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
cmp    $0x5c,%al
jne    1130 <str_escape+0x10>
movsbl (%rbx),%eax
cmp    $0x6e,%eax
je     1151 <str_escape+0x31>
cmp    $0x65,%eax
jne    1134 <str_escape+0x14>
mov    $0x1b,%al
jmp    1153 <str_escape+0x33>
mov    $0xa,%al
mov    %al,-0x1(%rbx)
lea    0x1(%rbx),%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <memmove@plt>
jmp    1134 <str_escape+0x14>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @str_escape(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %39, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %42
10: ; preds = %6
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 92
br i1 %14, label %15, label %38
15: ; preds = %10
store i32 0, i32* %4
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
switch i32 %19, label %22 [
i32 110, label %20
i32 101, label %21
]
20: ; preds = %15
store i32 10, i32* %4
br label %22
21: ; preds = %15
store i32 27, i32* %4
br label %22
22: ; preds = %15, %21, %20
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = load i32, i32* %4
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %3
store i8 %27, i8* %28
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 2
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @memmove(i8* %30, i8* %32, i32 %35)
br label %37
37: ; preds = %25, %22
br label %38
38: ; preds = %37, %10
br label %39
39: ; preds = %38
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %3
br label %6
42: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @str_escape(i8* %0) {
br label %2
2: ; preds = %15, %1
%3 = phi i8* [ %0, %1 ], [ %16, %15 ]
%4 = load i8, i8* %3
switch i8 %4, label %15 [
i8 0, label %17
i8 92, label %5
]
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %15 [
i32 110, label %10
i32 101, label %9
]
9: ; preds = %5
br label %10
10: ; preds = %5, %9
%11 = phi i8 [ 27, %9 ], [ 10, %5 ]
store i8 %11, i8* %3
%12 = getelementptr inbounds i8, i8* %3, i64 2
%13 = tail call i32 @strlen(i8* %6)
%14 = tail call i32 @memmove(i8* %6, i8* %12, i32 %13)
br label %15
15: ; preds = %5, %10, %2
%16 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
17: ; preds = %2
ret void
}