#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*/ assert(int);
int sqlite3_column_int(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/,
                       int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_reset(int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char const *);
int db_count_client_operators(sqlite3 *db) {
  static sqlite3_stmt *stmt;
  static const char query[] = "SELECT COUNT(*) FROM client WHERE operator_flag "
                              "= 1 OR local_operator_flag = 1;";
  int ret;
  do {
    if (db == NULL) {
      if (stmt != NULL) {
        sqlite3_finalize(stmt);
        stmt = NULL;
      }
      return 0;
    }
  } while (0);
  do {
    if (stmt == NULL) {
      ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
      assert(ret == SQLITE_OK);
    }
  } while (0);
  sqlite3_reset(stmt);
  ret = sqlite3_step(stmt);
  assert(ret == SQLITE_ROW);
  return sqlite3_column_int(stmt, 0);
}


x86 assembly (clang, -O0):
<db_count_client_operators>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b8 <db_count_client_operators+0x48>
cmpq   $0x0,0x2ed1(%rip)
je     11ac <db_count_client_operators+0x3c>
mov    0x2ec4(%rip),%rdi
call   1080 <sqlite3_finalize@plt>
movq   $0x0,0x2eb4(%rip)
movl   $0x0,-0x4(%rbp)
jmp    1268 <db_count_client_operators+0xf8>
jmp    11bd <db_count_client_operators+0x4d>
jmp    11c2 <db_count_client_operators+0x52>
cmpq   $0x0,0x2e96(%rip)
jne    121e <db_count_client_operators+0xae>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe21(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe0f(%rip),%rsi
lea    0x2e68(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <sqlite3_prepare_v2@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    1223 <db_count_client_operators+0xb3>
mov    0x2e36(%rip),%rdi
call   1030 <sqlite3_reset@plt>
mov    0x2e2a(%rip),%rdi
call   1070 <sqlite3_step@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2d90(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2e02(%rip),%rdi
xor    %esi,%esi
call   1050 <sqlite3_column_int@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_count_client_operators>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ee2(%rip),%rdi
test   %rbx,%rbx
je     1207 <db_count_client_operators+0x97>
test   %rdi,%rdi
jne    11cd <db_count_client_operators+0x5d>
lea    0xe6d(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x2ebe(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   1090 <sqlite3_prepare_v2@plt>
mov    0x2e2f(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1060 <assert@plt>
mov    0x2e93(%rip),%rdi
call   1030 <sqlite3_reset@plt>
mov    0x2e87(%rip),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2df3(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1060 <assert@plt>
mov    0x2e67(%rip),%rdi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <sqlite3_column_int@plt>
test   %rdi,%rdi
je     121c <db_count_client_operators+0xac>
call   1080 <sqlite3_finalize@plt>
movq   $0x0,0x2e44(%rip)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@db_count_client_operators.stmt = internal global i32* null
@db_count_client_operators.query = internal constant [80 x i8] c"SELECT COUNT(*) FROM client WHERE operator_flag = 1 OR local_operator_flag = 1;\00"
@SQLITE_OK = global i32 0
@SQLITE_ROW = global i32 0
define i32 @db_count_client_operators(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
br label %5
5: ; preds = %1
%6 = load i32*, i32** %3
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = load i32*, i32** @db_count_client_operators.stmt
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32*, i32** @db_count_client_operators.stmt
%13 = call i32 @sqlite3_finalize(i32* %12)
store i32* null, i32** @db_count_client_operators.stmt
br label %14
14: ; preds = %11, %8
store i32 0, i32* %2
br label %42
15: ; preds = %5
br label %16
16: ; preds = %15
br label %17
17: ; preds = %16
%18 = load i32*, i32** @db_count_client_operators.stmt
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %29
20: ; preds = %17
%21 = load i32*, i32** %3
%22 = call i32 @strlen(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @db_count_client_operators.query, i64 0, i64 0))
%23 = call i32 @sqlite3_prepare_v2(i32* %21, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @db_count_client_operators.query, i64 0, i64 0), i32 %22, i32** @db_count_client_operators.stmt, i32* null)
store i32 %23, i32* %4
%24 = load i32, i32* %4
%25 = load i32, i32* @SQLITE_OK
%26 = icmp eq i32 %24, %25
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
br label %29
29: ; preds = %20, %17
br label %30
30: ; preds = %29
%31 = load i32*, i32** @db_count_client_operators.stmt
%32 = call i32 @sqlite3_reset(i32* %31)
%33 = load i32*, i32** @db_count_client_operators.stmt
%34 = call i32 @sqlite3_step(i32* %33)
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = load i32, i32* @SQLITE_ROW
%37 = icmp eq i32 %35, %36
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i32*, i32** @db_count_client_operators.stmt
%41 = call i32 @sqlite3_column_int(i32* %40, i32 0)
store i32 %41, i32* %2
br label %42
42: ; preds = %30, %14
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@db_count_client_operators.stmt = internal global i32* null
@db_count_client_operators.query = internal constant [80 x i8] c"SELECT COUNT(*) FROM client WHERE operator_flag = 1 OR local_operator_flag = 1;\00"
@SQLITE_OK = global i32 0
@SQLITE_ROW = global i32 0
define i32 @db_count_client_operators(i32* %0) {
%2 = icmp eq i32* %0, null
%3 = load i32*, i32** @db_count_client_operators.stmt
%4 = icmp eq i32* %3, null
br i1 %2, label %5, label %8
5: ; preds = %1
br i1 %4, label %28, label %6
6: ; preds = %5
%7 = tail call i32 @sqlite3_finalize(i32* %3)
store i32* null, i32** @db_count_client_operators.stmt
br label %28
8: ; preds = %1
br i1 %4, label %9, label %17
9: ; preds = %8
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @db_count_client_operators.query, i64 0, i64 0))
%11 = tail call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @db_count_client_operators.query, i64 0, i64 0), i32 %10, i32** @db_count_client_operators.stmt, i32* null)
%12 = load i32, i32* @SQLITE_OK
%13 = icmp eq i32 %11, %12
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = load i32*, i32** @db_count_client_operators.stmt
br label %17
17: ; preds = %9, %8
%18 = phi i32* [ %16, %9 ], [ %3, %8 ]
%19 = tail call i32 @sqlite3_reset(i32* %18)
%20 = load i32*, i32** @db_count_client_operators.stmt
%21 = tail call i32 @sqlite3_step(i32* %20)
%22 = load i32, i32* @SQLITE_ROW
%23 = icmp eq i32 %21, %22
%24 = zext i1 %23 to i32
%25 = tail call i32 @assert(i32 %24)
%26 = load i32*, i32** @db_count_client_operators.stmt
%27 = tail call i32 @sqlite3_column_int(i32* %26, i32 0)
br label %28
28: ; preds = %5, %6, %17
%29 = phi i32 [ %27, %17 ], [ 0, %6 ], [ 0, %5 ]
ret i32 %29
}