// File: /workspace/github_c_makefile_star2_O2/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, 0x3(%rsp)
leaq 0x8(%rdi), %r14
movq %r14, %rdi
callq 0x2380
testl %eax, %eax
jne 0x4f1f
leaq 0x30(%rbx), %r15
movl $0x0, 0x4(%rsp)
leaq 0x3(%rsp), %rbp
pushq $0x1
popq %r12
movl 0x60(%rbx), %eax
testl %eax, %eax
jne 0x4db7
movq %r15, %rdi
movq %r14, %rsi
callq 0x2100
testl %eax, %eax
je 0x4d9c
jmp 0x4ef7
cmpl $0x2, %eax
je 0x4e3a
movq %rbp, %r13
movq 0x70(%rbx), %rbp
movq %r14, %rdi
callq 0x2230
testl %eax, %eax
jne 0x4f2f
movq %rbp, %rdi
callq 0x3940
movq %rax, %rbp
testq %rax, %rax
jne 0x4dee
callq 0x2080
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movq %r14, %rdi
callq 0x2380
testl %eax, %eax
jne 0x4f1f
movq %rbp, 0x78(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x80(%rbx)
movl 0x64(%rbx), %edi
movq %r13, %rbp
movq %r13, %rsi
movq %r12, %rdx
callq 0x58ec
cmpq $0x1, %rax
jne 0x4f3f
cmpl $0x2, 0x60(%rbx)
je 0x4d9c
andl $0x0, 0x60(%rbx)
jmp 0x4d9c
movl 0x68(%rbx), %edi
callq 0x2180
testl %eax, %eax
je 0x4e76
callq 0x2080
cmpl $0x0, (%rax)
je 0x4e68
movq %rax, %r12
leaq 0x1681(%rip), %rdi      # 0x64db
xorl %eax, %eax
callq 0x4835
andl $0x0, (%r12)
jmp 0x4e76
leaq 0x166c(%rip), %rdi      # 0x64db
xorl %eax, %eax
callq 0x49c4
movl 0x64(%rbx), %edi
callq 0x2180
testl %eax, %eax
je 0x4eb2
callq 0x2080
cmpl $0x0, (%rax)
je 0x4ea4
movq %rax, %r12
leaq 0x1645(%rip), %rdi      # 0x64db
xorl %eax, %eax
callq 0x4835
andl $0x0, (%r12)
jmp 0x4eb2
leaq 0x1630(%rip), %rdi      # 0x64db
xorl %eax, %eax
callq 0x49c4
movq %r15, %rdi
callq 0x22d0
testl %eax, %eax
jne 0x4f59
movq %r14, %rdi
callq 0x2230
testl %eax, %eax
jne 0x4f2f
movq %r14, %rdi
callq 0x2130
testl %eax, %eax
jne 0x4f69
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 0x1868(%rip), %rdi      # 0x676d
movq %rax, %rsi
xorl %eax, %eax
callq 0x49c4
callq 0x2080
andl $0x0, (%rax)
pushq $0x1
popq %rdi
callq 0x2300
movl %eax, %edi
callq 0x2360
leaq 0x1791(%rip), %rdi      # 0x66be
jmp 0x4f05
movl %eax, %edi
callq 0x2360
leaq 0x17cc(%rip), %rdi      # 0x6709
jmp 0x4f05
callq 0x2080
cmpl $0x0, (%rax)
jne 0x4f79
leaq 0x1833(%rip), %rdi      # 0x6783
xorl %eax, %eax
callq 0x49c4
jmp 0x4f17
movl %eax, %edi
callq 0x2360
leaq 0x183b(%rip), %rdi      # 0x67a2
jmp 0x4f05
movl %eax, %edi
callq 0x2360
leaq 0x1844(%rip), %rdi      # 0x67bb
jmp 0x4f05
movq %rax, %rbx
leaq 0x1800(%rip), %rdi      # 0x6783
xorl %eax, %eax
callq 0x4835
andl $0x0, (%rbx)
jmp 0x4f17