#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_RES;
typedef int /*<<< orphan*/ MYSQL;

/* Variables and functions */
int /*<<< orphan*/ _log(char *, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int mysql_affected_rows(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_errno(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_error(int /*<<< orphan*/ *);
scalar_t__ mysql_field_count(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_free_result(int /*<<< orphan*/ *);
int mysql_num_rows(int /*<<< orphan*/ *);
scalar_t__ mysql_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *mysql_store_result(int /*<<< orphan*/ *);
int _am_mysql_simple_query(MYSQL *mysql, char *fmt_query) {
  MYSQL_RES *result = 0;
  int rc = -1;
  if (mysql_query(mysql, fmt_query)) {
    rc = -1;
    _log("ERROR", "Failed to execute query: Error (%d): %s\n",
         mysql_errno(mysql), mysql_error(mysql));
    goto _simple_query_free;
  }
  if ((result = mysql_store_result(mysql)) == 0) {
    if (mysql_field_count(mysql) == 0) {
      rc = mysql_affected_rows(mysql);
      goto _simple_query_free;
    } else {
      rc = -1;
      _log("ERROR", "Failed to store query results: Error (%d): %s\n",
           mysql_errno(mysql), mysql_error(mysql));
      goto _simple_query_free;
    }
  }
  rc = mysql_num_rows(result);
_simple_query_free:
  if (result != 0)
    mysql_free_result(result);
  return rc;
}


x86 assembly (clang, -O0):
<_am_mysql_simple_query>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <mysql_query@plt>
cmp    $0x0,%rax
je     11ff <_am_mysql_simple_query+0x6f>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <mysql_errno@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <mysql_error@plt>
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
lea    0xe12(%rip),%rdi
lea    0xe11(%rip),%rsi
call   1030 <_log@plt>
jmp    127f <_am_mysql_simple_query+0xef>
mov    -0x8(%rbp),%rdi
call   10b0 <mysql_store_result@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1273 <_am_mysql_simple_query+0xe3>
mov    -0x8(%rbp),%rdi
call   1070 <mysql_field_count@plt>
cmp    $0x0,%rax
jne    123a <_am_mysql_simple_query+0xaa>
mov    -0x8(%rbp),%rdi
call   1060 <mysql_affected_rows@plt>
mov    %eax,-0x1c(%rbp)
jmp    127f <_am_mysql_simple_query+0xef>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <mysql_errno@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <mysql_error@plt>
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xd9e(%rip),%rdi
lea    0xdc6(%rip),%rsi
call   1030 <_log@plt>
jmp    127f <_am_mysql_simple_query+0xef>
mov    -0x18(%rbp),%rdi
call   10a0 <mysql_num_rows@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1293 <_am_mysql_simple_query+0x103>
mov    -0x18(%rbp),%rdi
call   1080 <mysql_free_result@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_am_mysql_simple_query>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <mysql_query@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     11d1 <_am_mysql_simple_query+0x41>
call   1050 <mysql_errno@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <mysql_error@plt>
lea    0xe46(%rip),%rdi
lea    0xe45(%rip),%rsi
mov    %ebp,%edx
mov    %eax,%ecx
call   1030 <_log@plt>
mov    $0xffffffff,%eax
jmp    11f2 <_am_mysql_simple_query+0x62>
call   10b0 <mysql_store_result@plt>
test   %rax,%rax
je     11f7 <_am_mysql_simple_query+0x67>
mov    %rax,%r14
mov    %rax,%rdi
call   10a0 <mysql_num_rows@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1080 <mysql_free_result@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
call   1070 <mysql_field_count@plt>
test   %rax,%rax
je     1226 <_am_mysql_simple_query+0x96>
mov    %rbx,%rdi
call   1050 <mysql_errno@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <mysql_error@plt>
lea    0xde3(%rip),%rdi
lea    0xe0b(%rip),%rsi
jmp    11c1 <_am_mysql_simple_query+0x31>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <mysql_affected_rows@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"ERROR\00"
@.str.1 = [41 x i8] c"Failed to execute query: Error (%d): %s\0A\00"
@.str.2 = [47 x i8] c"Failed to store query results: Error (%d): %s\0A\00"
define i32 @_am_mysql_simple_query(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32* null, i32** %5
store i32 -1, i32* %6
%7 = load i32*, i32** %3
%8 = load i8*, i8** %4
%9 = call i64 @mysql_query(i32* %7, i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
store i32 -1, i32* %6
%12 = load i32*, i32** %3
%13 = call i32 @mysql_errno(i32* %12)
%14 = load i32*, i32** %3
%15 = call i32 @mysql_error(i32* %14)
%16 = call i32 @_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %15)
br label %37
17: ; preds = %2
%18 = load i32*, i32** %3
%19 = call i32* @mysql_store_result(i32* %18)
store i32* %19, i32** %5
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i32*, i32** %3
%23 = call i64 @mysql_field_count(i32* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32*, i32** %3
%27 = call i32 @mysql_affected_rows(i32* %26)
store i32 %27, i32* %6
br label %37
28: ; preds = %21
store i32 -1, i32* %6
%29 = load i32*, i32** %3
%30 = call i32 @mysql_errno(i32* %29)
%31 = load i32*, i32** %3
%32 = call i32 @mysql_error(i32* %31)
%33 = call i32 @_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %32)
br label %37
34: ; preds = %17
%35 = load i32*, i32** %5
%36 = call i32 @mysql_num_rows(i32* %35)
store i32 %36, i32* %6
br label %37
37: ; preds = %34, %28, %25, %11
%38 = load i32*, i32** %5
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32*, i32** %5
%42 = call i32 @mysql_free_result(i32* %41)
br label %43
43: ; preds = %40, %37
%44 = load i32, i32* %6
ret i32 %44
}

LLVM IR (-O2):
@.str = [6 x i8] c"ERROR\00"
@.str.1 = [41 x i8] c"Failed to execute query: Error (%d): %s\0A\00"
@.str.2 = [47 x i8] c"Failed to store query results: Error (%d): %s\0A\00"
define i32 @_am_mysql_simple_query(i32* %0, i8* %1) {
%3 = tail call i64 @mysql_query(i32* %0, i8* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i32 @mysql_errno(i32* %0)
%7 = tail call i32 @mysql_error(i32* %0)
%8 = tail call i32 @_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %7)
br label %24
9: ; preds = %2
%10 = tail call i32* @mysql_store_result(i32* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = tail call i64 @mysql_field_count(i32* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @mysql_affected_rows(i32* %0)
br label %24
17: ; preds = %12
%18 = tail call i32 @mysql_errno(i32* %0)
%19 = tail call i32 @mysql_error(i32* %0)
%20 = tail call i32 @_log(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %19)
br label %24
21: ; preds = %9
%22 = tail call i32 @mysql_num_rows(i32* %10)
%23 = tail call i32 @mysql_free_result(i32* %10)
br label %24
24: ; preds = %17, %15, %5, %21
%25 = phi i32 [ %22, %21 ], [ -1, %17 ], [ %16, %15 ], [ -1, %5 ]
ret i32 %25
}