// File: /workspace/github_cpp_makefile_star2_O2/ctz[P]openssl-bench/bench.cc
// Function: test_handshake_resume(unsigned int, Context&, Context&, bool)
static void test_handshake_resume(const unsigned n_threads, Context &server_ctx,
                                  Context &client_ctx,
                                  const bool with_tickets) {
  const size_t handshakes = apply_work_multiplier(4096);

  server_ctx.enable_resume();
  client_ctx.enable_resume();

  std::string prefix_server, prefix_client;

  if (!with_tickets) {
    server_ctx.disable_tickets();
    client_ctx.disable_tickets();
    prefix_server = "handshake-resume\tserver\t";
    prefix_client = "handshake-resume\tclient\t";

#ifdef BORINGSSL
    if (server_ctx.is_tls13()) {
      printf("!!! BoringSSL does not support stateful resumption for TLS1.3\n");
      return;
    }
#endif
  } else {
    prefix_server = "handshake-ticket\tserver\t";
    prefix_client = "handshake-ticket\tclient\t";
  }

  SSL_SESSION *client_session;

  {
    Conn initial_server(server_ctx.open());
    Conn initial_client(client_ctx.open());
    initial_client.set_sni("localhost");
    do_handshake(initial_client, initial_server);

    // pass some data to ensure ticket receipt
    initial_server.write((const uint8_t *)"hello", 5);
    initial_server.transfer_to(initial_client);

    uint8_t buf[5];
    initial_client.read(buf, 5);

    initial_client.show_kx();
    client_session = initial_client.get_session();
    assert(SSL_SESSION_is_resumable(client_session));
    initial_server.ragged_close();

    prefix_server += initial_client.get_cipher_string();
    prefix_client += initial_client.get_cipher_string();
  }

  client_ctx.bodge_disable_resume();

  std::vector<std::thread> threads;
  std::vector<Timings> results(n_threads);

  for (unsigned i = 0; i < n_threads; i++) {
    threads.push_back(std::thread(
        &test_handshake_resume_one, std::ref(results[i]), std::ref(server_ctx),
        std::ref(client_ctx), client_session, handshakes));
  }

  for (unsigned i = 0; i < n_threads; i++) {
    threads[i].join();
  }

  server_ctx.dump_sess_stats();
  print_results(prefix_server.c_str(), prefix_client.c_str(), results,
                handshakes, "handshakes/s");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, %r13
movl %edi, %ebp
movl $0x1000, %edi           # imm = 0x1000
callq 0x4791
movq %rax, 0x20(%rsp)
movq %r13, %rdi
callq 0x6012
movq %r15, 0x10(%rsp)
movq %r15, %rdi
callq 0x6012
leaq 0xe8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0x108(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
testl %ebx, %ebx
je 0x4089
leaq 0x35bf(%rip), %rsi      # 0x7632
leaq 0xd8(%rsp), %rdi
callq 0x3550
leaq 0x35c4(%rip), %rsi      # 0x764b
jmp 0x40b6
movq %r13, %rdi
callq 0x605a
movq 0x10(%rsp), %rdi
callq 0x605a
leaq 0x355e(%rip), %rsi      # 0x7600
leaq 0xd8(%rsp), %rdi
callq 0x3550
leaq 0x3563(%rip), %rsi      # 0x7619
leaq 0xf8(%rsp), %rdi
callq 0x3550
movq %r13, %rdi
callq 0x52f6
leaq 0xa0(%rsp), %rdi
movq %rax, %rsi
callq 0x52fe
movq 0x10(%rsp), %rdi
callq 0x52f6
leaq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0x52fe
leaq 0x3348(%rip), %rsi      # 0x7441
leaq 0x48(%rsp), %rdi
callq 0x5c5e
leaq 0x48(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x45d4
leaq 0x3548(%rip), %rsi      # 0x7664
leaq 0xa0(%rsp), %rdi
pushq $0x5
popq %rdx
callq 0x579e
leaq 0xa0(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x57bc
leaq 0x48(%rsp), %rdi
leaq 0x18(%rsp), %rsi
pushq $0x5
popq %rdx
callq 0x5856
leaq 0x48(%rsp), %rdi
callq 0x6078
leaq 0x48(%rsp), %rdi
callq 0x60e0
movq %rax, 0x98(%rsp)
movq %rax, %rdi
callq 0x33e0
testl %eax, %eax
je 0x4377
leaq 0xa0(%rsp), %rdi
callq 0x6106
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x53a6
leaq 0xd8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3570
leaq 0x28(%rsp), %rdi
callq 0x3150
leaq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x53a6
leaq 0xf8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x3570
leaq 0x28(%rsp), %rdi
callq 0x3150
leaq 0x48(%rsp), %rdi
callq 0x5420
leaq 0xa0(%rsp), %rdi
callq 0x5420
movq 0x10(%rsp), %rdi
callq 0x6112
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
andq $0x0, 0xb0(%rsp)
movl %ebp, %ebx
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %rbx, %rsi
callq 0x51ea
movq %rbx, %r15
shlq $0x4, %r15
xorl %r14d, %r14d
leaq 0x28(%rsp), %r12
leaq 0xa0(%rsp), %rbp
cmpq %r14, %r15
je 0x42cb
leaq 0x982(%rip), %rax       # 0x4bd1
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
addq %r14, %rax
movq %rax, 0x90(%rsp)
movq %r13, 0x88(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
leaq 0x90(%rsp), %rdx
leaq 0x88(%rsp), %rcx
leaq 0x80(%rsp), %r8
leaq 0x98(%rsp), %r9
callq 0x6122
movq %rbp, %rdi
movq %r12, %rsi
callq 0x5554
movq %r12, %rdi
callq 0x52e8
addq $0x10, %r14
jmp 0x423f
shlq $0x3, %rbx
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x42ed
movq 0xa0(%rsp), %rdi
addq %r14, %rdi
callq 0x34c0
addq $0x8, %r14
jmp 0x42d2
movq %r13, %rdi
callq 0x61ce
leaq 0xd8(%rsp), %rbx
movq (%rbx), %rdi
leaq 0xf8(%rsp), %r14
movsd 0x20(%rsp), %xmm1
unpcklps 0x2cfb(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x2d03(%rip), %xmm1     # 0x7020
movq (%r14), %rsi
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0x31c2(%rip), %rcx      # 0x74f5
leaq 0x48(%rsp), %r15
movq %r15, %rdx
callq 0x4601
movq %r15, %rdi
callq 0x5498
leaq 0xa0(%rsp), %rdi
callq 0x544a
movq %r14, %rdi
callq 0x3150
movq %rbx, %rdi
callq 0x3150
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x32ec(%rip), %rdi      # 0x766a
leaq 0x2e53(%rip), %rsi      # 0x71d8
leaq 0x3307(%rip), %rcx      # 0x7693
movl $0x2aa, %edx            # imm = 0x2AA
callq 0x31d0
jmp 0x43e0
movq %rax, %rbx
jmp 0x43fc
jmp 0x43bb
jmp 0x43a3
jmp 0x43c2
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3150
jmp 0x43c5
jmp 0x43c2
movq %rax, %rbx
jmp 0x43cf
jmp 0x43bb
movq %rax, %rbx
jmp 0x4409
jmp 0x43c2
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5420
leaq 0xa0(%rsp), %rdi
callq 0x5420
jmp 0x4409
jmp 0x43e0
movq %rax, %rbx
jmp 0x43f2
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x52e8
leaq 0x48(%rsp), %rdi
callq 0x5498
leaq 0xa0(%rsp), %rdi
callq 0x544a
leaq 0xf8(%rsp), %rdi
callq 0x3150
leaq 0xd8(%rsp), %rdi
callq 0x3150
movq %rbx, %rdi
callq 0x34d0