#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 *, scalar_t__);
char *strchr(char *, char);
scalar_t__ strlen(char *);
void escapestr(char *value) {
  char *s;
  s = strchr(value, '\\');
  while (s) {
    memmove(s + 1, s, strlen(s) + 1);
    value[s - value] = '\\';
    s = strchr(s + 2, '\\');
  }
  s = strchr(value, '"');
  while (s) {
    memmove(s + 1, s, strlen(s) + 1);
    value[s - value] = '\\';
    s = strchr(s + 2, '"');
  }
}


x86 assembly (clang, -O0):
<escapestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b8 <escapestr+0x88>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x5c,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    $0x5c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
jmp    114e <escapestr+0x1e>
mov    -0x8(%rbp),%rdi
mov    $0x22,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1234 <escapestr+0x104>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x5c,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    $0x22,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
jmp    11ca <escapestr+0x9a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escapestr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x5c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1187 <escapestr+0x57>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r15
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <memmove@plt>
movb   $0x5c,(%rbx)
add    $0x2,%rbx
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1150 <escapestr+0x20>
mov    %r14,%rdi
mov    $0x22,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11d7 <escapestr+0xa7>
mov    %rax,%rbx
nopl   0x0(%rax)
lea    0x1(%rbx),%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <memmove@plt>
movb   $0x5c,(%rbx)
add    $0x2,%rbx
mov    %rbx,%rdi
mov    $0x22,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a0 <escapestr+0x70>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @escapestr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i8* @strchr(i8* %4, i8 signext 92)
store i8* %5, i8** %3
br label %6
6: ; preds = %9, %1
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8*, i8** %3
%13 = load i8*, i8** %3
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = call i32 @memmove(i8* %11, i8* %12, i64 %15)
%17 = load i8*, i8** %2
%18 = load i8*, i8** %3
%19 = load i8*, i8** %2
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = getelementptr inbounds i8, i8* %17, i64 %22
store i8 92, i8* %23
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 2
%26 = call i8* @strchr(i8* %25, i8 signext 92)
store i8* %26, i8** %3
br label %6
27: ; preds = %6
%28 = load i8*, i8** %2
%29 = call i8* @strchr(i8* %28, i8 signext 34)
store i8* %29, i8** %3
br label %30
30: ; preds = %33, %27
%31 = load i8*, i8** %3
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %51
33: ; preds = %30
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8*, i8** %3
%37 = load i8*, i8** %3
%38 = call i64 @strlen(i8* %37)
%39 = add nsw i64 %38, 1
%40 = call i32 @memmove(i8* %35, i8* %36, i64 %39)
%41 = load i8*, i8** %2
%42 = load i8*, i8** %3
%43 = load i8*, i8** %2
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = getelementptr inbounds i8, i8* %41, i64 %46
store i8 92, i8* %47
%48 = load i8*, i8** %3
%49 = getelementptr inbounds i8, i8* %48, i64 2
%50 = call i8* @strchr(i8* %49, i8 signext 34)
store i8* %50, i8** %3
br label %30
51: ; preds = %30
ret void
}

LLVM IR (-O2):
define void @escapestr(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 92)
%3 = icmp eq i8* %2, null
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = ptrtoint i8* %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i8* [ %2, %4 ], [ %16, %6 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = tail call i64 @strlen(i8* %7)
%10 = add nsw i64 %9, 1
%11 = tail call i32 @memmove(i8* %8, i8* %7, i64 %10)
%12 = ptrtoint i8* %7 to i64
%13 = sub i64 %12, %5
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 92, i8* %14
%15 = getelementptr inbounds i8, i8* %7, i64 2
%16 = tail call i8* @strchr(i8* %15, i8 signext 92)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %6
18: ; preds = %6, %1
%19 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 34)
%20 = icmp eq i8* %19, null
br i1 %20, label %35, label %21
21: ; preds = %18
%22 = ptrtoint i8* %0 to i64
br label %23
23: ; preds = %21, %23
%24 = phi i8* [ %19, %21 ], [ %33, %23 ]
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = tail call i64 @strlen(i8* %24)
%27 = add nsw i64 %26, 1
%28 = tail call i32 @memmove(i8* %25, i8* %24, i64 %27)
%29 = ptrtoint i8* %24 to i64
%30 = sub i64 %29, %22
%31 = getelementptr inbounds i8, i8* %0, i64 %30
store i8 92, i8* %31
%32 = getelementptr inbounds i8, i8* %24, i64 2
%33 = tail call i8* @strchr(i8* %32, i8 signext 34)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %23
35: ; preds = %23, %18
ret void
}