#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 */
struct db_remote {
  int dummy;
};
typedef int /*<<< orphan*/ sqlite3_stmt;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ SQLITE_DONE;
scalar_t__ SQLITE_OK;
scalar_t__ SQLITE_ROW;
int /*<<< orphan*/ closedatabase(int /*<<< orphan*/ *);
int /*<<< orphan*/ db_createremote(struct db_remote *, int /*<<< orphan*/,
                                   char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ opendatabase(int /*<<< orphan*/ **);
int /*<<< orphan*/ sqlite3_bind_int(int /*<<< orphan*/ *, int, unsigned int);
int /*<<< orphan*/ sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int);
scalar_t__ sqlite3_finalize(int /*<<< orphan*/ *);
scalar_t__ sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int,
                              int /*<<< orphan*/ **, int /*<<< orphan*/);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int db_loadremote(struct db_remote *remote, unsigned int id) {
  sqlite3 *db;
  sqlite3_stmt *res;
  opendatabase(&db);
  if (sqlite3_prepare_v2(
          db,
          "SELECT id, name, urldatabase, urlpackages FROM remotes WHERE id = ?",
          -1, &res, 0) != SQLITE_OK)
    exit(EXIT_FAILURE);
  sqlite3_bind_int(res, 1, id);
  if (sqlite3_step(res) != SQLITE_ROW)
    exit(EXIT_FAILURE);
  db_createremote(
      remote, sqlite3_column_int(res, 0), (char *)sqlite3_column_text(res, 1),
      (char *)sqlite3_column_text(res, 2), (char *)sqlite3_column_text(res, 3));
  if (sqlite3_step(res) != SQLITE_DONE)
    exit(EXIT_FAILURE);
  if (sqlite3_finalize(res) != SQLITE_OK)
    exit(EXIT_FAILURE);
  closedatabase(db);
  return 1;
}


x86 assembly (clang, -O0):
<db_loadremote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <opendatabase@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3d(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %r8d,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%rax
je     11f2 <db_loadremote+0x52>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x1,%esi
call   1030 <sqlite3_bind_int@plt>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2db5(%rip),%rcx
cmp    (%rcx),%rax
je     122a <db_loadremote+0x8a>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1080 <sqlite3_column_text@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1080 <sqlite3_column_text@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x3,%esi
call   1080 <sqlite3_column_text@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    %rax,%r8
call   10c0 <db_createremote@plt>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2d3f(%rip),%rcx
cmp    (%rcx),%rax
je     12b0 <db_loadremote+0x110>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
mov    0x2d28(%rip),%rcx
cmp    (%rcx),%rax
je     12d7 <db_loadremote+0x137>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <closedatabase@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_loadremote>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
call   1060 <opendatabase@plt>
mov    0x8(%rsp),%rdi
lea    0xe39(%rip),%rsi
mov    %rsp,%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    0x2e0a(%rip),%r12
cmp    (%r12),%rax
jne    12a3 <db_loadremote+0x103>
mov    (%rsp),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1030 <sqlite3_bind_int@plt>
mov    (%rsp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%rax
jne    12a3 <db_loadremote+0x103>
mov    (%rsp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_int@plt>
mov    %eax,%r15d
mov    (%rsp),%rdi
mov    $0x1,%esi
call   1080 <sqlite3_column_text@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
mov    $0x2,%esi
call   1080 <sqlite3_column_text@plt>
mov    %rax,%rbp
mov    (%rsp),%rdi
mov    $0x3,%esi
call   1080 <sqlite3_column_text@plt>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %rbp,%rcx
mov    %rax,%r8
call   10c0 <db_createremote@plt>
mov    (%rsp),%rdi
call   1050 <sqlite3_step@plt>
mov    0x2d65(%rip),%rcx
cmp    (%rcx),%rax
jne    12a3 <db_loadremote+0x103>
mov    (%rsp),%rdi
call   1090 <sqlite3_finalize@plt>
cmp    (%r12),%rax
jne    12a3 <db_loadremote+0x103>
mov    0x8(%rsp),%rdi
call   1070 <closedatabase@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.db_remote = type { i32 }
@.str = [68 x i8] c"SELECT id, name, urldatabase, urlpackages FROM remotes WHERE id = ?\00"
@SQLITE_OK = global i64 0
@EXIT_FAILURE = global i32 0
@SQLITE_ROW = global i64 0
@SQLITE_DONE = global i64 0
define i32 @db_loadremote(%struct.db_remote* %0, i32 %1) {
%3 = alloca %struct.db_remote*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
store %struct.db_remote* %0, %struct.db_remote** %3
store i32 %1, i32* %4
%7 = call i32 @opendatabase(i32** %5)
%8 = load i32*, i32** %5
%9 = call i64 @sqlite3_prepare_v2(i32* %8, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %6, i32 0)
%10 = load i64, i64* @SQLITE_OK
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = load i32, i32* %4
%18 = call i32 @sqlite3_bind_int(i32* %16, i32 1, i32 %17)
%19 = load i32*, i32** %6
%20 = call i64 @sqlite3_step(i32* %19)
%21 = load i64, i64* @SQLITE_ROW
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %15
%27 = load %struct.db_remote*, %struct.db_remote** %3
%28 = load i32*, i32** %6
%29 = call i32 @sqlite3_column_int(i32* %28, i32 0)
%30 = load i32*, i32** %6
%31 = call i64 @sqlite3_column_text(i32* %30, i32 1)
%32 = inttoptr i64 %31 to i8*
%33 = load i32*, i32** %6
%34 = call i64 @sqlite3_column_text(i32* %33, i32 2)
%35 = inttoptr i64 %34 to i8*
%36 = load i32*, i32** %6
%37 = call i64 @sqlite3_column_text(i32* %36, i32 3)
%38 = inttoptr i64 %37 to i8*
%39 = call i32 @db_createremote(%struct.db_remote* %27, i32 %29, i8* %32, i8* %35, i8* %38)
%40 = load i32*, i32** %6
%41 = call i64 @sqlite3_step(i32* %40)
%42 = load i64, i64* @SQLITE_DONE
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %47
44: ; preds = %26
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %26
%48 = load i32*, i32** %6
%49 = call i64 @sqlite3_finalize(i32* %48)
%50 = load i64, i64* @SQLITE_OK
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %47
%56 = load i32*, i32** %5
%57 = call i32 @closedatabase(i32* %56)
ret i32 1
}

LLVM IR (-O2):
%struct.db_remote = type { i32 }
@.str = [68 x i8] c"SELECT id, name, urldatabase, urlpackages FROM remotes WHERE id = ?\00"
@SQLITE_OK = global i64 0
@EXIT_FAILURE = global i32 0
@SQLITE_ROW = global i64 0
@SQLITE_DONE = global i64 0
define i32 @db_loadremote(%struct.db_remote* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = bitcast i32** %3 to i8*
%6 = bitcast i32** %4 to i8*
%7 = call i32 @opendatabase(i32** %3)
%8 = load i32*, i32** %3
%9 = call i64 @sqlite3_prepare_v2(i32* %8, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %4, i32 0)
%10 = load i64, i64* @SQLITE_OK
%11 = icmp eq i64 %9, %10
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = call i32 @sqlite3_bind_int(i32* %16, i32 1, i32 %1)
%18 = load i32*, i32** %4
%19 = call i64 @sqlite3_step(i32* %18)
%20 = load i64, i64* @SQLITE_ROW
%21 = icmp eq i64 %19, %20
br i1 %21, label %25, label %22
22: ; preds = %15
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %15
%26 = load i32*, i32** %4
%27 = call i32 @sqlite3_column_int(i32* %26, i32 0)
%28 = load i32*, i32** %4
%29 = call i64 @sqlite3_column_text(i32* %28, i32 1)
%30 = inttoptr i64 %29 to i8*
%31 = load i32*, i32** %4
%32 = call i64 @sqlite3_column_text(i32* %31, i32 2)
%33 = inttoptr i64 %32 to i8*
%34 = load i32*, i32** %4
%35 = call i64 @sqlite3_column_text(i32* %34, i32 3)
%36 = inttoptr i64 %35 to i8*
%37 = call i32 @db_createremote(%struct.db_remote* %0, i32 %27, i8* %30, i8* %33, i8* %36)
%38 = load i32*, i32** %4
%39 = call i64 @sqlite3_step(i32* %38)
%40 = load i64, i64* @SQLITE_DONE
%41 = icmp eq i64 %39, %40
br i1 %41, label %45, label %42
42: ; preds = %25
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %25
%46 = load i32*, i32** %4
%47 = call i64 @sqlite3_finalize(i32* %46)
%48 = load i64, i64* @SQLITE_OK
%49 = icmp eq i64 %47, %48
br i1 %49, label %53, label %50
50: ; preds = %45
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %45
%54 = load i32*, i32** %3
%55 = call i32 @closedatabase(i32* %54)
ret i32 1
}