// File: /workspace/github_c_makefile_star2_O3/dpw[P]skinny-mutex/perf.c
// Function: contention_thread
static void *contention_thread(void *v_thread_info)
{
	struct contention_thread_info *thread_info = v_thread_info;
	struct contention_info *info = thread_info->info;
	int i = thread_info->thread_index;
	int reps = info->thread_reps;
	int j;

	/* Lock our first mutex */
	assert(!mutex_lock(&info->mutexes[i]));

	/* Indicate that we are ready for the test. */
	assert(!pthread_mutex_lock(&info->ready_mutex));
	if (++info->ready_count == CONTENTION_THREAD_COUNT)
		assert(!pthread_cond_signal(&info->ready_cond));
	assert(!pthread_mutex_unlock(&info->ready_mutex));

	/* Line up to start */
	assert(!pthread_mutex_lock(&thread_info->start_mutex));
	assert(!pthread_mutex_unlock(&thread_info->start_mutex));

	thread_info->start = now_usecs();

	for (j = 1; j < reps; j++) {
		int next = (i + 1) % CONTENTION_MUTEX_COUNT;
		assert(!mutex_lock(&info->mutexes[next]));
		assert(!mutex_unlock(&info->mutexes[i]));
		i = next;
	}

	thread_info->stop = now_usecs();

	assert(!mutex_unlock(&info->mutexes[i]));
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r13
movq (%rdi), %r15
movl 0x30(%rdi), %r14d
movl 0x84(%r15), %ebp
movslq %r14d, %r12
movl $0x1, %ecx
xorl %eax, %eax
lock
cmpxchgq %rcx, (%r15,%r12,8)
jne 0x20ec
leaq 0x28(%r15), %rbx
movq %rbx, %rdi
callq 0x11b0
testl %eax, %eax
jne 0x2105
movl 0x80(%r15), %eax
incl %eax
movl %eax, 0x80(%r15)
cmpl $0x4, %eax
jne 0x200f
leaq 0x50(%r15), %rdi
callq 0x10d0
testl %eax, %eax
jne 0x2181
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x2124
leaq 0x8(%r13), %rbx
movq %rbx, %rdi
callq 0x11b0
testl %eax, %eax
jne 0x2143
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x2162
callq 0x1f5d
movq %r13, (%rsp)
movq %rax, 0x38(%r13)
cmpl $0x2, %ebp
jl 0x20bf
decl %ebp
xorl %edx, %edx
movl $0x1, %ebx
leal 0x1(%r14), %eax
movslq %eax, %r13
imulq $0x66666667, %r13, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x21, %rax
addl %ecx, %eax
leal (%rax,%rax,4), %eax
subl %eax, %r13d
movslq %r13d, %r12
xorl %eax, %eax
lock
cmpxchgq %rbx, (%r15,%r12,8)
jne 0x20a5
movslq %r14d, %rcx
movl $0x1, %eax
lock
cmpxchgq %rdx, (%r15,%rcx,8)
jne 0x20b2
movl %r13d, %r14d
decl %ebp
jne 0x205e
jmp 0x20bf
leaq (%r15,%r12,8), %rdi
callq 0x124d
xorl %edx, %edx
jmp 0x208c
leaq (%r15,%rcx,8), %rdi
callq 0x1278
xorl %edx, %edx
jmp 0x209c
callq 0x1f5d
movq (%rsp), %rcx
movq %rax, 0x40(%rcx)
xorl %ecx, %ecx
movl $0x1, %eax
lock
cmpxchgq %rcx, (%r15,%r12,8)
jne 0x20fa
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq (%r15,%r12,8), %rdi
callq 0x1222
jmp 0x1fd5
leaq (%r15,%r12,8), %rdi
callq 0x12a3
jmp 0x20db
leaq 0x1436(%rip), %rdi      # 0x3542
leaq 0x1098(%rip), %rsi      # 0x31ab
leaq 0x1408(%rip), %rcx      # 0x3522
movl $0x95, %edx
callq 0x10c0
leaq 0x1467(%rip), %rdi      # 0x3592
leaq 0x1079(%rip), %rsi      # 0x31ab
leaq 0x13e9(%rip), %rcx      # 0x3522
movl $0x98, %edx
callq 0x10c0
leaq 0x1472(%rip), %rdi      # 0x35bc
leaq 0x105a(%rip), %rsi      # 0x31ab
leaq 0x13ca(%rip), %rcx      # 0x3522
movl $0x9b, %edx
callq 0x10c0
leaq 0x1482(%rip), %rdi      # 0x35eb
leaq 0x103b(%rip), %rsi      # 0x31ab
leaq 0x13ab(%rip), %rcx      # 0x3522
movl $0x9c, %edx
callq 0x10c0
leaq 0x13e2(%rip), %rdi      # 0x356a
leaq 0x101c(%rip), %rsi      # 0x31ab
leaq 0x138c(%rip), %rcx      # 0x3522
movl $0x97, %edx
callq 0x10c0