#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *, void *,
                 char **);
int /*<<< orphan*/ sqlite3_free(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int update2(sqlite3 *db, int id, char *address) {
  char sql[128];
  sprintf(sql, "UPDATE student set address = '%s' where ID=%d;", address, id);
  char *err = NULL;
  int rc = sqlite3_exec(db, sql, NULL, (void *)0, &err);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "SQL error: %s\n", err);
    sqlite3_free(err);
  } else {
    fprintf(stdout, "Operation done successfully\n");
  }
  return rc;
}


x86 assembly (clang, -O0):
<update2>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe95(%rip),%rsi
call   1060 <sprintf@plt>
movq   $0x0,-0xa8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0xa8(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0xac(%rbp)
mov    -0xac(%rbp),%eax
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%eax
je     11e3 <update2+0xa3>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0xa8(%rbp),%rdx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0xa8(%rbp),%rdi
call   1050 <sqlite3_free@plt>
jmp    11fa <update2+0xba>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0xac(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update2>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %esi,%ecx
mov    %rdi,%rbx
lea    0xeaa(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1060 <sprintf@plt>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
mov    %eax,%ebx
mov    0x2e5f(%rip),%rax
cmp    (%rax),%ebx
jne    11a6 <update2+0x66>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11cc <update2+0x8c>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xe74(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1050 <sqlite3_free@plt>
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [47 x i8] c"UPDATE student set address = '%s' where ID=%d;\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [15 x i8] c"SQL error: %s\0A\00"
@stdout = global i32 0
@.str.2 = [29 x i8] c"Operation done successfully\0A\00"
define i32 @update2(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [128 x i8]
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %6
%12 = load i32, i32* %5
%13 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12)
store i8* null, i8** %8
%14 = load i32*, i32** %4
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%16 = call i32 @sqlite3_exec(i32* %14, i8* %15, i32* null, i8* null, i8** %8)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = load i32, i32* @SQLITE_OK
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %26
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %8
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %8
%25 = call i32 @sqlite3_free(i8* %24)
br label %29
26: ; preds = %3
%27 = load i32, i32* @stdout
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %26, %20
%30 = load i32, i32* %9
ret i32 %30
}

LLVM IR (-O2):
@.str = [47 x i8] c"UPDATE student set address = '%s' where ID=%d;\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [15 x i8] c"SQL error: %s\0A\00"
@stdout = global i32 0
@.str.2 = [29 x i8] c"Operation done successfully\0A\00"
define i32 @update2(i32* %0, i32 %1, i8* %2) {
%4 = alloca [128 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %1)
%8 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%9 = call i32 @sqlite3_exec(i32* %0, i8* %6, i32* null, i8* null, i8** %5)
%10 = load i32, i32* @SQLITE_OK
%11 = icmp eq i32 %9, %10
br i1 %11, label %18, label %12
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %5
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %5
%17 = call i32 @sqlite3_free(i8* %16)
br label %21
18: ; preds = %3
%19 = load i32, i32* @stdout
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %18, %12
ret i32 %9
}