// File: /workspace/github_cpp_makefile_star2_O2/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 %ebp, %ebp
leaq 0x8(%rsp), %r14
leaq 0x5ea(%rip), %r15       # 0x29b5
leaq 0x608(%rip), %r12       # 0x29da
leaq 0x4d87(%rip), %r13      # 0x7160
xorl %ebx, %ebx
cmpq $0x2710, %rbp           # imm = 0x2710
je 0x2509
movq %r14, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
callq 0x2684
movq %r14, %rdi
leaq 0x3af(%rip), %rsi       # 0x27af
callq 0x2752
movq %r14, %rdi
leaq 0x3c5(%rip), %rsi       # 0x27d4
callq 0x2752
movq %r14, %rdi
leaq 0x3db(%rip), %rsi       # 0x27f9
callq 0x2752
movq %r14, %rdi
leaq 0x3f1(%rip), %rsi       # 0x281e
callq 0x2752
movq %r14, %rdi
leaq 0x407(%rip), %rsi       # 0x2843
callq 0x2752
movq %r14, %rdi
leaq 0x41d(%rip), %rsi       # 0x2868
callq 0x2752
movq %r14, %rdi
leaq 0x433(%rip), %rsi       # 0x288d
callq 0x2752
movq %r14, %rdi
leaq 0x449(%rip), %rsi       # 0x28b2
callq 0x2752
movq %r14, %rdi
leaq 0x45f(%rip), %rsi       # 0x28d7
callq 0x2752
movq %r14, %rdi
leaq 0x475(%rip), %rsi       # 0x28fc
callq 0x2752
movq %r14, %rdi
leaq 0x48b(%rip), %rsi       # 0x2921
callq 0x2752
movq %r14, %rdi
leaq 0x4a1(%rip), %rsi       # 0x2946
callq 0x2752
movq %r14, %rdi
leaq 0x4b7(%rip), %rsi       # 0x296b
callq 0x2752
movq %r14, %rdi
leaq 0x4cd(%rip), %rsi       # 0x2990
callq 0x2752
movq %r14, %rdi
movq %r15, %rsi
callq 0x2752
movq %r14, %rdi
movq %r12, %rsi
callq 0x2752
movq %r14, %rdi
callq 0x2a00
incq %rbp
xorl %eax, %eax
cmpq $0x80, %rax
je 0x23db
xorl %ecx, %ecx
cmpq %rbp, (%rax,%r13)
setne %cl
addq %rcx, %rbx
addq $0x8, %rax
jmp 0x24eb
xorl %r12d, %r12d
movq 0x4ac5(%rip), %r14      # 0x6fd8
leaq 0x1af2(%rip), %r15      # 0x400c
cmpq $0x80, %r12
je 0x2540
movq (%r12,%r13), %rsi
movq %r14, %rdi
callq 0x20f0
movq %rax, %rdi
movq %r15, %rsi
callq 0x2170
addq $0x8, %r12
jmp 0x251a
movq 0x4a91(%rip), %rdi      # 0x6fd8
leaq 0x1ab6(%rip), %rsi      # 0x4004
callq 0x2170
leaq 0x10(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
xorl %r12d, %r12d
leaq 0x4c69(%rip), %r13      # 0x71e0
leaq 0x8(%rsp), %r14
movq %rsp, %r15
cmpq $0x80, %r12
je 0x25a4
movq (%r12,%r13), %rax
movq %rax, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x2a7e
incq (%rax)
addq $0x8, %r12
jmp 0x257f
cmpq $0x5, 0x30(%rsp)
sbbq $-0x1, %rbx
movq 0x20(%rsp), %r13
movq 0x4a1e(%rip), %r14      # 0x6fd8
leaq 0x1a4a(%rip), %r15      # 0x400b
leaq 0x1a3c(%rip), %r12      # 0x4004
leaq 0x10(%rsp), %rax
cmpq %rax, %r13
je 0x2610
movq 0x20(%r13), %rsi
movq 0x28(%r13), %rbp
movq %r14, %rdi
callq 0x2acd
movq %rax, %rdi
movq %r15, %rsi
callq 0x2170
movq %rax, %rdi
movq %rbp, %rsi
callq 0x20f0
movq %rax, %rdi
movq %r12, %rsi
callq 0x2170
movq %r13, %rdi
callq 0x2100
movq %rax, %r13
jmp 0x25c8
movq 0x49c1(%rip), %rdi      # 0x6fd8
leaq 0x19e8(%rip), %rsi      # 0x4006
callq 0x2170
movq %rax, %rdi
movq %rbx, %rsi
callq 0x20f0
leaq 0x19cf(%rip), %rsi      # 0x4004
movq %rax, %rdi
callq 0x2170
leaq 0x8(%rsp), %rdi
callq 0x30c4
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x265f
jmp 0x265f
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x30c4
jmp 0x267b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2a00
movq %rbx, %rdi
callq 0x2220
nop