// File: /workspace/github_c_makefile_star2_O1/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 0x3671
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3730
movq %rax, %r14
leaq 0xdd1a(%rip), %rdi      # 0x11386
jmp 0x38f9
movl (%rsp), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x2110
cmpl $-0x1, %eax
je 0x373c
callq 0x24e0
cmpl $-0x1, %eax
je 0x3756
movl %eax, %ebp
testl %eax, %eax
je 0x378e
movl $0x28, %edi
callq 0x2330
testq %rax, %rax
je 0x388f
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        # 0x393b
movl $0x8, %edx
movl $0x8, %ecx
movq %rax, %r9
callq 0x78ac
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x3855
movl 0x4(%rsp), %edi
callq 0x2200
testl %eax, %eax
je 0x391f
callq 0x20a0
movq %rax, %r14
movl (%rax), %eax
cmpl $0x4, %eax
je 0x36fc
leaq 0xdff9(%rip), %rdi      # 0x1171c
testl %eax, %eax
jne 0x3869
jmp 0x3880
leaq 0xdc4f(%rip), %rdi      # 0x11386
jmp 0x3916
callq 0x20a0
cmpl $0x0, (%rax)
je 0x383c
movq %rax, %rbx
leaq 0xdc3d(%rip), %rdi      # 0x11391
jmp 0x376e
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3845
movq %rax, %rbx
leaq 0xdc47(%rip), %rdi      # 0x113b5
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%rbx)
jmp 0x389b
callq 0x20a0
cmpl $0x4, (%rax)
jne 0x3931
movl (%rsp), %edi
callq 0x2200
testl %eax, %eax
jne 0x3780
movl 0x4(%rsp), %ebp
leaq 0x8(%rsp), %r14
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
callq 0x924c
testq %rax, %rax
je 0x382d
movq %rax, %r12
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3825
movq %r12, %r13
addq $0x8, %r13
movq %r14, %rsi
movq %r15, %rdx
callq 0x9fa4
testl %eax, %eax
jne 0x3931
movl $0x8, %edx
movl %ebp, %edi
movq %r15, %rsi
callq 0x918c
cmpq $-0x1, %rax
je 0x3931
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %ebp, %edi
callq 0x918c
cmpq $-0x1, %rax
je 0x3931
movq 0x8(%rsp), %rdi
callq 0x2040
movq (%r13), %rdi
addq $0x8, %r13
testq %rdi, %rdi
jne 0x37c7
movq %r12, %rdi
callq 0x9963
movl $0xa, %edi
callq 0x24c0
jmp 0x37a8
leaq 0xdb4e(%rip), %rdi      # 0x11391
jmp 0x384c
leaq 0xdb69(%rip), %rdi      # 0x113b5
xorl %eax, %eax
callq 0xa413
jmp 0x389b
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3879
movq %rax, %r14
leaq 0xdb51(%rip), %rdi      # 0x113ba
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%r14)
jmp 0x3887
leaq 0xdb3a(%rip), %rdi      # 0x113ba
xorl %eax, %eax
callq 0xa413
movq %rbx, %rdi
callq 0x2040
movl %ebp, %edi
movl $0xf, %esi
callq 0x2310
movl 0x4(%rsp), %edi
callq 0x2200
testl %eax, %eax
je 0x38d9
callq 0x20a0
cmpl $0x0, (%rax)
je 0x38cb
movq %rax, %rbx
leaq 0xde60(%rip), %rdi      # 0x1171c
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%rbx)
jmp 0x38d9
leaq 0xde4a(%rip), %rdi      # 0x1171c
xorl %eax, %eax
callq 0xa413
movl (%rsp), %edi
callq 0x2200
testl %eax, %eax
je 0x390b
callq 0x20a0
cmpl $0x0, (%rax)
je 0x390f
movq %rax, %r14
leaq 0xde23(%rip), %rdi      # 0x1171c
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%r14)
jmp 0x391f
xorl %ebx, %ebx
jmp 0x391f
leaq 0xde06(%rip), %rdi      # 0x1171c
xorl %ebx, %ebx
xorl %eax, %eax
callq 0xa413
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x20c0