#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;
scalar_t__ SQLITE_ROW;
int /*<<< orphan*/ SQLITE_STATIC;
int /*<<< orphan*/ assert(int);
int sqlite3_bind_text(int /*<<< orphan*/ *, int, char const *, int,
                      int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_column_int64(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*/ *);
scalar_t__ sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char const *);
int db_get_operator_id(sqlite3 *db, const char *un, const char *pw,
                       sqlite3_int64 *id) {
  static sqlite3_stmt *stmt;
  static const char query[] =
      "SELECT id_oper FROM operator WHERE username = ? AND password = ?;";
  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_text(stmt, 1, un, -1, SQLITE_STATIC);
  assert(ret == SQLITE_OK);
  ret = sqlite3_bind_text(stmt, 2, pw, -1, SQLITE_STATIC);
  assert(ret == SQLITE_OK);
  if (sqlite3_step(stmt) != SQLITE_ROW)
    return 1;
  *id = sqlite3_column_int64(stmt, 0);
  return 0;
}


x86 assembly (clang, -O0):
<db_get_operator_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d4 <db_get_operator_id+0x54>
cmpq   $0x0,0x2ebd(%rip)
je     11c8 <db_get_operator_id+0x48>
mov    0x2eb0(%rip),%rdi
call   1090 <sqlite3_finalize@plt>
movq   $0x0,0x2ea0(%rip)
movl   $0x0,-0x4(%rbp)
jmp    1310 <db_get_operator_id+0x190>
jmp    11d9 <db_get_operator_id+0x59>
jmp    11de <db_get_operator_id+0x5e>
cmpq   $0x0,0x2e82(%rip)
jne    123a <db_get_operator_id+0xba>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe05(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xdf3(%rip),%rsi
lea    0x2e54(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
jmp    123f <db_get_operator_id+0xbf>
mov    0x2e22(%rip),%rdi
call   1030 <sqlite3_reset@plt>
mov    0x2e16(%rip),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2d7b(%rip),%rax
mov    (%rax),%r8d
mov    $0x1,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2d6c(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2dd6(%rip),%rdi
mov    -0x20(%rbp),%rdx
mov    0x2d3b(%rip),%rax
mov    (%rax),%r8d
mov    $0x2,%esi
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2d2c(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2d96(%rip),%rdi
call   1060 <sqlite3_step@plt>
mov    0x2cf2(%rip),%rcx
cmp    (%rcx),%rax
je     12f3 <db_get_operator_id+0x173>
movl   $0x1,-0x4(%rbp)
jmp    1310 <db_get_operator_id+0x190>
mov    0x2d6e(%rip),%rdi
xor    %esi,%esi
call   1070 <sqlite3_column_int64@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_get_operator_id>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbp
mov    0x2ed6(%rip),%rdi
test   %rbp,%rbp
je     1283 <db_get_operator_id+0x103>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
test   %rdi,%rdi
jne    11ea <db_get_operator_id+0x6a>
lea    0xe50(%rip),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    0x2ea9(%rip),%rcx
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   10a0 <sqlite3_prepare_v2@plt>
mov    0x2e12(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1050 <assert@plt>
mov    0x2e7e(%rip),%rdi
call   1030 <sqlite3_reset@plt>
mov    0x2e72(%rip),%rdi
mov    0x2ddb(%rip),%r12
mov    (%r12),%r8d
mov    $0x1,%ebp
mov    $0x1,%esi
mov    %rbx,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
mov    0x2dc9(%rip),%rbx
xor    %edi,%edi
cmp    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
mov    0x2e35(%rip),%rdi
mov    (%r12),%r8d
mov    $0x2,%esi
mov    %r15,%rdx
mov    $0xffffffff,%ecx
call   1080 <sqlite3_bind_text@plt>
xor    %edi,%edi
cmp    (%rbx),%eax
sete   %dil
call   1050 <assert@plt>
mov    0x2e0b(%rip),%rdi
call   1060 <sqlite3_step@plt>
mov    0x2d67(%rip),%rcx
cmp    (%rcx),%rax
jne    129a <db_get_operator_id+0x11a>
mov    0x2df3(%rip),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
call   1070 <sqlite3_column_int64@plt>
mov    %eax,(%r14)
jmp    129a <db_get_operator_id+0x11a>
xor    %ebp,%ebp
test   %rdi,%rdi
je     129a <db_get_operator_id+0x11a>
call   1090 <sqlite3_finalize@plt>
movq   $0x0,0x2dce(%rip)
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@db_get_operator_id.stmt = internal global i32* null
@db_get_operator_id.query = internal constant [66 x i8] c"SELECT id_oper FROM operator WHERE username = ? AND password = ?;\00"
@SQLITE_OK = global i32 0
@SQLITE_STATIC = global i32 0
@SQLITE_ROW = global i64 0
define i32 @db_get_operator_id(i32* %0, i8* %1, i8* %2, i32* nocapture writeonly %3) {
%5 = icmp eq i32* %0, null
%6 = load i32*, i32** @db_get_operator_id.stmt
%7 = icmp eq i32* %6, null
br i1 %5, label %8, label %11
8: ; preds = %4
br i1 %7, label %44, label %9
9: ; preds = %8
%10 = tail call i32 @sqlite3_finalize(i32* %6)
store i32* null, i32** @db_get_operator_id.stmt
br label %44
11: ; preds = %4
br i1 %7, label %12, label %20
12: ; preds = %11
%13 = tail call i32 @strlen(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @db_get_operator_id.query, i64 0, i64 0))
%14 = tail call i32 @sqlite3_prepare_v2(i32* %0, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @db_get_operator_id.query, i64 0, i64 0), i32 %13, i32** @db_get_operator_id.stmt, i32* null)
%15 = load i32, i32* @SQLITE_OK
%16 = icmp eq i32 %14, %15
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = load i32*, i32** @db_get_operator_id.stmt
br label %20
20: ; preds = %12, %11
%21 = phi i32* [ %19, %12 ], [ %6, %11 ]
%22 = tail call i32 @sqlite3_reset(i32* %21)
%23 = load i32*, i32** @db_get_operator_id.stmt
%24 = load i32, i32* @SQLITE_STATIC
%25 = tail call i32 @sqlite3_bind_text(i32* %23, i32 1, i8* %1, i32 -1, i32 %24)
%26 = load i32, i32* @SQLITE_OK
%27 = icmp eq i32 %25, %26
%28 = zext i1 %27 to i32
%29 = tail call i32 @assert(i32 %28)
%30 = load i32*, i32** @db_get_operator_id.stmt
%31 = load i32, i32* @SQLITE_STATIC
%32 = tail call i32 @sqlite3_bind_text(i32* %30, i32 2, i8* %2, i32 -1, i32 %31)
%33 = load i32, i32* @SQLITE_OK
%34 = icmp eq i32 %32, %33
%35 = zext i1 %34 to i32
%36 = tail call i32 @assert(i32 %35)
%37 = load i32*, i32** @db_get_operator_id.stmt
%38 = tail call i64 @sqlite3_step(i32* %37)
%39 = load i64, i64* @SQLITE_ROW
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %20
%42 = load i32*, i32** @db_get_operator_id.stmt
%43 = tail call i32 @sqlite3_column_int64(i32* %42, i32 0)
store i32 %43, i32* %3
br label %44
44: ; preds = %20, %8, %9, %41
%45 = phi i32 [ 0, %41 ], [ 0, %9 ], [ 0, %8 ], [ 1, %20 ]
ret i32 %45
}