#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_int64;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int SQLITE_OK;
int SQLITE_ROW;
int /*<<< orphan*/ assert(int);
int sqlite3_bind_int64(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
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_channels(sqlite3 *db, sqlite3_int64 id_client) {
  static sqlite3_stmt *stmt;
  static const char query[] =
      "SELECT COUNT(*) FROM membership WHERE id_client = ?;";
  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_bind_int64(stmt, 1, id_client);
  assert(ret == SQLITE_OK);
  ret = sqlite3_step(stmt);
  assert(ret == SQLITE_ROW);
  return sqlite3_column_int(stmt, 0);
}


x86 assembly (clang, -O0):
<db_count_client_channels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cb <db_count_client_channels+0x4b>
cmpq   $0x0,0x2ec6(%rip)
je     11bf <db_count_client_channels+0x3f>
mov    0x2eb9(%rip),%rdi
call   1090 <sqlite3_finalize@plt>
movq   $0x0,0x2ea9(%rip)
movl   $0x0,-0x4(%rbp)
jmp    12ab <db_count_client_channels+0x12b>
jmp    11d0 <db_count_client_channels+0x50>
jmp    11d5 <db_count_client_channels+0x55>
cmpq   $0x0,0x2e8b(%rip)
jne    1231 <db_count_client_channels+0xb1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe0e(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xdfc(%rip),%rsi
lea    0x2e5d(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
jmp    1236 <db_count_client_channels+0xb6>
mov    0x2e2b(%rip),%rdi
call   1040 <sqlite3_reset@plt>
mov    0x2e1f(%rip),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   1030 <sqlite3_bind_int64@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    0x2def(%rip),%rdi
call   1080 <sqlite3_step@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2d4d(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    0x2dc7(%rip),%rdi
xor    %esi,%esi
call   1060 <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_channels>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2eda(%rip),%rdi
test   %rbx,%rbx
je     123d <db_count_client_channels+0xbd>
mov    %esi,%ebp
test   %rdi,%rdi
jne    11df <db_count_client_channels+0x5f>
lea    0xe5b(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x2eb4(%rip),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    0x2e1d(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1070 <assert@plt>
mov    0x2e89(%rip),%rdi
call   1040 <sqlite3_reset@plt>
mov    0x2e7d(%rip),%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   1030 <sqlite3_bind_int64@plt>
mov    0x2dea(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1070 <assert@plt>
mov    0x2e56(%rip),%rdi
call   1080 <sqlite3_step@plt>
mov    0x2dba(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1070 <assert@plt>
mov    0x2e36(%rip),%rdi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <sqlite3_column_int@plt>
test   %rdi,%rdi
je     1252 <db_count_client_channels+0xd2>
call   1090 <sqlite3_finalize@plt>
movq   $0x0,0x2e16(%rip)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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