// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
movl $0x38, %edi
callq 0x2220
testq %rax, %rax
je 0x541f
movq %rax, %rbx
movl $0x20, %esi
xorl %edi, %edi
callq 0x5a64
movq %rax, (%rbx)
testq %rax, %rax
je 0x5417
movq %r14, 0x28(%rbx)
movq $0x0, 0x30(%rbx)
movq %r15, %rdi
callq 0x3e74
testq %rax, %rax
je 0x540f
movq %rax, %r14
movq (%rax), %rsi
testq %rsi, %rsi
je 0x51cc
movq %r14, %r12
addq $0x8, %r12
movq %rbx, %rdi
callq 0x553e
testl %eax, %eax
jne 0x53d1
movq (%r12), %rsi
addq $0x8, %r12
testq %rsi, %rsi
jne 0x51af
movq $0x1, 0x30(%rbx)
leaq 0x8(%rsp), %rcx
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x21f0
testl %eax, %eax
je 0x520b
callq 0x2090
cmpl $0x0, (%rax)
je 0x52b9
movq %rax, %r15
leaq 0x255f(%rip), %rdi      # 0x7765
jmp 0x53b3
movl 0x8(%rsp), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x20f0
cmpl $-0x1, %eax
je 0x52c5
movl 0x8(%rsp), %r13d
movl 0xc(%rsp), %r12d
callq 0x2330
testl %eax, %eax
je 0x5433
movl %eax, 0xc(%rbx)
cmpl $-0x1, %eax
je 0x5353
movl 0x8(%rsp), %edi
movl %edi, 0x8(%rbx)
movq $0x0, 0x18(%rbx)
movq %rbx, %rsi
addq $0x10, %rsi
leaq 0x3c1(%rip), %r8        # 0x562a
movl $0x8, %edx
movl $0x8, %ecx
movq %rbx, %r9
callq 0x5f48
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x52e9
movl 0xc(%rsp), %edi
callq 0x2180
testl %eax, %eax
je 0x532b
callq 0x2090
cmpl $0x0, (%rax)
je 0x531d
movq %rax, %r15
leaq 0x2282(%rip), %rdi      # 0x752b
xorl %eax, %eax
callq 0x4ef8
movl $0x0, (%r15)
jmp 0x532b
leaq 0x24a5(%rip), %rdi      # 0x7765
jmp 0x53ca
callq 0x2090
cmpl $0x0, (%rax)
je 0x530d
movq %rax, %r15
leaq 0x2497(%rip), %rdi      # 0x7770
xorl %eax, %eax
callq 0x4ef8
movl $0x0, (%r15)
jmp 0x5353
callq 0x2090
cmpl $0x0, (%rax)
je 0x5338
movq %rax, %r15
leaq 0x2497(%rip), %rdi      # 0x7794
xorl %eax, %eax
callq 0x4ef8
movl $0x0, (%r15)
jmp 0x5346
leaq 0x245c(%rip), %rdi      # 0x7770
xorl %eax, %eax
callq 0x5017
jmp 0x5353
leaq 0x2207(%rip), %rdi      # 0x752b
xorl %eax, %eax
callq 0x5017
movq %r14, %rdi
callq 0x4586
jmp 0x5421
leaq 0x2455(%rip), %rdi      # 0x7794
xorl %eax, %eax
callq 0x5017
movl 0xc(%rbx), %edi
movl $0xf, %esi
callq 0x2210
movl 0xc(%rsp), %edi
callq 0x2180
testl %eax, %eax
je 0x5392
callq 0x2090
cmpl $0x0, (%rax)
je 0x5384
movq %rax, %r15
leaq 0x21b7(%rip), %rdi      # 0x752b
xorl %eax, %eax
callq 0x4ef8
movl $0x0, (%r15)
jmp 0x5392
leaq 0x21a0(%rip), %rdi      # 0x752b
xorl %eax, %eax
callq 0x5017
movl 0x8(%rsp), %edi
callq 0x2180
testl %eax, %eax
je 0x53d1
callq 0x2090
cmpl $0x0, (%rax)
je 0x53c3
movq %rax, %r15
leaq 0x2178(%rip), %rdi      # 0x752b
xorl %eax, %eax
callq 0x4ef8
movl $0x0, (%r15)
jmp 0x53d1
leaq 0x2161(%rip), %rdi      # 0x752b
xorl %eax, %eax
callq 0x5017
movq %r14, %rdi
callq 0x4586
movq (%rbx), %rdi
movl $0x20, %esi
callq 0x5bca
testq %rax, %rax
je 0x540f
movq %rax, %r14
decq %r14
movq (%rbx), %rdi
movl $0x20, %edx
movq %r14, %rsi
callq 0x5d0c
movq (%rax), %rdi
callq 0x456a
addq $-0x1, %r14
jb 0x53f1
movq (%rbx), %rdi
callq 0x5b0c
movq %rbx, %rdi
callq 0x2040
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, %edi
callq 0x2180
testl %eax, %eax
je 0x5470
callq 0x2090
cmpl $0x0, (%rax)
jne 0x5459
leaq 0x20db(%rip), %rdi      # 0x752b
xorl %eax, %eax
callq 0x5017
jmp 0x5470
movq %rax, %rbx
leaq 0x20c8(%rip), %rdi      # 0x752b
xorl %eax, %eax
callq 0x4ef8
movl $0x0, (%rbx)
callq 0x21a0
leaq 0x18(%rsp), %rbx
leaq 0x20(%rsp), %r14
movq %r15, %rdi
callq 0x3e74
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x5528
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x54ff
movq 0x10(%rsp), %r13
addq $0x8, %r13
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4bb2
testl %eax, %eax
jne 0x5534
movl $0x8, %edx
movl %r12d, %edi
movq %rbx, %rsi
callq 0x6578
cmpq $-0x1, %rax
je 0x5534
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl %r12d, %edi
callq 0x6578
cmpq $-0x1, %rax
je 0x5534
movq 0x20(%rsp), %rdi
callq 0x2040
movq (%r13), %rdi
addq $0x8, %r13
testq %rdi, %rdi
jne 0x54ab
movq 0x10(%rsp), %rdi
callq 0x4586
movq $0x0, 0x18(%rsp)
movl $0x8, %edx
movl %r12d, %edi
movq %rbx, %rsi
callq 0x6578
cmpq $-0x1, %rax
je 0x5534
movl %ebp, %edi
callq 0x2320
jmp 0x547f
movl $0x1, %edi
callq 0x20a0