#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_stmt;
typedef int /*<<< orphan*/ sqlite3;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int SQLITE_OK;
int SQLITE_OPEN_READWRITE;
scalar_t__ SQLITE_ROW;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *const, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fwrite(char const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *const);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_close_v2(int /*<<< orphan*/ *);
char *sqlite3_column_blob(int /*<<< orphan*/ *, int /*<<< orphan*/);
int sqlite3_column_bytes(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_initialize();
int sqlite3_open_v2(char const *const, int /*<<< orphan*/ **, int,
                    int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_shutdown();
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  sqlite3 *db = NULL;
  sqlite3_stmt *stmt = NULL;
  FILE *fblob = NULL;
  int res = 0;
  int blob_size = 0;
  int flags = SQLITE_OPEN_READWRITE;
  const char *blob_data = NULL;
  char *sql_data = "SELECT data FROM blobs WHERE id = 1";
  if (argc < 3) {
    fprintf(stderr, "Usage: %s <database> <filename>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  const char *const db_name = (argc && argv[1]) ? argv[1] : "";
  const char *const data_name = (argc && argv[2]) ? argv[2] : "";
  if (sqlite3_initialize() != SQLITE_OK) {
    fprintf(stderr, "Err. Unable to initialize the library.\n");
    exit(EXIT_FAILURE);
  }
  res = sqlite3_open_v2(db_name, &db, flags, NULL);
  if (res != SQLITE_OK) {
    fprintf(stderr, "Err. Can't create database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    exit(EXIT_FAILURE);
  }
  if (sqlite3_prepare_v2(db, sql_data, -1, &stmt, NULL) != SQLITE_OK) {
    fprintf(stderr, "Err. Unable to create Prepared Statement.\n");
    exit(EXIT_FAILURE);
  }
  if (sqlite3_step(stmt) == SQLITE_ROW) {
    blob_size = sqlite3_column_bytes(stmt, 0);
    blob_data = sqlite3_column_blob(stmt, 0);
  }
  fblob = fopen(data_name, "w");
  if (fblob == NULL) {
    fprintf(stderr, "Err. Open file failed: %s\n", strerror(errno));
    return 1;
  }
  if (fwrite(blob_data, blob_size, 1, fblob) != 1) {
    fprintf(stderr, "Err. Write file failed: %s\n", strerror(errno));
    return 1;
  } else
    printf("Written BLOB data into \'%s\'\n", data_name);
  fclose(fblob);
  if (sqlite3_finalize(stmt) == SQLITE_OK)
    puts("... Prepared Statemend destroyed.");
  if (sqlite3_close_v2(db) == SQLITE_OK)
    puts("... Closed database connection. ");
  sqlite3_shutdown();
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
lea    0xd76(%rip),%rax
mov    %rax,-0x48(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    12c4 <main+0x94>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd75(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
je     12ee <main+0xbe>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     12ee <main+0xbe>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
jmp    12fe <main+0xce>
lea    0xe18(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    12fe <main+0xce>
mov    -0x60(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1330 <main+0x100>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     1330 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x68(%rbp)
jmp    1340 <main+0x110>
lea    0xdd6(%rip),%rax
mov    %rax,-0x68(%rbp)
jmp    1340 <main+0x110>
mov    -0x68(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1030 <sqlite3_initialize@plt>
mov    0x2c8a(%rip),%rcx
cmp    (%rcx),%eax
je     1383 <main+0x153>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
lea    0xcd7(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x50(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1110 <sqlite3_open_v2@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2c3c(%rip),%rcx
cmp    (%rcx),%eax
je     13ec <main+0x1bc>
mov    0x2c1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_errmsg@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xc9f(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <sqlite3_close@plt>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1100 <sqlite3_prepare_v2@plt>
mov    0x2bd2(%rip),%rcx
cmp    (%rcx),%eax
je     143b <main+0x20b>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
lea    0xc67(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <sqlite3_step@plt>
mov    0x2b65(%rip),%rcx
cmp    (%rcx),%rax
jne    1471 <main+0x241>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   10d0 <sqlite3_column_bytes@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_blob@plt>
mov    %rax,-0x40(%rbp)
mov    -0x58(%rbp),%rdi
lea    0xc3c(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    14ca <main+0x29a>
mov    0x2b39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2b25(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x70(%rbp),%edi
mov    %rax,%rdx
lea    0xc03(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1596 <main+0x366>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1140 <fwrite@plt>
cmp    $0x1,%eax
je     1522 <main+0x2f2>
mov    0x2ae1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2acd(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xbc6(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1596 <main+0x366>
mov    -0x58(%rbp),%rsi
lea    0xbc4(%rip),%rdi
call   1070 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   10f0 <sqlite3_finalize@plt>
mov    0x2a95(%rip),%rcx
cmp    (%rcx),%eax
jne    155f <main+0x32f>
lea    0xbb4(%rip),%rdi
call   1050 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1130 <sqlite3_close_v2@plt>
mov    0x2a71(%rip),%rcx
cmp    (%rcx),%eax
jne    1583 <main+0x353>
lea    0xbb2(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1080 <sqlite3_shutdown@plt>
mov    0x2a27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
cmp    $0x2,%edi
jle    1421 <main+0x1f1>
mov    0x2d90(%rip),%rax
mov    (%rax),%r14d
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%r13
test   %r13,%r13
lea    0xe98(%rip),%rbx
cmove  %rbx,%r13
xor    %eax,%eax
call   1030 <sqlite3_initialize@plt>
mov    0x2d59(%rip),%r15
cmp    (%r15),%eax
jne    143d <main+0x20d>
test   %rbp,%rbp
cmovne %rbp,%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1110 <sqlite3_open_v2@plt>
cmp    (%r15),%eax
jne    144f <main+0x21f>
mov    0x10(%rsp),%rdi
lea    0xd42(%rip),%rsi
xor    %r14d,%r14d
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1100 <sqlite3_prepare_v2@plt>
cmp    (%r15),%eax
jne    1481 <main+0x251>
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_step@plt>
mov    0x2cc3(%rip),%rcx
cmp    (%rcx),%rax
jne    1312 <main+0xe2>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   10d0 <sqlite3_column_bytes@plt>
mov    %eax,%r14d
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <sqlite3_column_blob@plt>
mov    %rax,%r12
jmp    1315 <main+0xe5>
xor    %r12d,%r12d
lea    0xd9c(%rip),%rsi
mov    %r13,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     13b3 <main+0x183>
mov    %rax,%rbp
mov    %r15,%rbx
mov    $0x1,%r15d
mov    %r12,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1140 <fwrite@plt>
cmp    $0x1,%eax
jne    13e5 <main+0x1b5>
lea    0xd95(%rip),%rdi
mov    %r13,%rsi
call   1070 <printf@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    0x8(%rsp),%rdi
call   10f0 <sqlite3_finalize@plt>
cmp    (%rbx),%eax
jne    1386 <main+0x156>
lea    0xd8d(%rip),%rdi
call   1050 <puts@plt>
mov    0x10(%rsp),%rdi
call   1130 <sqlite3_close_v2@plt>
cmp    (%rbx),%eax
jne    13a0 <main+0x170>
lea    0xd95(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1080 <sqlite3_shutdown@plt>
mov    0x2c0a(%rip),%rax
mov    (%rax),%r15d
jmp    140f <main+0x1df>
mov    0x2c16(%rip),%rax
mov    (%rax),%ebx
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
lea    0xce9(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%r15d
jmp    140f <main+0x1df>
mov    0x2be4(%rip),%rax
mov    (%rax),%ebx
mov    0x2bd3(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
lea    0xcd2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ba8(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xbf0(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1498 <main+0x268>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
lea    0xbf8(%rip),%rsi
jmp    1491 <main+0x261>
mov    0x2b7a(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   1090 <sqlite3_errmsg@plt>
lea    0xc04(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   10c0 <sqlite3_close@plt>
jmp    1498 <main+0x268>
mov    0x2b48(%rip),%rax
mov    (%rax),%edi
lea    0xbfc(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x2b21(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@SQLITE_OPEN_READWRITE = global i32 0
@.str = [36 x i8] c"SELECT data FROM blobs WHERE id = 1\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Usage: %s <database> <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@SQLITE_OK = global i32 0
@.str.3 = [40 x i8] c"Err. Unable to initialize the library.\0A\00"
@.str.4 = [32 x i8] c"Err. Can't create database: %s\0A\00"
@.str.5 = [43 x i8] c"Err. Unable to create Prepared Statement.\0A\00"
@SQLITE_ROW = global i64 0
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [27 x i8] c"Err. Open file failed: %s\0A\00"
@errno = global i32 0
@.str.8 = [28 x i8] c"Err. Write file failed: %s\0A\00"
@.str.9 = [29 x i8] c"Written BLOB data into '%s'\0A\00"
@.str.10 = [34 x i8] c"... Prepared Statemend destroyed.\00"
@.str.11 = [33 x i8] c"... Closed database connection. \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i32* null, i32** %8
store i32 0, i32* %9
store i32 0, i32* %10
%16 = load i32, i32* @SQLITE_OPEN_READWRITE
store i32 %16, i32* %11
store i8* null, i8** %12
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8** %13
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %27
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %2
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
br label %40
39: ; preds = %30, %27
br label %40
40: ; preds = %39, %35
%41 = phi i8* [ %38, %35 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %39 ]
store i8* %41, i8** %14
%42 = load i32, i32* %4
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %53
44: ; preds = %40
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
br label %54
53: ; preds = %44, %40
br label %54
54: ; preds = %53, %49
%55 = phi i8* [ %52, %49 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %53 ]
store i8* %55, i8** %15
%56 = call i32 (...) @sqlite3_initialize()
%57 = load i32, i32* @SQLITE_OK
%58 = icmp ne i32 %56, %57
br i1 %58, label %59, label %64
59: ; preds = %54
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %54
%65 = load i8*, i8** %14
%66 = load i32, i32* %11
%67 = call i32 @sqlite3_open_v2(i8* %65, i32** %6, i32 %66, i32* null)
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = load i32, i32* @SQLITE_OK
%70 = icmp ne i32 %68, %69
br i1 %70, label %71, label %80
71: ; preds = %64
%72 = load i32, i32* @stderr
%73 = load i32*, i32** %6
%74 = call i8* @sqlite3_errmsg(i32* %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %74)
%76 = load i32*, i32** %6
%77 = call i32 @sqlite3_close(i32* %76)
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %64
%81 = load i32*, i32** %6
%82 = load i8*, i8** %13
%83 = call i32 @sqlite3_prepare_v2(i32* %81, i8* %82, i32 -1, i32** %7, i32* null)
%84 = load i32, i32* @SQLITE_OK
%85 = icmp ne i32 %83, %84
br i1 %85, label %86, label %91
86: ; preds = %80
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%89 = load i32, i32* @EXIT_FAILURE
%90 = call i32 @exit(i32 %89)
unreachable
91: ; preds = %80
%92 = load i32*, i32** %7
%93 = call i64 @sqlite3_step(i32* %92)
%94 = load i64, i64* @SQLITE_ROW
%95 = icmp eq i64 %93, %94
br i1 %95, label %96, label %101
96: ; preds = %91
%97 = load i32*, i32** %7
%98 = call i32 @sqlite3_column_bytes(i32* %97, i32 0)
store i32 %98, i32* %10
%99 = load i32*, i32** %7
%100 = call i8* @sqlite3_column_blob(i32* %99, i32 0)
store i8* %100, i8** %12
br label %101
101: ; preds = %96, %91
%102 = load i8*, i8** %15
%103 = call i32* @fopen(i8* %102, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %103, i32** %8
%104 = load i32*, i32** %8
%105 = icmp eq i32* %104, null
br i1 %105, label %106, label %111
106: ; preds = %101
%107 = load i32, i32* @stderr
%108 = load i32, i32* @errno
%109 = call i8* @strerror(i32 %108)
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %109)
store i32 1, i32* %3
br label %144
111: ; preds = %101
%112 = load i8*, i8** %12
%113 = load i32, i32* %10
%114 = load i32*, i32** %8
%115 = call i32 @fwrite(i8* %112, i32 %113, i32 1, i32* %114)
%116 = icmp ne i32 %115, 1
br i1 %116, label %117, label %122
117: ; preds = %111
%118 = load i32, i32* @stderr
%119 = load i32, i32* @errno
%120 = call i8* @strerror(i32 %119)
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %118, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %120)
store i32 1, i32* %3
br label %144
122: ; preds = %111
%123 = load i8*, i8** %15
%124 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %123)
br label %125
125: ; preds = %122
%126 = load i32*, i32** %8
%127 = call i32 @fclose(i32* %126)
%128 = load i32*, i32** %7
%129 = call i32 @sqlite3_finalize(i32* %128)
%130 = load i32, i32* @SQLITE_OK
%131 = icmp eq i32 %129, %130
br i1 %131, label %132, label %134
132: ; preds = %125
%133 = call i32 @puts(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
br label %134
134: ; preds = %132, %125
%135 = load i32*, i32** %6
%136 = call i32 @sqlite3_close_v2(i32* %135)
%137 = load i32, i32* @SQLITE_OK
%138 = icmp eq i32 %136, %137
br i1 %138, label %139, label %141
139: ; preds = %134
%140 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0))
br label %141
141: ; preds = %139, %134
%142 = call i32 (...) @sqlite3_shutdown()
%143 = load i32, i32* @EXIT_SUCCESS
store i32 %143, i32* %3
br label %144
144: ; preds = %141, %117, %106
%145 = load i32, i32* %3
ret i32 %145
}

LLVM IR (-O2):
@SQLITE_OPEN_READWRITE = global i32 0
@.str = [36 x i8] c"SELECT data FROM blobs WHERE id = 1\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"Usage: %s <database> <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@SQLITE_OK = global i32 0
@.str.3 = [40 x i8] c"Err. Unable to initialize the library.\0A\00"
@.str.4 = [32 x i8] c"Err. Can't create database: %s\0A\00"
@.str.5 = [43 x i8] c"Err. Unable to create Prepared Statement.\0A\00"
@SQLITE_ROW = global i64 0
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [27 x i8] c"Err. Open file failed: %s\0A\00"
@errno = global i32 0
@.str.8 = [28 x i8] c"Err. Write file failed: %s\0A\00"
@.str.9 = [29 x i8] c"Written BLOB data into '%s'\0A\00"
@.str.10 = [34 x i8] c"... Prepared Statemend destroyed.\00"
@.str.11 = [33 x i8] c"... Closed database connection. \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%6 = bitcast i32** %4 to i8*
store i32* null, i32** %4
%7 = load i32, i32* @SQLITE_OPEN_READWRITE
%8 = icmp slt i32 %0, 3
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
%21 = select i1 %20, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* %19
%22 = tail call i32 (...) @sqlite3_initialize()
%23 = load i32, i32* @SQLITE_OK
%24 = icmp eq i32 %22, %23
br i1 %24, label %30, label %25
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %15
%31 = icmp eq i8* %17, null
%32 = select i1 %31, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* %17
%33 = call i32 @sqlite3_open_v2(i8* %32, i32** %3, i32 %7, i32* null)
%34 = load i32, i32* @SQLITE_OK
%35 = icmp eq i32 %33, %34
br i1 %35, label %45, label %36
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = load i32*, i32** %3
%39 = call i8* @sqlite3_errmsg(i32* %38)
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i32*, i32** %3
%42 = call i32 @sqlite3_close(i32* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %30
%46 = load i32*, i32** %3
%47 = call i32 @sqlite3_prepare_v2(i32* %46, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %4, i32* null)
%48 = load i32, i32* @SQLITE_OK
%49 = icmp eq i32 %47, %48
br i1 %49, label %55, label %50
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %45
%56 = load i32*, i32** %4
%57 = call i64 @sqlite3_step(i32* %56)
%58 = load i64, i64* @SQLITE_ROW
%59 = icmp eq i64 %57, %58
br i1 %59, label %60, label %65
60: ; preds = %55
%61 = load i32*, i32** %4
%62 = call i32 @sqlite3_column_bytes(i32* %61, i32 0)
%63 = load i32*, i32** %4
%64 = call i8* @sqlite3_column_blob(i32* %63, i32 0)
br label %65
65: ; preds = %60, %55
%66 = phi i32 [ %62, %60 ], [ 0, %55 ]
%67 = phi i8* [ %64, %60 ], [ null, %55 ]
%68 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%69 = icmp eq i32* %68, null
br i1 %69, label %70, label %75
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = load i32, i32* @errno
%73 = call i8* @strerror(i32 %72)
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %73)
br label %102
75: ; preds = %65
%76 = call i32 @fwrite(i8* %67, i32 %66, i32 1, i32* %68)
%77 = icmp eq i32 %76, 1
br i1 %77, label %83, label %78
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %81)
br label %102
83: ; preds = %75
%84 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %21)
%85 = call i32 @fclose(i32* %68)
%86 = load i32*, i32** %4
%87 = call i32 @sqlite3_finalize(i32* %86)
%88 = load i32, i32* @SQLITE_OK
%89 = icmp eq i32 %87, %88
br i1 %89, label %90, label %92
90: ; preds = %83
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
br label %92
92: ; preds = %90, %83
%93 = load i32*, i32** %3
%94 = call i32 @sqlite3_close_v2(i32* %93)
%95 = load i32, i32* @SQLITE_OK
%96 = icmp eq i32 %94, %95
br i1 %96, label %97, label %99
97: ; preds = %92
%98 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0))
br label %99
99: ; preds = %97, %92
%100 = call i32 (...) @sqlite3_shutdown()
%101 = load i32, i32* @EXIT_SUCCESS
br label %102
102: ; preds = %99, %78, %70
%103 = phi i32 [ 1, %70 ], [ 1, %78 ], [ %101, %99 ]
ret i32 %103
}