// File: /workspace/github_cpp_makefile_star2_O1/olegstrelnikov[P]thread-pool/test/main.cpp
// Function: main
int main() {
	std::size_t fails = 0;
	for (std::size_t j = 0; j < 10000; ++j) {
		{
			ThreadPool threadPool(4);
			threadPool.addTask(f<1>);
			threadPool.addTask(f<2>);
			threadPool.addTask(f<3>);
			threadPool.addTask(f<4>);
			threadPool.addTask(f<5>);
			threadPool.addTask(f<6>);
			threadPool.addTask(f<7>);
			threadPool.addTask(f<8>);
			threadPool.addTask(f<9>);
			threadPool.addTask(f<10>);
			threadPool.addTask(f<11>);
			threadPool.addTask(f<12>);
			threadPool.addTask(f<13>);
			threadPool.addTask(f<14>);
			threadPool.addTask(f<15>);
			threadPool.addTask(f<16>);
		}
		for (std::size_t i = 0; i < FUNCTIONS; ++i) {
			if (calls[i] != 1 + j) {
				++fails;
			}
		}
	} //for j
	for (std::size_t i = 0; i < FUNCTIONS; ++i) {
		std::cout << calls[i] << " ";
	}
	std::cout << "\n";
	std::map<thread_id_t, std::size_t> byThread;
	for (auto id: thread_ids) {
		++byThread[id];
	}
	if (byThread.size() > 4) {
		++fails;
	}
	for (auto pair: byThread) {
		std::cout << pair.first << ": " << pair.second << "\n";
	}
	std::cout << "fails: " << fails << "\n";
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
xorl %ebx, %ebx
leaq 0x8(%rsp), %r14
leaq 0x89b(%rip), %r13       # 0x2c76
leaq 0x8de(%rip), %rbp       # 0x2cc0
leaq 0x3d77(%rip), %r12      # 0x6160
xorl %r15d, %r15d
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
callq 0x2710
movq %r14, %rdi
leaq 0x462(%rip), %rsi       # 0x286a
callq 0x27fe
movq %r14, %rdi
leaq 0x49d(%rip), %rsi       # 0x28b4
callq 0x27fe
movq %r14, %rdi
leaq 0x4d8(%rip), %rsi       # 0x28fe
callq 0x27fe
movq %r14, %rdi
leaq 0x513(%rip), %rsi       # 0x2948
callq 0x27fe
movq %r14, %rdi
leaq 0x54e(%rip), %rsi       # 0x2992
callq 0x27fe
movq %r14, %rdi
leaq 0x589(%rip), %rsi       # 0x29dc
callq 0x27fe
movq %r14, %rdi
leaq 0x5c4(%rip), %rsi       # 0x2a26
callq 0x27fe
movq %r14, %rdi
leaq 0x5ff(%rip), %rsi       # 0x2a70
callq 0x27fe
movq %r14, %rdi
leaq 0x63a(%rip), %rsi       # 0x2aba
callq 0x27fe
movq %r14, %rdi
leaq 0x675(%rip), %rsi       # 0x2b04
callq 0x27fe
movq %r14, %rdi
leaq 0x6b0(%rip), %rsi       # 0x2b4e
callq 0x27fe
movq %r14, %rdi
leaq 0x6eb(%rip), %rsi       # 0x2b98
callq 0x27fe
movq %r14, %rdi
leaq 0x726(%rip), %rsi       # 0x2be2
callq 0x27fe
movq %r14, %rdi
leaq 0x761(%rip), %rsi       # 0x2c2c
callq 0x27fe
movq %r14, %rdi
movq %r13, %rsi
callq 0x27fe
movq %r14, %rdi
movq %rbp, %rsi
callq 0x27fe
movq %r14, %rdi
callq 0x2d0a
incq %r15
movq %rbx, %xmm0
movq %r15, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
xorl %eax, %eax
pcmpeqd %xmm4, %xmm4
movdqa (%rax,%r12), %xmm2
pcmpeqd %xmm1, %xmm2
pshufd $0xb1, %xmm2, %xmm3     # xmm3 = xmm2[1,0,3,2]
pand %xmm2, %xmm3
pxor %xmm4, %xmm3
psubq %xmm3, %xmm0
addq $0x10, %rax
cmpq $0x80, %rax
jne 0x2506
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
paddq %xmm0, %xmm1
movq %xmm1, %rbx
cmpq $0x2710, %r15           # imm = 0x2710
jne 0x23ec
xorl %r13d, %r13d
movq 0x3a86(%rip), %r14      # 0x5fd8
leaq 0x1ab3(%rip), %r15      # 0x400c
movq (%r13,%r12), %rsi
movq %r14, %rdi
callq 0x20f0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2190
addq $0x8, %r13
cmpq $0x80, %r13
jne 0x2559
movq 0x3a4e(%rip), %rdi      # 0x5fd8
leaq 0x1a73(%rip), %rsi      # 0x4004
movl $0x1, %edx
callq 0x2190
leaq 0x10(%rsp), %rax
movl $0x0, (%rax)
xorl %r14d, %r14d
movq %r14, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %r14, 0x20(%rax)
leaq 0x3c20(%rip), %r13      # 0x61e0
leaq 0x8(%rsp), %r15
movq %rsp, %r12
movq (%r14,%r13), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x2da6
incq (%rax)
addq $0x8, %r14
cmpq $0x80, %r14
jne 0x25c8
cmpq $0x5, 0x30(%rsp)
movq 0x20(%rsp), %r15
sbbq $-0x1, %rbx
leaq 0x10(%rsp), %rax
cmpq %rax, %r15
je 0x268f
leaq 0x19fc(%rip), %r13      # 0x400b
leaq 0x19ee(%rip), %rbp      # 0x4004
movq 0x20(%r15), %rsi
movq 0x28(%r15), %r12
testq %rsi, %rsi
je 0x2634
movq 0x39ae(%rip), %rdi      # 0x5fd8
callq 0x20f0
movq %rax, %r14
jmp 0x264f
movl $0x24, %edx
movq 0x3998(%rip), %r14      # 0x5fd8
movq %r14, %rdi
leaq 0x19ee(%rip), %rsi      # 0x4038
callq 0x2190
movl $0x2, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x2190
movq %r14, %rdi
movq %r12, %rsi
callq 0x20f0
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2190
movq %r15, %rdi
callq 0x2100
movq %rax, %r15
leaq 0x10(%rsp), %rax
cmpq %rax, %r15
jne 0x2616
movq 0x3942(%rip), %rdi      # 0x5fd8
leaq 0x1969(%rip), %rsi      # 0x4006
movl $0x7, %edx
callq 0x2190
movq 0x392a(%rip), %rdi      # 0x5fd8
movq %rbx, %rsi
callq 0x20f0
leaq 0x1947(%rip), %rsi      # 0x4004
movl $0x1, %edx
movq %rax, %rdi
callq 0x2190
leaq 0x8(%rsp), %rdi
callq 0x32d2
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x26ec
jmp 0x26ec
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x32d2
jmp 0x2708
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2d0a
movq %rbx, %rdi
callq 0x2220