#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*/ strcpy(char *, char *);
void fix_any_quotes(char *d) {
  char tmp[4096 + 1];
  char *tmp_ptr = tmp;
  strcpy(tmp, d);
  while (*tmp_ptr) {
    if (*tmp_ptr == '\'') {
      *d++ = '\'';
      *d++ = *tmp_ptr++;
    } else
      *d++ = *tmp_ptr++;
  }
  *d = '\0';
}


x86 assembly (clang, -O0):
<fix_any_quotes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x1018(%rbp),%rax
cmpb   $0x0,(%rax)
je     11cc <fix_any_quotes+0xbc>
mov    -0x1018(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    119f <fix_any_quotes+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x27,(%rax)
mov    -0x1018(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x1018(%rbp)
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    11c7 <fix_any_quotes+0xb7>
mov    -0x1018(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x1018(%rbp)
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    113d <fix_any_quotes+0x2d>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fix_any_quotes>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    113e <fix_any_quotes+0x2e>
nopl   (%rax)
movw   $0x2727,(%r14)
add    $0x2,%r14
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x27,%al
je     1130 <fix_any_quotes+0x20>
test   %al,%al
je     1156 <fix_any_quotes+0x46>
mov    %al,(%r14)
add    $0x1,%r14
add    $0x1,%rbx
jmp    113e <fix_any_quotes+0x2e>
movb   $0x0,(%r14)
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @fix_any_quotes(i8* %0) {
%2 = alloca [4097 x i8]
%3 = getelementptr inbounds [4097 x i8], [4097 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
br label %5
5: ; preds = %14, %1
%6 = phi i8* [ %0, %1 ], [ %15, %14 ]
%7 = phi i8* [ %3, %1 ], [ %16, %14 ]
%8 = load i8, i8* %7
switch i8 %8, label %12 [
i8 0, label %17
i8 39, label %9
]
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %6, i64 1
store i8 39, i8* %6
%11 = getelementptr inbounds i8, i8* %6, i64 2
store i8 39, i8* %10
br label %14
12: ; preds = %5
%13 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %8, i8* %6
br label %14
14: ; preds = %12, %9
%15 = phi i8* [ %11, %9 ], [ %13, %12 ]
%16 = getelementptr inbounds i8, i8* %7, i64 1
br label %5
17: ; preds = %5
store i8 0, i8* %6
ret void
}