// File: /workspace/github_c_makefile_star2_O3/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 0x5443
leaq 0x30(%rbx), %r15
xorl %ebp, %ebp
leaq 0x7(%rsp), %r12
movl 0x60(%rbx), %eax
testl %eax, %eax
jne 0x52d9
movq %r15, %rdi
movq %r14, %rsi
callq 0x2100
testl %eax, %eax
je 0x52be
jmp 0x5416
cmpl $0x2, %eax
je 0x5353
movq 0x70(%rbx), %r13
movq %r14, %rdi
callq 0x2230
testl %eax, %eax
jne 0x5453
movq %r13, %rdi
callq 0x3d88
movq %rax, %r13
testq %rax, %rax
jne 0x5309
callq 0x2080
movl (%rax), %ebp
movq %r14, %rdi
callq 0x2380
testl %eax, %eax
jne 0x5443
movq %r13, 0x78(%rbx)
movl %ebp, 0x80(%rbx)
movl 0x64(%rbx), %edi
movl $0x1, %edx
movq %r12, %rsi
callq 0x5e6c
cmpq $0x1, %rax
jne 0x5463
cmpl $0x2, 0x60(%rbx)
je 0x52be
movl $0x0, 0x60(%rbx)
jmp 0x52be
movl 0x68(%rbx), %edi
callq 0x2180
testl %eax, %eax
je 0x5392
callq 0x2080
cmpl $0x0, (%rax)
je 0x5384
movq %rax, %r12
leaq 0x2168(%rip), %rdi      # 0x74db
xorl %eax, %eax
callq 0x4e0c
movl $0x0, (%r12)
jmp 0x5392
leaq 0x2150(%rip), %rdi      # 0x74db
xorl %eax, %eax
callq 0x4f2b
movl 0x64(%rbx), %edi
callq 0x2180
testl %eax, %eax
je 0x53d1
callq 0x2080
cmpl $0x0, (%rax)
je 0x53c3
movq %rax, %r12
leaq 0x2129(%rip), %rdi      # 0x74db
xorl %eax, %eax
callq 0x4e0c
movl $0x0, (%r12)
jmp 0x53d1
leaq 0x2111(%rip), %rdi      # 0x74db
xorl %eax, %eax
callq 0x4f2b
movq %r15, %rdi
callq 0x22d0
testl %eax, %eax
jne 0x547d
movq %r14, %rdi
callq 0x2230
testl %eax, %eax
jne 0x5453
movq %r14, %rdi
callq 0x2130
testl %eax, %eax
jne 0x548d
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 0x23b7(%rip), %rdi      # 0x77db
movq %rax, %rsi
xorl %eax, %eax
callq 0x4f2b
callq 0x2080
movl $0x0, (%rax)
movl $0x1, %edi
callq 0x2300
movl %eax, %edi
callq 0x2360
leaq 0x22db(%rip), %rdi      # 0x772c
jmp 0x5424
movl %eax, %edi
callq 0x2360
leaq 0x2316(%rip), %rdi      # 0x7777
jmp 0x5424
callq 0x2080
cmpl $0x0, (%rax)
jne 0x549d
leaq 0x237d(%rip), %rdi      # 0x77f1
xorl %eax, %eax
callq 0x4f2b
jmp 0x5439
movl %eax, %edi
callq 0x2360
leaq 0x2385(%rip), %rdi      # 0x7810
jmp 0x5424
movl %eax, %edi
callq 0x2360
leaq 0x238e(%rip), %rdi      # 0x7829
jmp 0x5424
movq %rax, %rbx
leaq 0x234a(%rip), %rdi      # 0x77f1
xorl %eax, %eax
callq 0x4e0c
movl $0x0, (%rbx)
jmp 0x5439