#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *mysql_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_print_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_real_connect(int /*<<< orphan*/ *, char *, char *,
                                       char *, char *, unsigned int, char *,
                                       unsigned int);
int /*<<< orphan*/ stderr;
MYSQL *mysql_connect(char *hostname, char *username, char *password,
                     char *db_name, unsigned int port_num, char *socket_name,
                     unsigned int flags) {
  MYSQL *conn;
  conn = mysql_init(NULL);
  if (conn == NULL) {
    fprintf(stderr, "Error setting up MySQL Handler.\n");
    exit(1);
  }
  if (mysql_real_connect(conn, hostname, username, password, db_name, port_num,
                         socket_name, flags) == NULL) {
    mysql_print_error(conn);
    exit(1);
  }
  return conn;
}


x86 assembly (clang, -O0):
<mysql_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <mysql_init@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11aa <mysql_connect+0x5a>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
mov    -0x30(%rbp),%r10
mov    0x10(%rbp),%eax
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
call   1040 <mysql_real_connect@plt>
cmp    $0x0,%rax
jne    11f3 <mysql_connect+0xa3>
mov    -0x38(%rbp),%rdi
call   1070 <mysql_print_error@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x38(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mysql_connect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
xor    %edi,%edi
call   1050 <mysql_init@plt>
test   %rax,%rax
je     11b8 <mysql_connect+0x68>
mov    %rax,%rbx
mov    0x40(%rsp),%eax
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
mov    %r12,%r8
mov    %r15d,%r9d
push   %rax
push   0x8(%rsp)
call   1040 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %rax,%rax
je     11d7 <mysql_connect+0x87>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %rbx,%rdi
call   1070 <mysql_print_error@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Error setting up MySQL Handler.\0A\00"
define i32* @mysql_connect(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i8* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32*
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i8* %5, i8** %13
store i32 %6, i32* %14
%16 = call i32* @mysql_init(i32* null)
store i32* %16, i32** %15
%17 = load i32*, i32** %15
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %7
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %7
%24 = load i32*, i32** %15
%25 = load i8*, i8** %8
%26 = load i8*, i8** %9
%27 = load i8*, i8** %10
%28 = load i8*, i8** %11
%29 = load i32, i32* %12
%30 = load i8*, i8** %13
%31 = load i32, i32* %14
%32 = call i32* @mysql_real_connect(i32* %24, i8* %25, i8* %26, i8* %27, i8* %28, i32 %29, i8* %30, i32 %31)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %38
34: ; preds = %23
%35 = load i32*, i32** %15
%36 = call i32 @mysql_print_error(i32* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %23
%39 = load i32*, i32** %15
ret i32* %39
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Error setting up MySQL Handler.\0A\00"
define i32* @mysql_connect(i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i8* %5, i32 %6) {
%8 = tail call i32* @mysql_init(i32* null)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = tail call i32* @mysql_real_connect(i32* %8, i8* %0, i8* %1, i8* %2, i8* %3, i32 %4, i8* %5, i32 %6)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @mysql_print_error(i32* %8)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %14
ret i32* %8
}