#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;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ mysql_close(int /*<<< orphan*/ *);
char *mysql_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_query(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ mysql_real_connect(int /*<<< orphan*/ *, char *, char *,
                                      char *, char *, int, int /*<<< orphan*/ *,
                                      int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main() {
  int i;
  char query[24];
  MYSQL *mysql = mysql_init(NULL);
  if (!mysql_real_connect(mysql, "127.0.0.1", "root", "", "test", 3306, NULL,
                          0)) {
    fprintf(stderr, "Failed to connect to database: Error: %s\n",
            mysql_error(mysql));
    return 0;
  }
  mysql_query(mysql, "SELECT id FROM INFORMATION_SCHEMA.PROCESSLIST WHERE "
                     "COMMAND='Sleep' AND USER='vegaicm'");
  mysql_close(mysql);
  sleep(100);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <mysql_init@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe69(%rip),%rsi
lea    0xe6c(%rip),%rdx
lea    0xe98(%rip),%rcx
lea    0xe63(%rip),%r8
mov    $0xcea,%r9d
xor    %eax,%eax
xor    %eax,%eax
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1050 <mysql_real_connect@plt>
cmp    $0x0,%eax
jne    1207 <main+0x97>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <mysql_error@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe1e(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1231 <main+0xc1>
mov    -0x28(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1030 <mysql_query@plt>
mov    -0x28(%rbp),%rdi
call   1060 <mysql_close@plt>
mov    $0x64,%edi
call   1090 <sleep@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %edi,%edi
call   1070 <mysql_init@plt>
mov    %rax,%rbx
lea    0xe7c(%rip),%rsi
lea    0xe7f(%rip),%rdx
lea    0xeab(%rip),%rcx
lea    0xe76(%rip),%r8
mov    %rax,%rdi
mov    $0xcea,%r9d
push   $0x0
push   $0x0
call   1050 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %eax,%eax
je     11d6 <main+0x66>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1030 <mysql_query@plt>
mov    %rbx,%rdi
call   1060 <mysql_close@plt>
mov    $0x64,%edi
call   1090 <sleep@plt>
jmp    11f8 <main+0x88>
mov    0x2e03(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1080 <mysql_error@plt>
lea    0xe26(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"test\00"
@stderr = global i32 0
@.str.4 = [42 x i8] c"Failed to connect to database: Error: %s\0A\00"
@.str.5 = [87 x i8] c"SELECT id FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND='Sleep' AND USER='vegaicm'\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [24 x i8]
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @mysql_init(i32* null)
store i32* %5, i32** %4
%6 = load i32*, i32** %4
%7 = call i32 @mysql_real_connect(i32* %6, 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 ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 3306, i32* null, i32 0)
%8 = icmp ne i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32*, i32** %4
%12 = call i8* @mysql_error(i32* %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %12)
store i32 0, i32* %1
br label %20
14: ; preds = %0
%15 = load i32*, i32** %4
%16 = call i32 @mysql_query(i32* %15, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.5, i64 0, i64 0))
%17 = load i32*, i32** %4
%18 = call i32 @mysql_close(i32* %17)
%19 = call i32 @sleep(i32 100)
store i32 0, i32* %1
br label %20
20: ; preds = %14, %9
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"root\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"test\00"
@stderr = global i32 0
@.str.4 = [42 x i8] c"Failed to connect to database: Error: %s\0A\00"
@.str.5 = [87 x i8] c"SELECT id FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND='Sleep' AND USER='vegaicm'\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 ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 3306, 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 ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %12
8: ; preds = %0
%9 = tail call i32 @mysql_query(i32* %1, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.5, i64 0, i64 0))
%10 = tail call i32 @mysql_close(i32* %1)
%11 = tail call i32 @sleep(i32 100)
br label %12
12: ; preds = %8, %4
ret i32 0
}