#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_OK;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_column_count(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_open(char *, int /*<<< orphan*/ **);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/);
int get_column_count(char *database_name, char *sql) {
  int column_count = 0;
  int sql_return = 0;
  sqlite3 *handle = NULL;
  sqlite3_stmt *stmt = NULL;
  sqlite3_open(database_name, &handle);
  sql_return = sqlite3_prepare_v2(handle, sql, -1, &stmt, 0);
  if (sql_return != SQLITE_OK) {
    printf("SQLite couldn't parse SQL string.\n");
  } else {
    column_count = sqlite3_column_count(stmt);
  }
  sqlite3_finalize(stmt);
  sqlite3_close(handle);
  return column_count;
}


x86 assembly (clang, -O0):
<get_column_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x28(%rbp),%rcx
xor    %r8d,%r8d
call   1080 <sqlite3_prepare_v2@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%eax
je     11da <get_column_count+0x7a>
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
jmp    11e6 <get_column_count+0x86>
mov    -0x28(%rbp),%rdi
call   1060 <sqlite3_column_count@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <sqlite3_finalize@plt>
mov    -0x20(%rbp),%rdi
call   1050 <sqlite3_close@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_column_count>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rsi
call   1040 <sqlite3_open@plt>
mov    0x10(%rsp),%rdi
lea    0x8(%rsp),%rcx
xor    %ebp,%ebp
mov    %rbx,%rsi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1080 <sqlite3_prepare_v2@plt>
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%eax
jne    11ba <get_column_count+0x5a>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_column_count@plt>
mov    %eax,%ebp
jmp    11c6 <get_column_count+0x66>
lea    0xe3f(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_finalize@plt>
mov    0x10(%rsp),%rdi
call   1050 <sqlite3_close@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@.str = [35 x i8] c"SQLite couldn't parse SQL string.\0A\00"
define i32 @get_column_count(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32* null, i32** %7
store i32* null, i32** %8
%9 = load i8*, i8** %3
%10 = call i32 @sqlite3_open(i8* %9, i32** %7)
%11 = load i32*, i32** %7
%12 = load i8*, i8** %4
%13 = call i32 @sqlite3_prepare_v2(i32* %11, i8* %12, i32 -1, i32** %8, i32 0)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = load i32, i32* @SQLITE_OK
%16 = icmp ne i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %22
19: ; preds = %2
%20 = load i32*, i32** %8
%21 = call i32 @sqlite3_column_count(i32* %20)
store i32 %21, i32* %5
br label %22
22: ; preds = %19, %17
%23 = load i32*, i32** %8
%24 = call i32 @sqlite3_finalize(i32* %23)
%25 = load i32*, i32** %7
%26 = call i32 @sqlite3_close(i32* %25)
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@str = [34 x i8] c"SQLite couldn't parse SQL string.\00"
define i32 @get_column_count(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%6 = bitcast i32** %4 to i8*
store i32* null, i32** %4
%7 = call i32 @sqlite3_open(i8* %0, i32** %3)
%8 = load i32*, i32** %3
%9 = call i32 @sqlite3_prepare_v2(i32* %8, i8* %1, i32 -1, i32** %4, i32 0)
%10 = load i32, i32* @SQLITE_OK
%11 = icmp eq i32 %9, %10
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %17
14: ; preds = %2
%15 = load i32*, i32** %4
%16 = call i32 @sqlite3_column_count(i32* %15)
br label %17
17: ; preds = %14, %12
%18 = phi i32 [ 0, %12 ], [ %16, %14 ]
%19 = load i32*, i32** %4
%20 = call i32 @sqlite3_finalize(i32* %19)
%21 = load i32*, i32** %3
%22 = call i32 @sqlite3_close(i32* %21)
ret i32 %18
}