#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 SQLITE_ROW;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ sqlite3_column_text(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int strtol(char const *, char **, int);
long int Query_Max_Number_Of_Names(sqlite3 *db, sqlite3_stmt *stmt) {
  int rv;
  char *sql_stmt = "select min(t1.val, t2.val) from "
                   "(select count(*) as val from firstnames) as t1, "
                   "(select count(*) as val from lastnames) as t2;";
  rv = sqlite3_prepare_v2(db, sql_stmt, -1, &stmt, 0);
  if (rv != SQLITE_OK) {
    fprintf(stderr, "Preparation failed: %s\n", sqlite3_errmsg(db));
    return -1;
  }
  int result = -1;
  if ((rv = sqlite3_step(stmt)) == SQLITE_ROW) {
    result =
        strtol((const char *)sqlite3_column_text(stmt, 0), (char **)NULL, 10);
  }
  return result;
}


x86 assembly (clang, -O0):
<Query_Max_Number_Of_Names>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe89(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %r8d,%r8d
call   1080 <sqlite3_prepare_v2@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%eax
je     11dd <Query_Max_Number_Of_Names+0x7d>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <sqlite3_errmsg@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xeb4(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1226 <Query_Max_Number_Of_Names+0xc6>
movl   $0xffffffff,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%eax
jne    121e <Query_Max_Number_Of_Names+0xbe>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_text@plt>
mov    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Query_Max_Number_Of_Names>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsi,(%rsp)
lea    0xe8f(%rip),%rsi
mov    %rsp,%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1080 <sqlite3_prepare_v2@plt>
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
jne    11c7 <Query_Max_Number_Of_Names+0x67>
mov    (%rsp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,%ecx
mov    0x2e32(%rip),%rdx
mov    $0xffffffffffffffff,%rax
cmp    (%rdx),%ecx
jne    11f0 <Query_Max_Number_Of_Names+0x90>
mov    (%rsp),%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_text@plt>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
cltq
jmp    11f0 <Query_Max_Number_Of_Names+0x90>
mov    0x2e0a(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1030 <sqlite3_errmsg@plt>
lea    0xea0(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffffffffffff,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [127 x i8] c"select min(t1.val, t2.val) from (select count(*) as val from firstnames) as t1, (select count(*) as val from lastnames) as t2;\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"Preparation failed: %s\0A\00"
@SQLITE_ROW = global i32 0
define i64 @Query_Max_Number_Of_Names(i32* %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i32*, i32** %4
%10 = load i8*, i8** %7
%11 = call i32 @sqlite3_prepare_v2(i32* %9, i8* %10, i32 -1, i32** %5, i32 0)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = load i32, i32* @SQLITE_OK
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i32*, i32** %4
%18 = call i8* @sqlite3_errmsg(i32* %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i64 -1, i64* %3
br label %33
20: ; preds = %2
store i32 -1, i32* %8
%21 = load i32*, i32** %5
%22 = call i32 @sqlite3_step(i32* %21)
store i32 %22, i32* %6
%23 = load i32, i32* @SQLITE_ROW
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i32*, i32** %5
%27 = call i64 @sqlite3_column_text(i32* %26, i32 0)
%28 = inttoptr i64 %27 to i8*
%29 = call i32 @strtol(i8* %28, i8** null, i32 10)
store i32 %29, i32* %8
br label %30
30: ; preds = %25, %20
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
store i64 %32, i64* %3
br label %33
33: ; preds = %30, %15
%34 = load i64, i64* %3
ret i64 %34
}

LLVM IR (-O2):
@.str = [127 x i8] c"select min(t1.val, t2.val) from (select count(*) as val from firstnames) as t1, (select count(*) as val from lastnames) as t2;\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"Preparation failed: %s\0A\00"
@SQLITE_ROW = global i32 0
define i64 @Query_Max_Number_Of_Names(i32* %0, i32* %1) {
%3 = alloca i32*
store i32* %1, i32** %3
%4 = call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %3, i32 0)
%5 = load i32, i32* @SQLITE_OK
%6 = icmp eq i32 %4, %5
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i8* @sqlite3_errmsg(i32* %0)
%10 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %22
11: ; preds = %2
%12 = load i32*, i32** %3
%13 = call i32 @sqlite3_step(i32* %12)
%14 = load i32, i32* @SQLITE_ROW
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i32*, i32** %3
%18 = call i64 @sqlite3_column_text(i32* %17, i32 0)
%19 = inttoptr i64 %18 to i8*
%20 = call i32 @strtol(i8* nocapture %19, i8** null, i32 10)
%21 = sext i32 %20 to i64
br label %22
22: ; preds = %11, %16, %7
%23 = phi i64 [ -1, %7 ], [ %21, %16 ], [ -1, %11 ]
ret i64 %23
}