// File: /workspace/github_cpp_makefile_star2_O3/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 $0x128, %rsp            # imm = 0x128
movl %ecx, %ebx
movq %rdx, %r14
movq %rsi, %r13
movl %edi, %ebp
movl $0x1000, %edi           # imm = 0x1000
callq 0x4b7e
movq %rax, 0x48(%rsp)
movq %r13, %rdi
callq 0x652c
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0x652c
leaq 0x60(%rsp), %r15
movq %r15, -0x10(%r15)
xorl %eax, %eax
movq %rax, -0x8(%r15)
movb %al, (%r15)
leaq 0xb8(%rsp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
testl %ebx, %ebx
je 0x4079
leaq 0x35ac(%rip), %rcx      # 0x7608
leaq 0x50(%rsp), %rdi
movl $0x18, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x3410
leaq 0x35aa(%rip), %rcx      # 0x7621
jmp 0x40db
movq (%r13), %rdi
callq 0x3420
movq (%r13), %rdi
orq $0x4000, %rax           # imm = 0x4000
movq %rax, %rsi
callq 0x3520
movq 0x10(%rsp), %rax
movq (%rax), %rdi
callq 0x3420
movq 0x10(%rsp), %rcx
movq (%rcx), %rdi
orq $0x4000, %rax           # imm = 0x4000
movq %rax, %rsi
callq 0x3520
leaq 0x50(%rsp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x350f(%rip), %rcx      # 0x75d6
movl $0x18, %r8d
xorl %esi, %esi
callq 0x3410
leaq 0x3514(%rip), %rcx      # 0x75ef
leaq 0xa8(%rsp), %rdi
movq 0x8(%rdi), %rdx
movl $0x18, %r8d
xorl %esi, %esi
callq 0x3410
movq (%r13), %rdi
callq 0x32d0
leaq 0xf0(%rsp), %rdi
movq %rax, %rsi
callq 0x5a14
movq 0x10(%rsp), %rax
movq (%rax), %rdi
callq 0x32d0
leaq 0x70(%rsp), %rdi
movq %rax, %rsi
callq 0x5a14
leaq 0x3313(%rip), %rsi      # 0x7441
leaq 0x70(%rsp), %rdi
callq 0x620c
leaq 0x3302(%rip), %rsi      # 0x7441
leaq 0x70(%rsp), %rdi
callq 0x620c
leaq 0x70(%rsp), %rbx
leaq 0xf0(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c0e
testb %al, %al
jne 0x4156
leaq 0x34ce(%rip), %rsi      # 0x763a
leaq 0xf0(%rsp), %rdi
movl $0x5, %edx
callq 0x5daa
leaq 0xf0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x5dc8
leaq 0x70(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x5, %edx
callq 0x5e7e
leaq 0x70(%rsp), %rdi
callq 0x657c
leaq 0x70(%rsp), %rdi
callq 0x65e4
movq %rax, 0xe8(%rsp)
movq %rax, %rdi
callq 0x33c0
testl %eax, %eax
je 0x4460
movq 0xf0(%rsp), %rdi
movl $0x3, %esi
callq 0x3080
leaq 0x18(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x5a8e
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0x50(%rsp), %rdi
callq 0x3100
leaq 0x28(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x4220
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32c0
leaq 0x18(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x5a8e
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0xa8(%rsp), %rdi
callq 0x3100
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0x425d
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32c0
leaq 0x70(%rsp), %rdi
callq 0x5b16
leaq 0xf0(%rsp), %rdi
callq 0x5b16
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movl $0x2, %edx
movl $0x2c, %esi
xorl %ecx, %ecx
callq 0x3260
xorps %xmm0, %xmm0
movaps %xmm0, 0xf0(%rsp)
movq $0x0, 0x100(%rsp)
movl %ebp, %ebx
leaq 0x70(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %rbx, %rsi
callq 0x58ec
testl %ebp, %ebp
je 0x43ab
movl %ebp, 0x3c(%rsp)
movq %rbx, 0xc8(%rsp)
movq %rbx, %rbp
shlq $0x4, %rbp
xorl %ebx, %ebx
leaq 0x18(%rsp), %r12
leaq 0xe8(%rsp), %r15
leaq 0xf0(%rsp), %r14
leaq 0xe45(%rip), %rax       # 0x5136
movq %rax, 0x40(%rsp)
movq 0x70(%rsp), %rax
addq %rbx, %rax
movq %rax, 0xe0(%rsp)
movq %r13, 0xd8(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0xd0(%rsp)
leaq 0x48(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
leaq 0x40(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
leaq 0xd8(%rsp), %rcx
leaq 0xd0(%rsp), %r8
movq %r15, %r9
callq 0x6612
movq %r14, %rdi
movq %r12, %rsi
callq 0x5bae
cmpq $0x0, 0x18(%rsp)
jne 0x4503
addq $0x10, %rbx
cmpq %rbx, %rbp
jne 0x42ea
cmpl $0x0, 0x3c(%rsp)
leaq 0x60(%rsp), %r15
leaq 0xb8(%rsp), %r12
movq 0xc8(%rsp), %r14
je 0x43ab
shlq $0x3, %r14
xorl %ebx, %ebx
movq 0xf0(%rsp), %rdi
addq %rbx, %rdi
callq 0x34b0
addq $0x8, %rbx
cmpq %rbx, %r14
jne 0x4392
movq %r13, %rdi
callq 0x66c4
movq 0x50(%rsp), %rdi
movsd 0x48(%rsp), %xmm1
unpcklps 0x2c4b(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x2c53(%rip), %xmm1     # 0x7020
movq 0xa8(%rsp), %rsi
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
leaq 0x30e3(%rip), %rcx      # 0x74cb
leaq 0x70(%rsp), %rbx
movq %rbx, %rdx
callq 0x49e9
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x440d
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0xf0(%rsp), %rdi
callq 0x5b4c
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x4437
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x444e
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x32c0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x31d9(%rip), %rdi      # 0x7640
leaq 0x2d6a(%rip), %rsi      # 0x71d8
leaq 0x31f4(%rip), %rcx      # 0x7669
movl $0x2aa, %edx            # imm = 0x2AA
callq 0x31d0
jmp 0x44d7
movq %rax, %rbx
jmp 0x44f4
jmp 0x44c4
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
jne 0x44aa
jmp 0x450b
jmp 0x4508
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x450b
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x450b
jmp 0x4508
movq %rax, %rbx
jmp 0x4515
jmp 0x44c4
jmp 0x4508
movq %rax, %rbx
jmp 0x4522
jmp 0x4508
jmp 0x44d7
jmp 0x44d7
cmpq $0x0, 0x18(%rsp)
jne 0x4503
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x44f4
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x32c0
leaq 0xf0(%rsp), %rdi
callq 0x5b4c
jmp 0x4522
callq 0x30e0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x5b16
leaq 0xf0(%rsp), %rdi
callq 0x5b16
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x4547
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4563
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x34c0