// File: /workspace/github_cpp_makefile_star2_O3/shutow[P]shared_mutex/test2.cpp
// Function: test2()
int test2()
{
	printf("test 2:\n");
	printf("collision detection\n");

	Test t;
	std::vector<bool> rv(1000000, true);
	std::vector<std::thread> th;
	std::atomic<int> count;
	count = 0;
	const int numthreads = 12;
	for (int i = 0; i < numthreads; ++i)
	{
		th.emplace_back([&]()
		{
			while (true)
			{
				int c = count++;
				if (c >= (int)rv.size()) return;
				rv[c] = t.test();
			}
		});
	}
	for (int i = 0; i < numthreads; ++i) th[i].join();
	int res = 0;
	for (auto n : rv)
	{
		if (!n)
		{
			res = -1;
			break;
		}
	}
	if (res != 0)
		std::cout << "A collision between reading and writing threads had occured." << std::endl;
	else
		std::cout << "All went OK." << std::endl;
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1438, %rsp           # imm = 0x1438
leaq 0x1ec5(%rip), %rdi      # 0x5224
callq 0x2230
leaq 0x1ec1(%rip), %rdi      # 0x522c
callq 0x2230
leaq -0x1460(%rbp), %rbx
movq %rbx, %rdi
callq 0x2f8a
movq %rbx, %rdi
callq 0x21f0
movl %eax, %ecx
leaq (%rcx,%rcx,2), %rcx
shrq $0x20, %rcx
movl %eax, %edx
subl %ecx, %edx
shrl %edx
addl %ecx, %edx
shrl $0x1e, %edx
movl %edx, %ecx
shll $0x1f, %ecx
orl %edx, %ecx
leal (%rax,%rcx), %edx
cmpl $0x1, %edx
adcl %eax, %ecx
movq %rcx, -0xd8(%rbp)
leaq -0x1460(%rbp), %rdi
callq 0x2180
movabsq $0x271000000001, %rax   # imm = 0x271000000001
leaq -0xc8(%rbp), %rcx
movq %rax, -0x8(%rcx)
leaq -0x98(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movl $0x0, 0x8(%rax)
movq $0x64, 0x10(%rax)
xorl %ebx, %ebx
movq %rbx, 0x18(%rax)
movb $0x0, 0x20(%rax)
movq %rbx, 0x28(%rax)
leaq -0x40(%rbp), %rdx
movb $0x1, (%rdx)
leaq -0x1460(%rbp), %rdi
leaq -0x68(%rbp), %rcx
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x3a1c
leaq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq -0x4c(%rbp), %rcx
xorl %eax, %eax
xchgl %eax, (%rcx)
xorl %r13d, %r13d
leaq -0x4c(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x1460(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0xd8(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq -0x30(%rbp), %r13
je 0x348f
movq %r13, %rdi
leaq -0x68(%rbp), %rsi
callq 0x3736
movq -0x38(%rbp), %r13
addq $0x8, %r13
movq %r13, -0x38(%rbp)
jmp 0x3556
movq -0x40(%rbp), %rax
movq %r13, %r12
movq %rax, -0x48(%rbp)
subq %rax, %r12
movabsq $0x7ffffffffffffff8, %rax # imm = 0x7FFFFFFFFFFFFFF8
cmpq %rax, %r12
je 0x36a1
sarq $0x3, %r12
cmpq $0x1, %r12
movq %r12, %rax
adcq $0x0, %rax
leaq (%rax,%r12), %r15
movabsq $0xfffffffffffffff, %rcx # imm = 0xFFFFFFFFFFFFFFF
cmpq %rcx, %r15
cmovaeq %rcx, %r15
addq %r12, %rax
cmovbq %rcx, %r15
testq %r15, %r15
je 0x34f3
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x425a
movq %rax, %r14
jmp 0x34f6
xorl %r14d, %r14d
leaq (%r14,%r12,8), %r12
movq %r12, %rdi
leaq -0x68(%rbp), %rsi
callq 0x3736
movq %r14, %r12
cmpq %r13, -0x48(%rbp)
je 0x3531
movq %r14, %r12
movq -0x48(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%r12)
movq $0x0, (%rax)
addq $0x8, %rax
addq $0x8, %r12
cmpq %r13, %rax
jne 0x3516
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x353f
callq 0x2190
addq $0x8, %r12
movq %r14, -0x40(%rbp)
movq %r12, -0x38(%rbp)
leaq (%r14,%r15,8), %rax
movq %rax, -0x30(%rbp)
movq %r12, %r13
incl %ebx
cmpl $0xc, %ebx
jne 0x344e
xorl %ebx, %ebx
movq -0x40(%rbp), %rdi
addq %rbx, %rdi
callq 0x2270
addq $0x8, %rbx
cmpq $0x60, %rbx
jne 0x3563
movq -0x1460(%rbp), %rax
movq -0x1450(%rbp), %rcx
movl -0x1448(%rbp), %edx
cmpq %rcx, %rax
sete %sil
testl %edx, %edx
sete %dil
testb %dil, %sil
jne 0x35d2
xorl %esi, %esi
xorl %edi, %edi
movq (%rax), %r8
btq %rdi, %r8
jae 0x361c
xorl %r8d, %r8d
cmpl $0x3f, %edi
leal 0x1(%rdi), %edi
sete %r8b
leaq (%rax,%r8,8), %rax
cmovel %esi, %edi
cmpq %rcx, %rax
sete %r8b
cmpl %edx, %edi
sete %r9b
testb %r9b, %r8b
je 0x35a3
movq 0x49ff(%rip), %rbx      # 0x7fd8
leaq 0x1c1d(%rip), %rsi      # 0x51fd
movl $0xc, %edx
movq %rbx, %rdi
callq 0x21d0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x49cd(%rip), %rdi      # 0x7fd8
callq 0x2030
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x2120
jmp 0x3667
movq 0x49b5(%rip), %rbx      # 0x7fd8
leaq 0x1b96(%rip), %rsi      # 0x51c0
movl $0x3c, %edx
movq %rbx, %rdi
callq 0x21d0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x4983(%rip), %rdi      # 0x7fd8
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2120
leaq -0x40(%rbp), %rdi
callq 0x3a82
movq -0x1460(%rbp), %rdi
testq %rdi, %rdi
je 0x3681
callq 0x2190
leaq -0xc8(%rbp), %rdi
callq 0x3aba
movl %ebx, %eax
addq $0x1438, %rsp           # imm = 0x1438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b62(%rip), %rdi      # 0x520a
callq 0x20e0
movq %rax, %rbx
jmp 0x3722
jmp 0x36f9
movq %rax, %rbx
leaq -0x1460(%rbp), %rdi
callq 0x2180
jmp 0x372e
jmp 0x36f9
jmp 0x3705
movq %rax, %rdi
callq 0x20c0
testq %r14, %r14
jne 0x36e2
cmpq $0x0, (%r12)
je 0x36ea
callq 0x2090
movq %r14, %rdi
callq 0x2190
callq 0x2200
movq %rax, %rbx
callq 0x2250
jmp 0x3708
movq %rax, %rdi
callq 0x2bd5
jmp 0x3705
jmp 0x3705
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x3a82
movq -0x1460(%rbp), %rdi
testq %rdi, %rdi
je 0x3722
callq 0x2190
leaq -0xc8(%rbp), %rdi
callq 0x3aba
movq %rbx, %rdi
callq 0x2280