// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]spiped/liball/../lib/util/pthread_create_blocking_np.c
// Function: pthread_create_blocking_np
int
pthread_create_blocking_np(pthread_t * restrict thread,
    const pthread_attr_t * restrict attr,
    void * (*start_routine)(void *), void * restrict arg)
{
	struct wrapped_cookie * U;
	int rc;

	/*
	 * Allocate our cookie and store parameters.  The C standard does not
	 * require that variables with automatic storage duration are
	 * accessible by other threads; POSIX (and thus pthreads) does provide
	 * that guarantee, but out of an abundance of caution we take the
	 * option of using malloc in case this code ends up running on a
	 * non-POSIX system.
	 */
	if ((U = malloc(sizeof(struct wrapped_cookie))) == NULL) {
		rc = errno;
		goto err0;
	}
	U->start_routine = start_routine;
	U->arg = arg;

	/* Initialize synchronization-related variables. */
	if ((rc = pthread_mutex_init(&U->mutex, NULL)) != 0)
		goto err1;
	if ((rc = pthread_cond_init(&U->cond, NULL)) != 0)
		goto err2;
	U->running = 0;
	U->rc_sync = 0;

	/* Lock mutex. */
	if ((rc = pthread_mutex_lock(&U->mutex)) != 0)
		goto err3;

	/* Create the thread. */
	if ((rc = pthread_create(thread, attr, wrapped_thread, U)) != 0) {
		/*
		 * Don't record any pthread_mutex_unlock() error here; the
		 * error from pthread_create() is more important.
		 */
		pthread_mutex_unlock(&U->mutex);
		goto err3;
	}

	/* Wait for the thread to have started, then unlock the mutex. */
	while (!U->running) {
		/* Wait until signalled. */
		if ((rc = pthread_cond_wait(&U->cond, &U->mutex)) != 0)
			goto err5;

		/* Quit if there was an error in the synchronization. */
		if ((rc = U->rc_sync) != 0)
			goto err5;
	}
	if ((rc = pthread_mutex_unlock(&U->mutex)) != 0)
		goto err4;

	/* Clean up synchronization-related variables. */
	if ((rc = pthread_cond_destroy(&U->cond)) != 0)
		goto err2;
	if ((rc = pthread_mutex_destroy(&U->mutex)) != 0)
		goto err1;

	/* Clean up. */
	free(U);

	/* Success! */
	return (0);

err5:
	/*
	 * Don't record any errors in this clean-up; the existing value of rc
	 * is more important.
	 */
	pthread_mutex_unlock(&U->mutex);
err4:
	pthread_cancel(*thread);
	pthread_join(*thread, NULL);
err3:
	pthread_cond_destroy(&U->cond);
err2:
	pthread_mutex_destroy(&U->mutex);
err1:
	free(U);
err0:
	/* Failure! */
	return (rc);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x70, %edi
callq 0x21e0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x530b
callq 0x2080
movl (%rax), %eax
movl %eax, -0x34(%rbp)
jmp 0x54aa
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x22f0
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x5340
jmp 0x54a1
movq -0x30(%rbp), %rdi
addq $0x38, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x21c0
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x535e
jmp 0x5494
movq -0x30(%rbp), %rax
movl $0x0, 0x68(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x6c(%rax)
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x2300
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x538e
jmp 0x5487
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rcx
leaq 0x11f(%rip), %rdx       # 0x54c0
callq 0x2210
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x53c0
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x21d0
jmp 0x5487
jmp 0x53c2
movq -0x30(%rbp), %rax
cmpl $0x0, 0x68(%rax)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x53d5
jmp 0x5407
movq -0x30(%rbp), %rdi
addq $0x38, %rdi
movq -0x30(%rbp), %rsi
addq $0x10, %rsi
callq 0x20d0
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x53f4
jmp 0x545e
movq -0x30(%rbp), %rax
movl 0x6c(%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x5405
jmp 0x545e
jmp 0x53c2
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x21d0
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x541e
jmp 0x546b
movq -0x30(%rbp), %rdi
addq $0x38, %rdi
callq 0x2220
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x5435
jmp 0x5494
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x2100
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
je 0x544c
jmp 0x54a1
movq -0x30(%rbp), %rdi
callq 0x2030
movl $0x0, -0x4(%rbp)
jmp 0x54b0
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x21d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x22d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2290
movq -0x30(%rbp), %rdi
addq $0x38, %rdi
callq 0x2220
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x2100
movq -0x30(%rbp), %rdi
callq 0x2030
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)