// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../lib/serverpool/serverpool.c
// Function: serverpool_create
struct serverpool *
serverpool_create(const char * target, unsigned int freq, time_t ttl)
{
	struct serverpool * P;
	struct sock_addr ** sas;
	int fd[2];
	size_t i;

	/* Allocate server pool structure and (empty) array. */
	if ((P = malloc(sizeof(struct serverpool))) == NULL)
		goto err0;
	if ((P->A = serverpool_addrs_init(0)) == NULL)
		goto err1;

	/* Record TTL for future reference. */
	P->ttl = ttl;

	/* The first addresses will be generation #0. */
	P->generation = 0;

	/* Perform a first lookup. */
	if ((sas = sock_resolve(target)) == NULL)
		goto err2;

	/* Stuff the results into the server pool address list. */
	for (i = 0; sas[i] != NULL; i++) {
		/* Add this address to the pool. */
		if (addaddr(P, sas[i]))
			goto err3;
	}

	/* Next addresses will be generation #1. */
	P->generation = 1;

	/* Create a socket for the child to send us addresses. */
	if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
		warnp("socketpair");
		goto err3;
	}

	/* 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 err4;
	}

	/* Fork off the process to perform DNS lookups. */
	if ((P->pid = forkdns(target, fd[0], fd[1], freq)) == -1)
		goto err4;

	/* Start reading from the child. */
	P->s = fd[0];
	P->addr = NULL;
	if ((P->read_cookie = network_read(P->s, (uint8_t *)&P->addrlen,
	    sizeof(size_t), sizeof(size_t), callback_read_len, P)) == NULL) {
		warnp("Error reading address via socket");
		goto err5;
	}

	/* Close write socket; only the child needs it. */
	if (close(fd[1]))
		warnp("close");

	/* Free the initial list of addresses. */
	sock_addr_freelist(sas);

	/* Success! */
	return (P);

err5:
	kill(P->pid, SIGTERM);
err4:
	if (close(fd[1]))
		warnp("close");
	if (close(fd[0]))
		warnp("close");
err3:
	sock_addr_freelist(sas);
	for (i = serverpool_addrs_getsize(P->A); i > 0; i--)
		sock_addr_free(serverpool_addrs_get(P->A, i - 1)->sa);
err2:
	serverpool_addrs_free(P->A);
err1:
	free(P);
err0:
	return (NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x38, %edi
callq 0x2240
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x6a7c
jmp 0x6dc4
xorl %eax, %eax
movl %eax, %edi
callq 0x6de0
movq -0x28(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x6a97
jmp 0x6dbb
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x10(%rbp), %rdi
callq 0x4950
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x6ac7
jmp 0x6daf
movq $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x6b0d
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x6e10
cmpl $0x0, %eax
je 0x6afd
jmp 0x6d63
jmp 0x6aff
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x6acf
movq -0x28(%rbp), %rax
movq $0x1, 0x30(%rax)
leaq -0x38(%rbp), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x2210
cmpl $0x0, %eax
je 0x6b6c
jmp 0x6b32
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6b57
leaq 0x3d0a(%rip), %rdi      # 0xa84d
movb $0x0, %al
callq 0x65c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6b65
leaq 0x3cef(%rip), %rdi      # 0xa84d
movb $0x0, %al
callq 0x6810
jmp 0x6b67
jmp 0x6d63
movl -0x38(%rbp), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
movb $0x0, %al
callq 0x20f0
cmpl $-0x1, %eax
jne 0x6bc1
jmp 0x6b87
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6bac
leaq 0x3cc0(%rip), %rdi      # 0xa858
movb $0x0, %al
callq 0x65c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6bba
leaq 0x3ca5(%rip), %rdi      # 0xa858
movb $0x0, %al
callq 0x6810
jmp 0x6bbc
jmp 0x6cd5
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
movl -0x34(%rbp), %edx
movl -0x14(%rbp), %ecx
callq 0x6f50
movq -0x28(%rbp), %rcx
movl %eax, 0xc(%rcx)
cmpl $-0x1, %eax
jne 0x6be4
jmp 0x6cd5
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x28(%rbp), %rsi
addq $0x10, %rsi
movq -0x28(%rbp), %r9
movl $0x8, %ecx
leaq 0x497(%rip), %r8        # 0x70b0
movq %rcx, %rdx
callq 0x8150
movq -0x28(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x6c68
jmp 0x6c31
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6c56
leaq 0x3c3a(%rip), %rdi      # 0xa87c
movb $0x0, %al
callq 0x65c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6c64
leaq 0x3c1f(%rip), %rdi      # 0xa87c
movb $0x0, %al
callq 0x6810
jmp 0x6c66
jmp 0x6cc4
movl -0x34(%rbp), %edi
callq 0x21a0
cmpl $0x0, %eax
je 0x6cae
jmp 0x6c77
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6c9c
leaq 0x38ee(%rip), %rdi      # 0xa576
movb $0x0, %al
callq 0x65c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6caa
leaq 0x38d3(%rip), %rdi      # 0xa576
movb $0x0, %al
callq 0x6810
jmp 0x6cac
jmp 0x6cae
movq -0x30(%rbp), %rdi
callq 0x5580
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6dcc
movq -0x28(%rbp), %rax
movl 0xc(%rax), %edi
movl $0xf, %esi
callq 0x2230
movl -0x34(%rbp), %edi
callq 0x21a0
cmpl $0x0, %eax
je 0x6d1b
jmp 0x6ce4
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6d09
leaq 0x3881(%rip), %rdi      # 0xa576
movb $0x0, %al
callq 0x65c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6d17
leaq 0x3866(%rip), %rdi      # 0xa576
movb $0x0, %al
callq 0x6810
jmp 0x6d19
jmp 0x6d1b
movl -0x38(%rbp), %edi
callq 0x21a0
cmpl $0x0, %eax
je 0x6d61
jmp 0x6d2a
callq 0x20a0
cmpl $0x0, (%rax)
je 0x6d4f
leaq 0x383b(%rip), %rdi      # 0xa576
movb $0x0, %al
callq 0x65c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x6d5d
leaq 0x3820(%rip), %rdi      # 0xa576
movb $0x0, %al
callq 0x6810
jmp 0x6d5f
jmp 0x6d61
jmp 0x6d63
movq -0x30(%rbp), %rdi
callq 0x5580
movq -0x28(%rbp), %rax
movq (%rax), %rdi
callq 0x7270
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jbe 0x6dad
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x40(%rbp), %rsi
subq $0x1, %rsi
callq 0x7290
movq (%rax), %rdi
callq 0x5540
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x6d7c
jmp 0x6daf
movq -0x28(%rbp), %rax
movq (%rax), %rdi
callq 0x72c0
movq -0x28(%rbp), %rdi
callq 0x2040
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)