#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*/ exit(int);
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(void) {
  MYSQL *conn;
  MYSQL_RES *res;
  MYSQL_ROW row;
  char *server = "localhost";
  char *user = "root";
  char *password = "qu-cg123";
  char *database = "mysql";
  conn = mysql_init(NULL);
  if (!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0)) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    exit(1);
  }
  if (mysql_query(conn, "show tables")) {
    fprintf(stderr, "%s\n", mysql_error(conn));
    exit(1);
  }
  res = mysql_use_result(conn);
  printf("MySQL Tables in mysql database:\n");
  while ((row = mysql_fetch_row(res)) != NULL)
    printf("%s \n", row[0]);
  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    0xe3a(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe39(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe33(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe31(%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    1260 <main+0xb0>
mov    0x2daa(%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    0xdcd(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xdb7(%rip),%rsi
call   1030 <mysql_query@plt>
cmp    $0x0,%rax
je     12ab <main+0xfb>
mov    0x2d5f(%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    0xd82(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <mysql_use_result@plt>
mov    %rax,-0x18(%rbp)
lea    0xd6f(%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     12f7 <main+0x147>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c6 <main+0x116>
mov    -0x18(%rbp),%rdi
call   10a0 <mysql_free_result@plt>
mov    -0x10(%rbp),%rdi
call   1080 <mysql_close@plt>
xor    %eax,%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    0xe2a(%rip),%rsi
lea    0xe2d(%rip),%rdx
lea    0xe2b(%rip),%rcx
lea    0xe2d(%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     1282 <main+0xc2>
lea    0xe15(%rip),%rsi
mov    %r14,%rdi
call   1040 <mysql_query@plt>
test   %rax,%rax
jne    1282 <main+0xc2>
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     126a <main+0xaa>
lea    0xde9(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rax),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <mysql_fetch_row@plt>
test   %rax,%rax
jne    1250 <main+0x90>
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
mov    0x2d57(%rip),%rax
mov    (%rax),%ebx
mov    %r14,%rdi
call   10d0 <mysql_error@plt>
lea    0xd84(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [9 x i8] c"qu-cg123\00"
@.str.3 = [6 x i8] c"mysql\00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [12 x i8] c"show tables\00"
@.str.6 = [33 x i8] c"MySQL Tables in mysql database:\0A\00"
@.str.7 = [5 x i8] c"%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 ([6 x i8], [6 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 %23, 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)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %0
%24 = load i32*, i32** %2
%25 = call i64 @mysql_query(i32* %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i32*, i32** %2
%30 = call i8* @mysql_error(i32* %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = load i32*, i32** %2
%35 = call i32* @mysql_use_result(i32* %34)
store i32* %35, i32** %3
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %37
37: ; preds = %41, %33
%38 = load i32*, i32** %3
%39 = call i8** @mysql_fetch_row(i32* %38)
store i8** %39, i8*** %4
%40 = icmp ne i8** %39, null
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i8**, i8*** %4
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %44)
br label %37
46: ; preds = %37
%47 = load i32*, i32** %3
%48 = call i32 @mysql_free_result(i32* %47)
%49 = load i32*, i32** %2
%50 = call i32 @mysql_close(i32* %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [9 x i8] c"qu-cg123\00"
@.str.3 = [6 x i8] c"mysql\00"
@stderr = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [12 x i8] c"show tables\00"
@.str.7 = [5 x i8] c"%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 ([6 x i8], [6 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 %9
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)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i64 @mysql_query(i32* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i8* @mysql_error(i32* %1)
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = tail call i32* @mysql_use_result(i32* %1)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%20 = tail call i8** @mysql_fetch_row(i32* %18)
%21 = icmp eq i8** %20, null
br i1 %21, label %28, label %22
22: ; preds = %17, %22
%23 = phi i8** [ %26, %22 ], [ %20, %17 ]
%24 = load i8*, i8** %23
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %24)
%26 = tail call i8** @mysql_fetch_row(i32* %18)
%27 = icmp eq i8** %26, null
br i1 %27, label %28, label %22
28: ; preds = %22, %17
%29 = tail call i32 @mysql_free_result(i32* %18)
%30 = tail call i32 @mysql_close(i32* %1)
ret i32 0
}