// File: /workspace/github_c_makefile_star2_O1/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 0x1a12e5(%rip), %rdi    # 0x5a47f0
leaq 0x146da7(%rip), %rsi    # 0x54a2b9
leaq 0x18(%rsp), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x40f725
testl %eax, %eax
jne 0x403730
movq 0x1a12bd(%rip), %rdi    # 0x5a47f0
leaq 0x146d91(%rip), %rsi    # 0x54a2cb
leaq 0x10(%rsp), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x40f725
testl %eax, %eax
jne 0x403737
movq 0x1a1295(%rip), %rdi    # 0x5a47f0
leaq 0x146db2(%rip), %rsi    # 0x54a314
leaq 0x8(%rsp), %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x40f725
testl %eax, %eax
jne 0x40373e
cmpl $0x0, 0x1a127d(%rip)    # 0x5a4800
jle 0x4036bc
leaq 0x146d7e(%rip), %r14    # 0x54a30e
leaq 0x20(%rsp), %r15
xorl %r13d, %r13d
cmpl $0x2, %ebx
jl 0x4035ce
movq $0x5a4869, %rax         # imm = 0x5A4869
cmpb $0x0, (%rax)
je 0x4035ce
movq 0x18(%rsp), %rdi
callq 0x40b5c5
cmpl $0x65, %eax
jne 0x40371b
movq 0x18(%rsp), %rdi
callq 0x40aa37
testl %eax, %eax
jne 0x403714
testl %ebx, %ebx
jle 0x40367a
xorl %r12d, %r12d
testl %ebp, %ebp
je 0x4035f5
leaq 0x1a1244(%rip), %rdi    # 0x5a4828
callq 0x40408c
xorl %edx, %edx
divl 0x1a120f(%rip)          # 0x5a4800
movl %edx, %ecx
jmp 0x4035f9
leal (%r12,%r13), %ecx
movl $0x64, %esi
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x487370
movq 0x8(%rsp), %rdi
movl $0x1, %esi
movq %r15, %rdx
movl $0x10, %ecx
xorl %r8d, %r8d
callq 0x40ca7c
testl %eax, %eax
jne 0x4036ff
movq 0x8(%rsp), %rdi
callq 0x40b5c5
cmpl $0x64, %eax
je 0x40362d
cmpl $0x65, %eax
jne 0x4036f8
movq 0x8(%rsp), %rdi
callq 0x40ab79
testl %eax, %eax
jne 0x403706
movq 0x8(%rsp), %rdi
callq 0x40aa37
testl %eax, %eax
jne 0x40370d
callq 0x402c78
incl %r12d
cmpl %ebx, %r12d
jne 0x4035d9
cmpl $0x2, %ebx
jl 0x4036ac
movq $0x5a4869, %rax         # imm = 0x5A4869
cmpb $0x0, (%rax)
je 0x4036ac
movq 0x10(%rsp), %rdi
callq 0x40b5c5
cmpl $0x65, %eax
jne 0x403729
movq 0x10(%rsp), %rdi
callq 0x40aa37
testl %eax, %eax
jne 0x403722
addl %ebx, %r13d
cmpl 0x1a114a(%rip), %r13d   # 0x5a4800
jl 0x403598
movq 0x8(%rsp), %rdi
callq 0x40a8ca
testl %eax, %eax
jne 0x403745
movq 0x18(%rsp), %rdi
callq 0x40a8ca
testl %eax, %eax
jne 0x40374c
movq 0x10(%rsp), %rdi
callq 0x40a8ca
testl %eax, %eax
jne 0x403753
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x401ed7
movl %eax, %edi
callq 0x401dbf
movl %eax, %edi
callq 0x401de2
movl %eax, %edi
callq 0x401e05
movl %eax, %edi
callq 0x401d9c
movl %eax, %edi
callq 0x401d79
movl %eax, %edi
callq 0x401e4b
movl %eax, %edi
callq 0x401e28
movl %eax, %edi
callq 0x401d10
movl %eax, %edi
callq 0x401d33
movl %eax, %edi
callq 0x401d56
movl %eax, %edi
callq 0x401e6e
movl %eax, %edi
callq 0x401e91
movl %eax, %edi
callq 0x401eb4
nop