// File: /workspace/github_c_makefile_star2_O3/ukontainer[P]sqlite-bench/benchmark.c
// Function: benchmark_read
void benchmark_read(int order, int entries_per_batch) {
  int status;
  sqlite3_stmt *read_stmt, *begin_trans_stmt, *end_trans_stmt;

  char *read_str = "SELECT * FROM test WHERE key = ?";
  char *begin_trans_str = "BEGIN TRANSACTION";
  char *end_trans_str = "END TRANSACTION";

  /* Preparing sqlite3 statements */
  status = sqlite3_prepare_v2(db_, begin_trans_str, -1,
                              &begin_trans_stmt, NULL);
  error_check(status);
  status = sqlite3_prepare_v2(db_, end_trans_str, -1,
                              &end_trans_stmt, NULL);
  error_check(status);
  status = sqlite3_prepare_v2(db_, read_str, -1,
                              &read_stmt, NULL);
  error_check(status);

  bool transaction = (entries_per_batch > 1);
  for (int i = 0; i < reads_; i += entries_per_batch) {
    /* Begin read transaction */
    if (FLAGS_transaction && transaction) {
      status = sqlite3_step(begin_trans_stmt);
      step_error_check(status);
      status = sqlite3_reset(begin_trans_stmt);
      error_check(status);
    }

    /* Create and execute SQL statements */
    for (int j = 0; j < entries_per_batch; j++) {
      /* Create key value */
      char key[100];
      int k = (order == SEQUENTIAL) ? i + j : (rand_next(&rand_) % reads_);
      snprintf(key, sizeof(key), "%016d", k);

      /* Bind key value into read_stmt */
      status = sqlite3_bind_blob(read_stmt, 1, key, 16, SQLITE_STATIC);
      error_check(status);
      
      /* Execute read statement */
      while ((status = sqlite3_step(read_stmt)) == SQLITE_ROW) {}
      step_error_check(status);

      /* Reset SQLite statement for another use */
      status = sqlite3_clear_bindings(read_stmt);
      error_check(status);
      status = sqlite3_reset(read_stmt);
      error_check(status);
      finished_single_op();
    }

    /* End read transaction */
    if (FLAGS_transaction && transaction) {
      status = sqlite3_step(end_trans_stmt);
      step_error_check(status);
      status = sqlite3_reset(end_trans_stmt);
      error_check(status);
    }
  }

  status = sqlite3_finalize(read_stmt);
  error_check(status);
  status = sqlite3_finalize(begin_trans_stmt);
  error_check(status);
  status = sqlite3_finalize(end_trans_stmt);
  error_check(status);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %esi, %ebx
movl %edi, %ebp
movq 0x1a12c3(%rip), %rdi    # 0x5a47f0
leaq 0x146d85(%rip), %rsi    # 0x54a2b9
leaq 0x18(%rsp), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x40f8b1
testl %eax, %eax
jne 0x403768
movq 0x1a129b(%rip), %rdi    # 0x5a47f0
leaq 0x146d6f(%rip), %rsi    # 0x54a2cb
leaq 0x10(%rsp), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x40f8b1
testl %eax, %eax
jne 0x40376f
movq 0x1a1273(%rip), %rdi    # 0x5a47f0
leaq 0x146d90(%rip), %rsi    # 0x54a314
leaq 0x8(%rsp), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x40f8b1
testl %eax, %eax
jne 0x403776
cmpl $0x0, 0x1a125b(%rip)    # 0x5a4800
jle 0x4036f4
movq $0x5a4869, %rax         # imm = 0x5A4869
movb (%rax), %al
leaq 0x146d53(%rip), %r14    # 0x54a30e
leaq 0x20(%rsp), %r15
xorl %r13d, %r13d
cmpl $0x2, %ebx
jl 0x4035f2
testb $0x1, %al
je 0x4035f2
movq 0x18(%rsp), %rdi
callq 0x40b77e
cmpl $0x65, %eax
jne 0x40374c
movq 0x18(%rsp), %rdi
callq 0x40abee
testl %eax, %eax
je 0x4035fa
jmp 0x403753
testl %ebx, %ebx
jle 0x4036db
xorl %r12d, %r12d
testl %ebp, %ebp
je 0x403619
leaq 0x1a1220(%rip), %rdi    # 0x5a4828
callq 0x404078
xorl %edx, %edx
divl 0x1a11eb(%rip)          # 0x5a4800
movl %edx, %ecx
jmp 0x40361d
leal (%r12,%r13), %ecx
movl $0x64, %esi
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x4869f0
movq 0x8(%rsp), %rdi
movl $0x1, %esi
movq %r15, %rdx
movl $0x10, %ecx
xorl %r8d, %r8d
callq 0x40cc86
testl %eax, %eax
jne 0x403737
movq 0x8(%rsp), %rdi
callq 0x40b77e
cmpl $0x64, %eax
je 0x403651
cmpl $0x65, %eax
jne 0x403730
movq 0x8(%rsp), %rdi
callq 0x40ad30
testl %eax, %eax
jne 0x40373e
movq 0x8(%rsp), %rdi
callq 0x40abee
testl %eax, %eax
jne 0x403745
callq 0x402c88
incl %r12d
cmpl %ebx, %r12d
jne 0x4035fd
cmpl $0x2, %ebx
setl %cl
movq $0x5a4869, %rax         # imm = 0x5A4869
movb (%rax), %al
movl %eax, %edx
xorb $0x1, %dl
orb %cl, %dl
jne 0x4036e4
movq 0x10(%rsp), %rdi
callq 0x40b77e
cmpl $0x65, %eax
jne 0x40375a
movq 0x10(%rsp), %rdi
callq 0x40abee
testl %eax, %eax
jne 0x403761
movq $0x5a4869, %rax         # imm = 0x5A4869
movb (%rax), %al
addl %ebx, %r13d
cmpl 0x1a1112(%rip), %r13d   # 0x5a4800
jl 0x4035c3
movq 0x8(%rsp), %rdi
callq 0x40aa81
testl %eax, %eax
jne 0x40377d
movq 0x18(%rsp), %rdi
callq 0x40aa81
testl %eax, %eax
jne 0x403784
movq 0x10(%rsp), %rdi
callq 0x40aa81
testl %eax, %eax
jne 0x40378b
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x401ef1
movl %eax, %edi
callq 0x401dd9
movl %eax, %edi
callq 0x401dfc
movl %eax, %edi
callq 0x401e1f
movl %eax, %edi
callq 0x401d93
movl %eax, %edi
callq 0x401db6
movl %eax, %edi
callq 0x401e42
movl %eax, %edi
callq 0x401e65
movl %eax, %edi
callq 0x401d2a
movl %eax, %edi
callq 0x401d4d
movl %eax, %edi
callq 0x401d70
movl %eax, %edi
callq 0x401e88
movl %eax, %edi
callq 0x401eab
movl %eax, %edi
callq 0x401ece
nop