#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 */
scalar_t__ strchr(char *, char const);
char *EscapeChars(char *dest, const char *src) {
  char *origDest = dest;
  for (; *src; ++src) {
    if (strchr(" \\\"\'", *src)) {
      *dest++ = '\\';
    }
    *dest++ = *src;
  }
  *dest = 0;
  return origDest;
}


x86 assembly (clang, -O0):
<EscapeChars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     118c <EscapeChars+0x7c>
mov    -0x10(%rbp),%rax
lea    0xec0(%rip),%rdi
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1164 <EscapeChars+0x54>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1128 <EscapeChars+0x18>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EscapeChars>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rsi),%al
mov    %rdi,%rbx
test   %al,%al
je     1172 <EscapeChars+0x62>
mov    %rsi,%r12
add    $0x1,%r12
lea    0xece(%rip),%r15
mov    %r14,%rbx
jmp    1159 <EscapeChars+0x49>
nopw   0x0(%rax,%rax,1)
movzbl -0x1(%r12),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
movzbl (%r12),%eax
add    $0x1,%r12
test   %al,%al
je     1172 <EscapeChars+0x62>
movsbl %al,%esi
mov    %r15,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1140 <EscapeChars+0x30>
movb   $0x5c,(%rbx)
add    $0x1,%rbx
jmp    1140 <EscapeChars+0x30>
movb   $0x0,(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c" \\\22'\00"
define i8* @EscapeChars(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
store i8* %6, i8** %5
br label %7
7: ; preds = %24, %2
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
store i8 92, i8* %17
br label %19
19: ; preds = %16, %11
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
store i8 %21, i8* %22
br label %24
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
br label %7
27: ; preds = %7
%28 = load i8*, i8** %3
store i8 0, i8* %28
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
@.str = [5 x i8] c" \\\22'\00"
define i8* @EscapeChars(i8* returned writeonly %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2, %13
%6 = phi i8 [ %18, %13 ], [ %3, %2 ]
%7 = phi i8* [ %16, %13 ], [ %0, %2 ]
%8 = phi i8* [ %17, %13 ], [ %1, %2 ]
%9 = tail call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 92, i8* %7
br label %13
13: ; preds = %11, %5
%14 = phi i8* [ %12, %11 ], [ %7, %5 ]
%15 = load i8, i8* %8
%16 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %15, i8* %14
%17 = getelementptr inbounds i8, i8* %8, i64 1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %5
20: ; preds = %13, %2
%21 = phi i8* [ %0, %2 ], [ %16, %13 ]
store i8 0, i8* %21
ret i8* %0
}