// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]spiped/liball/../lib/dnsthread/dnsthread.c
// Function: workthread
static void *
workthread(void * cookie)
{
	struct dnsthread_internal * T = cookie;
	char * addr;
	struct sock_addr ** sas;
	int res_errno = 0;
	int rc;
	uint8_t zero = 0;

	/* Grab the mutex. */
	if ((rc = pthread_mutex_lock(&T->mtx)) != 0) {
		warn0("pthread_mutex_lock: %s", strerror(rc));
		exit(1);
	}

	/* Infinite loop doing work until told to suicide. */
	do {
		/*
		 * Sleep on the condition variable as long as we're in the
		 * SLEEPING state.
		 */
		while (T->state == THREAD_SLEEPING) {
			/* Sleep until we're woken up. */
			if ((rc = pthread_cond_wait(&T->cv, &T->mtx)) != 0) {
				warn0("pthread_cond_wait: %s", strerror(rc));
				exit(1);
			}
		}

		/* If we need to kill ourself, stop looping. */
		if (T->state == THREAD_SUICIDE)
			break;

		/* Grab the work. */
		addr = T->addr;

		/* Release the mutex. */
		if ((rc = pthread_mutex_unlock(&T->mtx)) != 0) {
			warn0("pthread_mutex_unlock: %s", strerror(rc));
			exit(1);
		}

		/* Perform the address resolution. */
		if ((sas = sock_resolve(addr)) == NULL)
			res_errno = errno;

		/* Grab the mutex again. */
		if ((rc = pthread_mutex_lock(&T->mtx)) != 0) {
			warn0("pthread_mutex_lock: %s", strerror(rc));
			exit(1);
		}

		/* Write the answer back. */
		T->sas = sas;
		T->res_errno = res_errno;

		/* Send a completion message. */
		if (noeintr_write(T->wakeupsock[0], &zero, 1) != 1) {
			warnp("Error writing to wakeup socket");
			exit(1);
		}

		/* Return to sleeping, unless we were instructed to die. */
		if (T->state != THREAD_SUICIDE)
			T->state = THREAD_SLEEPING;
	} while (1);

	/* Close the socket pair. */
	if (close(T->wakeupsock[1]))
		warnp("close");
	if (close(T->wakeupsock[0]))
		warnp("close");

	/* Destroy the condition variable. */
	if ((rc = pthread_cond_destroy(&T->cv)) != 0) {
		warn0("pthread_cond_destroy: %s", strerror(rc));
		exit(1);
	}

	/* Release the mutex. */
	if ((rc = pthread_mutex_unlock(&T->mtx)) != 0) {
		warn0("pthread_mutex_unlock: %s", strerror(rc));
		exit(1);
	}

	/* Destroy the mutex. */
	if ((rc = pthread_mutex_destroy(&T->mtx)) != 0) {
		warn0("pthread_mutex_destroy: %s", strerror(rc));
		exit(1);
	}

	/* Free the control structure. */
	free(T);

	/* Successful thread termination. */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movb $0x0, 0x7(%rsp)
leaq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0x2380
testl %eax, %eax
jne 0x543b
leaq 0x30(%rbx), %r15
xorl %ebp, %ebp
leaq 0x7(%rsp), %r12
movl 0x60(%rbx), %eax
testl %eax, %eax
jne 0x52d1
movq %r15, %rdi
movq %r14, %rsi
callq 0x2100
testl %eax, %eax
je 0x52b6
jmp 0x540e
cmpl $0x2, %eax
je 0x534b
movq 0x70(%rbx), %r13
movq %r14, %rdi
callq 0x2230
testl %eax, %eax
jne 0x544b
movq %r13, %rdi
callq 0x3d5c
movq %rax, %r13
testq %rax, %rax
jne 0x5301
callq 0x2080
movl (%rax), %ebp
movq %r14, %rdi
callq 0x2380
testl %eax, %eax
jne 0x543b
movq %r13, 0x78(%rbx)
movl %ebp, 0x80(%rbx)
movl 0x64(%rbx), %edi
movl $0x1, %edx
movq %r12, %rsi
callq 0x5e70
cmpq $0x1, %rax
jne 0x545b
cmpl $0x2, 0x60(%rbx)
je 0x52b6
movl $0x0, 0x60(%rbx)
jmp 0x52b6
movl 0x68(%rbx), %edi
callq 0x2180
testl %eax, %eax
je 0x538a
callq 0x2080
cmpl $0x0, (%rax)
je 0x537c
movq %rax, %r12
leaq 0x2160(%rip), %rdi      # 0x74cb
xorl %eax, %eax
callq 0x4e04
movl $0x0, (%r12)
jmp 0x538a
leaq 0x2148(%rip), %rdi      # 0x74cb
xorl %eax, %eax
callq 0x4f23
movl 0x64(%rbx), %edi
callq 0x2180
testl %eax, %eax
je 0x53c9
callq 0x2080
cmpl $0x0, (%rax)
je 0x53bb
movq %rax, %r12
leaq 0x2121(%rip), %rdi      # 0x74cb
xorl %eax, %eax
callq 0x4e04
movl $0x0, (%r12)
jmp 0x53c9
leaq 0x2109(%rip), %rdi      # 0x74cb
xorl %eax, %eax
callq 0x4f23
movq %r15, %rdi
callq 0x22d0
testl %eax, %eax
jne 0x5475
movq %r14, %rdi
callq 0x2230
testl %eax, %eax
jne 0x544b
movq %r14, %rdi
callq 0x2130
testl %eax, %eax
jne 0x5485
movq %rbx, %rdi
callq 0x2040
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x2360
leaq 0x23af(%rip), %rdi      # 0x77cb
movq %rax, %rsi
xorl %eax, %eax
callq 0x4f23
callq 0x2080
movl $0x0, (%rax)
movl $0x1, %edi
callq 0x2300
movl %eax, %edi
callq 0x2360
leaq 0x22d3(%rip), %rdi      # 0x771c
jmp 0x541c
movl %eax, %edi
callq 0x2360
leaq 0x230e(%rip), %rdi      # 0x7767
jmp 0x541c
callq 0x2080
cmpl $0x0, (%rax)
jne 0x5495
leaq 0x2375(%rip), %rdi      # 0x77e1
xorl %eax, %eax
callq 0x4f23
jmp 0x5431
movl %eax, %edi
callq 0x2360
leaq 0x237d(%rip), %rdi      # 0x7800
jmp 0x541c
movl %eax, %edi
callq 0x2360
leaq 0x2386(%rip), %rdi      # 0x7819
jmp 0x541c
movq %rax, %rbx
leaq 0x2342(%rip), %rdi      # 0x77e1
xorl %eax, %eax
callq 0x4e04
movl $0x0, (%rbx)
jmp 0x5431