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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ mysql_close(int /*<<< orphan*/ *);
char *mysql_error(int /*<<< orphan*/ *);
char **mysql_fetch_row(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_free_result(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_init(int /*<<< orphan*/ *);
scalar_t__ mysql_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ mysql_real_connect(int /*<<< orphan*/ *, char *, char *,
                                      char *, char *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *mysql_use_result(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main() {
  MYSQL *conn;
  MYSQL_RES *res;
  MYSQL_ROW row;
  char *server = "localhost";
  char *user = "user";
  char *password = "password";
  char *database = "cpp_test";
  conn = mysql_init(NULL);
  if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    return -1;
  }
  if (mysql_query(conn, "select * from cpp_testTAB")) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    return -1;
  }
  res = mysql_use_result(conn);
  printf("MySQL Tables in mysql database:\n");
  while ((row = mysql_fetch_row(res)) != NULL) {
    printf("%s %s %s %s\n", row[0], row[1], row[2], row[3]);
  }
  mysql_free_result(res);
  mysql_close(conn);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe49(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe43(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe41(%rip),%rax
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <mysql_init@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
xor    %r9d,%r9d
xor    %eax,%eax
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1070 <mysql_real_connect@plt>
cmp    $0x0,%eax
jne    1252 <main+0xb2>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <mysql_error@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xe24(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <main+0x17c>
mov    -0x10(%rbp),%rdi
lea    0xdc4(%rip),%rsi
call   1030 <mysql_query@plt>
cmp    $0x0,%rax
je     129f <main+0xff>
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <mysql_error@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xdd7(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <main+0x17c>
mov    -0x10(%rbp),%rdi
call   10b0 <mysql_use_result@plt>
mov    %rax,-0x18(%rbp)
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <mysql_fetch_row@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1303 <main+0x163>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%r8
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ba <main+0x11a>
mov    -0x18(%rbp),%rdi
call   10a0 <mysql_free_result@plt>
mov    -0x10(%rbp),%rdi
call   1080 <mysql_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %edi,%edi
call   10a0 <mysql_init@plt>
mov    %rax,%r14
lea    0xe3a(%rip),%rsi
lea    0xe3d(%rip),%rdx
lea    0xe3b(%rip),%rcx
lea    0xe3d(%rip),%r8
mov    %rax,%rdi
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1080 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %eax,%eax
je     1206 <main+0x56>
lea    0xe28(%rip),%rsi
mov    %r14,%rdi
call   1040 <mysql_query@plt>
test   %rax,%rax
je     122f <main+0x7f>
mov    0x2dd3(%rip),%rax
mov    (%rax),%ebx
mov    %r14,%rdi
call   10d0 <mysql_error@plt>
lea    0xe26(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1298 <main+0xe8>
mov    %r14,%rdi
call   10c0 <mysql_use_result@plt>
mov    %rax,%rbx
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <mysql_fetch_row@plt>
test   %rax,%rax
je     1286 <main+0xd6>
lea    0xde1(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    0x10(%rax),%rcx
mov    0x18(%rax),%r8
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <mysql_fetch_row@plt>
test   %rax,%rax
jne    1260 <main+0xb0>
mov    %rbx,%rdi
call   10b0 <mysql_free_result@plt>
mov    %r14,%rdi
call   1090 <mysql_close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"user\00"
@.str.2 = [9 x i8] c"password\00"
@.str.3 = [9 x i8] c"cpp_test\00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [26 x i8] c"select * from cpp_testTAB\00"
@.str.6 = [33 x i8] c"MySQL Tables in mysql database:\0A\00"
@.str.7 = [13 x i8] c"%s %s %s %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %8
%9 = call i32* @mysql_init(i32* null)
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = load i8*, i8** %7
%14 = load i8*, i8** %8
%15 = call i32 @mysql_real_connect(i32* %10, i8* %11, i8* %12, i8* %13, i8* %14, i32 0, i32* null, i32 0)
%16 = icmp ne i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %0
%18 = load i32, i32* @stderr
%19 = load i32*, i32** %2
%20 = call i8* @mysql_error(i32* %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %20)
store i32 -1, i32* %1
br label %58
22: ; preds = %0
%23 = load i32*, i32** %2
%24 = call i64 @mysql_query(i32* %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = load i32*, i32** %2
%29 = call i8* @mysql_error(i32* %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %29)
store i32 -1, i32* %1
br label %58
31: ; preds = %22
%32 = load i32*, i32** %2
%33 = call i32* @mysql_use_result(i32* %32)
store i32* %33, i32** %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %39, %31
%36 = load i32*, i32** %3
%37 = call i8** @mysql_fetch_row(i32* %36)
store i8** %37, i8*** %4
%38 = icmp ne i8** %37, null
br i1 %38, label %39, label %53
39: ; preds = %35
%40 = load i8**, i8*** %4
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %4
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = load i8**, i8*** %4
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %4
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %42, i8* %45, i8* %48, i8* %51)
br label %35
53: ; preds = %35
%54 = load i32*, i32** %3
%55 = call i32 @mysql_free_result(i32* %54)
%56 = load i32*, i32** %2
%57 = call i32 @mysql_close(i32* %56)
store i32 0, i32* %1
br label %58
58: ; preds = %53, %26, %17
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"user\00"
@.str.2 = [9 x i8] c"password\00"
@.str.3 = [9 x i8] c"cpp_test\00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [26 x i8] c"select * from cpp_testTAB\00"
@.str.7 = [13 x i8] c"%s %s %s %s\0A\00"
@str = [32 x i8] c"MySQL Tables in mysql database:\00"
define i32 @main() {
%1 = tail call i32* @mysql_init(i32* null)
%2 = tail call i32 @mysql_real_connect(i32* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 0, i32* null, i32 0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i8* @mysql_error(i32* %1)
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %35
8: ; preds = %0
%9 = tail call i64 @mysql_query(i32* %1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i8* @mysql_error(i32* %1)
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %13)
br label %35
15: ; preds = %8
%16 = tail call i32* @mysql_use_result(i32* %1)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%18 = tail call i8** @mysql_fetch_row(i32* %16)
%19 = icmp eq i8** %18, null
br i1 %19, label %32, label %20
20: ; preds = %15, %20
%21 = phi i8** [ %30, %20 ], [ %18, %15 ]
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8*, i8** %21, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8*, i8** %21, i64 2
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8*, i8** %21, i64 3
%28 = load i8*, i8** %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %22, i8* %24, i8* %26, i8* %28)
%30 = tail call i8** @mysql_fetch_row(i32* %16)
%31 = icmp eq i8** %30, null
br i1 %31, label %32, label %20
32: ; preds = %20, %15
%33 = tail call i32 @mysql_free_result(i32* %16)
%34 = tail call i32 @mysql_close(i32* %1)
br label %35
35: ; preds = %32, %11, %4
%36 = phi i32 [ -1, %11 ], [ 0, %32 ], [ -1, %4 ]
ret i32 %36
}