#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 mysql_errno(int /*<<< orphan*/ *);
char *mysql_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ *mysql_init(int /*<<< orphan*/);
scalar_t__ mysql_real_connect(int /*<<< orphan*/ *, char *, char *, char *,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, char *);
MYSQL *connectToMysql() {
  MYSQL *connection = 0;
  connection = mysql_init(0);
  if (connection == 0) {
    printf("connectToMysql::Error %d: %s\n", mysql_errno(connection),
           mysql_error(connection));
    return 0;
  }
  if (mysql_real_connect(connection, "localhost", "root", "root", 0, 0, 0, 0) ==
      0) {
    printf("connectToMysql::Error %d: %s\n", mysql_errno(connection),
           mysql_error(connection));
    return 0;
  }
  return connection;
}


x86 assembly (clang, -O0):
<connectToMysql>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
xor    %edi,%edi
call   1060 <mysql_init@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11aa <connectToMysql+0x5a>
mov    -0x10(%rbp),%rdi
call   1040 <mysql_errno@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <mysql_error@plt>
mov    -0x14(%rbp),%esi
mov    %rax,%rdx
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    121f <connectToMysql+0xcf>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
lea    0xe6c(%rip),%rcx
xor    %r9d,%r9d
mov    %rcx,%rdx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1050 <mysql_real_connect@plt>
cmp    $0x0,%rax
jne    1217 <connectToMysql+0xc7>
mov    -0x10(%rbp),%rdi
call   1040 <mysql_errno@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <mysql_error@plt>
mov    -0x18(%rbp),%esi
mov    %rax,%rdx
lea    0xdfb(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    121f <connectToMysql+0xcf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connectToMysql>:
push   %rbp
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <mysql_init@plt>
test   %rax,%rax
je     11b5 <connectToMysql+0x65>
mov    %rax,%rbx
lea    0xeb5(%rip),%rsi
lea    0xeb8(%rip),%rcx
mov    %rax,%rdi
mov    %rcx,%rdx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1050 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %rax,%rax
jne    11d8 <connectToMysql+0x88>
mov    %rbx,%rdi
call   1040 <mysql_errno@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <mysql_error@plt>
lea    0xe59(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
xor    %ebx,%ebx
jmp    11d8 <connectToMysql+0x88>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <mysql_errno@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1070 <mysql_error@plt>
lea    0xe32(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"connectToMysql::Error %d: %s\0A\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [5 x i8] c"root\00"
define i32* @connectToMysql() {
%1 = alloca i32*
%2 = alloca i32*
store i32* null, i32** %2
%3 = call i32* @mysql_init(i32 0)
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32*, i32** %2
%8 = call i32 @mysql_errno(i32* %7)
%9 = load i32*, i32** %2
%10 = call i8* @mysql_error(i32* %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %10)
store i32* null, i32** %1
br label %24
12: ; preds = %0
%13 = load i32*, i32** %2
%14 = call i64 @mysql_real_connect(i32* %13, 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 ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0, i32 0, i32 0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i32*, i32** %2
%18 = call i32 @mysql_errno(i32* %17)
%19 = load i32*, i32** %2
%20 = call i8* @mysql_error(i32* %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %18, i8* %20)
store i32* null, i32** %1
br label %24
22: ; preds = %12
%23 = load i32*, i32** %2
store i32* %23, i32** %1
br label %24
24: ; preds = %22, %16, %6
%25 = load i32*, i32** %1
ret i32* %25
}

LLVM IR (-O2):
@.str = [30 x i8] c"connectToMysql::Error %d: %s\0A\00"
@.str.1 = [10 x i8] c"localhost\00"
@.str.2 = [5 x i8] c"root\00"
define i32* @connectToMysql() {
%1 = tail call i32* @mysql_init(i32 0)
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 @mysql_errno(i32* null)
%5 = tail call i8* @mysql_error(i32* null)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %4, i8* %5)
br label %14
7: ; preds = %0
%8 = tail call i64 @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 ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0, i32 0, i32 0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i32 @mysql_errno(i32* %1)
%12 = tail call i8* @mysql_error(i32* %1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %12)
br label %14
14: ; preds = %7, %10, %3
%15 = phi i32* [ null, %3 ], [ null, %10 ], [ %1, %7 ]
ret i32* %15
}