#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*/ sqlite3;

/* Variables and functions */
scalar_t__ SQLITE_OK;
int /*<<< orphan*/ error(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
scalar_t__ sqlite3_open(char const *, int /*<<< orphan*/ **);
void *db_sqlite3_connect(const char *host, const unsigned short port,
                         const char *username, const char *password,
                         const char *db) {
  sqlite3 *dbh = NULL;
  (void)host;
  (void)port;
  (void)username;
  (void)password;
  if (db && *db && sqlite3_open(db, &dbh) != SQLITE_OK) {
    error("[sqlite3_connect] %s", sqlite3_errmsg(dbh));
    dbh = NULL;
  }
  return (void *)dbh;
}


x86 assembly (clang, -O0):
<db_sqlite3_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ae <db_sqlite3_connect+0x7e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ae <db_sqlite3_connect+0x7e>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
je     11ae <db_sqlite3_connect+0x7e>
mov    -0x30(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    %eax,%esi
lea    0xe5f(%rip),%rdi
call   1050 <error@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_sqlite3_connect>:
push   %rax
movq   $0x0,(%rsp)
test   %r8,%r8
je     1178 <db_sqlite3_connect+0x48>
cmpb   $0x0,(%r8)
je     1178 <db_sqlite3_connect+0x48>
mov    %rsp,%rsi
mov    %r8,%rdi
call   1030 <sqlite3_open@plt>
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%rax
jne    1161 <db_sqlite3_connect+0x31>
mov    (%rsp),%rax
pop    %rcx
ret
mov    (%rsp),%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
call   1050 <error@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@SQLITE_OK = global i64 0
@.str = [21 x i8] c"[sqlite3_connect] %s\00"
define i8* @db_sqlite3_connect(i8* %0, i16 zeroext %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
store i8* %0, i8** %6
store i16 %1, i16* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
store i32* null, i32** %11
%12 = load i8*, i8** %6
%13 = load i16, i16* %7
%14 = load i8*, i8** %8
%15 = load i8*, i8** %9
%16 = load i8*, i8** %10
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %32
18: ; preds = %5
%19 = load i8*, i8** %10
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = load i8*, i8** %10
%25 = call i64 @sqlite3_open(i8* %24, i32** %11)
%26 = load i64, i64* @SQLITE_OK
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32*, i32** %11
%30 = call i32 @sqlite3_errmsg(i32* %29)
%31 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %30)
store i32* null, i32** %11
br label %32
32: ; preds = %28, %23, %18, %5
%33 = load i32*, i32** %11
%34 = bitcast i32* %33 to i8*
ret i8* %34
}

LLVM IR (-O2):
@SQLITE_OK = global i64 0
@.str = [21 x i8] c"[sqlite3_connect] %s\00"
define i8* @db_sqlite3_connect(i8* nocapture readnone %0, i16 zeroext %1, i8* nocapture readnone %2, i8* nocapture readnone %3, i8* %4) {
%6 = alloca i32*
%7 = bitcast i32** %6 to i8*
store i32* null, i32** %6
%8 = icmp eq i8* %4, null
br i1 %8, label %23, label %9
9: ; preds = %5
%10 = load i8, i8* %4
%11 = icmp eq i8 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %9
%13 = call i64 @sqlite3_open(i8* %4, i32** %6)
%14 = load i64, i64* @SQLITE_OK
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = bitcast i32** %6 to i8**
%18 = load i8*, i8** %17
br label %23
19: ; preds = %12
%20 = load i32*, i32** %6
%21 = call i32 @sqlite3_errmsg(i32* %20)
%22 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %16, %19, %9, %5
%24 = phi i8* [ %18, %16 ], [ null, %19 ], [ null, %9 ], [ null, %5 ]
ret i8* %24
}