#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 *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sql_error(int /*<<< orphan*/ *);
int sql_prepare(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/ **, int);
int sqlite3_changes(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int stmt_stdout(int /*<<< orphan*/ *, int *);
int sql_stdout(sqlite3 *db, const char *sql, int *rowcount) {
  int rc;
  sqlite3_stmt *stmt;
  rc = sql_prepare(db, sql, &stmt, -1);
  if (rc != SQLITE_OK) {
    sql_error(db);
    return rc;
  }
  rc = stmt_stdout(stmt, rowcount);
  sqlite3_finalize(stmt);
  if (rc == SQLITE_DONE) {
    if (sqlite3_changes(db) > 0)
      fprintf(stdout, "Query done. %i rows affected.", sqlite3_changes(db));
  } else {
    sql_error(db);
  }
  printf("\n");
  return rc;
}


x86 assembly (clang, -O0):
<sql_stdout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    $0xffffffff,%ecx
call   1060 <sql_prepare@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%eax
je     11c3 <sql_stdout+0x53>
mov    -0x10(%rbp),%rdi
call   1040 <sql_error@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1246 <sql_stdout+0xd6>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <stmt_stdout@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1090 <sqlite3_finalize@plt>
mov    -0x24(%rbp),%eax
mov    0x2df2(%rip),%rcx
cmp    (%rcx),%eax
jne    122b <sql_stdout+0xbb>
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_changes@plt>
cmp    $0x0,%eax
jle    1226 <sql_stdout+0xb6>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_changes@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%edx
lea    0xddf(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1234 <sql_stdout+0xc4>
mov    -0x10(%rbp),%rdi
call   1040 <sql_error@plt>
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sql_stdout>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rdi,%r14
mov    %rsp,%rdx
mov    $0xffffffff,%ecx
call   1060 <sql_prepare@plt>
mov    %eax,%ebx
mov    0x2e55(%rip),%rax
cmp    (%rax),%ebx
jne    11e8 <sql_stdout+0x78>
mov    (%rsp),%rdi
mov    %r15,%rsi
call   1070 <stmt_stdout@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1090 <sqlite3_finalize@plt>
mov    0x2e23(%rip),%rax
cmp    (%rax),%ebx
jne    11f2 <sql_stdout+0x82>
mov    %r14,%rdi
call   1080 <sqlite3_changes@plt>
test   %eax,%eax
jle    11fa <sql_stdout+0x8a>
mov    0x2e04(%rip),%rax
mov    (%rax),%ebp
mov    %r14,%rdi
call   1080 <sqlite3_changes@plt>
lea    0xe23(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
call   1050 <fprintf@plt>
jmp    11fa <sql_stdout+0x8a>
mov    %r14,%rdi
call   1040 <sql_error@plt>
jmp    1204 <sql_stdout+0x94>
mov    %r14,%rdi
call   1040 <sql_error@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@SQLITE_DONE = global i32 0
@stdout = global i32 0
@.str = [30 x i8] c"Query done. %i rows affected.\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @sql_stdout(i32* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%10 = load i32*, i32** %5
%11 = load i8*, i8** %6
%12 = call i32 @sql_prepare(i32* %10, i8* %11, i32** %9, i32 -1)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = load i32, i32* @SQLITE_OK
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32*, i32** %5
%18 = call i32 @sql_error(i32* %17)
%19 = load i32, i32* %8
store i32 %19, i32* %4
br label %45
20: ; preds = %3
%21 = load i32*, i32** %9
%22 = load i32*, i32** %7
%23 = call i32 @stmt_stdout(i32* %21, i32* %22)
store i32 %23, i32* %8
%24 = load i32*, i32** %9
%25 = call i32 @sqlite3_finalize(i32* %24)
%26 = load i32, i32* %8
%27 = load i32, i32* @SQLITE_DONE
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %20
%30 = load i32*, i32** %5
%31 = call i32 @sqlite3_changes(i32* %30)
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i32, i32* @stdout
%35 = load i32*, i32** %5
%36 = call i32 @sqlite3_changes(i32* %35)
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %33, %29
br label %42
39: ; preds = %20
%40 = load i32*, i32** %5
%41 = call i32 @sql_error(i32* %40)
br label %42
42: ; preds = %39, %38
%43 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* %8
store i32 %44, i32* %4
br label %45
45: ; preds = %42, %16
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@SQLITE_DONE = global i32 0
@stdout = global i32 0
@.str = [30 x i8] c"Query done. %i rows affected.\00"
define i32 @sql_stdout(i32* %0, i8* %1, i32* %2) {
%4 = alloca i32*
%5 = bitcast i32** %4 to i8*
%6 = call i32 @sql_prepare(i32* %0, i8* %1, i32** %4, i32 -1)
%7 = load i32, i32* @SQLITE_OK
%8 = icmp eq i32 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = call i32 @sql_error(i32* %0)
br label %29
11: ; preds = %3
%12 = load i32*, i32** %4
%13 = call i32 @stmt_stdout(i32* %12, i32* %2)
%14 = load i32*, i32** %4
%15 = call i32 @sqlite3_finalize(i32* %14)
%16 = load i32, i32* @SQLITE_DONE
%17 = icmp eq i32 %13, %16
br i1 %17, label %18, label %25
18: ; preds = %11
%19 = call i32 @sqlite3_changes(i32* %0)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32, i32* @stdout
%23 = call i32 @sqlite3_changes(i32* %0)
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %27
25: ; preds = %11
%26 = call i32 @sql_error(i32* %0)
br label %27
27: ; preds = %18, %21, %25
%28 = call i32 @putchar(i32 10)
br label %29
29: ; preds = %27, %9
%30 = phi i32 [ %6, %9 ], [ %13, %27 ]
ret i32 %30
}