// File: /workspace/github_cpp_makefile_star2_O2/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 0x1e8d(%rip), %rdi      # 0x5204
callq 0x2210
leaq 0x1e89(%rip), %rdi      # 0x520c
callq 0x2210
leaq -0x1470(%rbp), %rbx
movq %rbx, %rdi
callq 0x2e48
movq %rbx, %rdi
callq 0x21d0
xorl %r15d, %r15d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
divl %ecx
cmpl $0x1, %edx
adcl $0x0, %edx
leaq -0xd8(%rbp), %rbx
movq %rdx, -0x10(%rbx)
leaq -0x1470(%rbp), %rdi
callq 0x2e9e
movabsq $0x271000000001, %rax   # imm = 0x271000000001
movq %rax, -0x8(%rbx)
leaq -0xa8(%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)
andl $0x0, 0x8(%rax)
movq $0x64, 0x10(%rax)
andq $0x0, 0x18(%rax)
movb $0x0, 0x20(%rax)
andq $0x0, 0x28(%rax)
leaq -0x40(%rbp), %rdx
movb $0x1, (%rdx)
leaq -0x1470(%rbp), %rbx
leaq -0x78(%rbp), %rcx
movl $0xf4240, %esi          # imm = 0xF4240
movq %rbx, %rdi
callq 0x38d0
leaq -0x40(%rbp), %rax
andq $0x0, 0x10(%rax)
movq %rax, %r14
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq -0x44(%rbp), %rcx
xorl %eax, %eax
xchgl %eax, (%rcx)
pushq $0xc
popq %r12
subl $0x1, %r12d
jb 0x3544
leaq -0x44(%rbp), %rax
movq %rax, -0x78(%rbp)
movq %rbx, -0x70(%rbp)
leaq -0xe8(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq -0x30(%rbp), %r15
je 0x3493
movq %r15, %rdi
leaq -0x78(%rbp), %rsi
callq 0x369a
movq -0x38(%rbp), %r15
addq $0x8, %r15
movq %r15, -0x38(%rbp)
jmp 0x3452
movq %r14, %rdi
pushq $0x1
popq %rsi
leaq 0x1d4a(%rip), %rdx      # 0x51ea
callq 0x4298
movq %rax, %rbx
movq -0x40(%rbp), %r13
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x42de
movq %rbx, -0x58(%rbp)
movq %r15, %r14
movq %r13, %rbx
subq %r13, %r14
addq %rax, %r14
movq %r14, %rdi
leaq -0x78(%rbp), %rsi
movq %r15, %r13
movq %rax, %r15
callq 0x369a
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, -0x50(%rbp)
movq %r15, %rdx
leaq -0x40(%rbp), %r15
movq %r15, %rcx
callq 0x4328
leaq 0x8(%rax), %rdx
movq %r13, %rdi
movq -0x60(%rbp), %rsi
movq %r15, %r14
movq %r15, %rcx
callq 0x4328
movq %rax, %r15
testq %rbx, %rbx
je 0x3520
movq %rbx, %rdi
callq 0x2180
movq -0x50(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %r15, -0x38(%rbp)
movq -0x58(%rbp), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
leaq -0x1470(%rbp), %rbx
jmp 0x3452
xorl %ebx, %ebx
cmpq $0x60, %rbx
je 0x355e
movq -0x40(%rbp), %rdi
addq %rbx, %rdi
callq 0x2250
addq $0x8, %rbx
jmp 0x3546
movq -0x1470(%rbp), %rax
movq -0x1460(%rbp), %rcx
xorl %edx, %edx
movl -0x1458(%rbp), %esi
xorl %edi, %edi
cmpq %rcx, %rax
jne 0x357f
cmpl %esi, %edi
je 0x359e
movq (%rax), %r8
btq %rdi, %r8
jae 0x35bd
xorl %r8d, %r8d
cmpl $0x3f, %edi
leal 0x1(%rdi), %edi
sete %r8b
leaq (%rax,%r8,8), %rax
cmovel %edx, %edi
jmp 0x3576
movq 0x4a33(%rip), %rdi      # 0x7fd8
leaq 0x1c31(%rip), %rsi      # 0x51dd
callq 0x21a0
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x20f0
jmp 0x35db
movq 0x4a14(%rip), %rdi      # 0x7fd8
leaq 0x1bd5(%rip), %rsi      # 0x51a0
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
pushq $-0x1
popq %rbx
leaq -0x40(%rbp), %rdi
callq 0x3930
leaq -0x1470(%rbp), %rdi
callq 0x395c
leaq -0xd8(%rbp), %rdi
callq 0x3970
movl %ebx, %eax
addq $0x1448, %rsp           # imm = 0x1448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x3686
movq %rax, %rbx
leaq -0x1470(%rbp), %rdi
callq 0x2e9e
jmp 0x3692
jmp 0x366e
movq %rax, %rdi
callq 0x20c0
testq %r15, %r15
jne 0x363f
movq %r14, %rdi
callq 0x29f6
jmp 0x3655
movq %r15, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3b98
movq %rbx, %rdi
callq 0x2180
callq 0x21e0
movq %rax, %rbx
callq 0x2230
jmp 0x3671
movq %rax, %rdi
callq 0x2a61
jmp 0x366e
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x3930
leaq -0x1470(%rbp), %rdi
callq 0x395c
leaq -0xd8(%rbp), %rdi
callq 0x3970
movq %rbx, %rdi
callq 0x2260