#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*/ ZeroMemory(char *, int);
char *malloc(int);
int strlen(char *);
char *escapeQuotes(char *cp) {
  char *cp2 = malloc(strlen(cp) * 2 + 1);
  char *cp2start = cp2;
  ZeroMemory(cp2, strlen(cp) * 2 + 1);
  while (*cp) {
    if (*cp == '"') {
      *cp2 = '\\';
      cp2++;
    }
    *cp2 = *cp;
    cp2++;
    cp++;
  }
  cp2 = 0;
  return cp2start;
}


x86 assembly (clang, -O0):
<escapeQuotes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
shl    $0x1,%esi
add    $0x1,%esi
call   1040 <ZeroMemory@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d9 <escapeQuotes+0xa9>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11b0 <escapeQuotes+0x80>
mov    -0x10(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1180 <escapeQuotes+0x50>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escapeQuotes>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%esi
add    $0x1,%esi
mov    %r14,%rdi
call   1040 <ZeroMemory@plt>
mov    %r14,%rax
jmp    1184 <escapeQuotes+0x54>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x5c,(%rax)
add    $0x1,%rax
movzbl (%rbx),%ecx
mov    %cl,(%rax)
add    $0x1,%rax
add    $0x1,%rbx
movzbl (%rbx),%ecx
cmp    $0x22,%cl
je     1170 <escapeQuotes+0x40>
test   %cl,%cl
jne    117a <escapeQuotes+0x4a>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @escapeQuotes(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 1
%4 = or i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @strlen(i8* %0)
%7 = shl nsw i32 %6, 1
%8 = or i32 %7, 1
%9 = tail call i32 @ZeroMemory(i8* %5, i32 %8)
br label %10
10: ; preds = %17, %1
%11 = phi i8* [ %5, %1 ], [ %20, %17 ]
%12 = phi i8* [ %0, %1 ], [ %21, %17 ]
%13 = load i8, i8* %12
switch i8 %13, label %17 [
i8 0, label %22
i8 34, label %14
]
14: ; preds = %10
store i8 92, i8* %11
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = load i8, i8* %12
br label %17
17: ; preds = %10, %14
%18 = phi i8 [ %16, %14 ], [ %13, %10 ]
%19 = phi i8* [ %15, %14 ], [ %11, %10 ]
store i8 %18, i8* %19
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = getelementptr inbounds i8, i8* %12, i64 1
br label %10
22: ; preds = %10
ret i8* %5
}