#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;

/* Variables and functions */
int SQLITE_DONE;
int SQLITE_OK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_exec(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/, char **);
int /*<<< orphan*/ sqlite3_free(char *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       char const **);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void create_table(sqlite3 *db) {
  int rc = 0, row = 0;
  char *zErrMsg = 0;
  const char *sql;
  const char *tail;
  sqlite3_stmt *res;
  rc = sqlite3_prepare_v2(db,
                          "SELECT name FROM sqlite_master WHERE type='table' "
                          "AND name='TEMPERATURE_HISTORY';",
                          1000, &res, &tail);
  row = sqlite3_step(res);
  if (row == SQLITE_DONE) {
    sql = "CREATE TABLE TEMPERATURE_HISTORY("
          "TIMESTAMP   DATETIME DEFAULT CURRENT_TIMESTAMP,"
          "TEMPERATURE REAL NOT NULL DEFAULT 0,"
          "SENSOR INTEGER NOT NULL DEFAULT 1,"
          "PRIMARY KEY (TIMESTAMP, SENSOR)"
          ");";
    rc = sqlite3_exec(db, sql, NULL, 0, &zErrMsg);
    if (rc != SQLITE_OK) {
      fprintf(stderr, "SQL error: %s\n", zErrMsg);
      sqlite3_free(zErrMsg);
      sqlite3_close(db);
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<create_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x3e8,%edx
lea    -0x30(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1070 <sqlite3_prepare_v2@plt>
mov    %eax,-0xc(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%eax
jne    123e <create_table+0xce>
lea    0xe7b(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x18(%rbp),%r8
call   1030 <sqlite3_exec@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2de9(%rip),%rcx
cmp    (%rcx),%eax
je     1239 <create_table+0xc9>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xeef(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <sqlite3_free@plt>
mov    -0x8(%rbp),%rdi
call   1060 <sqlite3_close@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    123e <create_table+0xce>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_table>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0xe78(%rip),%rsi
lea    0x10(%rsp),%rcx
lea    0x18(%rsp),%r8
mov    $0x3e8,%edx
call   1070 <sqlite3_prepare_v2@plt>
mov    0x10(%rsp),%rdi
call   1040 <sqlite3_step@plt>
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%eax
jne    11d4 <create_table+0x64>
lea    0xe9a(%rip),%rsi
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%eax
jne    11da <create_table+0x6a>
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xf1b(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_free@plt>
mov    %rbx,%rdi
call   1060 <sqlite3_close@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [82 x i8] c"SELECT name FROM sqlite_master WHERE type='table' AND name='TEMPERATURE_HISTORY';\00"
@SQLITE_DONE = global i32 0
@.str.1 = [184 x i8] c"CREATE TABLE TEMPERATURE_HISTORY(TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP,TEMPERATURE REAL NOT NULL DEFAULT 0,SENSOR INTEGER NOT NULL DEFAULT 1,PRIMARY KEY (TIMESTAMP, SENSOR));\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.2 = [15 x i8] c"SQL error: %s\0A\00"
define void @create_table(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i32* %0, i32** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i8* null, i8** %5
%9 = load i32*, i32** %2
%10 = call i32 @sqlite3_prepare_v2(i32* %9, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0), i32 1000, i32** %8, i8** %7)
store i32 %10, i32* %3
%11 = load i32*, i32** %8
%12 = call i32 @sqlite3_step(i32* %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = load i32, i32* @SQLITE_DONE
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %33
16: ; preds = %1
store i8* getelementptr inbounds ([184 x i8], [184 x i8]* @.str.1, i64 0, i64 0), i8** %6
%17 = load i32*, i32** %2
%18 = load i8*, i8** %6
%19 = call i32 @sqlite3_exec(i32* %17, i8* %18, i32* null, i32 0, i8** %5)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = load i32, i32* @SQLITE_OK
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %32
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %5
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %5
%28 = call i32 @sqlite3_free(i8* %27)
%29 = load i32*, i32** %2
%30 = call i32 @sqlite3_close(i32* %29)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %16
br label %33
33: ; preds = %32, %1
ret void
}

LLVM IR (-O2):
@.str = [82 x i8] c"SELECT name FROM sqlite_master WHERE type='table' AND name='TEMPERATURE_HISTORY';\00"
@SQLITE_DONE = global i32 0
@.str.1 = [184 x i8] c"CREATE TABLE TEMPERATURE_HISTORY(TIMESTAMP DATETIME DEFAULT CURRENT_TIMESTAMP,TEMPERATURE REAL NOT NULL DEFAULT 0,SENSOR INTEGER NOT NULL DEFAULT 1,PRIMARY KEY (TIMESTAMP, SENSOR));\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.2 = [15 x i8] c"SQL error: %s\0A\00"
define void @create_table(i32* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%6 = bitcast i8** %3 to i8*
%7 = bitcast i32** %4 to i8*
%8 = call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0), i32 1000, i32** %4, i8** %3)
%9 = load i32*, i32** %4
%10 = call i32 @sqlite3_step(i32* %9)
%11 = load i32, i32* @SQLITE_DONE
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %25
13: ; preds = %1
%14 = call i32 @sqlite3_exec(i32* %0, i8* getelementptr inbounds ([184 x i8], [184 x i8]* @.str.1, i64 0, i64 0), i32* null, i32 0, i8** %2)
%15 = load i32, i32* @SQLITE_OK
%16 = icmp eq i32 %14, %15
br i1 %16, label %25, label %17
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %2
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = load i8*, i8** %2
%22 = call i32 @sqlite3_free(i8* %21)
%23 = call i32 @sqlite3_close(i32* %0)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %13, %1
ret void
}