#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*/ exit(int);
int /*<<< orphan*/ join_strings(char **, int, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sqlite3_free(char *);
int /*<<< orphan*/ sqlite3_get_table(int /*<<< orphan*/ *, char *, char ***,
                                     int *, int *, char **);
int get_latest_backup_dir(sqlite3 **db, char **string) {
  char **data;
  int row_number, col_number;
  char *error;
  sqlite3_get_table(
      *db,
      "SELECT directory FROM backup WHERE 1 ORDER BY timestamp DESC LIMIT 1",
      &data, &row_number, &col_number, &error);
  if (error != NULL) {
    printf("error SELECT SQLite: %s", error);
    sqlite3_free(error);
    exit(-1);
  }
  if (row_number == 0) {
    join_strings(string, 0);
    return 0;
  }
  join_strings(string, 1, data[1]);
  return 0;
}


x86 assembly (clang, -O0):
<get_latest_backup_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe92(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x28(%rbp),%r8
lea    -0x30(%rbp),%r9
call   1040 <sqlite3_get_table@plt>
cmpq   $0x0,-0x30(%rbp)
je     11b1 <get_latest_backup_dir+0x61>
mov    -0x30(%rbp),%rsi
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <sqlite3_free@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x24(%rbp)
jne    11d4 <get_latest_backup_dir+0x84>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1050 <join_strings@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <get_latest_backup_dir+0xa3>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x1,%esi
mov    $0x0,%al
call   1050 <join_strings@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_latest_backup_dir>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    (%rdi),%rdi
lea    0xe9e(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x4(%rsp),%rcx
lea    0x1c(%rsp),%r8
lea    0x8(%rsp),%r9
call   1040 <sqlite3_get_table@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
jne    11ba <get_latest_backup_dir+0x6a>
cmpl   $0x0,0x4(%rsp)
je     11a6 <get_latest_backup_dir+0x56>
mov    0x10(%rsp),%rax
mov    0x8(%rax),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <join_strings@plt>
jmp    11b2 <get_latest_backup_dir+0x62>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <join_strings@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_free@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [69 x i8] c"SELECT directory FROM backup WHERE 1 ORDER BY timestamp DESC LIMIT 1\00"
@.str.1 = [24 x i8] c"error SELECT SQLite: %s\00"
define i32 @get_latest_backup_dir(i32** %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32** %0, i32*** %4
store i8** %1, i8*** %5
%10 = load i32**, i32*** %4
%11 = load i32*, i32** %10
%12 = call i32 @sqlite3_get_table(i32* %11, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i8*** %6, i32* %7, i32* %8, i8** %9)
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8*, i8** %9
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %9
%19 = call i32 @sqlite3_free(i8* %18)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8**, i8*** %5
%26 = call i32 (i8**, i32, ...) @join_strings(i8** %25, i32 0)
store i32 0, i32* %3
br label %33
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = load i8**, i8*** %6
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i8**, i32, ...) @join_strings(i8** %28, i32 1, i8* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %27, %24
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [69 x i8] c"SELECT directory FROM backup WHERE 1 ORDER BY timestamp DESC LIMIT 1\00"
@.str.1 = [24 x i8] c"error SELECT SQLite: %s\00"
define i32 @get_latest_backup_dir(i32** nocapture %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = bitcast i8*** %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i8** %6 to i8*
%11 = load i32*, i32** %0
%12 = call i32 @sqlite3_get_table(i32* %11, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i8*** %3, i32* %4, i32* %5, i8** %6)
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %20, label %15
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%17 = load i8*, i8** %6
%18 = call i32 @sqlite3_free(i8* %17)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (i8**, i32, ...) @join_strings(i8** %1, i32 0)
br label %30
25: ; preds = %20
%26 = load i8**, i8*** %3
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8**, i32, ...) @join_strings(i8** %1, i32 1, i8* %28)
br label %30
30: ; preds = %25, %23
ret i32 0
}