#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 */
char *_am_mysql_query_return_row_0(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*/ *);
char *am_mysql_query_return_row_0(char *raw_query, struct plugin_conf *conf,
                                  struct client_context *client_context,
                                  const char *envp[], const char *argv[]) {
  MYSQL mysql;
  char *q = 0;
  char *res = 0;
  if (am_mysql_prepare_mysql(&mysql, conf) < 0) {
    _log("ERROR",
         "Could not prepare MySQL connection in am_mysql_query_return_row_0\n");
    return 0;
  }
  q = am_mysql_prepare_query(&mysql, raw_query, client_context, envp, argv);
  if (q == 0) {
    res = 0;
    _log("ERROR", "Failed to expand query %s\n", raw_query);
    goto query_return_row_0_free;
  }
  res = _am_mysql_query_return_row_0(&mysql, q);
query_return_row_0_free:
  mysql_close(&mysql);
  if (q != 0)
    am_free(q);
  return res;
}


x86 assembly (clang, -O0):
<am_mysql_query_return_row_0>:
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)
movq   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rsi
lea    -0x34(%rbp),%rdi
call   1040 <am_mysql_prepare_mysql@plt>
cmp    $0x0,%rax
jge    11c5 <am_mysql_query_return_row_0+0x65>
lea    0xe56(%rip),%rdi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1030 <_log@plt>
movq   $0x0,-0x8(%rbp)
jmp    1249 <am_mysql_query_return_row_0+0xe9>
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    1213 <am_mysql_query_return_row_0+0xb3>
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe00(%rip),%rdi
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1030 <_log@plt>
jmp    1224 <am_mysql_query_return_row_0+0xc4>
mov    -0x40(%rbp),%rsi
lea    -0x34(%rbp),%rdi
call   1070 <_am_mysql_query_return_row_0@plt>
mov    %rax,-0x48(%rbp)
lea    -0x34(%rbp),%rdi
call   1050 <mysql_close@plt>
cmpq   $0x0,-0x40(%rbp)
je     1241 <am_mysql_query_return_row_0+0xe1>
mov    -0x40(%rbp),%rdi
call   1060 <am_free@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<am_mysql_query_return_row_0>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rdi,%r15
lea    0x4(%rsp),%rdi
call   1040 <am_mysql_prepare_mysql@plt>
test   %rax,%rax
js     11c6 <am_mysql_query_return_row_0+0x66>
lea    0x4(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r14,%r8
call   1080 <am_mysql_prepare_query@plt>
test   %rax,%rax
je     11e0 <am_mysql_query_return_row_0+0x80>
mov    %rax,%rbx
lea    0x4(%rsp),%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1070 <_am_mysql_query_return_row_0@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1050 <mysql_close@plt>
mov    %rbx,%rdi
call   1060 <am_free@plt>
jmp    1205 <am_mysql_query_return_row_0+0xa5>
lea    0xe33(%rip),%rdi
lea    0xe32(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <_log@plt>
jmp    1205 <am_mysql_query_return_row_0+0xa5>
lea    0xe19(%rip),%rdi
lea    0xe5b(%rip),%rsi
xor    %r14d,%r14d
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <_log@plt>
lea    0x4(%rsp),%rdi
call   1050 <mysql_close@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.plugin_conf = type { i32 }
%struct.client_context = type { i32 }
@.str = [6 x i8] c"ERROR\00"
@.str.1 = [67 x i8] c"Could not prepare MySQL connection in am_mysql_query_return_row_0\0A\00"
@.str.2 = [27 x i8] c"Failed to expand query %s\0A\00"
define i8* @am_mysql_query_return_row_0(i8* %0, %struct.plugin_conf* %1, %struct.client_context* %2, i8** %3, i8** %4) {
%6 = alloca i8*
%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 i8*
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 i8* null, i8** %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 ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %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 i8* null, i8** %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 i8* @_am_mysql_query_return_row_0(i32* %12, i8* %32)
store i8* %33, i8** %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 i8*, i8** %14
store i8* %42, i8** %6
br label %43
43: ; preds = %41, %18
%44 = load i8*, i8** %6
ret i8* %44
}

LLVM IR (-O2):
%struct.plugin_conf = type { i32 }
%struct.client_context = type { i32 }
@.str = [6 x i8] c"ERROR\00"
@.str.1 = [67 x i8] c"Could not prepare MySQL connection in am_mysql_query_return_row_0\0A\00"
@.str.2 = [27 x i8] c"Failed to expand query %s\0A\00"
define i8* @am_mysql_query_return_row_0(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 ([67 x i8], [67 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 i8* @_am_mysql_query_return_row_0(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 i8* [ null, %10 ], [ %19, %18 ], [ null, %15 ]
ret i8* %23
}