// File: /workspace/github_c_makefile_star2_O1/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 0x5417
movq %rax, %rbx
movl $0x20, %esi
xorl %edi, %edi
callq 0x5a5c
movq %rax, (%rbx)
testq %rax, %rax
je 0x540f
movq %r14, 0x28(%rbx)
movq $0x0, 0x30(%rbx)
movq %r15, %rdi
callq 0x3e48
testq %rax, %rax
je 0x5407
movq %rax, %r14
movq (%rax), %rsi
testq %rsi, %rsi
je 0x51c4
movq %r14, %r12
addq $0x8, %r12
movq %rbx, %rdi
callq 0x5536
testl %eax, %eax
jne 0x53c9
movq (%r12), %rsi
addq $0x8, %r12
testq %rsi, %rsi
jne 0x51a7
movq $0x1, 0x30(%rbx)
leaq 0x8(%rsp), %rcx
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x21f0
testl %eax, %eax
je 0x5203
callq 0x2090
cmpl $0x0, (%rax)
je 0x52b1
movq %rax, %r15
leaq 0x254f(%rip), %rdi      # 0x774d
jmp 0x53ab
movl 0x8(%rsp), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
xorl %eax, %eax
callq 0x20f0
cmpl $-0x1, %eax
je 0x52bd
movl 0x8(%rsp), %r13d
movl 0xc(%rsp), %r12d
callq 0x2330
testl %eax, %eax
je 0x542b
movl %eax, 0xc(%rbx)
cmpl $-0x1, %eax
je 0x534b
movl 0x8(%rsp), %edi
movl %edi, 0x8(%rbx)
movq $0x0, 0x18(%rbx)
movq %rbx, %rsi
addq $0x10, %rsi
leaq 0x3c1(%rip), %r8        # 0x5622
movl $0x8, %edx
movl $0x8, %ecx
movq %rbx, %r9
callq 0x5f4c
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x52e1
movl 0xc(%rsp), %edi
callq 0x2180
testl %eax, %eax
je 0x5323
callq 0x2090
cmpl $0x0, (%rax)
je 0x5315
movq %rax, %r15
leaq 0x2272(%rip), %rdi      # 0x7513
xorl %eax, %eax
callq 0x4ef0
movl $0x0, (%r15)
jmp 0x5323
leaq 0x2495(%rip), %rdi      # 0x774d
jmp 0x53c2
callq 0x2090
cmpl $0x0, (%rax)
je 0x5305
movq %rax, %r15
leaq 0x2487(%rip), %rdi      # 0x7758
xorl %eax, %eax
callq 0x4ef0
movl $0x0, (%r15)
jmp 0x534b
callq 0x2090
cmpl $0x0, (%rax)
je 0x5330
movq %rax, %r15
leaq 0x2487(%rip), %rdi      # 0x777c
xorl %eax, %eax
callq 0x4ef0
movl $0x0, (%r15)
jmp 0x533e
leaq 0x244c(%rip), %rdi      # 0x7758
xorl %eax, %eax
callq 0x500f
jmp 0x534b
leaq 0x21f7(%rip), %rdi      # 0x7513
xorl %eax, %eax
callq 0x500f
movq %r14, %rdi
callq 0x455f
jmp 0x5419
leaq 0x2445(%rip), %rdi      # 0x777c
xorl %eax, %eax
callq 0x500f
movl 0xc(%rbx), %edi
movl $0xf, %esi
callq 0x2210
movl 0xc(%rsp), %edi
callq 0x2180
testl %eax, %eax
je 0x538a
callq 0x2090
cmpl $0x0, (%rax)
je 0x537c
movq %rax, %r15
leaq 0x21a7(%rip), %rdi      # 0x7513
xorl %eax, %eax
callq 0x4ef0
movl $0x0, (%r15)
jmp 0x538a
leaq 0x2190(%rip), %rdi      # 0x7513
xorl %eax, %eax
callq 0x500f
movl 0x8(%rsp), %edi
callq 0x2180
testl %eax, %eax
je 0x53c9
callq 0x2090
cmpl $0x0, (%rax)
je 0x53bb
movq %rax, %r15
leaq 0x2168(%rip), %rdi      # 0x7513
xorl %eax, %eax
callq 0x4ef0
movl $0x0, (%r15)
jmp 0x53c9
leaq 0x2151(%rip), %rdi      # 0x7513
xorl %eax, %eax
callq 0x500f
movq %r14, %rdi
callq 0x455f
movq (%rbx), %rdi
movl $0x20, %esi
callq 0x5bcb
testq %rax, %rax
je 0x5407
movq %rax, %r14
decq %r14
movq (%rbx), %rdi
movl $0x20, %edx
movq %r14, %rsi
callq 0x5d0d
movq (%rax), %rdi
callq 0x4543
addq $-0x1, %r14
jb 0x53e9
movq (%rbx), %rdi
callq 0x5b0d
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 0x5468
callq 0x2090
cmpl $0x0, (%rax)
jne 0x5451
leaq 0x20cb(%rip), %rdi      # 0x7513
xorl %eax, %eax
callq 0x500f
jmp 0x5468
movq %rax, %rbx
leaq 0x20b8(%rip), %rdi      # 0x7513
xorl %eax, %eax
callq 0x4ef0
movl $0x0, (%rbx)
callq 0x21a0
leaq 0x18(%rsp), %rbx
leaq 0x20(%rsp), %r14
movq %r15, %rdi
callq 0x3e48
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x5520
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x54f7
movq 0x10(%rsp), %r13
addq $0x8, %r13
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4ba0
testl %eax, %eax
jne 0x552c
movl $0x8, %edx
movl %r12d, %edi
movq %rbx, %rsi
callq 0x655c
cmpq $-0x1, %rax
je 0x552c
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl %r12d, %edi
callq 0x655c
cmpq $-0x1, %rax
je 0x552c
movq 0x20(%rsp), %rdi
callq 0x2040
movq (%r13), %rdi
addq $0x8, %r13
testq %rdi, %rdi
jne 0x54a3
movq 0x10(%rsp), %rdi
callq 0x455f
movq $0x0, 0x18(%rsp)
movl $0x8, %edx
movl %r12d, %edi
movq %rbx, %rsi
callq 0x655c
cmpq $-0x1, %rax
je 0x552c
movl %ebp, %edi
callq 0x2320
jmp 0x5477
movl $0x1, %edi
callq 0x20a0