#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 */
struct plugin_conf {
  int dummy;
};
struct client_context {
  int dummy;
};
typedef int /*<<< orphan*/ MYSQL;

/* Variables and functions */
int _am_mysql_simple_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ _log(char *, char *, ...);
int /*<<< orphan*/ am_free(char *);
scalar_t__ am_mysql_prepare_mysql(int /*<<< orphan*/ *, struct plugin_conf *);
char *am_mysql_prepare_query(int /*<<< orphan*/ *, char *,
                             struct client_context *, char const **,
                             char const **);
int /*<<< orphan*/ mysql_close(int /*<<< orphan*/ *);
int am_mysql_simple_query(char *raw_query, struct plugin_conf *conf,
                          struct client_context *client_context,
                          const char *envp[], const char *argv[]) {
  MYSQL mysql;
  char *q = 0;
  int rc = -1;
  if (am_mysql_prepare_mysql(&mysql, conf) < 0) {
    _log("ERROR",
         "Could not prepare MySQL connection in am_mysql_simple_query\n");
    return -1;
  }
  q = am_mysql_prepare_query(&mysql, raw_query, client_context, envp, argv);
  if (q == 0) {
    rc = -1;
    _log("ERROR", "Failed to expand query %s\n", raw_query);
    goto simple_query_free;
  }
  rc = _am_mysql_simple_query(&mysql, q);
simple_query_free:
  mysql_close(&mysql);
  if (q != 0)
    am_free(q);
  return rc;
}


x86 assembly (clang, -O0):
<am_mysql_simple_query>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0xffffffff,-0x44(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x34(%rbp),%rdi
call   1050 <am_mysql_prepare_mysql@plt>
cmp    $0x0,%rax
jge    11c3 <am_mysql_simple_query+0x63>
lea    0xe57(%rip),%rdi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1030 <_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1243 <am_mysql_simple_query+0xe3>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    -0x34(%rbp),%rdi
call   1080 <am_mysql_prepare_query@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1210 <am_mysql_simple_query+0xb0>
movl   $0xffffffff,-0x44(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe03(%rip),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1030 <_log@plt>
jmp    1220 <am_mysql_simple_query+0xc0>
mov    -0x40(%rbp),%rsi
lea    -0x34(%rbp),%rdi
call   1040 <_am_mysql_simple_query@plt>
mov    %eax,-0x44(%rbp)
lea    -0x34(%rbp),%rdi
call   1060 <mysql_close@plt>
cmpq   $0x0,-0x40(%rbp)
je     123d <am_mysql_simple_query+0xdd>
mov    -0x40(%rbp),%rdi
call   1070 <am_free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<am_mysql_simple_query>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rdi,%r14
lea    0x4(%rsp),%rdi
call   1050 <am_mysql_prepare_mysql@plt>
test   %rax,%rax
js     11c4 <am_mysql_simple_query+0x64>
lea    0x4(%rsp),%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %r15,%r8
call   1080 <am_mysql_prepare_query@plt>
test   %rax,%rax
je     11db <am_mysql_simple_query+0x7b>
mov    %rax,%rbx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <_am_mysql_simple_query@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <mysql_close@plt>
mov    %rbx,%rdi
call   1070 <am_free@plt>
jmp    1202 <am_mysql_simple_query+0xa2>
lea    0xe35(%rip),%rdi
lea    0xe34(%rip),%rsi
xor    %eax,%eax
call   1030 <_log@plt>
jmp    11fd <am_mysql_simple_query+0x9d>
lea    0xe1e(%rip),%rdi
lea    0xe5a(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <_log@plt>
lea    0x4(%rsp),%rdi
call   1060 <mysql_close@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.plugin_conf = type { i32 }
%struct.client_context = type { i32 }
@.str = [6 x i8] c"ERROR\00"
@.str.1 = [61 x i8] c"Could not prepare MySQL connection in am_mysql_simple_query\0A\00"
@.str.2 = [27 x i8] c"Failed to expand query %s\0A\00"
define i32 @am_mysql_simple_query(i8* %0, %struct.plugin_conf* %1, %struct.client_context* %2, i8** %3, i8** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.plugin_conf*
%9 = alloca %struct.client_context*
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
store i8* %0, i8** %7
store %struct.plugin_conf* %1, %struct.plugin_conf** %8
store %struct.client_context* %2, %struct.client_context** %9
store i8** %3, i8*** %10
store i8** %4, i8*** %11
store i8* null, i8** %13
store i32 -1, i32* %14
%15 = load %struct.plugin_conf*, %struct.plugin_conf** %8
%16 = call i64 @am_mysql_prepare_mysql(i32* %12, %struct.plugin_conf* %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %5
%19 = call i32 (i8*, i8*, ...) @_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %43
20: ; preds = %5
%21 = load i8*, i8** %7
%22 = load %struct.client_context*, %struct.client_context** %9
%23 = load i8**, i8*** %10
%24 = load i8**, i8*** %11
%25 = call i8* @am_mysql_prepare_query(i32* %12, i8* %21, %struct.client_context* %22, i8** %23, i8** %24)
store i8* %25, i8** %13
%26 = load i8*, i8** %13
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %20
store i32 -1, i32* %14
%29 = load i8*, i8** %7
%30 = call i32 (i8*, i8*, ...) @_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %34
31: ; preds = %20
%32 = load i8*, i8** %13
%33 = call i32 @_am_mysql_simple_query(i32* %12, i8* %32)
store i32 %33, i32* %14
br label %34
34: ; preds = %31, %28
%35 = call i32 @mysql_close(i32* %12)
%36 = load i8*, i8** %13
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i8*, i8** %13
%40 = call i32 @am_free(i8* %39)
br label %41
41: ; preds = %38, %34
%42 = load i32, i32* %14
store i32 %42, i32* %6
br label %43
43: ; preds = %41, %18
%44 = load i32, i32* %6
ret i32 %44
}

LLVM IR (-O2):
%struct.plugin_conf = type { i32 }
%struct.client_context = type { i32 }
@.str = [6 x i8] c"ERROR\00"
@.str.1 = [61 x i8] c"Could not prepare MySQL connection in am_mysql_simple_query\0A\00"
@.str.2 = [27 x i8] c"Failed to expand query %s\0A\00"
define i32 @am_mysql_simple_query(i8* %0, %struct.plugin_conf* %1, %struct.client_context* %2, i8** %3, i8** %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = call i64 @am_mysql_prepare_mysql(i32* %6, %struct.plugin_conf* %1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = call i32 (i8*, i8*, ...) @_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
br label %22
12: ; preds = %5
%13 = call i8* @am_mysql_prepare_query(i32* %6, i8* %0, %struct.client_context* %2, i8** %3, i8** %4)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 (i8*, i8*, ...) @_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%17 = call i32 @mysql_close(i32* %6)
br label %22
18: ; preds = %12
%19 = call i32 @_am_mysql_simple_query(i32* %6, i8* %13)
%20 = call i32 @mysql_close(i32* %6)
%21 = call i32 @am_free(i8* %13)
br label %22
22: ; preds = %15, %18, %10
%23 = phi i32 [ -1, %10 ], [ %19, %18 ], [ -1, %15 ]
ret i32 %23
}