// File: /workspace/github_c_makefile_star2_O2/martintopholm[P]xping/http.c
// Function: probe_new
struct probe *
probe_new(const char *line, void *owner)
{
	struct probe *prb;
	union addr sa;
	int salen;
	int port;
	regmatch_t match[RE_MAX];
	char forced[512];
	char *end;
	int i, j;

	if (regexec(&re_target, line, RE_MAX, match, 0) != 0) {
		fprintf(stderr, "probe_add: can't parse %.128s\n", line);
		return NULL;
	}

	prb = calloc(1, sizeof(*prb));
	if (prb == NULL) {
		perror("probe_add: calloc");
		return (prb);
	}
	prb->owner = owner;

	if (line[match[RE_PROTO].rm_so + 4] == 's') {
#ifdef WITH_SSL
		long ssl_options;
		prb->ssl_ctx = SSL_CTX_new(SSLv23_method());
		if (prb->ssl_ctx == NULL) {
			perror("probe_add: SSL_CTX_new");
			return NULL;
		}
		ssl_options = SSL_CTX_get_options(prb->ssl_ctx);
		ssl_options |= SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1;
		SSL_CTX_set_options(prb->ssl_ctx, ssl_options);
#else /* !WITH_SSL */
		free(prb);
		fprintf(stderr, "probe_add: ssl support not compiled in\n");
		return NULL;
#endif /* WITH_SSL */
	}

	strncat(prb->host, line + match[RE_HOST].rm_so,
	    MIN(sizeof(prb->host) - 1,
	    match[RE_HOST].rm_eo - match[RE_HOST].rm_so));
	if (match[RE_PORT].rm_so  != -1)
		port = strtol(line + match[RE_PORT].rm_so + 1, &end, 10);
#ifdef WITH_SSL
	else if (prb->ssl_ctx != NULL)
		port = 443;
#endif /* !WITH_SSL */
	else
		port = 80;

	/* prb->query NULL termination is provided by calloc */
	if (match[RE_URL].rm_so != -1)
		for (i = match[RE_URL].rm_so, j = 0; i < match[RE_URL].rm_eo &&
		    j + 3 < sizeof(prb->query) - 1; i++) {
			const char *src = &line[i];
			if (uri_chars[(unsigned char)*src])
				prb->query[j++] = *src;
			else if (*src == ' ')
				prb->query[j++] = '+';
			else
				prb->query[j++] = '%',
				    prb->query[j++] = to_hex(*src >> 4),
				    prb->query[j++] = to_hex(*src & 0xf);
		}
	else
		prb->query[0] = '/';

	/*
	 * Check for presence of forced address e.g. example.com[127.0.0.1].
	 * If present parse the address or return an error. Otherwise
	 * check the hostname for an ip literal, if it doesn't parse
	 * leave it to target_add to resolve.
	 */
	salen = sizeof(sa);
	if (match[RE_FORCED].rm_so != -1) {
		forced[0] = '\0';
		strncat(forced, line + match[RE_FORCED].rm_so,
		    MIN(sizeof(forced) - 1,
		    match[RE_FORCED].rm_eo - match[RE_FORCED].rm_so));
		if (evutil_parse_sockaddr_port(forced, &sa.sa, &salen) == 0) {
			sa(prb)->sa_family = sa.sa.sa_family;
			if (sa.sa.sa_family == AF_INET6) {
				memcpy(&sin6(prb)->sin6_addr,
				    &sa.sin6.sin6_addr,
				    sizeof(sin6(prb)->sin6_addr));
			} else {
				memcpy(&sin(prb)->sin_addr, &sa.sin.sin_addr,
				    sizeof(sin(prb)->sin_addr));
			}
			prb->resolved = 1;
		} else {
			fprintf(stderr, "probe_add: can't parse %.128s\n",
			    line);
			free(prb);
			return NULL;
		}
	} else {
		salen = sizeof(sa);
		if (evutil_parse_sockaddr_port(prb->host, &sa.sa,
		    &salen) == 0) {
			sa(prb)->sa_family = sa.sa.sa_family;
			if (sa.sa.sa_family == AF_INET6) {
				memcpy(&sin6(prb)->sin6_addr,
				    &sa.sin6.sin6_addr,
				    sizeof(sin6(prb)->sin6_addr));
			} else {
				memcpy(&sin(prb)->sin_addr, &sa.sin.sin_addr,
				    sizeof(sin(prb)->sin_addr));
			}
			prb->resolved = 1;
		} else {
			prb->dnstask = dnstask_new(prb->host, resolved, prb);
			if (prb->dnstask == NULL) {
				free(prb);
				return NULL;
			}
		}
	}
	sin(prb)->sin_port = htons(port);
	return (prb);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rsi, %r15
movq %rdi, %r14
leaq 0x547a(%rip), %rdi      # 0x82b8
pushq $0x8
popq %rdx
leaq 0x20(%rsp), %rcx
movq %r14, %rsi
xorl %r8d, %r8d
callq 0x2280
testl %eax, %eax
jne 0x3022
pushq $0x1
popq %rdi
movl $0xb8, %esi
callq 0x2120
testq %rax, %rax
je 0x3041
movq %rax, %rbx
movq %r15, 0xb0(%rax)
movslq 0x28(%rsp), %rax
cmpb $0x73, 0x4(%r14,%rax)
je 0x304f
movslq 0x38(%rsp), %rsi
movl 0x3c(%rsp), %eax
subl %esi, %eax
addq %r14, %rsi
cmpl $0x3f, %eax
pushq $0x3f
popq %rdx
cmovbl %eax, %edx
movq %rbx, %rdi
callq 0x2130
movslq 0x50(%rsp), %rax
cmpq $-0x1, %rax
je 0x2ecd
leaq (%r14,%rax), %rdi
incq %rdi
leaq 0x68(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x22f0
movq %rax, %r15
jmp 0x2ed2
movw $0x50, %r15w
movslq 0x58(%rsp), %rax
cmpq $-0x1, %rax
je 0x2f61
movslq 0x5c(%rsp), %rcx
xorl %r8d, %r8d
leaq 0x2230(%rip), %rdx      # 0x5120
leaq 0x2449(%rip), %rsi      # 0x5340
cmpq %rcx, %rax
jge 0x2f65
leal 0x3(%r8), %edi
cmpl $0x3e, %edi
ja 0x2f65
movb (%r14,%rax), %r11b
movzbl %r11b, %r10d
cmpb $0x0, (%r10,%rdx)
movslq %r8d, %r9
je 0x2f21
incl %r8d
movb %r11b, 0x60(%rbx,%r9)
jmp 0x2f31
leaq 0x1(%r9), %r8
cmpb $0x20, %r11b
jne 0x2f3c
movb $0x2b, 0x60(%rbx,%r9)
movl %r8d, %edi
incq %rax
movl %edi, %r8d
jmp 0x2ef7
movb $0x25, 0x60(%rbx,%r9)
movl %r10d, %r11d
shrl $0x4, %r11d
movb (%r11,%rsi), %r11b
movb %r11b, 0x60(%rbx,%r8)
andl $0xf, %r10d
movb (%r10,%rsi), %r8b
movb %r8b, 0x62(%rbx,%r9)
jmp 0x2f34
movb $0x2f, 0x60(%rbx)
movl $0x1c, (%rsp)
movslq 0x48(%rsp), %rax
cmpq $-0x1, %rax
je 0x2fd1
leaq 0x70(%rsp), %r12
movb $0x0, (%r12)
movq %rax, %rsi
addq %r14, %rsi
movl 0x4c(%rsp), %edx
subl %eax, %edx
movl $0x1ff, %eax            # imm = 0x1FF
cmpl %eax, %edx
cmovael %eax, %edx
movq %r12, %rdi
callq 0x2130
leaq 0x4(%rsp), %rsi
movq %rsp, %rdx
movq %r12, %rdi
callq 0x20a0
testl %eax, %eax
jne 0x3075
movzwl 0x4(%rsp), %eax
movw %ax, 0x44(%rbx)
cmpw $0xa, %ax
jne 0x3008
movups 0xc(%rsp), %xmm0
movups %xmm0, 0x4c(%rbx)
jmp 0x300f
leaq 0x4(%rsp), %rsi
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x20a0
testl %eax, %eax
je 0x2fb7
leaq 0xc0(%rip), %rsi        # 0x30ac
movq %rbx, %rdi
movq %rbx, %rdx
callq 0x3df4
movq %rax, 0xa8(%rbx)
testq %rax, %rax
jne 0x3016
jmp 0x3090
movl 0x8(%rsp), %eax
movl %eax, 0x48(%rbx)
movl $0x1, 0x40(%rbx)
rolw $0x8, %r15w
movw %r15w, 0x46(%rbx)
jmp 0x309a
movq 0x4faf(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
leaq 0x2266(%rip), %rsi      # 0x5299
xorl %ebx, %ebx
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
jmp 0x309a
leaq 0x2270(%rip), %rdi      # 0x52b8
callq 0x2170
jmp 0x3098
movq %rbx, %rdi
callq 0x2250
movq 0x4f7a(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x2262(%rip), %rdi      # 0x52ca
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x23e0
jmp 0x3098
movq 0x4f5c(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
leaq 0x2213(%rip), %rsi      # 0x5299
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
movq %rbx, %rdi
callq 0x2250
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r14
popq %r15
retq