#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 *escape_str(char *str) {
  size_t w = 0, i = 0;
  int escape_next = 1;
  for (i = 0; str[i]; i++) {
    if (!escape_next && str[i] == '\\') {
      escape_next = 0;
      continue;
    }
    str[w++] = str[i];
    escape_next = 1;
  }
  str[w] = 0;
  return str;
}


x86 assembly (clang, -O0):
<escape_str>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     119d <escape_str+0x9d>
cmpl   $0x0,-0x1c(%rbp)
jne    1164 <escape_str+0x64>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    1164 <escape_str+0x64>
movl   $0x0,-0x1c(%rbp)
jmp    118c <escape_str+0x8c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x10(%rbp)
mov    %dl,(%rax,%rcx,1)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1127 <escape_str+0x27>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_str>:
mov    %rdi,%rax
mov    (%rdi),%dl
xor    %ecx,%ecx
test   %dl,%dl
je     1120 <escape_str+0x20>
nopl   0x0(%rax,%rax,1)
mov    %dl,(%rax,%rcx,1)
movzbl 0x1(%rax,%rcx,1),%edx
add    $0x1,%rcx
test   %dl,%dl
jne    1110 <escape_str+0x10>
movb   $0x0,(%rax,%rcx,1)
ret

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

LLVM IR (-O2):
define i8* @escape_str(i8* returned %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %10, %4 ], [ %2, %1 ]
%6 = phi i64 [ %8, %4 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %5, i8* %7
%8 = add i64 %6, 1
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %4
12: ; preds = %4, %1
%13 = phi i64 [ 0, %1 ], [ %8, %4 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 0, i8* %14
ret i8* %0
}