#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ *we_wordv;
};
typedef TYPE_1__ wordexp_t;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_open(int /*<<< orphan*/, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wordexp(char *, TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ wordfree(TYPE_1__ *);
sqlite3 *sqlite3_open_db(char *db_name) {
  sqlite3 *db;
  int rc;
  wordexp_t exp_result;
  wordexp(db_name, &exp_result, 0);
  rc = sqlite3_open(exp_result.we_wordv[0], &db);
  if (rc) {
    fprintf(
        stderr, "%s:%d >> Error: %s\n",
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/db.c",
        50, sqlite3_errmsg(db));
    sqlite3_close(db);
    db = NULL;
  }
  wordfree(&exp_result);
  return db;
}


x86 assembly (clang, -O0):
<sqlite3_open_db>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1080 <wordexp@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11db <sqlite3_open_db+0x7b>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%r8
lea    0xe47(%rip),%rsi
lea    0xe54(%rip),%rdx
mov    $0x32,%ecx
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_close@plt>
movq   $0x0,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1070 <wordfree@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite3_open_db>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1080 <wordexp@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <sqlite3_open@plt>
test   %eax,%eax
je     11c4 <sqlite3_open_db+0x64>
mov    0x2e55(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe63(%rip),%rsi
lea    0xe70(%rip),%rdx
mov    %ebx,%edi
mov    $0x32,%ecx
mov    %rax,%r8
call   1050 <fprintf@plt>
mov    (%rsp),%rdi
call   1060 <sqlite3_close@plt>
movq   $0x0,(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <wordfree@plt>
mov    (%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32* }
@stderr = global i32 0
@.str = [20 x i8] c"%s:%d >> Error: %s\0A\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/db.c\00"
define i32* @sqlite3_open_db(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.TYPE_4__
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @wordexp(i8* %6, %struct.TYPE_4__* %5, i32 0)
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i32 0, i32 0
%9 = load i32*, i32** %8
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = call i32 @sqlite3_open(i32 %11, i32** %3)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i32*, i32** %3
%18 = call i8* @sqlite3_errmsg(i32* %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 50, i8* %18)
%20 = load i32*, i32** %3
%21 = call i32 @sqlite3_close(i32* %20)
store i32* null, i32** %3
br label %22
22: ; preds = %15, %1
%23 = call i32 @wordfree(%struct.TYPE_4__* %5)
%24 = load i32*, i32** %3
ret i32* %24
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32* }
@stderr = global i32 0
@.str = [20 x i8] c"%s:%d >> Error: %s\0A\00"
@.str.1 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/db.c\00"
define i32* @sqlite3_open_db(i8* %0) {
%2 = alloca i32*
%3 = alloca %struct.TYPE_4__
%4 = bitcast i32** %2 to i8*
%5 = bitcast %struct.TYPE_4__* %3 to i8*
%6 = call i32 @wordexp(i8* %0, %struct.TYPE_4__* %3, i32 0)
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%8 = load i32*, i32** %7
%9 = load i32, i32* %8
%10 = call i32 @sqlite3_open(i32 %9, i32** %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i32*, i32** %2
%15 = call i8* @sqlite3_errmsg(i32* %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.1, i64 0, i64 0), i32 50, i8* %15)
%17 = load i32*, i32** %2
%18 = call i32 @sqlite3_close(i32* %17)
store i32* null, i32** %2
br label %19
19: ; preds = %12, %1
%20 = call i32 @wordfree(%struct.TYPE_4__* %3)
%21 = load i32*, i32** %2
ret i32* %21
}