// File: ctz[P]openssl-bench/bench.cc
// Function: test_handshake_one(Timings&, unsigned int, Context&, Context&)
static void test_handshake_one(Timings &timings_out, const unsigned handshakes,
                               Context &server_ctx, Context &client_ctx) {
  double time_client = 0;
  double time_server = 0;

  LatencyOutput client_latency("client");
  LatencyOutput server_latency("server");

  for (size_t i = 0; i < handshakes; i++) {
    Conn server(server_ctx.open());
    Conn client(client_ctx.open());

    client.set_sni("localhost");

    double t, time_client_one = 0, time_server_one = 0;

    t = get_time();
    client.connect();
    client.transfer_to(server);
    time_client_one += get_time() - t;

    t = get_time();
    server.accept();
    server.transfer_to(client);
    time_server_one += get_time() - t;

    t = get_time();
    client.connect();
    client.transfer_to(server);
    time_client_one += get_time() - t;

    t = get_time();
    server.accept();
    server.transfer_to(client);
    time_server_one += get_time() - t;

    client_latency.sample(time_client_one);
    server_latency.sample(time_server_one);
    time_client += time_client_one;
    time_server += time_server_one;

    assert(server.accept());
    assert(client.connect());
    assert(!server.was_resumed());
    assert(!client.was_resumed());
  }

  timings_out.client.store(time_client);
  timings_out.server.store(time_server);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
leaq 0x8f87(%rip), %rsi      # 0xe4b8
leaq -0x38(%rbp), %rdi
callq 0xb040
leaq 0x8f7e(%rip), %rsi      # 0xe4bf
leaq -0x40(%rbp), %rdi
callq 0xb040
jmp 0x554c
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl -0xc(%rbp), %ecx
cmpq %rcx, %rax
jae 0x591e
movq -0x18(%rbp), %rdi
callq 0x6500
movq %rax, -0xe8(%rbp)
jmp 0x5576
movq -0xe8(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x6520
jmp 0x558b
movq -0x20(%rbp), %rdi
callq 0x6500
movq %rax, -0xf0(%rbp)
jmp 0x559d
movq -0xf0(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x6520
jmp 0x55b2
leaq 0x8e3e(%rip), %rsi      # 0xe3f7
leaq -0xc8(%rbp), %rdi
callq 0xa9b0
jmp 0x55c7
movq $0x0, -0xd8(%rbp)
movq $0x0, -0xe0(%rbp)
callq 0x53f0
movsd %xmm0, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xaa50
jmp 0x55f8
leaq -0xc8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x7b80
jmp 0x560d
callq 0x53f0
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
subsd %xmm0, %xmm1
movsd -0xd8(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
callq 0x53f0
movsd %xmm0, -0xd0(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xaa10
jmp 0x5650
leaq -0x90(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x7b80
jmp 0x5665
callq 0x53f0
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
subsd %xmm0, %xmm1
movsd -0xe0(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xe0(%rbp)
callq 0x53f0
movsd %xmm0, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0xaa50
jmp 0x56a8
leaq -0xc8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x7b80
jmp 0x56bd
callq 0x53f0
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
subsd %xmm0, %xmm1
movsd -0xd8(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
callq 0x53f0
movsd %xmm0, -0xd0(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xaa10
jmp 0x5700
leaq -0x90(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x7b80
jmp 0x5715
callq 0x53f0
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
subsd %xmm0, %xmm1
movsd -0xe0(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd -0xd8(%rbp), %xmm0
leaq -0x38(%rbp), %rdi
callq 0xb1f0
jmp 0x5750
movsd -0xe0(%rbp), %xmm0
leaq -0x40(%rbp), %rdi
callq 0xb1f0
jmp 0x5763
movsd -0xd8(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0xe0(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xaa10
movb %al, -0xf1(%rbp)
jmp 0x57a3
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x57af
jmp 0x57b1
jmp 0x5820
leaq 0x8d0e(%rip), %rdi      # 0xe4c6
leaq 0x8a20(%rip), %rsi      # 0xe1df
movl $0x20e, %edx            # imm = 0x20E
leaq 0x8d0b(%rip), %rcx      # 0xe4d6
callq 0x3210
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x596c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x5963
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x5910
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x6770
jmp 0x5910
leaq -0xc8(%rbp), %rdi
callq 0xaa50
movb %al, -0xf2(%rbp)
jmp 0x5834
movb -0xf2(%rbp), %al
testb $0x1, %al
jne 0x5840
jmp 0x5842
jmp 0x5861
leaq 0x8cda(%rip), %rdi      # 0xe523
leaq 0x898f(%rip), %rsi      # 0xe1df
movl $0x20f, %edx            # imm = 0x20F
leaq 0x8c7a(%rip), %rcx      # 0xe4d6
callq 0x3210
leaq -0x90(%rbp), %rdi
callq 0xb250
movb %al, -0xf3(%rbp)
jmp 0x5875
movb -0xf3(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x5883
jmp 0x5885
jmp 0x58a4
leaq 0x8ca8(%rip), %rdi      # 0xe534
leaq 0x894c(%rip), %rsi      # 0xe1df
movl $0x210, %edx            # imm = 0x210
leaq 0x8c37(%rip), %rcx      # 0xe4d6
callq 0x3210
leaq -0xc8(%rbp), %rdi
callq 0xb250
movb %al, -0xf4(%rbp)
jmp 0x58b8
movb -0xf4(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x58c6
jmp 0x58c8
jmp 0x58e7
leaq 0x8c7b(%rip), %rdi      # 0xe54a
leaq 0x8909(%rip), %rsi      # 0xe1df
movl $0x211, %edx            # imm = 0x211
leaq 0x8bf4(%rip), %rcx      # 0xe4d6
callq 0x3210
leaq -0xc8(%rbp), %rdi
callq 0x6770
leaq -0x90(%rbp), %rdi
callq 0x6770
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x5554
leaq -0x90(%rbp), %rdi
callq 0x6770
jmp 0x5963
movq -0x8(%rbp), %rdi
movsd -0x28(%rbp), %xmm0
movl $0x5, %esi
callq 0x7d40
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
movsd -0x30(%rbp), %xmm0
movl $0x5, %esi
callq 0x7d40
leaq -0x40(%rbp), %rdi
callq 0xb280
leaq -0x38(%rbp), %rdi
callq 0xb280
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0xb280
leaq -0x38(%rbp), %rdi
callq 0xb280
movq -0x48(%rbp), %rdi
callq 0x3590
nop