#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 SQLITE_OK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/, char **);
int /*<<< orphan*/ sqlite3_free(char *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void dbCreateTable() {
  sqlite3 *db;
  char *zErrMsg = 0;
  int rc = sqlite3_open("log.db", &db);
  if (rc) {
    fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
    exit(0);
  } else {
    fprintf(stderr, "Opened database successfully\n");
  }
  char *sql = "DROP TABLE IF EXISTS DB_LOG;"
              "CREATE TABLE DB_LOG("
              "ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
              "CONTENT           TEXT    NOT NULL,"
              "LEVEL            INT     NOT NULL,"
              "CREATE_TIME      TIMESTAMP NOT NULL DEFAULT "
              "(datetime('now','localtime')));";
  rc = sqlite3_exec(db, sql, NULL, 0, &zErrMsg);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "SQL error: %s\n", zErrMsg);
    sqlite3_free(zErrMsg);
  } else {
    fprintf(stdout, "Table created successfully\n");
  }
}


x86 assembly (clang, -O0):
<dbCreateTable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
lea    0xe89(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11bd <dbCreateTable+0x5d>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    0xe63(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x10(%rbp),%r8
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%eax
je     1234 <dbCreateTable+0xd4>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xf0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_free@plt>
jmp    124b <dbCreateTable+0xeb>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xef8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbCreateTable>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe89(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <sqlite3_open@plt>
mov    0x2e50(%rip),%r14
mov    (%r14),%ebx
test   %eax,%eax
jne    1205 <dbCreateTable+0xa5>
lea    0xe8a(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x10(%rsp),%rdi
lea    0xe93(%rip),%rsi
lea    0x8(%rsp),%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%eax
jne    11dd <dbCreateTable+0x7d>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xf68(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11fd <dbCreateTable+0x9d>
mov    (%r14),%edi
mov    0x8(%rsp),%rdx
lea    0xf41(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x10(%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xdf1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"log.db\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Can't open database: %s\0A\00"
@.str.2 = [30 x i8] c"Opened database successfully\0A\00"
@.str.3 = [239 x i8] c"DROP TABLE IF EXISTS DB_LOG;CREATE TABLE DB_LOG(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,CONTENT TEXT NOT NULL,LEVEL INT NOT NULL,CREATE_TIME TIMESTAMP NOT NULL DEFAULT (datetime('now','localtime')));\00"
@SQLITE_OK = global i32 0
@.str.4 = [15 x i8] c"SQL error: %s\0A\00"
@stdout = global i32 0
@.str.5 = [28 x i8] c"Table created successfully\0A\00"
define void @dbCreateTable() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* null, i8** %2
%5 = call i32 @sqlite3_open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32** %1)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32*, i32** %1
%11 = call i8* @sqlite3_errmsg(i32* %10)
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %14
store i8* getelementptr inbounds ([239 x i8], [239 x i8]* @.str.3, i64 0, i64 0), i8** %4
%18 = load i32*, i32** %1
%19 = load i8*, i8** %4
%20 = call i32 @sqlite3_exec(i32* %18, i8* %19, i32* null, i32 0, i8** %2)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = load i32, i32* @SQLITE_OK
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %2
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %2
%29 = call i32 @sqlite3_free(i8* %28)
br label %33
30: ; preds = %17
%31 = load i32, i32* @stdout
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %33
33: ; preds = %30, %24
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"log.db\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Can't open database: %s\0A\00"
@.str.2 = [30 x i8] c"Opened database successfully\0A\00"
@.str.3 = [239 x i8] c"DROP TABLE IF EXISTS DB_LOG;CREATE TABLE DB_LOG(ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,CONTENT TEXT NOT NULL,LEVEL INT NOT NULL,CREATE_TIME TIMESTAMP NOT NULL DEFAULT (datetime('now','localtime')));\00"
@SQLITE_OK = global i32 0
@.str.4 = [15 x i8] c"SQL error: %s\0A\00"
@stdout = global i32 0
@.str.5 = [28 x i8] c"Table created successfully\0A\00"
define void @dbCreateTable() {
%1 = alloca i32*
%2 = alloca i8*
%3 = bitcast i32** %1 to i8*
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = call i32 @sqlite3_open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32** %1)
%6 = icmp eq i32 %5, 0
%7 = load i32, i32* @stderr
br i1 %6, label %13, label %8
8: ; preds = %0
%9 = load i32*, i32** %1
%10 = call i8* @sqlite3_errmsg(i32* %9)
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %0
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32*, i32** %1
%16 = call i32 @sqlite3_exec(i32* %15, i8* getelementptr inbounds ([239 x i8], [239 x i8]* @.str.3, i64 0, i64 0), i32* null, i32 0, i8** %2)
%17 = load i32, i32* @SQLITE_OK
%18 = icmp eq i32 %16, %17
br i1 %18, label %25, label %19
19: ; preds = %13
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %2
%24 = call i32 @sqlite3_free(i8* %23)
br label %28
25: ; preds = %13
%26 = load i32, i32* @stdout
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %28
28: ; preds = %25, %19
ret void
}