#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*/ LOG_INFO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ mysql_close(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_real_connect(int /*<<< orphan*/ *, char *,
                                       char const *, char const *, char const *,
                                       int /*<<< orphan*/, int /*<<< orphan*/ *,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/);
MYSQL *openSQL(const char *db_username, const char *db_passwd,
               const char *db_name) {
  MYSQL *con = mysql_init(NULL);
  if (con == NULL) {
    syslog(LOG_INFO, "Error in openSQL: %s  Exiting...\n", mysql_error(con));
    exit(1);
  }
  if (mysql_real_connect(con, "127.0.0.1", db_username, db_passwd, db_name, 0,
                         NULL, 0) == NULL) {
    syslog(LOG_INFO, "Error in openSQL: %s  Exiting...\n", mysql_error(con));
    mysql_close(con);
    exit(1);
  }
  return con;
}


x86 assembly (clang, -O0):
<openSQL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <mysql_init@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bc <openSQL+0x5c>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <mysql_error@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xe53(%rip),%rsi
call   1030 <syslog@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xe4f(%rip),%rsi
xor    %r9d,%r9d
xor    %eax,%eax
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1040 <mysql_real_connect@plt>
cmp    $0x0,%rax
jne    1230 <openSQL+0xd0>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <mysql_error@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%edx
lea    0xde8(%rip),%rsi
call   1030 <syslog@plt>
mov    -0x20(%rbp),%rdi
call   1050 <mysql_close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openSQL>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %edi,%edi
call   1060 <mysql_init@plt>
test   %rax,%rax
je     11b4 <openSQL+0x54>
mov    %rax,%rbx
lea    0xe9b(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1040 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %rax,%rax
je     11de <openSQL+0x7e>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e25(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   1070 <mysql_error@plt>
lea    0xe35(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <syslog@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1070 <mysql_error@plt>
lea    0xe0a(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
call   1030 <syslog@plt>
mov    %rbx,%rdi
call   1050 <mysql_close@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@LOG_INFO = global i32 0
@.str = [34 x i8] c"Error in openSQL: %s Exiting...\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
define i32* @openSQL(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = call i32* @mysql_init(i32* null)
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* @LOG_INFO
%13 = load i32*, i32** %7
%14 = call i32 @mysql_error(i32* %13)
%15 = call i32 @syslog(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
%18 = load i32*, i32** %7
%19 = load i8*, i8** %4
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = call i32* @mysql_real_connect(i32* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %20, i8* %21, i32 0, i32* null, i32 0)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %32
24: ; preds = %17
%25 = load i32, i32* @LOG_INFO
%26 = load i32*, i32** %7
%27 = call i32 @mysql_error(i32* %26)
%28 = call i32 @syslog(i32 %25, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %7
%30 = call i32 @mysql_close(i32* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
%33 = load i32*, i32** %7
ret i32* %33
}

LLVM IR (-O2):
@LOG_INFO = global i32 0
@.str = [34 x i8] c"Error in openSQL: %s Exiting...\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
define i32* @openSQL(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32* @mysql_init(i32* null)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = load i32, i32* @LOG_INFO
%8 = tail call i32 @mysql_error(i32* null)
%9 = tail call i32 @syslog(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = tail call i32* @mysql_real_connect(i32* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1, i8* %2, i32 0, i32* null, i32 0)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* @LOG_INFO
%16 = tail call i32 @mysql_error(i32* %4)
%17 = tail call i32 @syslog(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = tail call i32 @mysql_close(i32* %4)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %11
ret i32* %4
}