#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 */
struct db_client {
  int dummy;
};
typedef int /*<<< orphan*/ sqlite3_stmt;
typedef int /*<<< orphan*/ sqlite3_int64;
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int SQLITE_OK;
scalar_t__ SQLITE_ROW;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ db_fill_client_from_row(int /*<<< orphan*/ *,
                                           struct db_client *,
                                           int /*<<< orphan*/);
int sqlite3_bind_int64(int /*<<< orphan*/ *, int, 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*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char const *);
int db_get_client(sqlite3 *db, sqlite3_int64 id, struct db_client *out) {
  static sqlite3_stmt *stmt;
  static const char query[] = "SELECT * FROM client 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);
  assert(ret == SQLITE_OK);
  if (sqlite3_step(stmt) != SQLITE_ROW)
    return 1;
  db_fill_client_from_row(stmt, out, 0);
  return 0;
}


x86 assembly (clang, -O0):
<db_get_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cf <db_get_client+0x4f>
cmpq   $0x0,0x2ec2(%rip)
je     11c3 <db_get_client+0x43>
mov    0x2eb5(%rip),%rdi
call   1090 <sqlite3_finalize@plt>
movq   $0x0,0x2ea5(%rip)
movl   $0x0,-0x4(%rbp)
jmp    12b7 <db_get_client+0x137>
jmp    11d4 <db_get_client+0x54>
jmp    11d9 <db_get_client+0x59>
cmpq   $0x0,0x2e87(%rip)
jne    1235 <db_get_client+0xb5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe0a(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xdf8(%rip),%rsi
lea    0x2e59(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2dc2(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    123a <db_get_client+0xba>
mov    0x2e27(%rip),%rdi
call   1040 <sqlite3_reset@plt>
mov    0x2e1b(%rip),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   1030 <sqlite3_bind_int64@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    0x2deb(%rip),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2d4f(%rip),%rcx
cmp    (%rcx),%rax
je     129e <db_get_client+0x11e>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <db_get_client+0x137>
mov    0x2dc3(%rip),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1080 <db_fill_client_from_row@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_get_client>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ed7(%rip),%rdi
test   %rbx,%rbx
je     1243 <db_get_client+0xc3>
mov    %rdx,%r14
mov    %esi,%ebp
test   %rdi,%rdi
jne    11e5 <db_get_client+0x65>
lea    0xe55(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x2eae(%rip),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    0x2e17(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1060 <assert@plt>
mov    0x2e83(%rip),%rdi
call   1040 <sqlite3_reset@plt>
mov    0x2e77(%rip),%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
mov    %ebp,%edx
call   1030 <sqlite3_bind_int64@plt>
mov    0x2ddf(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1060 <assert@plt>
mov    0x2e4b(%rip),%rdi
call   1070 <sqlite3_step@plt>
mov    0x2daf(%rip),%rcx
cmp    (%rcx),%rax
jne    125a <db_get_client+0xda>
mov    0x2e33(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %edx,%edx
call   1080 <db_fill_client_from_row@plt>
jmp    125a <db_get_client+0xda>
xor    %ebx,%ebx
test   %rdi,%rdi
je     125a <db_get_client+0xda>
call   1090 <sqlite3_finalize@plt>
movq   $0x0,0x2e0e(%rip)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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