// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq -0x28(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x2310
cmpl $0x0, %eax
je 0x3973
jmp 0x3939
callq 0x20a0
cmpl $0x0, (%rax)
je 0x395e
leaq 0x1aba2(%rip), %rdi     # 0x1e4ec
movb $0x0, %al
callq 0xe670
callq 0x20a0
movl $0x0, (%rax)
jmp 0x396c
leaq 0x1ab87(%rip), %rdi     # 0x1e4ec
movb $0x0, %al
callq 0xe8c0
jmp 0x396e
jmp 0x3c17
movl -0x28(%rbp), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
movb $0x0, %al
callq 0x2120
cmpl $-0x1, %eax
jne 0x39c8
jmp 0x398e
callq 0x20a0
cmpl $0x0, (%rax)
je 0x39b3
leaq 0x1ab58(%rip), %rdi     # 0x1e4f7
movb $0x0, %al
callq 0xe670
callq 0x20a0
movl $0x0, (%rax)
jmp 0x39c1
leaq 0x1ab3d(%rip), %rdi     # 0x1e4f7
movb $0x0, %al
callq 0xe8c0
jmp 0x39c3
jmp 0x3b89
callq 0x24f0
movl %eax, -0x2c(%rbp)
movl %eax, %ecx
movl %ecx, -0x30(%rbp)
subl $-0x1, %eax
je 0x39e5
jmp 0x39dc
movl -0x30(%rbp), %eax
testl %eax, %eax
je 0x3a21
jmp 0x3a52
jmp 0x39e7
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3a0c
leaq 0x1ab23(%rip), %rdi     # 0x1e51b
movb $0x0, %al
callq 0xe670
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3a1a
leaq 0x1ab08(%rip), %rdi     # 0x1e51b
movb $0x0, %al
callq 0xe8c0
jmp 0x3a1c
jmp 0x3b89
jmp 0x3a23
movl -0x28(%rbp), %edi
callq 0x2220
cmpl $0x0, %eax
je 0x3a46
callq 0x20a0
cmpl $0x4, (%rax)
jne 0x3a3c
jmp 0x3a23
movl $0x1, %edi
callq 0x20c0
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x3c30
jmp 0x3a54
movl $0x28, %edi
callq 0x2350
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x3a6d
jmp 0x3b7c
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl -0x28(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x20(%rbp), %rsi
addq $0x10, %rsi
movq -0x20(%rbp), %r9
movl $0x8, %ecx
leaq 0x23d(%rip), %r8        # 0x3d00
movq %rcx, %rdx
callq 0xa410
movq -0x20(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x3b12
jmp 0x3adb
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3b00
leaq 0x1aa34(%rip), %rdi     # 0x1e520
movb $0x0, %al
callq 0xe670
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3b0e
leaq 0x1aa19(%rip), %rdi     # 0x1e520
movb $0x0, %al
callq 0xe8c0
jmp 0x3b10
jmp 0x3b73
jmp 0x3b14
movl -0x24(%rbp), %edi
callq 0x2220
cmpl $0x0, %eax
je 0x3b66
callq 0x20a0
cmpl $0x4, (%rax)
jne 0x3b2d
jmp 0x3b14
jmp 0x3b2f
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3b54
leaq 0x1af83(%rip), %rdi     # 0x1eac3
movb $0x0, %al
callq 0xe670
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3b62
leaq 0x1af68(%rip), %rdi     # 0x1eac3
movb $0x0, %al
callq 0xe8c0
jmp 0x3b64
jmp 0x3b73
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3c1f
movq -0x20(%rbp), %rdi
callq 0x2040
movl -0x2c(%rbp), %edi
movl $0xf, %esi
callq 0x2330
movl -0x24(%rbp), %edi
callq 0x2220
cmpl $0x0, %eax
je 0x3bcf
jmp 0x3b98
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3bbd
leaq 0x1af1a(%rip), %rdi     # 0x1eac3
movb $0x0, %al
callq 0xe670
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3bcb
leaq 0x1aeff(%rip), %rdi     # 0x1eac3
movb $0x0, %al
callq 0xe8c0
jmp 0x3bcd
jmp 0x3bcf
movl -0x28(%rbp), %edi
callq 0x2220
cmpl $0x0, %eax
je 0x3c15
jmp 0x3bde
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3c03
leaq 0x1aed4(%rip), %rdi     # 0x1eac3
movb $0x0, %al
callq 0xe670
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3c11
leaq 0x1aeb9(%rip), %rdi     # 0x1eac3
movb $0x0, %al
callq 0xe8c0
jmp 0x3c13
jmp 0x3c15
jmp 0x3c17
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)