#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 */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *full_path(char const *, char const *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ xfree(char *);
sqlite3 *open_sqlite_db(const char *path, const char *lang) {
  int ret;
  sqlite3 *result;
  char *fpath = full_path(path, lang);
  ret = sqlite3_open(fpath, &result);
  if (ret) {
    fprintf(stderr, "error: %s\n", sqlite3_errmsg(result));
    sqlite3_close(result);
    result = NULL;
  }
  xfree(fpath);
  return result;
}


x86 assembly (clang, -O0):
<open_sqlite_db>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <full_path@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d3 <open_sqlite_db+0x73>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <sqlite3_close@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <xfree@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_sqlite_db>:
push   %rbp
push   %rbx
push   %rax
call   1080 <full_path@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1030 <sqlite3_open@plt>
test   %eax,%eax
je     11ae <open_sqlite_db+0x4e>
mov    0x2e5f(%rip),%rax
mov    (%rax),%ebp
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe6d(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    (%rsp),%rdi
call   1070 <sqlite3_close@plt>
movq   $0x0,(%rsp)
mov    %rbx,%rdi
call   1040 <xfree@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"error: %s\0A\00"
define i32* @open_sqlite_db(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = call i8* @full_path(i8* %8, i8* %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = call i32 @sqlite3_open(i8* %11, i32** %6)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i32*, i32** %6
%18 = call i8* @sqlite3_errmsg(i32* %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %6
%21 = call i32 @sqlite3_close(i32* %20)
store i32* null, i32** %6
br label %22
22: ; preds = %15, %2
%23 = load i8*, i8** %7
%24 = call i32 @xfree(i8* %23)
%25 = load i32*, i32** %6
ret i32* %25
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"error: %s\0A\00"
define i32* @open_sqlite_db(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = tail call i8* @full_path(i8* %0, i8* %1)
%6 = call i32 @sqlite3_open(i8* %5, i32** %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i32*, i32** %3
%11 = call i8* @sqlite3_errmsg(i32* %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %3
%14 = call i32 @sqlite3_close(i32* %13)
store i32* null, i32** %3
br label %15
15: ; preds = %8, %2
%16 = call i32 @xfree(i8* %5)
%17 = load i32*, i32** %3
ret i32* %17
}