// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
pushq $0x1
popq %rdi
leaq 0x8(%rsp), %rcx
movl %edi, %esi
xorl %edx, %edx
callq 0x2300
testl %eax, %eax
je 0x30ca
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3183
movq %rax, %r14
leaq 0xd24d(%rip), %rdi      # 0x10312
jmp 0x333c
movl 0x8(%rsp), %edi
pushq $0x4
popq %rsi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x2110
cmpl $-0x1, %eax
je 0x318f
callq 0x24f0
cmpl $-0x1, %eax
je 0x31a9
movl %eax, %ebp
testl %eax, %eax
je 0x31de
pushq $0x28
popq %rdi
callq 0x2340
testq %rax, %rax
je 0x32d6
movq %rax, %rbx
movq %r14, (%rax)
movl 0x8(%rsp), %edi
movl %edi, 0x8(%rax)
movl %ebp, 0xc(%rax)
movq %rax, %rsi
addq $0x10, %rsi
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
leaq 0x245(%rip), %r8        # 0x3379
pushq $0x8
popq %rcx
movq %rcx, %rdx
movq %rax, %r9
callq 0x6dd8
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x329f
movl 0xc(%rsp), %edi
callq 0x2200
testl %eax, %eax
je 0x335f
callq 0x20a0
movq %rax, %r14
movl (%rax), %eax
cmpl $0x4, %eax
je 0x314f
leaq 0xd507(%rip), %rdi      # 0x1067d
testl %eax, %eax
jne 0x32b3
jmp 0x32c7
leaq 0xd188(%rip), %rdi      # 0x10312
jmp 0x3356
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3286
movq %rax, %rbx
leaq 0xd176(%rip), %rdi      # 0x1031d
jmp 0x31c1
callq 0x20a0
cmpl $0x0, (%rax)
je 0x328f
movq %rax, %rbx
leaq 0xd180(%rip), %rdi      # 0x10341
xorl %eax, %eax
callq 0x945d
andl $0x0, (%rbx)
jmp 0x32e0
callq 0x20a0
cmpl $0x4, (%rax)
jne 0x3371
movl 0x8(%rsp), %edi
callq 0x2200
testl %eax, %eax
jne 0x31d0
movl 0xc(%rsp), %ebp
leaq 0x10(%rsp), %r15
leaq 0x20(%rsp), %r12
pushq $0x8
popq %r13
movq %rbx, %rdi
callq 0x8568
testq %rax, %rax
je 0x3279
movq %rax, 0x18(%rsp)
movq %rax, %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x326f
movq %r15, %rsi
movq %r12, %rdx
callq 0x912d
testl %eax, %eax
jne 0x3371
movl %ebp, %edi
movq %r12, %rsi
movq %r13, %rdx
callq 0x84b8
cmpq $-0x1, %rax
je 0x3371
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %rdx
movl %ebp, %edi
callq 0x84b8
cmpq $-0x1, %rax
je 0x3371
movq 0x10(%rsp), %rdi
callq 0x2040
addq $0x8, %r14
jmp 0x3212
movq 0x18(%rsp), %rdi
callq 0x8b67
pushq $0xa
popq %rdi
callq 0x24d0
jmp 0x31fd
leaq 0xd090(%rip), %rdi      # 0x1031d
jmp 0x3296
leaq 0xd0ab(%rip), %rdi      # 0x10341
xorl %eax, %eax
callq 0x95ec
jmp 0x32e0
callq 0x20a0
cmpl $0x0, (%rax)
je 0x32c0
movq %rax, %r14
leaq 0xd093(%rip), %rdi      # 0x10346
xorl %eax, %eax
callq 0x945d
andl $0x0, (%r14)
jmp 0x32ce
leaq 0xd07f(%rip), %rdi      # 0x10346
xorl %eax, %eax
callq 0x95ec
movq %rbx, %rdi
callq 0x2040
pushq $0xf
popq %rsi
movl %ebp, %edi
callq 0x2320
movl 0xc(%rsp), %edi
callq 0x2200
testl %eax, %eax
je 0x331b
callq 0x20a0
cmpl $0x0, (%rax)
je 0x330d
movq %rax, %rbx
leaq 0xd37c(%rip), %rdi      # 0x1067d
xorl %eax, %eax
callq 0x945d
andl $0x0, (%rbx)
jmp 0x331b
leaq 0xd369(%rip), %rdi      # 0x1067d
xorl %eax, %eax
callq 0x95ec
movl 0x8(%rsp), %edi
callq 0x2200
testl %eax, %eax
je 0x334b
callq 0x20a0
cmpl $0x0, (%rax)
je 0x334f
movq %rax, %r14
leaq 0xd341(%rip), %rdi      # 0x1067d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x945d
andl $0x0, (%r14)
jmp 0x335f
xorl %ebx, %ebx
jmp 0x335f
leaq 0xd327(%rip), %rdi      # 0x1067d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x95ec
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdi
callq 0x20c0