// File: suyash[P]chan/misc/chan_speed_test_async.cc
// Function: measure(int)
void measure(int numThreads) {
	chan::unbuffered_chan<int> c;

	for (int i = 0; i < numThreads; i++) {
		serverThreads[i] = std::async(std::launch::async, server, std::ref(c), i);
		clientThreads[i] = std::async(std::launch::async, client, std::ref(c), i);
	}

	for (int i = 0; i < numThreads; i++) {
		serverThreads[i].wait();
		clientThreads[i].wait();
	}

	auto smallestStart = startTimes[0];
	for (int i = 1; i < numThreads; i++) {
		if (startTimes[i] < smallestStart) {
			smallestStart = startTimes[i];
		}
	}

	auto largestEnd = endTimes[0];
	for (int i = 1; i < numThreads; i++) {
		if (endTimes[i] > largestEnd) {
			largestEnd = endTimes[i];
		}
	}

	uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
	                  largestEnd - smallestStart)
	                  .count();

#ifdef __APPLE__
	printf(
	    "chan: %d*%d send/recv time in ms: %lld (%f nr_of_msg/msec)\n",
	    numThreads, RUN_SIZE, ms, double(numThreads * RUN_SIZE) / ms);
#else
	printf(
	    "chan: %d*%d send/recv time in ms: %ld (%f nr_of_msg/msec)\n",
	    numThreads, RUN_SIZE, ms, double(numThreads * RUN_SIZE) / ms);
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movl %edi, -0x4(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x3c80
movl $0x0, -0x10c(%rbp)
movl -0x10c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x37b1
leaq -0x108(%rbp), %rdi
callq 0x3ec0
movq %rax, -0x128(%rbp)
leaq -0x11d(%rip), %rdx      # 0x35a0
leaq -0x120(%rbp), %rdi
movl $0x1, %esi
leaq -0x128(%rbp), %rcx
leaq -0x10c(%rbp), %r8
callq 0x3cf0
jmp 0x36de
movslq -0x10c(%rbp), %rax
shlq $0x4, %rax
leaq 0xeaf0(%rip), %rdi      # 0x121e0
addq %rax, %rdi
leaq -0x120(%rbp), %rsi
movq %rsi, -0x198(%rbp)
callq 0x3ef0
movq -0x198(%rbp), %rdi
callq 0x3c30
leaq -0x108(%rbp), %rdi
callq 0x3ec0
movq %rax, -0x150(%rbp)
leaq -0x11c(%rip), %rdx      # 0x3610
leaq -0x148(%rbp), %rdi
movl $0x1, %esi
leaq -0x150(%rbp), %rcx
leaq -0x10c(%rbp), %r8
callq 0x3cf0
jmp 0x374d
movslq -0x10c(%rbp), %rax
leaq 0xeb85(%rip), %rdi      # 0x122e0
shlq $0x4, %rax
addq %rax, %rdi
leaq -0x148(%rbp), %rsi
callq 0x3ef0
leaq -0x148(%rbp), %rdi
callq 0x3c30
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0x3694
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x4080
jmp 0x39ec
movl $0x0, -0x154(%rbp)
movl -0x154(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x3811
movslq -0x154(%rbp), %rax
shlq $0x4, %rax
leaq 0xea08(%rip), %rdi      # 0x121e0
addq %rax, %rdi
callq 0x3f40
jmp 0x37e2
movslq -0x154(%rbp), %rax
shlq $0x4, %rax
leaq 0xeaec(%rip), %rdi      # 0x122e0
addq %rax, %rdi
callq 0x3f40
jmp 0x37fe
jmp 0x3800
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
jmp 0x37bb
movq 0xebd8(%rip), %rax      # 0x123f0
movq %rax, -0x160(%rbp)
movl $0x1, -0x164(%rbp)
movl -0x164(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x3892
movslq -0x164(%rbp), %rcx
leaq 0xebae(%rip), %rax      # 0x123f0
leaq (%rax,%rcx,8), %rdi
leaq -0x160(%rbp), %rsi
callq 0x3f70
movb %al, -0x199(%rbp)
jmp 0x385a
movb -0x199(%rbp), %al
testb $0x1, %al
jne 0x3866
jmp 0x387f
movslq -0x164(%rbp), %rcx
leaq 0xeb7c(%rip), %rax      # 0x123f0
movq (%rax,%rcx,8), %rax
movq %rax, -0x160(%rbp)
jmp 0x3881
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0x3829
movq 0xebd7(%rip), %rax      # 0x12470
movq %rax, -0x170(%rbp)
movl $0x1, -0x174(%rbp)
movl -0x174(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x3913
movslq -0x174(%rbp), %rcx
leaq 0xebad(%rip), %rax      # 0x12470
leaq (%rax,%rcx,8), %rdi
leaq -0x170(%rbp), %rsi
callq 0x3fb0
movb %al, -0x19a(%rbp)
jmp 0x38db
movb -0x19a(%rbp), %al
testb $0x1, %al
jne 0x38e7
jmp 0x3900
movslq -0x174(%rbp), %rcx
leaq 0xeb7b(%rip), %rax      # 0x12470
movq (%rax,%rcx,8), %rax
movq %rax, -0x170(%rbp)
jmp 0x3902
movl -0x174(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x174(%rbp)
jmp 0x38aa
leaq -0x170(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x4010
movq %rax, -0x1a8(%rbp)
jmp 0x392f
movq -0x1a8(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x3fe0
movq %rax, -0x1b0(%rbp)
jmp 0x3952
movq -0x1b0(%rbp), %rax
movq %rax, -0x188(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x4060
movq %rax, -0x1b8(%rbp)
jmp 0x3975
movq -0x1b8(%rbp), %rax
movq %rax, -0x180(%rbp)
movl -0x4(%rbp), %esi
movq -0x180(%rbp), %rcx
imull $0x30d4, %esi, %eax     # imm = 0x30D4
cvtsi2sd %eax, %xmm0
movq %rcx, %xmm1
movaps 0x766d(%rip), %xmm2     # 0xb010
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x7671(%rip), %xmm2     # 0xb020
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x76c7(%rip), %rdi      # 0xb090
movl $0x30d4, %edx           # imm = 0x30D4
movb $0x1, %al
callq 0x3030
jmp 0x39d7
leaq -0x108(%rbp), %rdi
callq 0x4080
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x130(%rbp), %rdi
callq 0x32c0
nopl (%rax,%rax)