// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/s3/dns.c
// Function: dns_reader_start
struct dns_reader *
dns_reader_start(struct s3_request_queue * Q, const char * target)
{
	struct dns_reader * DR;
	int fd[2];
	pid_t pid;

	/* Create a socket for feeding addresses back. */
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
		warnp("socketpair");
		goto err0;
	}

	/* Mark the read end of the socket pair as non-blocking. */
	if (fcntl(fd[0], F_SETFL, O_NONBLOCK) == -1) {
		warnp("Cannot make dns socket non-blocking");
		goto err1;
	}

	/* Fork a child to perform the DNS lookups. */
	switch ((pid = fork())) {
	case -1:
		/* Fork failed. */
		warnp("fork");
		goto err1;
	case 0:
		/*
		 * In child process.  Close read socket so that if the
		 * parent dies or is killed we will notice the socket being
		 * reset and will stop doing DNS lookups.
		 */
		while (close(fd[0])) {
			if (errno == EINTR)
				continue;
			_exit(1);
		}

		/* Perform DNS lookups and write the results to the socket. */
		dnsrun(target, fd[1]);
		/* NOTREACHED */
	default:
		/* In parent process. */
		break;
	}

	/* Bake a cookie. */
	if ((DR = malloc(sizeof(struct dns_reader))) == NULL)
		goto err2;
	DR->Q = Q;
	DR->s = fd[0];
	DR->pid = pid;
	DR->addr = NULL;
	DR->read_cookie = NULL;

	/* Start reading an address. */
	if ((DR->read_cookie = network_read(DR->s, (uint8_t *)&DR->addrlen,
	    sizeof(size_t), sizeof(size_t), callback_read_len, DR)) == NULL) {
		warnp("Error reading address via socket");
		goto err3;
	}

	/* Close write socket so that we'll get EOF if the child dies. */
	while (close(fd[1])) {
		if (errno == EINTR)
			continue;
		warnp("close");
		goto err3;	/* We'll close again, but it's harmless. */
	}

	/* Success! */
	return (DR);

err3:
	free(DR);
err2:
	kill(pid, SIGTERM);
err1:
	if (close(fd[1]))
		warnp("close");
	if (close(fd[0]))
		warnp("close");
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %rcx
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x22f0
testl %eax, %eax
je 0x3639
callq 0x20a0
cmpl $0x0, (%rax)
je 0x36f8
movq %rax, %r14
leaq 0xdcde(%rip), %rdi      # 0x11312
jmp 0x38c1
movl (%rsp), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x2110
cmpl $-0x1, %eax
je 0x3704
callq 0x24e0
cmpl $-0x1, %eax
je 0x371e
movl %eax, %ebp
testl %eax, %eax
je 0x3756
movl $0x28, %edi
callq 0x2330
testq %rax, %rax
je 0x3857
movq %rax, %rbx
movq %r14, (%rax)
movl (%rsp), %edi
movl %edi, 0x8(%rax)
movl %ebp, 0xc(%rax)
movq %rax, %rsi
addq $0x10, %rsi
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
leaq 0x25e(%rip), %r8        # 0x3903
movl $0x8, %edx
movl $0x8, %ecx
movq %rax, %r9
callq 0x7868
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x381d
movl 0x4(%rsp), %edi
callq 0x2200
testl %eax, %eax
je 0x38e7
callq 0x20a0
movq %rax, %r14
movl (%rax), %eax
cmpl $0x4, %eax
je 0x36c4
leaq 0xdfc1(%rip), %rdi      # 0x116ac
testl %eax, %eax
jne 0x3831
jmp 0x3848
leaq 0xdc13(%rip), %rdi      # 0x11312
jmp 0x38de
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3804
movq %rax, %rbx
leaq 0xdc01(%rip), %rdi      # 0x1131d
jmp 0x3736
callq 0x20a0
cmpl $0x0, (%rax)
je 0x380d
movq %rax, %rbx
leaq 0xdc0b(%rip), %rdi      # 0x11341
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%rbx)
jmp 0x3863
callq 0x20a0
cmpl $0x4, (%rax)
jne 0x38f9
movl (%rsp), %edi
callq 0x2200
testl %eax, %eax
jne 0x3748
movl 0x4(%rsp), %ebp
leaq 0x8(%rsp), %r14
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
callq 0x92b8
testq %rax, %rax
je 0x37f5
movq %rax, %r12
movq (%rax), %rdi
testq %rdi, %rdi
je 0x37ed
movq %r12, %r13
addq $0x8, %r13
movq %r14, %rsi
movq %r15, %rdx
callq 0x9ff6
testl %eax, %eax
jne 0x38f9
movl $0x8, %edx
movl %ebp, %edi
movq %r15, %rsi
callq 0x91f8
cmpq $-0x1, %rax
je 0x38f9
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %ebp, %edi
callq 0x91f8
cmpq $-0x1, %rax
je 0x38f9
movq 0x8(%rsp), %rdi
callq 0x2040
movq (%r13), %rdi
addq $0x8, %r13
testq %rdi, %rdi
jne 0x378f
movq %r12, %rdi
callq 0x99ca
movl $0xa, %edi
callq 0x24c0
jmp 0x3770
leaq 0xdb12(%rip), %rdi      # 0x1131d
jmp 0x3814
leaq 0xdb2d(%rip), %rdi      # 0x11341
xorl %eax, %eax
callq 0xa45b
jmp 0x3863
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3841
movq %rax, %r14
leaq 0xdb15(%rip), %rdi      # 0x11346
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%r14)
jmp 0x384f
leaq 0xdafe(%rip), %rdi      # 0x11346
xorl %eax, %eax
callq 0xa45b
movq %rbx, %rdi
callq 0x2040
movl %ebp, %edi
movl $0xf, %esi
callq 0x2310
movl 0x4(%rsp), %edi
callq 0x2200
testl %eax, %eax
je 0x38a1
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3893
movq %rax, %rbx
leaq 0xde28(%rip), %rdi      # 0x116ac
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%rbx)
jmp 0x38a1
leaq 0xde12(%rip), %rdi      # 0x116ac
xorl %eax, %eax
callq 0xa45b
movl (%rsp), %edi
callq 0x2200
testl %eax, %eax
je 0x38d3
callq 0x20a0
cmpl $0x0, (%rax)
je 0x38d7
movq %rax, %r14
leaq 0xddeb(%rip), %rdi      # 0x116ac
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%r14)
jmp 0x38e7
xorl %ebx, %ebx
jmp 0x38e7
leaq 0xddce(%rip), %rdi      # 0x116ac
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xa45b
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x20c0