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

/* Variables and functions */
char *cfg_find(char *);
int /*<<< orphan*/ mysql_close(void *);
void *mysql_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ mysql_real_connect(void *, char *, char *, char *, char *,
                                      int /*<<< orphan*/, int /*<<< orphan*/ *,
                                      int /*<<< orphan*/);
void *sql_create() {
  MYSQL *mysql;
  char *dbserv;
  char *dbuser;
  char *dbpass;
  char *dbname;
  dbserv = cfg_find("sql.host");
  dbuser = cfg_find("sql.user");
  dbpass = cfg_find("sql.pass");
  dbname = cfg_find("sql.database");
  mysql = mysql_init(NULL);
  if (!mysql_real_connect(mysql, dbserv, dbuser, dbpass, dbname, 0, NULL, 0)) {
    mysql_close(mysql);
    return NULL;
  }
  return mysql;
}


x86 assembly (clang, -O0):
<sql_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <cfg_find@plt>
mov    %rax,-0x18(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <cfg_find@plt>
mov    %rax,-0x20(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <cfg_find@plt>
mov    %rax,-0x28(%rbp)
lea    0xe9c(%rip),%rdi
call   1030 <cfg_find@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <mysql_init@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
xor    %r9d,%r9d
xor    %eax,%eax
movq   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
call   1040 <mysql_real_connect@plt>
cmp    $0x0,%eax
jne    11e2 <sql_create+0xa2>
mov    -0x10(%rbp),%rdi
call   1050 <mysql_close@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ea <sql_create+0xaa>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sql_create>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xeb0(%rip),%rdi
call   1030 <cfg_find@plt>
mov    %rax,%r14
lea    0xeaa(%rip),%rdi
call   1030 <cfg_find@plt>
mov    %rax,%r15
lea    0xea4(%rip),%rdi
call   1030 <cfg_find@plt>
mov    %rax,%r12
lea    0xe9e(%rip),%rdi
call   1030 <cfg_find@plt>
mov    %rax,%r13
xor    %edi,%edi
call   1060 <mysql_init@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
xor    %r9d,%r9d
push   $0x0
push   $0x0
call   1040 <mysql_real_connect@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    11bc <sql_create+0x7c>
mov    %rbx,%rdi
call   1050 <mysql_close@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"sql.host\00"
@.str.1 = [9 x i8] c"sql.user\00"
@.str.2 = [9 x i8] c"sql.pass\00"
@.str.3 = [13 x i8] c"sql.database\00"
define i8* @sql_create() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = call i8* @cfg_find(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %3
%8 = call i8* @cfg_find(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i8* %8, i8** %4
%9 = call i8* @cfg_find(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i8* %9, i8** %5
%10 = call i8* @cfg_find(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i8* %10, i8** %6
%11 = call i8* @mysql_init(i32* null)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = load i8*, i8** %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i32 @mysql_real_connect(i8* %12, i8* %13, i8* %14, i8* %15, i8* %16, i32 0, i32* null, i32 0)
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %0
%20 = load i8*, i8** %2
%21 = call i32 @mysql_close(i8* %20)
store i8* null, i8** %1
br label %24
22: ; preds = %0
%23 = load i8*, i8** %2
store i8* %23, i8** %1
br label %24
24: ; preds = %22, %19
%25 = load i8*, i8** %1
ret i8* %25
}

LLVM IR (-O2):
@.str = [9 x i8] c"sql.host\00"
@.str.1 = [9 x i8] c"sql.user\00"
@.str.2 = [9 x i8] c"sql.pass\00"
@.str.3 = [13 x i8] c"sql.database\00"
define i8* @sql_create() {
%1 = tail call i8* @cfg_find(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @cfg_find(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i8* @cfg_find(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i8* @cfg_find(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i8* @mysql_init(i32* null)
%6 = tail call i32 @mysql_real_connect(i8* %5, i8* %1, i8* %2, i8* %3, i8* %4, i32 0, i32* null, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @mysql_close(i8* %5)
br label %10
10: ; preds = %0, %8
%11 = phi i8* [ null, %8 ], [ %5, %0 ]
ret i8* %11
}