// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
leaq 0x17461c(%rip), %rax    # 0x577314
movq %rax, -0x30(%rbp)
leaq 0x1745b6(%rip), %rax    # 0x5772b9
movq %rax, -0x38(%rbp)
leaq 0x1745bd(%rip), %rax    # 0x5772cb
movq %rax, -0x40(%rbp)
movq 0x1cfbd7(%rip), %rdi    # 0x5d28f0
movq -0x38(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x412c70
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
movq 0x1cfbae(%rip), %rdi    # 0x5d28f0
movq -0x40(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x412c70
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
movq 0x1cfb85(%rip), %rdi    # 0x5d28f0
movq -0x30(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x412c70
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
cmpl $0x1, -0x8(%rbp)
setg %al
andb $0x1, %al
movb %al, -0x41(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl 0x1cfb57(%rip), %eax    # 0x5d2900
jge 0x402f20
movq $0x5d2969, %rax         # imm = 0x5D2969
testb $0x1, (%rax)
je 0x402de9
testb $0x1, -0x41(%rbp)
je 0x402de9
movq -0x20(%rbp), %rdi
callq 0x40e590
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x403230
movq -0x20(%rbp), %rdi
callq 0x40cda0
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x402ed6
cmpl $0x0, -0x4(%rbp)
jne 0x402e10
movl -0x48(%rbp), %edx
addl -0x4c(%rbp), %edx
movl %edx, -0xb8(%rbp)
jmp 0x402e2a
leaq 0x1cfb11(%rip), %rdi    # 0x5d2928
callq 0x404740
xorl %edx, %edx
divl 0x1cfadc(%rip)          # 0x5d2900
movl %edx, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movl %eax, -0xb4(%rbp)
leaq -0xb0(%rbp), %rdi
movl -0xb4(%rbp), %ecx
movl $0x64, %esi
leaq 0x1744bf(%rip), %rdx    # 0x57730e
movb $0x0, %al
callq 0x4b4180
movq -0x18(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
movl $0x1, %esi
movl $0x10, %ecx
xorl %eax, %eax
movl %eax, %r8d
callq 0x40f4a0
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
movq -0x18(%rbp), %rdi
callq 0x40e590
movl %eax, -0xc(%rbp)
cmpl $0x64, %eax
jne 0x402e93
jmp 0x402e80
movl -0xc(%rbp), %edi
callq 0x403230
movq -0x18(%rbp), %rdi
callq 0x40cfd0
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
movq -0x18(%rbp), %rdi
callq 0x40cda0
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
callq 0x401b60
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x402df0
movq $0x5d2969, %rax         # imm = 0x5D2969
testb $0x1, (%rax)
je 0x402f10
testb $0x1, -0x41(%rbp)
je 0x402f10
movq -0x28(%rbp), %rdi
callq 0x40e590
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x403230
movq -0x28(%rbp), %rdi
callq 0x40cda0
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
jmp 0x402f12
movl -0x8(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x402da0
movq -0x18(%rbp), %rdi
callq 0x40cb40
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
movq -0x20(%rbp), %rdi
callq 0x40cb40
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
movq -0x28(%rbp), %rdi
callq 0x40cb40
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x401f20
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)