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


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)
mov    -0x8(%rbp),%rax
mov    %rax,-0x1020(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x1018(%rbp),%rax
cmpb   $0x0,(%rax)
je     11eb <fix_any_quotes+0xdb>
mov    -0x1018(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    11be <fix_any_quotes+0xae>
mov    -0x1018(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x27,%eax
je     11be <fix_any_quotes+0xae>
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    11e6 <fix_any_quotes+0xd6>
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    1148 <fix_any_quotes+0x38>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1020(%rbp),%rax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fix_any_quotes>:
push   %rbx
sub    $0x1010,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0x1(%rsp),%rax
mov    %rbx,%rcx
jmp    113d <fix_any_quotes+0x2d>
movw   $0x2727,(%rcx)
add    $0x2,%rcx
add    $0x1,%rax
movzbl -0x1(%rax),%edx
cmp    $0x27,%dl
je     1150 <fix_any_quotes+0x40>
test   %dl,%dl
jne    1155 <fix_any_quotes+0x45>
jmp    1161 <fix_any_quotes+0x51>
nopl   0x0(%rax)
cmpb   $0x27,(%rax)
jne    1130 <fix_any_quotes+0x20>
mov    %dl,(%rcx)
add    $0x1,%rcx
add    $0x1,%rax
jmp    113d <fix_any_quotes+0x2d>
movb   $0x0,(%rcx)
mov    %rbx,%rax
add    $0x1010,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @fix_any_quotes(i8* returned %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 = %18, %1
%6 = phi i8* [ %3, %1 ], [ %20, %18 ]
%7 = phi i8* [ %0, %1 ], [ %19, %18 ]
%8 = load i8, i8* %6
switch i8 %8, label %16 [
i8 0, label %21
i8 39, label %9
]
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 39
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %7, i64 1
store i8 39, i8* %7
%15 = getelementptr inbounds i8, i8* %7, i64 2
store i8 39, i8* %14
br label %18
16: ; preds = %5, %9
%17 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %8, i8* %7
br label %18
18: ; preds = %16, %13
%19 = phi i8* [ %15, %13 ], [ %17, %16 ]
%20 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
21: ; preds = %5
store i8 0, i8* %7
ret i8* %0
}