// File: gkalsi[P]barbecue/test.cc
// Function: main
int main(int argc, char* argv[]) {
	BoundedBlockingQueue<int> bbq;

	vector<thread> producerThreads;
	thread consumerThread(consumer, &bbq, kNumEntries * kNumProducerThreads);

	for (int i = 0; i < kNumProducerThreads; i++) {
		producerThreads.emplace_back(producer, &bbq, kNumEntries);
	}

	consumerThread.join();
	for (int i = 0; i < kNumProducerThreads; i++) {
		producerThreads[i].join();
	}

	int nerrors = 0;
	for (const auto& result : results) {
		// Each producer thread contributes one entry.
		if (result.second != kNumProducerThreads) {
			cout << "Error. Element " << result.first << " appears " 
				 << result.second << " times, expected " << kNumProducerThreads
				 << endl;
			nerrors++;
		}
	}

	cout << "test finished with " << nerrors << " error(s)." << endl;

	return 0;
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movl $0x0, 0x174(%rsp)
movl %edi, 0x170(%rsp)
movq %rsi, 0x168(%rsp)
leaq 0xc0(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x2890
leaq 0xa8(%rsp), %rdi
callq 0x28d0
movq 0x48(%rsp), %rax
movq %rax, 0x98(%rsp)
movl $0xb71b0, 0x94(%rsp) # imm = 0xB71B0
leaq 0x2f1(%rip), %rsi       # 0x26e0
leaq 0xa0(%rsp), %rdi
leaq 0x98(%rsp), %rdx
leaq 0x94(%rsp), %rcx
callq 0x28e0
jmp 0x240e
movl $0x0, 0x80(%rsp)
cmpl $0x32, 0x80(%rsp)
jge 0x24aa
leaq 0xc0(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x365(%rip), %rsi       # 0x27a0
leaq 0x4bc2(%rip), %rcx      # 0x7004
leaq 0xa8(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x29b0
jmp 0x2456
jmp 0x2458
movl 0x80(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x80(%rsp)
jmp 0x2419
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
jmp 0x26b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x88(%rsp)
movl %eax, 0x84(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x2b30
jmp 0x26b8
leaq 0xa0(%rsp), %rdi
callq 0x21e0
jmp 0x24b9
movl $0x0, 0x74(%rsp)
cmpl $0x32, 0x74(%rsp)
jge 0x24f3
movslq 0x74(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x2a40
movq %rax, %rdi
callq 0x21e0
jmp 0x24e4
jmp 0x24e6
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x24c1
movl $0x0, 0x70(%rsp)
leaq 0x8c36(%rip), %rax      # 0xb138
movq %rax, 0x68(%rsp)
leaq 0x8c2a(%rip), %rdi      # 0xb138
callq 0x2a60
movq %rax, 0x60(%rsp)
leaq 0x8c19(%rip), %rdi      # 0xb138
callq 0x2a90
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2ac0
testb $0x1, %al
jne 0x2541
jmp 0x261f
leaq 0x60(%rsp), %rdi
callq 0x2ae0
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpl $0x32, 0x4(%rax)
je 0x260e
movq 0x8a72(%rip), %rdi      # 0xafd8
leaq 0x4a9c(%rip), %rsi      # 0x7009
callq 0x2130
movq %rax, 0x40(%rsp)
jmp 0x2579
movq 0x40(%rsp), %rdi
movq 0x50(%rsp), %rax
movl (%rax), %esi
callq 0x21f0
movq %rax, 0x38(%rsp)
jmp 0x2591
movq 0x38(%rsp), %rdi
leaq 0x4a7c(%rip), %rsi      # 0x7019
callq 0x2130
movq %rax, 0x30(%rsp)
jmp 0x25a9
movq 0x30(%rsp), %rdi
movq 0x50(%rsp), %rax
movl 0x4(%rax), %esi
callq 0x2170
movq %rax, 0x28(%rsp)
jmp 0x25c2
movq 0x28(%rsp), %rdi
leaq 0x4a55(%rip), %rsi      # 0x7023
callq 0x2130
movq %rax, 0x20(%rsp)
jmp 0x25da
movq 0x20(%rsp), %rdi
movl $0x32, %esi
callq 0x21f0
movq %rax, 0x18(%rsp)
jmp 0x25f0
movq 0x18(%rsp), %rdi
movq 0x89c4(%rip), %rsi      # 0xafc0
callq 0x2160
jmp 0x2603
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0x2610
leaq 0x60(%rsp), %rdi
callq 0x2b00
jmp 0x2529
movq 0x89b2(%rip), %rdi      # 0xafd8
leaq 0x4a08(%rip), %rsi      # 0x7035
callq 0x2130
movq %rax, 0x10(%rsp)
jmp 0x2639
movq 0x10(%rsp), %rdi
movl 0x70(%rsp), %esi
callq 0x21f0
movq %rax, 0x8(%rsp)
jmp 0x264e
movq 0x8(%rsp), %rdi
leaq 0x49ef(%rip), %rsi      # 0x7049
callq 0x2130
movq %rax, (%rsp)
jmp 0x2665
movq (%rsp), %rdi
movq 0x8950(%rip), %rsi      # 0xafc0
callq 0x2160
jmp 0x2677
movl $0x0, 0x174(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x2b30
leaq 0xa8(%rsp), %rdi
callq 0x2b50
leaq 0xc0(%rsp), %rdi
callq 0x2bb0
movl 0x174(%rsp), %eax
addq $0x178, %rsp            # imm = 0x178
retq
leaq 0xa8(%rsp), %rdi
callq 0x2b50
leaq 0xc0(%rsp), %rdi
callq 0x2bb0
movq 0x88(%rsp), %rdi
callq 0x2200
nop