// File: /workspace/github_c_makefile_star2_O1/wtarreau[P]httpterm/httpterm.c
// Function: str2listener
struct listener *str2listener(char *str, struct listener *tail) {
    struct listener *l;
    char *c, *next, *range, *dupstr;
    int port, end;

    next = dupstr = strdup(str);
    
    while (next && *next) {
	struct sockaddr_storage ss;

	str = next;
	/* 1) look for the end of the first address */
	if ((next = strchr(str, ',')) != NULL) {
	    *next++ = 0;
	}

	/* 2) look for the addr/port delimiter, it's the last colon. */
	if ((range = strrchr(str, ':')) == NULL) {
	    Alert("Missing port number: '%s'\n", str);
	    goto fail;
	}	    

	*range++ = 0;

	if (strrchr(str, ':') != NULL) {
	    /* IPv6 address contains ':' */
	    memset(&ss, 0, sizeof(ss));
	    ss.ss_family = AF_INET6;

	    if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in6 *)&ss)->sin6_addr)) {
		Alert("Invalid server address: '%s'\n", str);
		goto fail;
	    }
	}
	else {
	    memset(&ss, 0, sizeof(ss));
	    ss.ss_family = AF_INET;

	    if (*str == '*' || *str == '\0') { /* INADDR_ANY */
		((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY;
	    }
	    else if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in *)&ss)->sin_addr)) {
		struct hostent *he;
		
		if ((he = gethostbyname(str)) == NULL) {
		    Alert("Invalid server name: '%s'\n", str);
		    goto fail;
		}
		else
		    ((struct sockaddr_in *)&ss)->sin_addr =
			*(struct in_addr *) *(he->h_addr_list);
	    }
	}

	/* 3) look for the port-end delimiter */
	if ((c = strchr(range, '-')) != NULL) {
	    *c++ = 0;
	    end = atol(c);
	}
	else {
	    end = atol(range);
	}

	port = atol(range);

	if (port < 1 || port > 65535) {
	    Alert("Invalid port '%d' specified for address '%s'.\n", port, str);
	    goto fail;
	}

	if (end < 1 || end > 65535) {
	    Alert("Invalid port '%d' specified for address '%s'.\n", end, str);
	    goto fail;
	}

	for (; port <= end; port++) {
	    l = (struct listener *)calloc(1, sizeof(struct listener));
	    l->next = tail;
	    tail = l;

	    l->fd = -1;
	    l->addr = ss;
	    if (ss.ss_family == AF_INET6)
		((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port);
	    else
		((struct sockaddr_in *)(&l->addr))->sin_port = htons(port);

	} /* end for(port) */
    } /* end while(next) */
    free(dupstr);
    return tail;
 fail:
    free(dupstr);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rbx
callq 0x23e0
leaq 0x72d6(%rip), %r14      # 0xa1cd
movq %rax, 0x8(%rsp)
movq %rax, %r15
testq %r15, %r15
je 0x3134
movq %r15, %rbp
cmpb $0x0, (%r15)
je 0x3134
movq %rbp, %rdi
movl $0x2c, %esi
callq 0x2160
testq %rax, %rax
je 0x2f32
movq %rax, %r15
incq %r15
movb $0x0, (%rax)
jmp 0x2f35
xorl %r15d, %r15d
movq %rbp, %rdi
movl $0x3a, %esi
callq 0x2180
testq %rax, %rax
je 0x2fb3
movq %rax, %r13
movb $0x0, (%rax)
movq %rbp, %rdi
movl $0x3a, %esi
callq 0x2180
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
testq %rax, %rax
je 0x2fcf
movw $0xa, 0x10(%rsp)
movl $0xa, %edi
movq %rbp, %rsi
leaq 0x18(%rsp), %rdx
callq 0x2260
testl %eax, %eax
jne 0x3049
movq %r14, %rdi
jmp 0x2fba
leaq 0x71f8(%rip), %rdi      # 0xa1b2
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2a00
movl $0x4, %r12d
jmp 0x30c4
movw $0x2, 0x10(%rsp)
movzbl (%rbp), %eax
cmpl $0x2a, %eax
je 0x2fe3
testl %eax, %eax
jne 0x2fed
movl $0x0, 0x14(%rsp)
jmp 0x3049
movl $0x2, %edi
movq %rbp, %rsi
leaq 0x14(%rsp), %rdx
callq 0x2260
testl %eax, %eax
jne 0x3049
movq %r15, (%rsp)
movq %rbp, %rdi
callq 0x2220
movq %rax, %r15
testq %rax, %rax
je 0x3029
movq 0x18(%r15), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x14(%rsp)
xorl %r12d, %r12d
jmp 0x3040
leaq 0x7167(%rip), %rdi      # 0xa197
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2a00
movl $0x4, %r12d
testq %r15, %r15
movq (%rsp), %r15
je 0x30c4
movq %r15, (%rsp)
incq %r13
movq %r13, %rdi
movl $0x2d, %esi
callq 0x2160
movq %r13, %rdi
testq %rax, %rax
je 0x306e
movq %rax, %rdi
incq %rdi
movb $0x0, (%rax)
callq 0x2320
movq %rax, %r15
movq %r13, %rdi
callq 0x2320
movq %rax, %r13
movl $0xffff0000, %ecx       # imm = 0xFFFF0000
addl %ecx, %eax
cmpl %ecx, %eax
ja 0x3098
leaq 0x7158(%rip), %rdi      # 0xa1eb
movl %r13d, %esi
jmp 0x30b0
leal -0x10000(%r15), %eax
cmpl $0xffff0001, %eax       # imm = 0xFFFF0001
jae 0x30cf
leaq 0x713e(%rip), %rdi      # 0xa1eb
movl %r15d, %esi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2a00
movl $0x4, %r12d
movq (%rsp), %r15
testl %r12d, %r12d
je 0x2eff
jmp 0x312c
xorl %r12d, %r12d
cmpl %r15d, %r13d
jg 0x30c0
incl %r15d
leaq 0x10(%rsp), %r14
movq %rbx, %rbp
movl $0x1, %edi
movl $0x90, %esi
callq 0x21f0
movq %rax, %rbx
movq %rbp, 0x88(%rax)
leaq 0x8(%rax), %rdi
movl $0x10, %ecx
movl %r13d, %eax
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
rolw $0x8, %ax
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movw %ax, 0xa(%rbx)
incl %r13d
cmpl %r13d, %r15d
jne 0x30df
leaq 0x70a3(%rip), %r14      # 0xa1cd
jmp 0x30c0
cmpl $0x4, %r12d
jne 0x3140
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
callq 0x2050
jmp 0x3140
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq