// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1448, %rsp           # imm = 0x1448
leaq 0x1e49(%rip), %rdi      # 0x5224
callq 0x2230
leaq 0x1e45(%rip), %rdi      # 0x522c
callq 0x2230
leaq -0x1468(%rbp), %rbx
movq %rbx, %rdi
callq 0x3008
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, -0xe0(%rbp)
leaq -0x1468(%rbp), %rdi
callq 0x2180
movabsq $0x271000000001, %rax   # imm = 0x271000000001
leaq -0xd0(%rbp), %rcx
movq %rax, -0x8(%rcx)
leaq -0xa0(%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 -0x1468(%rbp), %rdi
leaq -0x70(%rbp), %rcx
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x3b8e
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 %r14d, %r14d
leaq -0x4c(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x1468(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0xe0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %r13
cmpq -0x30(%rbp), %r13
je 0x3508
movq %r13, %rdi
leaq -0x70(%rbp), %rsi
callq 0x37e2
addq $0x8, -0x38(%rbp)
jmp 0x35d3
movq -0x40(%rbp), %rax
movq %r13, %r12
movq %rax, -0x48(%rbp)
subq %rax, %r12
movabsq $0x7ffffffffffffff8, %rax # imm = 0x7FFFFFFFFFFFFFF8
cmpq %rax, %r12
je 0x3724
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
movq %r15, -0x58(%rbp)
je 0x356d
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x43b4
jmp 0x356f
xorl %eax, %eax
leaq (%rax,%r12,8), %r12
movq %r12, %rdi
leaq -0x70(%rbp), %rsi
movq %rax, %r15
callq 0x37e2
movq %r15, %r12
cmpq %r13, -0x48(%rbp)
je 0x35ad
movq %r15, %r12
movq -0x48(%rbp), %rax
movq %rbx, (%r12)
movq (%rax), %rcx
movq %rcx, (%r12)
movq %rbx, (%rax)
addq $0x8, %rax
addq $0x8, %r12
cmpq %r13, %rax
jne 0x3592
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x35bb
callq 0x2190
addq $0x8, %r12
movq %r15, -0x40(%rbp)
movq %r12, -0x38(%rbp)
movq -0x58(%rbp), %rax
leaq (%r15,%rax,8), %rax
movq %rax, -0x30(%rbp)
incl %r14d
cmpl $0xc, %r14d
jne 0x34ca
xorl %ebx, %ebx
movq -0x40(%rbp), %rdi
addq %rbx, %rdi
callq 0x2270
addq $0x8, %rbx
cmpq $0x60, %rbx
jne 0x35e2
movq -0x1468(%rbp), %rax
movq -0x1458(%rbp), %rcx
movl -0x1450(%rbp), %edx
cmpq %rcx, %rax
setne %sil
testl %edx, %edx
setne %dil
orb %sil, %dil
xorl %r14d, %r14d
cmpb $0x1, %dil
jne 0x3669
xorl %esi, %esi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
xorl %r8d, %r8d
movq (%rax), %r9
btq %r8, %r9
cmovael %edi, %r14d
jae 0x3669
xorl %r9d, %r9d
cmpl $0x3f, %r8d
leal 0x1(%r8), %r8d
sete %r9b
leaq (%rax,%r9,8), %rax
cmovel %esi, %r8d
cmpq %rcx, %rax
setne %r9b
cmpl %edx, %r8d
setne %r10b
orb %r9b, %r10b
jne 0x3632
testl %r14d, %r14d
leaq 0x1b8a(%rip), %rax      # 0x51fd
leaq 0x1b46(%rip), %rsi      # 0x51c0
cmoveq %rax, %rsi
movl $0xc, %eax
movl $0x3c, %edx
cmoveq %rax, %rdx
movq 0x4945(%rip), %rbx      # 0x7fd8
movq %rbx, %rdi
callq 0x21d0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x491f(%rip), %rdi      # 0x7fd8
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq -0x40(%rbp), %rdi
callq 0x3bf4
movq -0x1468(%rbp), %rdi
testq %rdi, %rdi
je 0x3703
callq 0x2190
xorl %eax, %eax
movq %rax, -0x1468(%rbp)
movl %eax, -0x1460(%rbp)
movq %rax, -0x1458(%rbp)
movl %eax, -0x1450(%rbp)
movq %rax, -0x1448(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3c2c
movl %r14d, %eax
addq $0x1448, %rsp           # imm = 0x1448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1adf(%rip), %rdi      # 0x520a
callq 0x20e0
movq %rax, %rbx
jmp 0x37ce
jmp 0x3782
movq %rax, %rbx
leaq -0x1468(%rbp), %rdi
callq 0x2180
jmp 0x37da
jmp 0x3782
jmp 0x378e
movq %rax, %rdi
callq 0x20c0
testq %r15, %r15
jne 0x376b
cmpq $0x0, (%r12)
je 0x3773
callq 0x2090
movq %r15, %rdi
callq 0x2190
callq 0x2200
movq %rax, %rbx
callq 0x2250
jmp 0x3791
movq %rax, %rdi
callq 0x2c4d
jmp 0x378e
jmp 0x378e
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x3bf4
movq -0x1468(%rbp), %rdi
testq %rdi, %rdi
je 0x37ce
callq 0x2190
xorl %eax, %eax
movq %rax, -0x1468(%rbp)
movl %eax, -0x1460(%rbp)
movq %rax, -0x1458(%rbp)
movl %eax, -0x1450(%rbp)
movq %rax, -0x1448(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3c2c
movq %rbx, %rdi
callq 0x2280