#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;

/* Variables and functions */
int SQLITE_OK;
int SQLITE_ROW;
int /*<<< orphan*/ assert(int);
int sqlite3_clear_bindings(int /*<<< orphan*/ *);
unsigned char const *sqlite3_column_text(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/);
int sqlite3_reset(int /*<<< orphan*/ *);
int sqlite3_step(int /*<<< orphan*/ *);
int _db_gated_call(sqlite3_stmt *st, int (*c)(const unsigned char *, void *),
                   void *arg) {
  int ret, res = -1;
  ret = sqlite3_step(st);
  if (ret == SQLITE_ROW) {
    res = c(sqlite3_column_text(st, 0), arg);
    ret = sqlite3_step(st);
    assert(ret != SQLITE_ROW);
  }
  ret = sqlite3_clear_bindings(st);
  assert(ret == SQLITE_OK);
  ret = sqlite3_reset(st);
  assert(ret == SQLITE_OK);
  return res;
}


x86 assembly (clang, -O0):
<_db_gated_call>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%eax
jne    11d1 <_db_gated_call+0x81>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,%rdi
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rsi
call   *%rax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <sqlite3_step@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1070 <sqlite3_clear_bindings@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <sqlite3_reset@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_db_gated_call>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <sqlite3_step@plt>
mov    0x2e68(%rip),%r12
mov    $0xffffffff,%r13d
cmp    (%r12),%eax
jne    11a9 <_db_gated_call+0x59>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <sqlite3_column_text@plt>
mov    %rax,%rdi
mov    %r15,%rsi
call   *%r14
mov    %eax,%r13d
mov    %rbx,%rdi
call   1050 <sqlite3_step@plt>
xor    %edi,%edi
cmp    (%r12),%eax
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1070 <sqlite3_clear_bindings@plt>
mov    0x2e30(%rip),%rbp
xor    %edi,%edi
cmp    0x0(%rbp),%eax
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <sqlite3_reset@plt>
xor    %edi,%edi
cmp    0x0(%rbp),%eax
sete   %dil
call   1040 <assert@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SQLITE_ROW = global i32 0
@SQLITE_OK = global i32 0
define i32 @_db_gated_call(i32* %0, i32 (i8*, i8*)* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32 (i8*, i8*)*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 (i8*, i8*)* %1, i32 (i8*, i8*)** %5
store i8* %2, i8** %6
store i32 -1, i32* %8
%9 = load i32*, i32** %4
%10 = call i32 @sqlite3_step(i32* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = load i32, i32* @SQLITE_ROW
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %3
%15 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %5
%16 = load i32*, i32** %4
%17 = call i8* @sqlite3_column_text(i32* %16, i32 0)
%18 = load i8*, i8** %6
%19 = call i32 %15(i8* %17, i8* %18)
store i32 %19, i32* %8
%20 = load i32*, i32** %4
%21 = call i32 @sqlite3_step(i32* %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = load i32, i32* @SQLITE_ROW
%24 = icmp ne i32 %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
br label %27
27: ; preds = %14, %3
%28 = load i32*, i32** %4
%29 = call i32 @sqlite3_clear_bindings(i32* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = load i32, i32* @SQLITE_OK
%32 = icmp eq i32 %30, %31
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32*, i32** %4
%36 = call i32 @sqlite3_reset(i32* %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = load i32, i32* @SQLITE_OK
%39 = icmp eq i32 %37, %38
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load i32, i32* %8
ret i32 %42
}

LLVM IR (-O2):
@SQLITE_ROW = global i32 0
@SQLITE_OK = global i32 0
define i32 @_db_gated_call(i32* %0, i32 (i8*, i8*)* nocapture %1, i8* %2) {
%4 = tail call i32 @sqlite3_step(i32* %0)
%5 = load i32, i32* @SQLITE_ROW
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %15
7: ; preds = %3
%8 = tail call i8* @sqlite3_column_text(i32* %0, i32 0)
%9 = tail call i32 %1(i8* %8, i8* %2)
%10 = tail call i32 @sqlite3_step(i32* %0)
%11 = load i32, i32* @SQLITE_ROW
%12 = icmp ne i32 %10, %11
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
br label %15
15: ; preds = %7, %3
%16 = phi i32 [ %9, %7 ], [ -1, %3 ]
%17 = tail call i32 @sqlite3_clear_bindings(i32* %0)
%18 = load i32, i32* @SQLITE_OK
%19 = icmp eq i32 %17, %18
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
%22 = tail call i32 @sqlite3_reset(i32* %0)
%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)
ret i32 %16
}