// File: /workspace/github_c_makefile_star2_O2/dpw[P]skinny-mutex/perf.c
// Function: contention
static void contention(struct test_results *res)
{
	struct contention_info info;
	struct contention_thread_info thread_infos[CONTENTION_THREAD_COUNT];
	pthread_t threads[CONTENTION_THREAD_COUNT];
	int i;

	for (i = 0; i < CONTENTION_MUTEX_COUNT; i++)
		assert(!mutex_init(&info.mutexes[i]));

	assert(!pthread_mutex_init(&info.ready_mutex, NULL));
	assert(!pthread_cond_init(&info.ready_cond, NULL));
	info.ready_count = 0;
	info.thread_reps = res->reps / CONTENTION_THREAD_COUNT;

	for (i = 0; i < CONTENTION_THREAD_COUNT; i++) {
		thread_infos[i].info = &info;
		thread_infos[i].thread_index = i;
		assert(!pthread_mutex_init(&thread_infos[i].start_mutex, NULL));
		assert(!pthread_mutex_lock(&thread_infos[i].start_mutex));
		assert(!pthread_create(&threads[i], NULL,
				       contention_thread, &thread_infos[i]));
	}

	assert(!pthread_mutex_lock(&info.ready_mutex));
	while (info.ready_count < CONTENTION_THREAD_COUNT)
		assert(!pthread_cond_wait(&info.ready_cond,
					  &info.ready_mutex));
	assert(!pthread_mutex_unlock(&info.ready_mutex));

	for (i = 0; i < CONTENTION_THREAD_COUNT; i++)
		assert(!pthread_mutex_unlock(&thread_infos[i].start_mutex));

	for (i = 0; i < CONTENTION_THREAD_COUNT; i++) {
		assert(!pthread_join(threads[i], NULL));
		assert(!pthread_mutex_destroy(&thread_infos[i].start_mutex));
	}

	for (i = 0; i < CONTENTION_MUTEX_COUNT; i++)
		assert(!mutex_destroy(&info.mutexes[i]));

	assert(!pthread_mutex_destroy(&info.ready_mutex));
	assert(!pthread_cond_destroy(&info.ready_cond));

	res->start = thread_infos[0].start;
	res->stop = thread_infos[0].stop;
	for (i = 1; i < CONTENTION_THREAD_COUNT; i++) {
		if (thread_infos[i].start < res->start)
			res->start = thread_infos[i].start;
		if (thread_infos[i].stop > res->stop)
			res->stop = thread_infos[i].stop;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, %rbx
xorl %eax, %eax
cmpq $0x5, %rax
je 0x1a56
andq $0x0, 0x38(%rsp,%rax,8)
incq %rax
jmp 0x1a45
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x11a0
testl %eax, %eax
jne 0x1d46
leaq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0x10f0
testl %eax, %eax
jne 0x1d65
leaq 0x38(%rsp), %r14
andl $0x0, 0x80(%r14)
movq %rbx, 0x8(%rsp)
movl (%rbx), %eax
pushq $0x4
popq %rcx
cltd
idivl %ecx
movl %eax, 0x84(%r14)
leaq 0x10(%rsp), %r12
leaq 0xc0(%rsp), %r13
xorl %ebx, %ebx
leaq 0x3c4(%rip), %rbp       # 0x1e7c
cmpq $0x4, %rbx
je 0x1b2a
movq %r14, (%r13)
movl %ebx, 0x30(%r13)
leaq 0x8(%r13), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x11a0
testl %eax, %eax
jne 0x1d08
movq %r15, %rdi
callq 0x11b0
testl %eax, %eax
jne 0x1ce9
movq %r12, %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x1140
incq %rbx
addq $0x8, %r12
addq $0x48, %r13
testl %eax, %eax
je 0x1ab8
leaq 0x1825(%rip), %rdi      # 0x3337
leaq 0x1692(%rip), %rsi      # 0x31ab
leaq 0x172e(%rip), %rcx      # 0x324e
movl $0xc2, %edx
callq 0x10c0
leaq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x11b0
testl %eax, %eax
jne 0x1d84
leaq 0x88(%rsp), %r15
cmpl $0x3, 0xb8(%rsp)
jg 0x1b7f
movq %r15, %rdi
movq %r14, %rsi
callq 0x1060
testl %eax, %eax
je 0x1b47
leaq 0x183f(%rip), %rdi      # 0x33a6
leaq 0x163d(%rip), %rsi      # 0x31ab
leaq 0x16d9(%rip), %rcx      # 0x324e
movl $0xc8, %edx
callq 0x10c0
movq %r14, %rdi
callq 0x1100
testl %eax, %eax
jne 0x1da3
pushq $0x8
popq %rcx
leaq 0x48(%rcx), %rbx
cmpq $0x170, %rbx            # imm = 0x170
je 0x1bd5
leaq (%rsp,%rcx), %rdi
addq $0xc0, %rdi
callq 0x1100
movq %rbx, %rcx
testl %eax, %eax
je 0x1b92
leaq 0x184a(%rip), %rdi      # 0x3407
leaq 0x15e7(%rip), %rsi      # 0x31ab
leaq 0x1683(%rip), %rcx      # 0x324e
movl $0xcc, %edx
callq 0x10c0
leaq 0xc8(%rsp), %r12
xorl %ebx, %ebx
cmpq $0x4, %rbx
je 0x1c2b
movq 0x10(%rsp,%rbx,8), %rdi
xorl %esi, %esi
callq 0x1180
testl %eax, %eax
jne 0x1d27
movq %r12, %rdi
callq 0x1090
incq %rbx
addq $0x48, %r12
testl %eax, %eax
je 0x1bdf
leaq 0x1848(%rip), %rdi      # 0x345b
leaq 0x1591(%rip), %rsi      # 0x31ab
leaq 0x162d(%rip), %rcx      # 0x324e
movl $0xd0, %edx
callq 0x10c0
xorl %eax, %eax
movq 0x8(%rsp), %rbx
cmpq $0x5, %rax
je 0x1c63
cmpq $0x0, 0x38(%rsp,%rax,8)
leaq 0x1(%rax), %rax
je 0x1c32
leaq 0x1845(%rip), %rdi      # 0x3490
leaq 0x1559(%rip), %rsi      # 0x31ab
leaq 0x15f5(%rip), %rcx      # 0x324e
movl $0xd4, %edx
callq 0x10c0
movq %r14, %rdi
callq 0x1090
testl %eax, %eax
jne 0x1dc2
movq %r15, %rdi
callq 0x1160
testl %eax, %eax
jne 0x1de1
movq 0xf8(%rsp), %rax
movq %rax, 0x8(%rbx)
movq 0x100(%rsp), %rdx
movq %rdx, 0x10(%rbx)
movl $0x88, %ecx
cmpq $0x160, %rcx            # imm = 0x160
je 0x1cd7
movq 0xb8(%rsp,%rcx), %rsi
cmpq %rax, %rsi
jge 0x1cbd
movq %rsi, 0x8(%rbx)
movq %rsi, %rax
movq 0xc0(%rsp,%rcx), %rsi
cmpq %rdx, %rsi
jle 0x1cd1
movq %rsi, 0x10(%rbx)
movq %rsi, %rdx
addq $0x48, %rcx
jmp 0x1ca0
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1615(%rip), %rdi      # 0x3305
leaq 0x14b4(%rip), %rsi      # 0x31ab
leaq 0x1550(%rip), %rcx      # 0x324e
movl $0xc0, %edx
callq 0x10c0
leaq 0x15be(%rip), %rdi      # 0x32cd
leaq 0x1495(%rip), %rsi      # 0x31ab
leaq 0x1531(%rip), %rcx      # 0x324e
movl $0xbf, %edx
callq 0x10c0
leaq 0x170d(%rip), %rdi      # 0x343b
leaq 0x1476(%rip), %rsi      # 0x31ab
leaq 0x1512(%rip), %rcx      # 0x324e
movl $0xcf, %edx
callq 0x10c0
leaq 0x1528(%rip), %rdi      # 0x3275
leaq 0x1457(%rip), %rsi      # 0x31ab
leaq 0x14f3(%rip), %rcx      # 0x324e
movl $0xb7, %edx
callq 0x10c0
leaq 0x1536(%rip), %rdi      # 0x32a2
leaq 0x1438(%rip), %rsi      # 0x31ab
leaq 0x14d4(%rip), %rcx      # 0x324e
movl $0xb8, %edx
callq 0x10c0
leaq 0x15f4(%rip), %rdi      # 0x337f
leaq 0x1419(%rip), %rsi      # 0x31ab
leaq 0x14b5(%rip), %rcx      # 0x324e
movl $0xc5, %edx
callq 0x10c0
leaq 0x1634(%rip), %rdi      # 0x33de
leaq 0x13fa(%rip), %rsi      # 0x31ab
leaq 0x1496(%rip), %rcx      # 0x324e
movl $0xc9, %edx
callq 0x10c0
leaq 0x16e8(%rip), %rdi      # 0x34b1
leaq 0x13db(%rip), %rsi      # 0x31ab
leaq 0x1477(%rip), %rcx      # 0x324e
movl $0xd6, %edx
callq 0x10c0
leaq 0x16f3(%rip), %rdi      # 0x34db
leaq 0x13bc(%rip), %rsi      # 0x31ab
leaq 0x1458(%rip), %rcx      # 0x324e
movl $0xd7, %edx
callq 0x10c0