#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 *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
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;
int main() {
  sqlite3 *db;
  char *zErrMsg = 0;
  int rc;
  rc = sqlite3_open("test.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 sql5[256];
  char *tname = "ttt";
  sprintf(sql5,
          "create table if not exists %s ("
          "id int not null,"
          "name text not null);",
          tname);
  printf("%s\n", sql5);
  rc = sqlite3_exec(db, sql5, NULL, NULL, &zErrMsg);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "SQL error: %s\n", zErrMsg);
    sqlite3_free(zErrMsg);
  } else {
    fprintf(stdout, "Table created successfully\n");
  }
  char *sql = "insert into ttt (id, name) values(22,'fuck')";
  rc = sqlite3_exec(db, sql, NULL, NULL, &zErrMsg);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "SQL error: %s\n", zErrMsg);
    sqlite3_free(zErrMsg);
  } else {
    fprintf(stdout, "Table insert data successfully\n");
  }
  sqlite3_close(db);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe4f(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11fd <main+0x6d>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x134(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x134(%rbp),%edi
mov    %rax,%rdx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xe24(%rip),%rax
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rdx
lea    0xe0c(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x120(%rbp),%rsi
lea    0xdd3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d71(%rip),%rcx
cmp    (%rcx),%eax
je     12a8 <main+0x118>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_free@plt>
jmp    12bf <main+0x12f>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xdec(%rip),%rax
mov    %rax,-0x130(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x130(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2cf3(%rip),%rcx
cmp    (%rcx),%eax
je     1326 <main+0x196>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd76(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1090 <sqlite3_free@plt>
jmp    133d <main+0x1ad>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_close@plt>
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x118,%rsp
movq   $0x0,(%rsp)
lea    0xe57(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <sqlite3_open@plt>
mov    0x2e1e(%rip),%r14
mov    (%r14),%ebx
test   %eax,%eax
jne    12bf <main+0x12f>
lea    0xe55(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe67(%rip),%rsi
lea    0xe5c(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
lea    0xe26(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
mov    %rsp,%r8
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    0x2dce(%rip),%rbx
cmp    (%rbx),%eax
jne    1237 <main+0xa7>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1255 <main+0xc5>
mov    (%r14),%edi
mov    (%rsp),%rdx
lea    0xe42(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_free@plt>
mov    0x8(%rsp),%rdi
lea    0xe51(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmp    (%rbx),%eax
jne    128a <main+0xfa>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12a8 <main+0x118>
mov    (%r14),%edi
mov    (%rsp),%rdx
lea    0xdef(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rsp),%rdi
call   1090 <sqlite3_free@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_close@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xd38(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"test.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 = [4 x i8] c"ttt\00"
@.str.4 = [68 x i8] c"create table if not exists %s (id int not null,name text not null);\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@SQLITE_OK = global i32 0
@.str.6 = [15 x i8] c"SQL error: %s\0A\00"
@stdout = global i32 0
@.str.7 = [28 x i8] c"Table created successfully\0A\00"
@.str.8 = [45 x i8] c"insert into ttt (id, name) values(22,'fuck')\00"
@.str.9 = [32 x i8] c"Table insert data successfully\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %3
%8 = call i32 @sqlite3_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32** %2)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = load i32*, i32** %2
%14 = call i8* @sqlite3_errmsg(i32* %13)
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %0
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %17
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %6
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%22 = load i8*, i8** %6
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %2
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%28 = call i32 @sqlite3_exec(i32* %26, i8* %27, i32* null, i32* null, i8** %3)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = load i32, i32* @SQLITE_OK
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %38
32: ; preds = %20
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %3
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %3
%37 = call i32 @sqlite3_free(i8* %36)
br label %41
38: ; preds = %20
%39 = load i32, i32* @stdout
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %41
41: ; preds = %38, %32
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i8** %7
%42 = load i32*, i32** %2
%43 = load i8*, i8** %7
%44 = call i32 @sqlite3_exec(i32* %42, i8* %43, i32* null, i32* null, i8** %3)
store i32 %44, i32* %4
%45 = load i32, i32* %4
%46 = load i32, i32* @SQLITE_OK
%47 = icmp ne i32 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %41
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %3
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %3
%53 = call i32 @sqlite3_free(i8* %52)
br label %57
54: ; preds = %41
%55 = load i32, i32* @stdout
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %57
57: ; preds = %54, %48
%58 = load i32*, i32** %2
%59 = call i32 @sqlite3_close(i32* %58)
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [8 x i8] c"test.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 = [4 x i8] c"ttt\00"
@.str.4 = [68 x i8] c"create table if not exists %s (id int not null,name text not null);\00"
@.str.5 = [4 x i8] c"%s\0A\00"
@SQLITE_OK = global i32 0
@.str.6 = [15 x i8] c"SQL error: %s\0A\00"
@stdout = global i32 0
@.str.7 = [28 x i8] c"Table created successfully\0A\00"
@.str.8 = [45 x i8] c"insert into ttt (id, name) values(22,'fuck')\00"
@.str.9 = [32 x i8] c"Table insert data successfully\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = bitcast i32** %1 to i8*
%5 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%6 = call i32 @sqlite3_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32** %1)
%7 = icmp eq i32 %6, 0
%8 = load i32, i32* @stderr
br i1 %7, label %14, label %9
9: ; preds = %0
%10 = load i32*, i32** %1
%11 = call i8* @sqlite3_errmsg(i32* %10)
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %8, 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 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %16)
%19 = load i32*, i32** %1
%20 = call i32 @sqlite3_exec(i32* %19, i8* %16, i32* null, i32* null, i8** %2)
%21 = load i32, i32* @SQLITE_OK
%22 = icmp eq i32 %20, %21
br i1 %22, label %29, label %23
23: ; preds = %14
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %2
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %2
%28 = call i32 @sqlite3_free(i8* %27)
br label %32
29: ; preds = %14
%30 = load i32, i32* @stdout
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
br label %32
32: ; preds = %29, %23
%33 = load i32*, i32** %1
%34 = call i32 @sqlite3_exec(i32* %33, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i32* null, i32* null, i8** %2)
%35 = load i32, i32* @SQLITE_OK
%36 = icmp eq i32 %34, %35
br i1 %36, label %43, label %37
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %2
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %2
%42 = call i32 @sqlite3_free(i8* %41)
br label %46
43: ; preds = %32
%44 = load i32, i32* @stdout
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %46
46: ; preds = %43, %37
%47 = load i32*, i32** %1
%48 = call i32 @sqlite3_close(i32* %47)
ret i32 0
}