// File: /workspace/github_c_makefile_star2_O2/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, %r12d
movl %edi, %ebp
movq 0x194beb(%rip), %rdi    # 0x5977f0
leaq 0x1356ad(%rip), %rsi    # 0x5382b9
pushq $-0x1
popq %rbx
leaq 0x10(%rsp), %rcx
movl %ebx, %edx
xorl %r8d, %r8d
callq 0x40d861
movl %eax, %edi
callq 0x401e32
movq 0x194bc4(%rip), %rdi    # 0x5977f0
leaq 0x135698(%rip), %rsi    # 0x5382cb
leaq 0x8(%rsp), %rcx
movl %ebx, %edx
xorl %r8d, %r8d
callq 0x40d861
movl %eax, %edi
callq 0x401e32
movq 0x194ba0(%rip), %rdi    # 0x5977f0
leaq 0x1356bd(%rip), %rsi    # 0x538314
movq %rsp, %rcx
movl %ebx, %edx
xorl %r8d, %r8d
callq 0x40d861
movl %eax, %edi
callq 0x401e32
testl %r12d, %r12d
movl $0x0, %r14d
cmovgl %r12d, %r14d
leaq 0x20(%rsp), %r15
pushq $0x10
popq %rbx
xorl %ecx, %ecx
movl %r12d, 0x1c(%rsp)
cmpl 0x194b73(%rip), %ecx    # 0x597800
jge 0x402db0
cmpl $0x2, %r12d
movq %rcx, %r13
jl 0x402ccd
movq $0x597869, %rax         # imm = 0x597869
cmpb $0x0, (%rax)
je 0x402ccd
movq 0x10(%rsp), %rdi
callq 0x40a229
movl %eax, %edi
callq 0x402e28
movq 0x10(%rsp), %rdi
callq 0x409808
movl %eax, %edi
callq 0x401e32
movq %r13, %rcx
xorl %r12d, %r12d
cmpl %r14d, %r12d
je 0x402d6c
testl %ebp, %ebp
je 0x402cf5
leaq 0x194b44(%rip), %rdi    # 0x597828
callq 0x4039a8
xorl %edx, %edx
divl 0x194b0f(%rip)          # 0x597800
movl %edx, %ecx
jmp 0x402cf8
addl %r12d, %ecx
movq %r15, %rdi
pushq $0x64
popq %rsi
leaq 0x135609(%rip), %rdx    # 0x53830e
xorl %eax, %eax
callq 0x474e90
movq (%rsp), %rdi
pushq $0x1
popq %rsi
movq %r15, %rdx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x40b284
movl %eax, %edi
callq 0x401e32
movq (%rsp), %rdi
callq 0x40a229
cmpl $0x64, %eax
je 0x402d27
movl %eax, %edi
callq 0x402e28
movq (%rsp), %rdi
callq 0x409934
movl %eax, %edi
callq 0x401e32
movq (%rsp), %rdi
callq 0x409808
movl %eax, %edi
callq 0x401e32
callq 0x401b98
incl %r12d
movq %r13, %rcx
jmp 0x402cd0
movl 0x1c(%rsp), %r12d
cmpl $0x2, %r12d
jl 0x402da8
movq $0x597869, %rax         # imm = 0x597869
cmpb $0x0, (%rax)
je 0x402da8
movq 0x8(%rsp), %rdi
callq 0x40a229
movl %eax, %edi
callq 0x402e28
movq 0x8(%rsp), %rdi
callq 0x409808
movl %eax, %edi
callq 0x401e32
movq %r13, %rcx
addl %r12d, %ecx
jmp 0x402c87
movq (%rsp), %rdi
callq 0x40969e
movl %eax, %edi
callq 0x401e32
movq 0x10(%rsp), %rdi
callq 0x40969e
movl %eax, %edi
callq 0x401e32
movq 0x8(%rsp), %rdi
callq 0x40969e
movl %eax, %edi
callq 0x401e32
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq