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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int SQLITE_OK;
int SQLITE_OPEN_CREATE;
int SQLITE_OPEN_READWRITE;
int /*<<< orphan*/ create_table(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ read_blob(int /*<<< orphan*/ *, char const *,
                             unsigned char **, int *);
int /*<<< orphan*/ sqlite3_close_v2(int /*<<< orphan*/ *);
int sqlite3_errcode(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_open_v2(char const *, int /*<<< orphan*/ **, int,
                    int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write_blob(int /*<<< orphan*/ *, char const *, unsigned char *, int);
int main(int argc, char *argv[]) {
  sqlite3 *db = NULL;
  bool is_write = 0;
  FILE *fp = NULL;
  int rc = 0;
  int flags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE;
  int blob_size = 0;
  unsigned char *blob_data = NULL;
  char const *db_filename = NULL;
  char const *input_file = NULL;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s [DB name] (write | read) [FILE]\n", argv[0]);
    return 1;
  }
  db_filename = argv[1];
  input_file = argv[3];
  if (argv[2][0] == 'w' || argv[2][0] == 'W') {
    is_write = 1;
  }
  rc = sqlite3_open_v2(db_filename, &db, flags, NULL);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "%d: Open database failed (%d: \'%s\')\n", 61,
            sqlite3_errcode(db), sqlite3_errmsg(db));
    return 1;
  }
  if (is_write) {
    create_table(db);
    fp = fopen(input_file, "r");
    if (fp == NULL) {
      fprintf(stderr, "%d: Open file failed (%s: \'%s\')\n", 72,
              strerror(errno), input_file);
      return 1;
    }
    if (fseek(fp, 0, SEEK_END) != 0) {
      fprintf(stderr, "%d: Seek file failed (%s : \'%s\')\n", 80,
              strerror(errno), input_file);
      fclose(fp);
      return 1;
    }
    blob_size = ftell(fp);
    blob_data = malloc(blob_size);
    if (fread(blob_data, sizeof(char), blob_size, fp)) {
      fprintf(stderr, "%d: Read file failed (%s: \'%s\')\n", 94,
              strerror(errno), blob_data);
      return 1;
    }
    if (SQLITE_OK != write_blob(db, input_file, blob_data, blob_size)) {
      fprintf(stderr, "%d: Write BLOB into database (%d: \'%s\')\n", 101,
              sqlite3_errcode(db), sqlite3_errmsg(db));
      return 1;
    } else
      printf("BLOB data \'%s\' successfully written.\n", input_file);
    free(blob_data);
    fclose(fp);
  } else {
    fp = fopen(input_file, "w");
    if (fp == NULL) {
      fprintf(stderr, "%d: Open file failed (%s: \'%s\')\n", 117,
              strerror(errno), input_file);
      return 1;
    }
    read_blob(db, input_file, &blob_data, &blob_size);
    if (!blob_data) {
      fprintf(stderr, "Database is empty.\n");
      return 1;
    }
    fwrite(blob_data, sizeof(char), blob_size, fp);
    printf("BLOB data \'%s\' successfully written.\n", input_file);
    free(blob_data);
    fclose(fp);
  }
  sqlite3_close_v2(db);
  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)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    0x2d89(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     12bf <main+0x9f>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    165f <main+0x43f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x77,%eax
je     12ff <main+0xdf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
cmp    $0x57,%eax
jne    1306 <main+0xe6>
movl   $0x1,-0x1c(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x30(%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    0x2cb1(%rip),%rcx
cmp    (%rcx),%eax
je     1378 <main+0x158>
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_errcode@plt>
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_errmsg@plt>
mov    -0x58(%rbp),%edi
mov    -0x54(%rbp),%ecx
mov    %rax,%r8
lea    0xccb(%rip),%rsi
mov    $0x3d,%edx
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    165f <main+0x43f>
cmpl   $0x0,-0x1c(%rbp)
je     156e <main+0x34e>
mov    -0x18(%rbp),%rdi
call   1040 <create_table@plt>
mov    -0x50(%rbp),%rdi
lea    0xcba(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    13ed <main+0x1cd>
mov    0x2c0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,%rcx
mov    -0x50(%rbp),%r8
lea    0xc7d(%rip),%rsi
mov    $0x48,%edx
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    165f <main+0x43f>
mov    -0x28(%rbp),%rdi
mov    0x2be8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10e0 <fseek@plt>
cmp    $0x0,%rax
je     1457 <main+0x237>
mov    0x2bae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2b9a(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rcx
mov    -0x50(%rbp),%r8
lea    0xc3d(%rip),%rsi
mov    $0x50,%edx
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    165f <main+0x43f>
mov    -0x28(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   10d0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
cmp    $0x0,%rax
je     14d1 <main+0x2b1>
mov    0x2b2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2b17(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rcx
mov    -0x40(%rbp),%r8
lea    0xbdc(%rip),%rsi
mov    $0x5e,%edx
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    165f <main+0x43f>
mov    0x2b00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%ecx
call   10f0 <write_blob@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
cmp    %ecx,%eax
je     1547 <main+0x327>
mov    0x2abb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_errcode@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_errmsg@plt>
mov    -0x70(%rbp),%edi
mov    -0x6c(%rbp),%ecx
mov    %rax,%r8
lea    0xb87(%rip),%rsi
mov    $0x65,%edx
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    165f <main+0x43f>
mov    -0x50(%rbp),%rsi
lea    0xb8d(%rip),%rdi
call   1080 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
jmp    164a <main+0x42a>
mov    -0x50(%rbp),%rdi
lea    0xb8c(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    15d0 <main+0x3b0>
mov    0x2a2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2a18(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rcx
mov    -0x50(%rbp),%r8
lea    0xa9a(%rip),%rsi
mov    $0x75,%edx
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    165f <main+0x43f>
mov    -0x18(%rbp),%rdi
mov    -0x50(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1060 <read_blob@plt>
cmpq   $0x0,-0x40(%rbp)
jne    1613 <main+0x3f3>
mov    0x29c9(%rip),%rax
mov    (%rax),%edi
lea    0xb07(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    165f <main+0x43f>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1130 <fwrite@plt>
mov    -0x50(%rbp),%rsi
lea    0xaac(%rip),%rdi
call   1080 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1120 <sqlite3_close_v2@plt>
mov    0x2956(%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,(%rsp)
mov    0x2d93(%rip),%rax
mov    (%rax),%eax
mov    0x2daa(%rip),%rcx
mov    (%rcx),%edx
movl   $0x0,0xc(%rsp)
movq   $0x0,0x10(%rsp)
cmp    $0x4,%edi
jne    1318 <main+0xf8>
or     %eax,%edx
mov    0x18(%rsi),%r14
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rax
mov    (%rax),%bl
mov    %rsp,%rsi
xor    %ecx,%ecx
call   1110 <sqlite3_open_v2@plt>
mov    0x2d55(%rip),%r12
cmp    (%r12),%eax
jne    1337 <main+0x117>
and    $0xdf,%bl
cmp    $0x57,%bl
jne    1373 <main+0x153>
mov    (%rsp),%rdi
call   1040 <create_table@plt>
lea    0xda7(%rip),%rsi
mov    %r14,%rdi
call   1100 <fopen@plt>
test   %rax,%rax
je     13fe <main+0x1de>
mov    %rax,%r13
mov    0x2d1c(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
test   %rax,%rax
je     145c <main+0x23c>
mov    0x2ce0(%rip),%rax
mov    (%rax),%ebp
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xd7c(%rip),%rsi
mov    %ebp,%edi
mov    $0x50,%edx
mov    %rax,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r13,%rdi
call   1070 <fclose@plt>
jmp    14e0 <main+0x2c0>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xcd5(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    14e0 <main+0x2c0>
mov    0x2c82(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1090 <sqlite3_errcode@plt>
mov    %eax,%ebp
mov    (%rsp),%rdi
call   10a0 <sqlite3_errmsg@plt>
lea    0xcd0(%rip),%rsi
mov    %ebx,%edi
mov    $0x3d,%edx
mov    %ebp,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    14e0 <main+0x2c0>
lea    0xd8b(%rip),%rsi
mov    %r14,%rdi
call   1100 <fopen@plt>
test   %rax,%rax
je     1425 <main+0x205>
mov    %rax,%r13
mov    (%rsp),%rdi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r14,%rsi
call   1060 <read_blob@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     14c9 <main+0x2a9>
mov    0xc(%rsp),%edx
mov    $0x1,%esi
mov    %r13,%rcx
call   1130 <fwrite@plt>
lea    0xd15(%rip),%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
mov    0x10(%rsp),%r15
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1070 <fclose@plt>
mov    (%rsp),%rdi
call   1120 <sqlite3_close_v2@plt>
mov    0x2bb9(%rip),%rax
mov    (%rax),%ebp
jmp    14e5 <main+0x2c5>
mov    0x2bbb(%rip),%rax
mov    (%rax),%ebx
mov    0x2baa(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xc36(%rip),%rsi
mov    %ebx,%edi
mov    $0x48,%edx
jmp    144a <main+0x22a>
mov    0x2b94(%rip),%rax
mov    (%rax),%ebx
mov    0x2b83(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xc0f(%rip),%rsi
mov    %ebx,%edi
mov    $0x75,%edx
mov    %rax,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    14e0 <main+0x2c0>
mov    %r13,%rdi
call   10c0 <ftell@plt>
mov    %eax,%ebx
mov    %eax,0xc(%rsp)
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x10(%rsp)
mov    $0x1,%ebp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r13,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     14f6 <main+0x2d6>
mov    0x2b24(%rip),%rax
mov    (%rax),%ebx
mov    0x2b13(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xbe2(%rip),%rsi
mov    %ebx,%edi
mov    $0x5e,%edx
mov    %rax,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    14e5 <main+0x2c5>
mov    0x2af0(%rip),%rax
mov    (%rax),%edi
lea    0xc2e(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%r12d
mov    (%rsp),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
call   10f0 <write_blob@plt>
cmp    %eax,%r12d
jne    1524 <main+0x304>
lea    0xbc8(%rip),%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
jmp    13d7 <main+0x1b7>
mov    0x2a95(%rip),%rax
mov    (%rax),%r14d
mov    (%rsp),%rdi
call   1090 <sqlite3_errcode@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   10a0 <sqlite3_errmsg@plt>
lea    0xb6d(%rip),%rsi
mov    %r14d,%edi
mov    $0x65,%edx
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    14e5 <main+0x2c5>

LLVM IR (-O0):
@SQLITE_OPEN_CREATE = global i32 0
@SQLITE_OPEN_READWRITE = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s [DB name] (write | read) [FILE]\0A\00"
@SQLITE_OK = global i32 0
@.str.1 = [37 x i8] c"%d: Open database failed (%d: '%s')\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [33 x i8] c"%d: Open file failed (%s: '%s')\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@.str.4 = [34 x i8] c"%d: Seek file failed (%s : '%s')\0A\00"
@.str.5 = [33 x i8] c"%d: Read file failed (%s: '%s')\0A\00"
@.str.6 = [41 x i8] c"%d: Write BLOB into database (%d: '%s')\0A\00"
@.str.7 = [38 x i8] c"BLOB data '%s' successfully written.\0A\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [20 x i8] c"Database is empty.\0A\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32 0, i32* %7
store i32* null, i32** %8
store i32 0, i32* %9
%15 = load i32, i32* @SQLITE_OPEN_CREATE
%16 = load i32, i32* @SQLITE_OPEN_READWRITE
%17 = or i32 %15, %16
store i32 %17, i32* %10
store i32 0, i32* %11
store i8* null, i8** %12
store i8* null, i8** %13
store i8* null, i8** %14
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 4
br i1 %19, label %20, label %26
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %24)
store i32 1, i32* %3
br label %166
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
store i8* %29, i8** %13
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
store i8* %32, i8** %14
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 119
br i1 %39, label %48, label %40
40: ; preds = %26
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 87
br i1 %47, label %48, label %49
48: ; preds = %40, %26
store i32 1, i32* %7
br label %49
49: ; preds = %48, %40
%50 = load i8*, i8** %13
%51 = load i32, i32* %10
%52 = call i32 @sqlite3_open_v2(i8* %50, i32** %6, i32 %51, i32* null)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = load i32, i32* @SQLITE_OK
%55 = icmp ne i32 %53, %54
br i1 %55, label %56, label %63
56: ; preds = %49
%57 = load i32, i32* @stderr
%58 = load i32*, i32** %6
%59 = call i32 @sqlite3_errcode(i32* %58)
%60 = load i32*, i32** %6
%61 = call i8* @sqlite3_errmsg(i32* %60)
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 61, i32 %59, i8* %61)
store i32 1, i32* %3
br label %166
63: ; preds = %49
%64 = load i32, i32* %7
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %131
66: ; preds = %63
%67 = load i32*, i32** %6
%68 = call i32 @create_table(i32* %67)
%69 = load i8*, i8** %14
%70 = call i32* @fopen(i8* %69, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %70, i32** %8
%71 = load i32*, i32** %8
%72 = icmp eq i32* %71, null
br i1 %72, label %73, label %79
73: ; preds = %66
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = call i8* @strerror(i32 %75)
%77 = load i8*, i8** %14
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 72, i8* %76, i8* %77)
store i32 1, i32* %3
br label %166
79: ; preds = %66
%80 = load i32*, i32** %8
%81 = load i32, i32* @SEEK_END
%82 = call i64 @fseek(i32* %80, i32 0, i32 %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %92
84: ; preds = %79
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = call i8* @strerror(i32 %86)
%88 = load i8*, i8** %14
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 80, i8* %87, i8* %88)
%90 = load i32*, i32** %8
%91 = call i32 @fclose(i32* %90)
store i32 1, i32* %3
br label %166
92: ; preds = %79
%93 = load i32*, i32** %8
%94 = call i32 @ftell(i32* %93)
store i32 %94, i32* %11
%95 = load i32, i32* %11
%96 = call i8* @malloc(i32 %95)
store i8* %96, i8** %12
%97 = load i8*, i8** %12
%98 = load i32, i32* %11
%99 = load i32*, i32** %8
%100 = call i64 @fread(i8* %97, i32 1, i32 %98, i32* %99)
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %108
102: ; preds = %92
%103 = load i32, i32* @stderr
%104 = load i32, i32* @errno
%105 = call i8* @strerror(i32 %104)
%106 = load i8*, i8** %12
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 94, i8* %105, i8* %106)
store i32 1, i32* %3
br label %166
108: ; preds = %92
%109 = load i32, i32* @SQLITE_OK
%110 = load i32*, i32** %6
%111 = load i8*, i8** %14
%112 = load i8*, i8** %12
%113 = load i32, i32* %11
%114 = call i32 @write_blob(i32* %110, i8* %111, i8* %112, i32 %113)
%115 = icmp ne i32 %109, %114
br i1 %115, label %116, label %123
116: ; preds = %108
%117 = load i32, i32* @stderr
%118 = load i32*, i32** %6
%119 = call i32 @sqlite3_errcode(i32* %118)
%120 = load i32*, i32** %6
%121 = call i8* @sqlite3_errmsg(i32* %120)
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 101, i32 %119, i8* %121)
store i32 1, i32* %3
br label %166
123: ; preds = %108
%124 = load i8*, i8** %14
%125 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %124)
br label %126
126: ; preds = %123
%127 = load i8*, i8** %12
%128 = call i32 @free(i8* %127)
%129 = load i32*, i32** %8
%130 = call i32 @fclose(i32* %129)
br label %162
131: ; preds = %63
%132 = load i8*, i8** %14
%133 = call i32* @fopen(i8* %132, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %133, i32** %8
%134 = load i32*, i32** %8
%135 = icmp eq i32* %134, null
br i1 %135, label %136, label %142
136: ; preds = %131
%137 = load i32, i32* @stderr
%138 = load i32, i32* @errno
%139 = call i8* @strerror(i32 %138)
%140 = load i8*, i8** %14
%141 = call i32 (i32, i8*, ...) @fprintf(i32 %137, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 117, i8* %139, i8* %140)
store i32 1, i32* %3
br label %166
142: ; preds = %131
%143 = load i32*, i32** %6
%144 = load i8*, i8** %14
%145 = call i32 @read_blob(i32* %143, i8* %144, i8** %12, i32* %11)
%146 = load i8*, i8** %12
%147 = icmp ne i8* %146, null
br i1 %147, label %151, label %148
148: ; preds = %142
%149 = load i32, i32* @stderr
%150 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
br label %166
151: ; preds = %142
%152 = load i8*, i8** %12
%153 = load i32, i32* %11
%154 = load i32*, i32** %8
%155 = call i32 @fwrite(i8* %152, i32 1, i32 %153, i32* %154)
%156 = load i8*, i8** %14
%157 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %156)
%158 = load i8*, i8** %12
%159 = call i32 @free(i8* %158)
%160 = load i32*, i32** %8
%161 = call i32 @fclose(i32* %160)
br label %162
162: ; preds = %151, %126
%163 = load i32*, i32** %6
%164 = call i32 @sqlite3_close_v2(i32* %163)
%165 = load i32, i32* @EXIT_SUCCESS
store i32 %165, i32* %3
br label %166
166: ; preds = %162, %148, %136, %116, %102, %84, %73, %56, %20
%167 = load i32, i32* %3
ret i32 %167
}

LLVM IR (-O2):
@SQLITE_OPEN_CREATE = global i32 0
@SQLITE_OPEN_READWRITE = global i32 0
@stderr = global i32 0
@.str = [43 x i8] c"Usage: %s [DB name] (write | read) [FILE]\0A\00"
@SQLITE_OK = global i32 0
@.str.1 = [37 x i8] c"%d: Open database failed (%d: '%s')\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [33 x i8] c"%d: Open file failed (%s: '%s')\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@.str.4 = [34 x i8] c"%d: Seek file failed (%s : '%s')\0A\00"
@.str.5 = [33 x i8] c"%d: Read file failed (%s: '%s')\0A\00"
@.str.6 = [41 x i8] c"%d: Write BLOB into database (%d: '%s')\0A\00"
@.str.7 = [38 x i8] c"BLOB data '%s' successfully written.\0A\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [20 x i8] c"Database is empty.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%7 = load i32, i32* @SQLITE_OPEN_CREATE
%8 = load i32, i32* @SQLITE_OPEN_READWRITE
%9 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%10 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%11 = icmp eq i32 %0, 4
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %111
16: ; preds = %2
%17 = or i32 %8, %7
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
%25 = call i32 @sqlite3_open_v2(i8* %19, i32** %3, i32 %17, i32* null)
%26 = load i32, i32* @SQLITE_OK
%27 = icmp eq i32 %25, %26
br i1 %27, label %35, label %28
28: ; preds = %16
%29 = load i32, i32* @stderr
%30 = load i32*, i32** %3
%31 = call i32 @sqlite3_errcode(i32* %30)
%32 = load i32*, i32** %3
%33 = call i8* @sqlite3_errmsg(i32* %32)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 61, i32 %31, i8* %33)
br label %111
35: ; preds = %16
%36 = and i8 %24, -33
%37 = icmp eq i8 %36, 87
br i1 %37, label %38, label %82
38: ; preds = %35
%39 = load i32*, i32** %3
%40 = call i32 @create_table(i32* %39)
%41 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 72, i8* %46, i8* %21)
br label %111
48: ; preds = %38
%49 = load i32, i32* @SEEK_END
%50 = call i64 @fseek(i32* %41, i32 0, i32 %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %58, label %52
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 80, i8* %55, i8* %21)
%57 = call i32 @fclose(i32* %41)
br label %111
58: ; preds = %48
%59 = call i32 @ftell(i32* %41)
store i32 %59, i32* %4
%60 = call i8* @malloc(i32 %59)
store i8* %60, i8** %5
%61 = call i64 @fread(i8* %60, i32 1, i32 %59, i32* %41)
%62 = icmp eq i64 %61, 0
br i1 %62, label %68, label %63
63: ; preds = %58
%64 = load i32, i32* @stderr
%65 = load i32, i32* @errno
%66 = call i8* @strerror(i32 %65)
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 94, i8* %66, i8* %60)
br label %111
68: ; preds = %58
%69 = load i32, i32* @SQLITE_OK
%70 = load i32*, i32** %3
%71 = call i32 @write_blob(i32* %70, i8* %21, i8* %60, i32 %59)
%72 = icmp eq i32 %69, %71
br i1 %72, label %80, label %73
73: ; preds = %68
%74 = load i32, i32* @stderr
%75 = load i32*, i32** %3
%76 = call i32 @sqlite3_errcode(i32* %75)
%77 = load i32*, i32** %3
%78 = call i8* @sqlite3_errmsg(i32* %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 101, i32 %76, i8* %78)
br label %111
80: ; preds = %68
%81 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %21)
br label %103
82: ; preds = %35
%83 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%84 = icmp eq i32* %83, null
br i1 %84, label %85, label %90
85: ; preds = %82
%86 = load i32, i32* @stderr
%87 = load i32, i32* @errno
%88 = call i8* @strerror(i32 %87)
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 117, i8* %88, i8* %21)
br label %111
90: ; preds = %82
%91 = load i32*, i32** %3
%92 = call i32 @read_blob(i32* %91, i8* %21, i8** %5, i32* %4)
%93 = load i8*, i8** %5
%94 = icmp eq i8* %93, null
br i1 %94, label %95, label %98
95: ; preds = %90
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
br label %111
98: ; preds = %90
%99 = load i32, i32* %4
%100 = call i32 @fwrite(i8* %93, i32 1, i32 %99, i32* %83)
%101 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %21)
%102 = load i8*, i8** %5
br label %103
103: ; preds = %98, %80
%104 = phi i8* [ %102, %98 ], [ %60, %80 ]
%105 = phi i32* [ %83, %98 ], [ %41, %80 ]
%106 = call i32 @free(i8* %104)
%107 = call i32 @fclose(i32* %105)
%108 = load i32*, i32** %3
%109 = call i32 @sqlite3_close_v2(i32* %108)
%110 = load i32, i32* @EXIT_SUCCESS
br label %111
111: ; preds = %103, %95, %85, %73, %63, %52, %43, %28, %12
%112 = phi i32 [ 1, %12 ], [ 1, %28 ], [ 1, %43 ], [ 1, %52 ], [ 1, %63 ], [ 1, %73 ], [ %110, %103 ], [ 1, %85 ], [ 1, %95 ]
ret i32 %112
}