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

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

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

	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 $0x1b0, %rsp            # imm = 0x1B0
movl %edi, -0x4(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x2b70
movl $0x0, -0x10c(%rbp)
movl -0x10c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x26b4
leaq -0x108(%rbp), %rdi
callq 0x2be0
movq %rax, -0x120(%rbp)
leaq -0x11d(%rip), %rsi      # 0x24b0
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rdx
leaq -0x10c(%rbp), %rcx
callq 0x2c10
jmp 0x25e9
movslq -0x10c(%rbp), %rcx
leaq 0x5b29(%rip), %rax      # 0x8120
leaq (%rax,%rcx,8), %rdi
leaq -0x118(%rbp), %rsi
movq %rsi, -0x188(%rbp)
callq 0x2ce0
movq -0x188(%rbp), %rdi
callq 0x2b10
leaq -0x108(%rbp), %rdi
callq 0x2be0
movq %rax, -0x140(%rbp)
leaq -0x114(%rip), %rsi      # 0x2520
leaq -0x138(%rbp), %rdi
leaq -0x140(%rbp), %rdx
leaq -0x10c(%rbp), %rcx
callq 0x2c10
jmp 0x2650
movslq -0x10c(%rbp), %rax
leaq 0x5b42(%rip), %rdi      # 0x81a0
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x138(%rbp), %rsi
callq 0x2ce0
leaq -0x138(%rbp), %rdi
callq 0x2b10
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0x25a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x128(%rbp)
movl %eax, -0x12c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x2e30
jmp 0x28e9
movl $0x0, -0x144(%rbp)
movl -0x144(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x270e
movslq -0x144(%rbp), %rcx
leaq 0x5a49(%rip), %rax      # 0x8120
leaq (%rax,%rcx,8), %rdi
callq 0x2150
jmp 0x26e2
movslq -0x144(%rbp), %rcx
leaq 0x5ab0(%rip), %rax      # 0x81a0
leaq (%rax,%rcx,8), %rdi
callq 0x2150
jmp 0x26fb
jmp 0x26fd
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x26be
movq 0x5b1b(%rip), %rax      # 0x8230
movq %rax, -0x150(%rbp)
movl $0x1, -0x154(%rbp)
movl -0x154(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x278f
movslq -0x154(%rbp), %rcx
leaq 0x5af1(%rip), %rax      # 0x8230
leaq (%rax,%rcx,8), %rdi
leaq -0x150(%rbp), %rsi
callq 0x2d20
movb %al, -0x189(%rbp)
jmp 0x2757
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x2763
jmp 0x277c
movslq -0x154(%rbp), %rcx
leaq 0x5abf(%rip), %rax      # 0x8230
movq (%rax,%rcx,8), %rax
movq %rax, -0x150(%rbp)
jmp 0x277e
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
jmp 0x2726
movq 0x5b1a(%rip), %rax      # 0x82b0
movq %rax, -0x160(%rbp)
movl $0x1, -0x164(%rbp)
movl -0x164(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x2810
movslq -0x164(%rbp), %rcx
leaq 0x5af0(%rip), %rax      # 0x82b0
leaq (%rax,%rcx,8), %rdi
leaq -0x160(%rbp), %rsi
callq 0x2d60
movb %al, -0x18a(%rbp)
jmp 0x27d8
movb -0x18a(%rbp), %al
testb $0x1, %al
jne 0x27e4
jmp 0x27fd
movslq -0x164(%rbp), %rcx
leaq 0x5abe(%rip), %rax      # 0x82b0
movq (%rax,%rcx,8), %rax
movq %rax, -0x160(%rbp)
jmp 0x27ff
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0x27a7
leaq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x2dc0
movq %rax, -0x198(%rbp)
jmp 0x282c
movq -0x198(%rbp), %rax
movq %rax, -0x180(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x2d90
movq %rax, -0x1a0(%rbp)
jmp 0x284f
movq -0x1a0(%rbp), %rax
movq %rax, -0x178(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x2e10
movq %rax, -0x1a8(%rbp)
jmp 0x2872
movq -0x1a8(%rbp), %rax
movq %rax, -0x170(%rbp)
movl -0x4(%rbp), %esi
movq -0x170(%rbp), %rcx
imull $0x30d4, %esi, %eax     # imm = 0x30D4
cvtsi2sd %eax, %xmm0
movq %rcx, %xmm1
movaps 0x2770(%rip), %xmm2     # 0x5010
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x2774(%rip), %xmm2     # 0x5020
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x276a(%rip), %rdi      # 0x5030
movl $0x30d4, %edx           # imm = 0x30D4
movb $0x1, %al
callq 0x2030
jmp 0x28d4
leaq -0x108(%rbp), %rdi
callq 0x2e30
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x128(%rbp), %rdi
callq 0x2170
nopw %cs:(%rax,%rax)