#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*/ MYSQL_READ_DEFAULT_GROUP;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ mysql_close(int /*<<< orphan*/ *);
scalar_t__ mysql_errno(int /*<<< orphan*/ *);
char *mysql_error(int /*<<< orphan*/ *);
char **mysql_fetch_row(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_options(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                 char *);
int /*<<< orphan*/ mysql_real_connect(int /*<<< orphan*/ *, char *, char *,
                                      char *, char *, int /*<<< orphan*/,
                                      int /*<<< orphan*/ *, int /*<<< orphan*/);
int mysql_real_query(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ *mysql_use_result(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ stderr;
void doit(void) {
  int err;
  MYSQL mysql;
  MYSQL_RES *res;
  MYSQL_ROW row;
  mysql_init(&mysql);
  mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "myapp");
  if (!mysql_real_connect(&mysql, "localhost", "test", "testpass", "test", 0,
                          NULL, 0)) {
    fprintf(stderr, "Failed to mysql_real_connect(): %s\n",
            mysql_error(&mysql));
    exit(1);
  }
  err = mysql_real_query(&mysql, ("SHOW STATUS"), sizeof("SHOW STATUS"));
  if (err) {
    fprintf(stderr, "mysql_real_query() returns error: %s\n",
            mysql_error(&mysql));
    exit(1);
  }
  res = mysql_use_result(&mysql);
  if (!res) {
    fprintf(stderr, "mysql_use_result() returns error: %s\n",
            mysql_error(&mysql));
    exit(1);
  }
  for (;;) {
    row = mysql_fetch_row(res);
    if (!row)
      break;
    printf("%s: %s\n", row[0], row[1]);
  }
  if (mysql_errno(&mysql)) {
    fprintf(stderr, "Got error while retrieving rows: %s\n",
            mysql_error(&mysql));
  }
  mysql_close(&mysql);
}


x86 assembly (clang, -O0):
<doit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x8(%rbp),%rdi
call   10a0 <mysql_init@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
lea    0xe1b(%rip),%rdx
call   1040 <mysql_options@plt>
lea    -0x8(%rbp),%rdi
lea    0xe11(%rip),%rsi
lea    0xe14(%rip),%r8
lea    0xe12(%rip),%rcx
xor    %r9d,%r9d
xor    %eax,%eax
mov    %r8,%rdx
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1080 <mysql_real_connect@plt>
cmp    $0x0,%eax
jne    125a <doit+0x9a>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x8(%rbp),%rdi
call   10d0 <mysql_error@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xdd3(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x8(%rbp),%rdi
lea    0xddd(%rip),%rsi
mov    $0xc,%edx
call   10b0 <mysql_real_query@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     12ad <doit+0xed>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x8(%rbp),%rdi
call   10d0 <mysql_error@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xdb0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x8(%rbp),%rdi
call   10c0 <mysql_use_result@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    12f6 <doit+0x136>
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x8(%rbp),%rdi
call   10d0 <mysql_error@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xd8d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    12fb <doit+0x13b>
mov    -0x10(%rbp),%rdi
call   1030 <mysql_fetch_row@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1318 <doit+0x158>
jmp    1338 <doit+0x178>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd6c(%rip),%rdi
call   1050 <printf@plt>
jmp    12fb <doit+0x13b>
lea    -0x8(%rbp),%rdi
call   1060 <mysql_errno@plt>
cmp    $0x0,%rax
je     1372 <doit+0x1b2>
mov    0x2c86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    -0x8(%rbp),%rdi
call   10d0 <mysql_error@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xd35(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x8(%rbp),%rdi
call   1090 <mysql_close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doit>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <mysql_init@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
lea    0xe1f(%rip),%rdx
mov    %rbx,%rdi
call   1040 <mysql_options@plt>
lea    0xe16(%rip),%rsi
lea    0xe1e(%rip),%rcx
lea    0xe12(%rip),%rdx
mov    %rbx,%rdi
mov    %rdx,%r8
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1080 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %eax,%eax
je     12d1 <doit+0x111>
lea    0xe1f(%rip),%rsi
lea    0x4(%rsp),%rdi
mov    $0xc,%edx
call   10b0 <mysql_real_query@plt>
test   %eax,%eax
jne    12ed <doit+0x12d>
lea    0x4(%rsp),%rdi
call   10c0 <mysql_use_result@plt>
test   %rax,%rax
je     1309 <doit+0x149>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <mysql_fetch_row@plt>
test   %rax,%rax
je     128c <doit+0xcc>
lea    0xe36(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rax),%rsi
mov    0x8(%rax),%rdx
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <mysql_fetch_row@plt>
test   %rax,%rax
jne    1270 <doit+0xb0>
lea    0x4(%rsp),%rdi
call   1060 <mysql_errno@plt>
test   %rax,%rax
je     12bf <doit+0xff>
mov    0x2d36(%rip),%rax
mov    (%rax),%ebx
lea    0x4(%rsp),%rdi
call   10d0 <mysql_error@plt>
lea    0xded(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
lea    0x4(%rsp),%rdi
call   1090 <mysql_close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2d00(%rip),%rax
mov    (%rax),%ebx
lea    0x4(%rsp),%rdi
call   10d0 <mysql_error@plt>
lea    0xd33(%rip),%rsi
jmp    1323 <doit+0x163>
mov    0x2ce4(%rip),%rax
mov    (%rax),%ebx
lea    0x4(%rsp),%rdi
call   10d0 <mysql_error@plt>
lea    0xd47(%rip),%rsi
jmp    1323 <doit+0x163>
mov    0x2cc8(%rip),%rax
mov    (%rax),%ebx
lea    0x4(%rsp),%rdi
call   10d0 <mysql_error@plt>
lea    0xd51(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@MYSQL_READ_DEFAULT_GROUP = global i32 0
@.str = [6 x i8] c"myapp\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [5 x i8] c"test\00"
@.str.3 = [9 x i8] c"testpass\00"
@stderr = global i32 0
@.str.4 = [36 x i8] c"Failed to mysql_real_connect(): %s\0A\00"
@.str.5 = [12 x i8] c"SHOW STATUS\00"
@.str.6 = [38 x i8] c"mysql_real_query() returns error: %s\0A\00"
@.str.7 = [38 x i8] c"mysql_use_result() returns error: %s\0A\00"
@.str.8 = [8 x i8] c"%s: %s\0A\00"
@.str.9 = [37 x i8] c"Got error while retrieving rows: %s\0A\00"
define void @doit() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8**
%5 = call i32 @mysql_init(i32* %2)
%6 = load i32, i32* @MYSQL_READ_DEFAULT_GROUP
%7 = call i32 @mysql_options(i32* %2, i32 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @mysql_real_connect(i32* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0, i32* null, i32 0)
%9 = icmp ne i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i8* @mysql_error(i32* %2)
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32 @mysql_real_query(i32* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 12)
store i32 %16, i32* %1
%17 = load i32, i32* %1
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i8* @mysql_error(i32* %2)
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = call i32* @mysql_use_result(i32* %2)
store i32* %25, i32** %3
%26 = load i32*, i32** %3
%27 = icmp ne i32* %26, null
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i8* @mysql_error(i32* %2)
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
br label %34
34: ; preds = %40, %33
%35 = load i32*, i32** %3
%36 = call i8** @mysql_fetch_row(i32* %35)
store i8** %36, i8*** %4
%37 = load i8**, i8*** %4
%38 = icmp ne i8** %37, null
br i1 %38, label %40, label %39
39: ; preds = %34
br label %48
40: ; preds = %34
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %4
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %43, i8* %46)
br label %34
48: ; preds = %39
%49 = call i64 @mysql_errno(i32* %2)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i8* @mysql_error(i32* %2)
%54 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %51, %48
%56 = call i32 @mysql_close(i32* %2)
ret void
}

LLVM IR (-O2):
@MYSQL_READ_DEFAULT_GROUP = global i32 0
@.str = [6 x i8] c"myapp\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [5 x i8] c"test\00"
@.str.3 = [9 x i8] c"testpass\00"
@stderr = global i32 0
@.str.4 = [36 x i8] c"Failed to mysql_real_connect(): %s\0A\00"
@.str.5 = [12 x i8] c"SHOW STATUS\00"
@.str.6 = [38 x i8] c"mysql_real_query() returns error: %s\0A\00"
@.str.7 = [38 x i8] c"mysql_use_result() returns error: %s\0A\00"
@.str.8 = [8 x i8] c"%s: %s\0A\00"
@.str.9 = [37 x i8] c"Got error while retrieving rows: %s\0A\00"
define void @doit() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @mysql_init(i32* %1)
%4 = load i32, i32* @MYSQL_READ_DEFAULT_GROUP
%5 = call i32 @mysql_options(i32* %1, i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @mysql_real_connect(i32* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0, i32* null, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i8* @mysql_error(i32* %1)
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32 @mysql_real_query(i32* %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 12)
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i8* @mysql_error(i32* %1)
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = call i32* @mysql_use_result(i32* %1)
%23 = icmp eq i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = call i8** @mysql_fetch_row(i32* %22)
%26 = icmp eq i8** %25, null
br i1 %26, label %40, label %32
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = call i8* @mysql_error(i32* %1)
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %24, %32
%33 = phi i8** [ %38, %32 ], [ %25, %24 ]
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8*, i8** %33, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %34, i8* %36)
%38 = call i8** @mysql_fetch_row(i32* %22)
%39 = icmp eq i8** %38, null
br i1 %39, label %40, label %32
40: ; preds = %32, %24
%41 = call i64 @mysql_errno(i32* %1)
%42 = icmp eq i64 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = call i8* @mysql_error(i32* %1)
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %43, %40
%48 = call i32 @mysql_close(i32* %1)
ret void
}