#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ strchr(char *, char);
char *escape_quotes(char *str) {
  static char buf[128];
  unsigned int i;
  for (i = 0; *str && i < sizeof(buf) - 1; str++) {
    if (strchr("\"\\", *str))
      buf[i++] = '\\';
    buf[i++] = *str;
  }
  buf[i] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<escape_quotes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
je     1145 <escape_quotes+0x35>
mov    -0xc(%rbp),%eax
cmp    $0x7f,%rax
setb   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1155 <escape_quotes+0x45>
jmp    11bc <escape_quotes+0xac>
mov    -0x8(%rbp),%rax
lea    0xea0(%rip),%rdi
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     118c <escape_quotes+0x7c>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2eb8(%rip),%rax
movb   $0x5c,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
mov    %eax,%eax
mov    %eax,%ecx
lea    0x2e98(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <escape_quotes+0x13>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
lea    0x2e78(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e6d(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_quotes>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    (%rdi),%al
xor    %r15d,%r15d
test   %al,%al
je     1181 <escape_quotes+0x71>
mov    %rdi,%rbx
add    $0x1,%rbx
lea    0xed0(%rip),%r14
lea    0x2f09(%rip),%r12
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     115a <escape_quotes+0x4a>
add    $0x1,%r15d
movb   $0x5c,0x0(%r13,%r12,1)
mov    %r15d,%ecx
movzbl -0x1(%rbx),%eax
lea    0x1(%rcx),%r15d
mov    %ecx,%edx
mov    %al,(%rdx,%r12,1)
movzbl (%rbx),%eax
test   %al,%al
je     117e <escape_quotes+0x6e>
add    $0x1,%rbx
mov    %r15,%r13
cmp    $0x7e,%ecx
jb     1140 <escape_quotes+0x30>
mov    %r15d,%r15d
lea    0x2eb8(%rip),%rax
movb   $0x0,(%r15,%rax,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@escape_quotes.buf = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"\22\\\00"
define i8* @escape_quotes(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %32, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = load i32, i32* %3
%11 = zext i32 %10 to i64
%12 = icmp ult i64 %11, 127
br label %13
13: ; preds = %9, %4
%14 = phi i1 [ false, %4 ], [ %12, %9 ]
br i1 %14, label %15, label %35
15: ; preds = %13
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32, i32* %3
%22 = add i32 %21, 1
store i32 %22, i32* %3
%23 = zext i32 %21 to i64
%24 = getelementptr inbounds [128 x i8], [128 x i8]* @escape_quotes.buf, i64 0, i64 %23
store i8 92, i8* %24
br label %25
25: ; preds = %20, %15
%26 = load i8*, i8** %2
%27 = load i8, i8* %26
%28 = load i32, i32* %3
%29 = add i32 %28, 1
store i32 %29, i32* %3
%30 = zext i32 %28 to i64
%31 = getelementptr inbounds [128 x i8], [128 x i8]* @escape_quotes.buf, i64 0, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %25
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %2
br label %4
35: ; preds = %13
%36 = load i32, i32* %3
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [128 x i8], [128 x i8]* @escape_quotes.buf, i64 0, i64 %37
store i8 0, i8* %38
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @escape_quotes.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@escape_quotes.buf = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"\22\\\00"
define i8* @escape_quotes(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %28, label %4
4: ; preds = %1, %14
%5 = phi i64 [ %23, %14 ], [ 0, %1 ]
%6 = phi i8 [ %21, %14 ], [ %2, %1 ]
%7 = phi i32 [ %17, %14 ], [ 0, %1 ]
%8 = phi i8* [ %20, %14 ], [ %0, %1 ]
%9 = tail call i64 @strchr(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = add nuw nsw i32 %7, 1
%13 = getelementptr inbounds [128 x i8], [128 x i8]* @escape_quotes.buf, i64 0, i64 %5
store i8 92, i8* %13
br label %14
14: ; preds = %11, %4
%15 = phi i32 [ %12, %11 ], [ %7, %4 ]
%16 = load i8, i8* %8
%17 = add nuw nsw i32 %15, 1
%18 = zext i32 %15 to i64
%19 = getelementptr inbounds [128 x i8], [128 x i8]* @escape_quotes.buf, i64 0, i64 %18
store i8 %16, i8* %19
%20 = getelementptr inbounds i8, i8* %8, i64 1
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
%23 = zext i32 %17 to i64
%24 = icmp ult i32 %15, 126
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %4, label %26
26: ; preds = %14
%27 = zext i32 %17 to i64
br label %28
28: ; preds = %1, %26
%29 = phi i64 [ %27, %26 ], [ 0, %1 ]
%30 = getelementptr inbounds [128 x i8], [128 x i8]* @escape_quotes.buf, i64 0, i64 %29
store i8 0, i8* %30
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @escape_quotes.buf, i64 0, i64 0)
}