#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 SQLITE_ROW;
int /*<<< orphan*/ perror(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*/);
scalar_t__ sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/);
char *sqlite3_sql(int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
scalar_t__ strlen(char *);
int update(sqlite3 *db, sqlite3_stmt *stmt, char *name, int age,
           char *address) {
  char *maxIDSQL = "select max(id) from student";
  int maxID = 0;
  int res = sqlite3_prepare_v2(db, maxIDSQL, (int)strlen(maxIDSQL), &stmt, 0);
  if (res == SQLITE_OK) {
    res = sqlite3_step(stmt);
    if (res == SQLITE_ROW) {
      maxID = (unsigned int)sqlite3_column_int(stmt, 0);
    }
  }
  if (maxID == 0) {
    maxID = 10;
  }
  char *insertSql = "update student set name=? where id=?";
  sqlite3_prepare_v2(db, insertSql, (int)strlen(insertSql), &stmt, 0);
  sqlite3_bind_text(stmt, 1, name, (int)strlen(name), 0);
  sqlite3_bind_int(stmt, 2, maxID);
  res = sqlite3_step(stmt);
  printf("%s\n", sqlite3_sql(stmt));
  if (res == SQLITE_DONE) {
    printf("update ok \n");
  } else {
    perror("update error");
  }
  if (stmt) {
    sqlite3_finalize(stmt);
    printf("update sqlite3_finalize\n");
  }
  return res;
}


x86 assembly (clang, -O0):
<update>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
lea    0xe3e(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    -0x10(%rbp),%rcx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%eax
jne    1242 <update+0xa2>
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    0x2da9(%rip),%rcx
cmp    (%rcx),%eax
jne    123d <update+0x9d>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_int@plt>
mov    %eax,-0x34(%rbp)
jmp    1242 <update+0xa2>
cmpl   $0x0,-0x34(%rbp)
jne    1253 <update+0xb3>
movl   $0xa,-0x34(%rbp)
lea    0xdc2(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
lea    -0x10(%rbp),%rcx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%esi
xor    %r8d,%r8d
call   1090 <sqlite3_bind_text@plt>
mov    -0x10(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    $0x2,%esi
call   1040 <sqlite3_bind_int@plt>
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sqlite3_sql@plt>
mov    %rax,%rsi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%eax
mov    0x2cda(%rip),%rcx
cmp    (%rcx),%eax
jne    1319 <update+0x179>
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1325 <update+0x185>
lea    0xd31(%rip),%rdi
call   10a0 <perror@plt>
cmpq   $0x0,-0x10(%rbp)
je     1347 <update+0x1a7>
mov    -0x10(%rbp),%rdi
call   10b0 <sqlite3_finalize@plt>
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rsi,0x8(%rsp)
lea    0xe45(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0x1b,%edx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%eax
jne    1201 <update+0x61>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_step@plt>
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%eax
jne    1201 <update+0x61>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_int@plt>
mov    %rax,%r15
test   %r15d,%r15d
jne    1207 <update+0x67>
mov    $0xa,%r15d
lea    0xe0e(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x24,%edx
xor    %r8d,%r8d
call   10c0 <sqlite3_prepare_v2@plt>
mov    0x8(%rsp),%rbx
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1090 <sqlite3_bind_text@plt>
mov    0x8(%rsp),%rdi
mov    $0x2,%esi
mov    %r15d,%edx
call   1050 <sqlite3_bind_int@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <sqlite3_sql@plt>
mov    %rax,%rdi
call   1040 <puts@plt>
mov    0x2d5c(%rip),%rax
cmp    (%rax),%ebx
jne    12b3 <update+0x113>
lea    0xddf(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     12a7 <update+0x107>
call   10b0 <sqlite3_finalize@plt>
lea    0xdac(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd87(%rip),%rdi
call   10a0 <perror@plt>
jmp    128c <update+0xec>

LLVM IR (-O0):
@.str = [28 x i8] c"select max(id) from student\00"
@SQLITE_OK = global i32 0
@SQLITE_ROW = global i32 0
@.str.1 = [37 x i8] c"update student set name=? where id=?\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@SQLITE_DONE = global i32 0
@.str.3 = [12 x i8] c"update ok \0A\00"
@.str.4 = [13 x i8] c"update error\00"
@.str.5 = [25 x i8] c"update sqlite3_finalize\0A\00"
define i32 @update(i32* %0, i32* %1, i8* %2, i32 %3, i8* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
store i32* %0, i32** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i8* %4, i8** %10
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8** %11
store i32 0, i32* %12
%15 = load i32*, i32** %6
%16 = load i8*, i8** %11
%17 = load i8*, i8** %11
%18 = call i64 @strlen(i8* %17)
%19 = trunc i64 %18 to i32
%20 = call i32 @sqlite3_prepare_v2(i32* %15, i8* %16, i32 %19, i32** %7, i32 0)
store i32 %20, i32* %13
%21 = load i32, i32* %13
%22 = load i32, i32* @SQLITE_OK
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %5
%25 = load i32*, i32** %7
%26 = call i32 @sqlite3_step(i32* %25)
store i32 %26, i32* %13
%27 = load i32, i32* %13
%28 = load i32, i32* @SQLITE_ROW
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32*, i32** %7
%32 = call i64 @sqlite3_column_int(i32* %31, i32 0)
%33 = trunc i64 %32 to i32
store i32 %33, i32* %12
br label %34
34: ; preds = %30, %24
br label %35
35: ; preds = %34, %5
%36 = load i32, i32* %12
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 10, i32* %12
br label %39
39: ; preds = %38, %35
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8** %14
%40 = load i32*, i32** %6
%41 = load i8*, i8** %14
%42 = load i8*, i8** %14
%43 = call i64 @strlen(i8* %42)
%44 = trunc i64 %43 to i32
%45 = call i32 @sqlite3_prepare_v2(i32* %40, i8* %41, i32 %44, i32** %7, i32 0)
%46 = load i32*, i32** %7
%47 = load i8*, i8** %8
%48 = load i8*, i8** %8
%49 = call i64 @strlen(i8* %48)
%50 = trunc i64 %49 to i32
%51 = call i32 @sqlite3_bind_text(i32* %46, i32 1, i8* %47, i32 %50, i32 0)
%52 = load i32*, i32** %7
%53 = load i32, i32* %12
%54 = call i32 @sqlite3_bind_int(i32* %52, i32 2, i32 %53)
%55 = load i32*, i32** %7
%56 = call i32 @sqlite3_step(i32* %55)
store i32 %56, i32* %13
%57 = load i32*, i32** %7
%58 = call i8* @sqlite3_sql(i32* %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %58)
%60 = load i32, i32* %13
%61 = load i32, i32* @SQLITE_DONE
%62 = icmp eq i32 %60, %61
br i1 %62, label %63, label %65
63: ; preds = %39
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %67
65: ; preds = %39
%66 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %67
67: ; preds = %65, %63
%68 = load i32*, i32** %7
%69 = icmp ne i32* %68, null
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32*, i32** %7
%72 = call i32 @sqlite3_finalize(i32* %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
br label %74
74: ; preds = %70, %67
%75 = load i32, i32* %13
ret i32 %75
}

LLVM IR (-O2):
@.str = [28 x i8] c"select max(id) from student\00"
@SQLITE_OK = global i32 0
@SQLITE_ROW = global i32 0
@.str.1 = [37 x i8] c"update student set name=? where id=?\00"
@SQLITE_DONE = global i32 0
@.str.4 = [13 x i8] c"update error\00"
@str = [24 x i8] c"update sqlite3_finalize\00"
@str.6 = [11 x i8] c"update ok \00"
define i32 @update(i32* %0, i32* %1, i8* %2, i32 %3, i8* nocapture readnone %4) {
%6 = alloca i32*
store i32* %1, i32** %6
%7 = call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 27, i32** %6, i32 0)
%8 = load i32, i32* @SQLITE_OK
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %20
10: ; preds = %5
%11 = load i32*, i32** %6
%12 = call i32 @sqlite3_step(i32* %11)
%13 = load i32, i32* @SQLITE_ROW
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32*, i32** %6
%17 = call i64 @sqlite3_column_int(i32* %16, i32 0)
%18 = trunc i64 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %5, %10, %15
br label %21
21: ; preds = %15, %20
%22 = phi i32 [ 10, %20 ], [ %18, %15 ]
%23 = call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 36, i32** %6, i32 0)
%24 = load i32*, i32** %6
%25 = call i64 @strlen(i8* dereferenceable(1) %2)
%26 = trunc i64 %25 to i32
%27 = call i32 @sqlite3_bind_text(i32* %24, i32 1, i8* %2, i32 %26, i32 0)
%28 = load i32*, i32** %6
%29 = call i32 @sqlite3_bind_int(i32* %28, i32 2, i32 %22)
%30 = load i32*, i32** %6
%31 = call i32 @sqlite3_step(i32* %30)
%32 = load i32*, i32** %6
%33 = call i8* @sqlite3_sql(i32* %32)
%34 = call i32 @puts(i8* dereferenceable(1) %33)
%35 = load i32, i32* @SQLITE_DONE
%36 = icmp eq i32 %31, %35
br i1 %36, label %37, label %39
37: ; preds = %21
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.6, i64 0, i64 0))
br label %41
39: ; preds = %21
%40 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39, %37
%42 = load i32*, i32** %6
%43 = icmp eq i32* %42, null
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = call i32 @sqlite3_finalize(i32* %42)
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %44, %41
ret i32 %31
}