#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 strlen(char const *);
int sqlite_sanatize(const char *input, char *output) {
  int i, j;
  j = 0;
  for (i = 0; i < strlen(input); ++i, ++j) {
    output[j] = input[i];
    if (input[i] == '\'') {
      ++j;
      output[j] = '\'';
    }
  }
  output[j] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<sqlite_sanatize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11a6 <sqlite_sanatize+0x96>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x27,%eax
jne    118a <sqlite_sanatize+0x7a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x27,(%rax,%rcx,1)
jmp    118f <sqlite_sanatize+0x7f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112e <sqlite_sanatize+0x1e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_sanatize>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
xor    %r12d,%r12d
test   %eax,%eax
jle    116c <sqlite_sanatize+0x5c>
xor    %ebx,%ebx
jmp    1147 <sqlite_sanatize+0x37>
xchg   %ax,%ax
add    $0x1,%rbx
add    $0x1,%r12d
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1169 <sqlite_sanatize+0x59>
movzbl (%r15,%rbx,1),%ecx
movslq %r12d,%rax
mov    %cl,(%r14,%rax,1)
cmpb   $0x27,(%r15,%rbx,1)
jne    1130 <sqlite_sanatize+0x20>
movb   $0x27,0x1(%r14,%rax,1)
add    $0x1,%rax
mov    %eax,%r12d
jmp    1130 <sqlite_sanatize+0x20>
movslq %r12d,%r12
movb   $0x0,(%r14,%r12,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @sqlite_sanatize(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %27
5: ; preds = %2, %18
%6 = phi i64 [ %20, %18 ], [ 0, %2 ]
%7 = phi i32 [ %21, %18 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %6
%9 = load i8, i8* %8
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 %9, i8* %11
%12 = load i8, i8* %8
%13 = icmp eq i8 %12, 39
br i1 %13, label %14, label %18
14: ; preds = %5
%15 = add nsw i32 %7, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 39, i8* %17
br label %18
18: ; preds = %5, %14
%19 = phi i32 [ %15, %14 ], [ %7, %5 ]
%20 = add nuw nsw i64 %6, 1
%21 = add nsw i32 %19, 1
%22 = tail call i32 @strlen(i8* %0)
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %20, %23
br i1 %24, label %5, label %25
25: ; preds = %18
%26 = sext i32 %21 to i64
br label %27
27: ; preds = %25, %2
%28 = phi i64 [ 0, %2 ], [ %26, %25 ]
%29 = getelementptr inbounds i8, i8* %1, i64 %28
store i8 0, i8* %29
ret i32 0
}