#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*/ free(char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void doubleApostrophe(char *strIn, char *strOut) {
  int i;
  char *strTmp;
  strcpy(strOut, "");
  i = 0;
  while (*strIn != '\0') {
    if (*strIn == '\'') {
      strOut[i] = '\'';
      i++;
      strOut[i] = '\'';
    } else {
      strOut[i] = *strIn;
    }
    strIn++;
    i++;
  }
  strOut[i] = '\0';
  strTmp = (char *)malloc(strlen(strOut) + 3);
  sprintf(strTmp, "'%s'", strOut);
  strcpy(strOut, strTmp);
  free(strTmp);
}


x86 assembly (clang, -O0):
<doubleApostrophe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e8 <doubleApostrophe+0x98>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x27,%eax
jne    11bd <doubleApostrophe+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x27,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x27,(%rax,%rcx,1)
jmp    11ce <doubleApostrophe+0x7e>
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <doubleApostrophe+0x27>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xde4(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doubleApostrophe>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea3(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
xor    %eax,%eax
jmp    1189 <doubleApostrophe+0x39>
nopl   (%rax)
cltq
movb   $0x27,(%r14,%rax,1)
add    $0x1,%eax
mov    $0x27,%cl
cltq
mov    %cl,(%r14,%rax,1)
add    $0x1,%rbx
add    $0x1,%eax
movzbl (%rbx),%ecx
cmp    $0x27,%cl
je     1170 <doubleApostrophe+0x20>
test   %cl,%cl
jne    117c <doubleApostrophe+0x2c>
cltq
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x3(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"'%s'\00"
define void @doubleApostrophe(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %9
9: ; preds = %37, %2
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %42
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 39
br i1 %18, label %19, label %30
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 39, i8* %23
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 39, i8* %29
br label %37
30: ; preds = %14
%31 = load i8*, i8** %3
%32 = load i8, i8* %31
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 %32, i8* %36
br label %37
37: ; preds = %30, %19
%38 = load i8*, i8** %3
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %3
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %9
42: ; preds = %9
%43 = load i8*, i8** %4
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 0, i8* %46
%47 = load i8*, i8** %4
%48 = call i64 @strlen(i8* %47)
%49 = add nsw i64 %48, 3
%50 = call i64 @malloc(i64 %49)
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %6
%52 = load i8*, i8** %6
%53 = load i8*, i8** %4
%54 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = load i8*, i8** %4
%56 = load i8*, i8** %6
%57 = call i32 @strcpy(i8* %55, i8* %56)
%58 = load i8*, i8** %6
%59 = call i32 @free(i8* %58)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"'%s'\00"
define void @doubleApostrophe(i8* nocapture %0, i8* %1) {
%3 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %12, %2
%5 = phi i32 [ 0, %2 ], [ %18, %12 ]
%6 = phi i8* [ %0, %2 ], [ %17, %12 ]
%7 = load i8, i8* %6
switch i8 %7, label %12 [
i8 0, label %19
i8 39, label %8
]
8: ; preds = %4
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 39, i8* %10
%11 = add nsw i32 %5, 1
br label %12
12: ; preds = %4, %8
%13 = phi i32 [ %11, %8 ], [ %5, %4 ]
%14 = phi i8 [ 39, %8 ], [ %7, %4 ]
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 %14, i8* %16
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = add nsw i32 %13, 1
br label %4
19: ; preds = %4
%20 = sext i32 %5 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
%22 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%23 = add nsw i64 %22, 3
%24 = tail call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
%26 = tail call i32 @sprintf(i8* dereferenceable(1) %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%27 = tail call i32 @strcpy(i8* %1, i8* %25)
%28 = tail call i32 @free(i8* %25)
ret void
}