#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sql_connect(char *, char *, char *, char *, int);
int /*<<< orphan*/ sql_disconnect();
int /*<<< orphan*/ sql_freeresult();
scalar_t__ sql_query(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sql_result();
int /*<<< orphan*/ sql_row(char *, int);
int main(int argc, char *argv[]) {
  printf("Trying to connect to sql database...");
  if (sql_connect("localhost", "root", "aKNbPhBD", "zombiesbeta", 3306))
    return 1;
  printf("ok\n");
  printf("Testing query...");
  if (sql_query("SELECT * FROM stats", 0))
    return 2;
  printf("ok\n");
  sql_result();
  printf("Getting first row of data...\n");
  char data[8096];
  while (!sql_row(data, 8096))
    printf("%s\n", data);
  sql_freeresult();
  sql_disconnect();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1fb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe87(%rip),%rdi
lea    0xe8a(%rip),%rsi
lea    0xe88(%rip),%rdx
lea    0xe8a(%rip),%rcx
mov    $0xcea,%r8d
call   1090 <sql_connect@plt>
cmp    $0x0,%rax
je     11d4 <main+0x64>
movl   $0x1,-0x4(%rbp)
jmp    128c <main+0x11c>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe67(%rip),%rdi
xor    %esi,%esi
call   1070 <sql_query@plt>
cmp    $0x0,%rax
je     1214 <main+0xa4>
movl   $0x2,-0x4(%rbp)
jmp    128c <main+0x11c>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1080 <sql_result@plt>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1fb0(%rbp),%rdi
mov    $0x1fa0,%esi
call   1040 <sql_row@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    125d <main+0xed>
jmp    1277 <main+0x107>
lea    -0x1fb0(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1237 <main+0xc7>
mov    $0x0,%al
call   1060 <sql_freeresult@plt>
mov    $0x0,%al
call   1050 <sql_disconnect@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1fb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x1fa8,%rsp
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe87(%rip),%rdi
lea    0xe8a(%rip),%rsi
lea    0xe88(%rip),%rdx
lea    0xe8a(%rip),%rcx
mov    $0xcea,%r8d
call   10a0 <sql_connect@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    1267 <main+0xe7>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6d(%rip),%rdi
xor    %esi,%esi
call   1080 <sql_query@plt>
mov    $0x2,%ebp
test   %rax,%rax
jne    1267 <main+0xe7>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1090 <sql_result@plt>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
mov    $0x1fa0,%esi
call   1050 <sql_row@plt>
test   %eax,%eax
jne    1259 <main+0xd9>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x1fa0,%esi
call   1050 <sql_row@plt>
test   %eax,%eax
je     1240 <main+0xc0>
xor    %eax,%eax
call   1070 <sql_freeresult@plt>
xor    %eax,%eax
call   1060 <sql_disconnect@plt>
mov    %ebp,%eax
add    $0x1fa8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Trying to connect to sql database...\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [5 x i8] c"root\00"
@.str.3 = [9 x i8] c"aKNbPhBD\00"
@.str.4 = [12 x i8] c"zombiesbeta\00"
@.str.5 = [4 x i8] c"ok\0A\00"
@.str.6 = [17 x i8] c"Testing query...\00"
@.str.7 = [20 x i8] c"SELECT * FROM stats\00"
@.str.8 = [30 x i8] c"Getting first row of data...\0A\00"
@.str.9 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @sql_connect(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 ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 3306)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %32
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%14 = call i64 @sql_query(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 0)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 2, i32* %3
br label %32
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 (...) @sql_result()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0))
br label %21
21: ; preds = %26, %17
%22 = getelementptr inbounds [8096 x i8], [8096 x i8]* %6, i64 0, i64 0
%23 = call i32 @sql_row(i8* %22, i32 8096)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = getelementptr inbounds [8096 x i8], [8096 x i8]* %6, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %27)
br label %21
29: ; preds = %21
%30 = call i32 (...) @sql_freeresult()
%31 = call i32 (...) @sql_disconnect()
store i32 0, i32* %3
br label %32
32: ; preds = %29, %16, %10
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [37 x i8] c"Trying to connect to sql database...\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [5 x i8] c"root\00"
@.str.3 = [9 x i8] c"aKNbPhBD\00"
@.str.4 = [12 x i8] c"zombiesbeta\00"
@.str.6 = [17 x i8] c"Testing query...\00"
@.str.7 = [20 x i8] c"SELECT * FROM stats\00"
@str.10 = [3 x i8] c"ok\00"
@str.11 = [29 x i8] c"Getting first row of data...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [8096 x i8]
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%5 = tail call i64 @sql_connect(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 ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 3306)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.10, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%10 = tail call i64 @sql_query(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.10, i64 0, i64 0))
%14 = tail call i32 (...) @sql_result()
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.11, i64 0, i64 0))
%16 = getelementptr inbounds [8096 x i8], [8096 x i8]* %3, i64 0, i64 0
%17 = call i32 @sql_row(i8* %16, i32 8096)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %12, %19
%20 = call i32 @puts(i8* %16)
%21 = call i32 @sql_row(i8* %16, i32 8096)
%22 = icmp eq i32 %21, 0
br i1 %22, label %19, label %23
23: ; preds = %19, %12
%24 = call i32 (...) @sql_freeresult()
%25 = call i32 (...) @sql_disconnect()
br label %26
26: ; preds = %7, %2, %23
%27 = phi i32 [ 0, %23 ], [ 1, %2 ], [ 2, %7 ]
ret i32 %27
}