#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sqlite3_bind_int(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ sqlite3_bind_text(int /*<<< orphan*/ *, int, char *, int,
                                     int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int insert(sqlite3 *db, sqlite3_stmt *stmt, char *name, int age,
           char *address) {
  char *insertSql = "insert into student(name,age,address) values(?,?,?);";
  int res = sqlite3_prepare_v2(db, insertSql, (int)strlen(insertSql), &stmt, 0);
  if (res != SQLITE_OK) {
    printf("sqlite3_prepare_v2 error\n");
    fprintf(stderr, "prepare error %s\n", sqlite3_errmsg(db));
    return -1;
  }
  sqlite3_bind_text(stmt, 1, name, (int)strlen(name), 0);
  sqlite3_bind_int(stmt, 2, age);
  sqlite3_bind_text(stmt, 3, address, (int)strlen(address), 0);
  res = sqlite3_step(stmt);
  if (res != SQLITE_DONE) {
    printf("sqlite3_step error\n");
    return -1;
  }
  if (stmt) {
    sqlite3_finalize(stmt);
    printf("insert sqlite3_finalize\n");
  }
  return res;
}


x86 assembly (clang, -O0):
<insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
lea    0xe4b(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
xor    %r8d,%r8d
call   10b0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%eax
je     123c <insert+0xac>
lea    0xe31(%rip),%rdi
call   1050 <printf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <sqlite3_errmsg@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xe24(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <insert+0x179>
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%esi
xor    %r8d,%r8d
call   1090 <sqlite3_bind_text@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    $0x2,%esi
call   1030 <sqlite3_bind_int@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rdx
mov    %eax,%ecx
mov    $0x3,%esi
xor    %r8d,%r8d
call   1090 <sqlite3_bind_text@plt>
mov    -0x18(%rbp),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2d0d(%rip),%rcx
cmp    (%rcx),%eax
je     12e3 <insert+0x153>
lea    0xd8f(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <insert+0x179>
cmpq   $0x0,-0x18(%rbp)
je     1303 <insert+0x173>
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
lea    0xd77(%rip),%rdi
call   1050 <printf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%r15
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %rdi,%rbx
mov    %rsi,(%rsp)
lea    0xe52(%rip),%rsi
mov    %rsp,%rcx
mov    $0x34,%edx
xor    %r8d,%r8d
call   10b0 <sqlite3_prepare_v2@plt>
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%eax
jne    1252 <insert+0xc2>
mov    (%rsp),%rbx
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1090 <sqlite3_bind_text@plt>
mov    (%rsp),%rdi
mov    $0x2,%esi
mov    %r14d,%edx
call   1040 <sqlite3_bind_int@plt>
mov    (%rsp),%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1090 <sqlite3_bind_text@plt>
mov    (%rsp),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,%ebx
mov    0x2d9e(%rip),%rax
cmp    (%rax),%ebx
jne    1282 <insert+0xf2>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1293 <insert+0x103>
call   10a0 <sqlite3_finalize@plt>
lea    0xdfc(%rip),%rdi
call   1030 <puts@plt>
jmp    1293 <insert+0x103>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1060 <sqlite3_errmsg@plt>
lea    0xdbf(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
jmp    128e <insert+0xfe>
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"insert into student(name,age,address) values(?,?,?);\00"
@SQLITE_OK = global i32 0
@.str.1 = [26 x i8] c"sqlite3_prepare_v2 error\0A\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"prepare error %s\0A\00"
@SQLITE_DONE = global i32 0
@.str.3 = [20 x i8] c"sqlite3_step error\0A\00"
@.str.4 = [25 x i8] c"insert sqlite3_finalize\0A\00"
define i32 @insert(i32* %0, i32* %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8** %12
%14 = load i32*, i32** %7
%15 = load i8*, i8** %12
%16 = load i8*, i8** %12
%17 = call i64 @strlen(i8* %16)
%18 = trunc i64 %17 to i32
%19 = call i32 @sqlite3_prepare_v2(i32* %14, i8* %15, i32 %18, i32** %8, i32 0)
store i32 %19, i32* %13
%20 = load i32, i32* %13
%21 = load i32, i32* @SQLITE_OK
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %5
%24 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = load i32*, i32** %7
%27 = call i8* @sqlite3_errmsg(i32* %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 -1, i32* %6
br label %61
29: ; preds = %5
%30 = load i32*, i32** %8
%31 = load i8*, i8** %9
%32 = load i8*, i8** %9
%33 = call i64 @strlen(i8* %32)
%34 = trunc i64 %33 to i32
%35 = call i32 @sqlite3_bind_text(i32* %30, i32 1, i8* %31, i32 %34, i32 0)
%36 = load i32*, i32** %8
%37 = load i32, i32* %10
%38 = call i32 @sqlite3_bind_int(i32* %36, i32 2, i32 %37)
%39 = load i32*, i32** %8
%40 = load i8*, i8** %11
%41 = load i8*, i8** %11
%42 = call i64 @strlen(i8* %41)
%43 = trunc i64 %42 to i32
%44 = call i32 @sqlite3_bind_text(i32* %39, i32 3, i8* %40, i32 %43, i32 0)
%45 = load i32*, i32** %8
%46 = call i32 @sqlite3_step(i32* %45)
store i32 %46, i32* %13
%47 = load i32, i32* %13
%48 = load i32, i32* @SQLITE_DONE
%49 = icmp ne i32 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %29
%51 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %6
br label %61
52: ; preds = %29
%53 = load i32*, i32** %8
%54 = icmp ne i32* %53, null
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = load i32*, i32** %8
%57 = call i32 @sqlite3_finalize(i32* %56)
%58 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %55, %52
%60 = load i32, i32* %13
store i32 %60, i32* %6
br label %61
61: ; preds = %59, %50, %23
%62 = load i32, i32* %6
ret i32 %62
}

LLVM IR (-O2):
@.str = [53 x i8] c"insert into student(name,age,address) values(?,?,?);\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.2 = [18 x i8] c"prepare error %s\0A\00"
@SQLITE_DONE = global i32 0
@str = [24 x i8] c"insert sqlite3_finalize\00"
@str.5 = [19 x i8] c"sqlite3_step error\00"
@str.6 = [25 x i8] c"sqlite3_prepare_v2 error\00"
define i32 @insert(i32* %0, i32* %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i32*
store i32* %1, i32** %6
%7 = call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 52, i32** %6, i32 0)
%8 = load i32, i32* @SQLITE_OK
%9 = icmp eq i32 %7, %8
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = call i8* @sqlite3_errmsg(i32* %0)
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %38
15: ; preds = %5
%16 = load i32*, i32** %6
%17 = call i64 @strlen(i8* dereferenceable(1) %2)
%18 = trunc i64 %17 to i32
%19 = call i32 @sqlite3_bind_text(i32* %16, i32 1, i8* %2, i32 %18, i32 0)
%20 = load i32*, i32** %6
%21 = call i32 @sqlite3_bind_int(i32* %20, i32 2, i32 %3)
%22 = load i32*, i32** %6
%23 = call i64 @strlen(i8* dereferenceable(1) %4)
%24 = trunc i64 %23 to i32
%25 = call i32 @sqlite3_bind_text(i32* %22, i32 3, i8* %4, i32 %24, i32 0)
%26 = load i32*, i32** %6
%27 = call i32 @sqlite3_step(i32* %26)
%28 = load i32, i32* @SQLITE_DONE
%29 = icmp eq i32 %27, %28
br i1 %29, label %32, label %30
30: ; preds = %15
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
br label %38
32: ; preds = %15
%33 = load i32*, i32** %6
%34 = icmp eq i32* %33, null
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = call i32 @sqlite3_finalize(i32* %33)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %32, %35, %30, %10
%39 = phi i32 [ -1, %10 ], [ -1, %30 ], [ %27, %35 ], [ %27, %32 ]
ret i32 %39
}