// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2420
movq %rax, -0x40(%rbp)
movq %rax, -0x30(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x30(%rbp)
movb %al, -0xd1(%rbp)
je 0x33f6
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0xd1(%rbp)
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x3405
jmp 0x36d9
movq -0x30(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2c, %esi
callq 0x2160
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x3437
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
movl $0x3a, %esi
callq 0x2190
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x3466
movq -0x10(%rbp), %rsi
leaq 0xae7b(%rip), %rdi      # 0xe2d5
movb $0x0, %al
callq 0x2d40
jmp 0x36ec
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
movl $0x3a, %esi
callq 0x2190
cmpq $0x0, %rax
je 0x34e4
leaq -0xc8(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x21c0
movw $0xa, -0xc8(%rbp)
movzwl -0xc8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
addq $0x8, %rdx
callq 0x2280
cmpl $0x0, %eax
jne 0x34df
movq -0x10(%rbp), %rsi
leaq 0xae1d(%rip), %rdi      # 0xe2f0
movb $0x0, %al
callq 0x2d40
jmp 0x36ec
jmp 0x358d
leaq -0xc8(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x21c0
movw $0x2, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
je 0x3518
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x3524
movl $0x0, -0xc4(%rbp)
jmp 0x358b
movzwl -0xc8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
addq $0x4, %rdx
callq 0x2280
cmpl $0x0, %eax
jne 0x3589
movq -0x10(%rbp), %rdi
callq 0x2240
movq %rax, -0xd0(%rbp)
cmpq $0x0, %rax
jne 0x3571
movq -0x10(%rbp), %rsi
leaq 0xad55(%rip), %rdi      # 0xe2ba
movb $0x0, %al
callq 0x2d40
jmp 0x36ec
movq -0xd0(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
jmp 0x3589
jmp 0x358b
jmp 0x358d
movq -0x38(%rbp), %rdi
movl $0x2d, %esi
callq 0x2160
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x35c5
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movb $0x0, (%rax)
movq -0x28(%rbp), %rdi
callq 0x2350
movl %eax, -0x48(%rbp)
jmp 0x35d1
movq -0x38(%rbp), %rdi
callq 0x2350
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2350
movl %eax, -0x44(%rbp)
cmpl $0x1, -0x44(%rbp)
jl 0x35ec
cmpl $0xffff, -0x44(%rbp)    # imm = 0xFFFF
jle 0x3606
movl -0x44(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0xad14(%rip), %rdi      # 0xe30e
movb $0x0, %al
callq 0x2d40
jmp 0x36ec
cmpl $0x1, -0x48(%rbp)
jl 0x3615
cmpl $0xffff, -0x48(%rbp)    # imm = 0xFFFF
jle 0x362f
movl -0x48(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0xaceb(%rip), %rdi      # 0xe30e
movb $0x0, %al
callq 0x2d40
jmp 0x36ec
jmp 0x3631
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jg 0x36d4
movl $0x1, %edi
movl $0x90, %esi
callq 0x2210
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x88(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
leaq -0xc8(%rbp), %rsi
movl $0x80, %edx
callq 0x2270
movzwl -0xc8(%rbp), %eax
cmpl $0xa, %eax
jne 0x36ae
movl -0x44(%rbp), %eax
movzwl %ax, %edi
callq 0x2140
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0xa(%rax)
jmp 0x36c4
movl -0x44(%rbp), %eax
movzwl %ax, %edi
callq 0x2140
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0xa(%rax)
jmp 0x36c6
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3631
jmp 0x33d4
movq -0x40(%rbp), %rdi
callq 0x2040
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x36fd
movq -0x40(%rbp), %rdi
callq 0x2040
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopw (%rax,%rax)