#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 /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ SQLITE_DONE;
scalar_t__ SQLITE_OK;
scalar_t__ SQLITE_ROW;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
unsigned int sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sqlite3_finalize(int /*<<< orphan*/ *);
scalar_t__ sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int,
                              int /*<<< orphan*/ **, int /*<<< orphan*/);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
unsigned int countremotes(sqlite3 *db) {
  sqlite3_stmt *res;
  unsigned int count;
  if (sqlite3_prepare_v2(db, "SELECT COUNT(*) AS count FROM remotes", -1, &res,
                         0) != SQLITE_OK)
    exit(EXIT_FAILURE);
  if (sqlite3_step(res) == SQLITE_ROW)
    count = sqlite3_column_int(res, 0);
  if (sqlite3_step(res) != SQLITE_DONE)
    exit(EXIT_FAILURE);
  if (sqlite3_finalize(res) != SQLITE_OK)
    exit(EXIT_FAILURE);
  return count;
}


x86 assembly (clang, -O0):
<countremotes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x10(%rbp),%rcx
xor    %r8d,%r8d
call   1060 <sqlite3_prepare_v2@plt>
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
je     1196 <countremotes+0x46>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%rax
jne    11bd <countremotes+0x6d>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <sqlite3_column_int@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%rax
je     11e4 <countremotes+0x94>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_finalize@plt>
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%rax
je     120b <countremotes+0xbb>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countremotes>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rsi
mov    %rsp,%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1060 <sqlite3_prepare_v2@plt>
mov    0x2e76(%rip),%r14
cmp    (%r14),%rax
jne    11c6 <countremotes+0x76>
mov    (%rsp),%rdi
call   1040 <sqlite3_step@plt>
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
jne    1199 <countremotes+0x49>
mov    (%rsp),%rdi
xor    %esi,%esi
call   1030 <sqlite3_column_int@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1040 <sqlite3_step@plt>
mov    0x2e2f(%rip),%rcx
cmp    (%rcx),%rax
jne    11c6 <countremotes+0x76>
mov    (%rsp),%rdi
call   1050 <sqlite3_finalize@plt>
cmp    (%r14),%rax
jne    11c6 <countremotes+0x76>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"SELECT COUNT(*) AS count FROM remotes\00"
@SQLITE_OK = global i64 0
@EXIT_FAILURE = global i32 0
@SQLITE_ROW = global i64 0
@SQLITE_DONE = global i64 0
define i32 @countremotes(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i64 @sqlite3_prepare_v2(i32* %5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %3, i32 0)
%7 = load i64, i64* @SQLITE_OK
%8 = icmp ne i64 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i64 @sqlite3_step(i32* %13)
%15 = load i64, i64* @SQLITE_ROW
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32*, i32** %3
%19 = call i32 @sqlite3_column_int(i32* %18, i32 0)
store i32 %19, i32* %4
br label %20
20: ; preds = %17, %12
%21 = load i32*, i32** %3
%22 = call i64 @sqlite3_step(i32* %21)
%23 = load i64, i64* @SQLITE_DONE
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %20
%29 = load i32*, i32** %3
%30 = call i64 @sqlite3_finalize(i32* %29)
%31 = load i64, i64* @SQLITE_OK
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %28
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
@.str = [38 x i8] c"SELECT COUNT(*) AS count FROM remotes\00"
@SQLITE_OK = global i64 0
@EXIT_FAILURE = global i32 0
@SQLITE_ROW = global i64 0
@SQLITE_DONE = global i64 0
define i32 @countremotes(i32* %0) {
%2 = alloca i32*
%3 = bitcast i32** %2 to i8*
%4 = call i64 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 -1, i32** %2, i32 0)
%5 = load i64, i64* @SQLITE_OK
%6 = icmp eq i64 %4, %5
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = load i32*, i32** %2
%12 = call i64 @sqlite3_step(i32* %11)
%13 = load i64, i64* @SQLITE_ROW
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32*, i32** %2
%17 = call i32 @sqlite3_column_int(i32* %16, i32 0)
br label %18
18: ; preds = %15, %10
%19 = phi i32 [ %17, %15 ], [ undef, %10 ]
%20 = load i32*, i32** %2
%21 = call i64 @sqlite3_step(i32* %20)
%22 = load i64, i64* @SQLITE_DONE
%23 = icmp eq i64 %21, %22
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %18
%28 = load i32*, i32** %2
%29 = call i64 @sqlite3_finalize(i32* %28)
%30 = load i64, i64* @SQLITE_OK
%31 = icmp eq i64 %29, %30
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %27
ret i32 %19
}