#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*/ MYSQL;

/* Variables and functions */
scalar_t__ calloc(size_t, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ mysql_real_escape_string(int /*<<< orphan*/ *, char *,
                                            char const *, unsigned long);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
char *mysqlStringEscape(MYSQL *mysql_connection, const char *input) {
  char *ret;
  char output[1024];
  size_t ln;
  if (input == NULL) {
    ret = (char *)malloc(sizeof(char));
    *(ret) = '\0';
  } else {
    mysql_real_escape_string(mysql_connection, output, input,
                             (unsigned long)strlen(input));
    ln = strlen(output) + 1;
    ret = (char *)calloc(ln, sizeof(char));
    strcpy(ret, output);
  }
  return ret;
}


x86 assembly (clang, -O0):
<mysqlStringEscape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1188 <mysqlStringEscape+0x38>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    120f <mysqlStringEscape+0xbf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x440(%rbp),%rdi
mov    -0x438(%rbp),%rsi
mov    -0x430(%rbp),%rdx
movslq %eax,%rcx
call   1070 <mysql_real_escape_string@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mysqlStringEscape>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
test   %rsi,%rsi
je     11ab <mysqlStringEscape+0x5b>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <mysql_real_escape_string@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
jmp    11bb <mysqlStringEscape+0x6b>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @mysqlStringEscape(i32* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i64 @malloc(i32 1)
%8 = inttoptr i64 %7 to i8*
store i8 0, i8* %8
br label %19
9: ; preds = %2
%10 = tail call i32 @strlen(i8* %1)
%11 = sext i32 %10 to i64
%12 = call i32 @mysql_real_escape_string(i32* %0, i8* %4, i8* %1, i64 %11)
%13 = call i32 @strlen(i8* %4)
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = call i64 @calloc(i64 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
%18 = call i32 @strcpy(i8* %17, i8* %4)
br label %19
19: ; preds = %9, %6
%20 = phi i8* [ %8, %6 ], [ %17, %9 ]
ret i8* %20
}