// File: /workspace/github_c_makefile_star2_O1/dxwc[P]sfeed/util.c
// Function: parseuri
int
parseuri(const char *s, struct uri *u, int rel)
{
	const char *p = s, *b;
	char *endptr = NULL;
	size_t i;
	unsigned long l;

	u->proto[0] = u->host[0] = u->path[0] = u->port[0] = '\0';
	if (!*s)
		return 0;

	/* prefix is "//", don't read protocol, skip to domain parsing */
	if (!strncmp(p, "//", 2)) {
		p += 2; /* skip "//" */
	} else {
		/* protocol part */
		for (p = s; *p && (isalpha((unsigned char)*p) || isdigit((unsigned char)*p) ||
			       *p == '+' || *p == '-' || *p == '.'); p++)
			;
		if (!strncmp(p, "://", 3)) {
			if ((size_t)(p - s) >= sizeof(u->proto))
				return -1; /* protocol too long */
			memcpy(u->proto, s, p - s);
			u->proto[p - s] = '\0';
			p += 3; /* skip "://" */
		} else {
			p = s; /* no protocol format, set to start */
			/* relative url: read rest as path, else as domain */
			if (rel)
				goto readpath;
		}
	}
	/* IPv6 address */
	if (*p == '[') {
		/* bracket not found or host too long */
		if (!(b = strchr(p, ']')) || (size_t)(b - p) < 3 ||
		    (size_t)(b - p) >= sizeof(u->host))
			return -1;
		memcpy(u->host, p, b - p + 1);
		u->host[b - p + 1] = '\0';
		p = b + 1;
	} else {
		/* domain / host part, skip until port, path or end. */
		if ((i = strcspn(p, ":/")) >= sizeof(u->host))
			return -1; /* host too long */
		memcpy(u->host, p, i);
		u->host[i] = '\0';
		p = &p[i];
	}
	/* port */
	if (*p == ':') {
		if ((i = strcspn(++p, "/")) >= sizeof(u->port))
			return -1; /* port too long */
		memcpy(u->port, p, i);
		u->port[i] = '\0';
		/* check for valid port: range 1 - 65535 */
		errno = 0;
		l = strtoul(u->port, &endptr, 10);
		if (errno || u->port[0] == '\0' || *endptr ||
		    !l || l > 65535)
			return -1;
		p = &p[i];
	}
readpath:
	if (u->host[0]) {
		p = &p[strspn(p, "/")];
		strlcpy(u->path, "/", sizeof(u->path));
	} else {
		/* absolute uri must have a host specified */
		if (!rel)
			return -1;
	}
	/* treat truncation as an error */
	if (strlcat(u->path, p, sizeof(u->path)) >= sizeof(u->path))
		return -1;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, 0x4(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
movb %r12b, 0x930(%rsi)
movb %r12b, 0x130(%rsi)
movb %r12b, 0x30(%rsi)
movb %r12b, (%rsi)
cmpb %r12b, (%rdi)
je 0x1b70
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x30(%rsi), %rbp
leaq 0x1bd7(%rip), %rsi      # 0x3510
movl $0x2, %edx
callq 0x1050
testl %eax, %eax
je 0x19b4
movb (%r14), %r15b
movq %r14, %r13
testb %r15b, %r15b
je 0x198f
callq 0x11d0
movq (%rax), %rax
movabsq $0x680000000000, %rcx   # imm = 0x680000000000
movq %r14, %r13
movzbl %r15b, %edx
movzwl (%rax,%rdx,2), %esi
testl $0xc00, %esi            # imm = 0xC00
jne 0x1983
cmpb $0x2e, %r15b
ja 0x198f
btq %rdx, %rcx
jae 0x198f
movb 0x1(%r13), %r15b
incq %r13
testb %r15b, %r15b
jne 0x1967
leaq 0x1b79(%rip), %rsi      # 0x350f
movl $0x3, %edx
movq %r13, %rdi
callq 0x1050
testl %eax, %eax
je 0x19ba
cmpl $0x0, 0x4(%rsp)
jne 0x1b26
jmp 0x19ea
addq $0x2, %r14
jmp 0x19ea
movq %r13, %r15
subq %r14, %r15
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0x2f, %r15
ja 0x1b70
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1150
movb $0x0, (%rbx,%r15)
addq $0x3, %r13
movq %r13, %r14
movq %rbp, 0x8(%rsp)
cmpb $0x5b, (%r14)
jne 0x1a4f
movq %r14, %rdi
movl $0x5d, %esi
callq 0x1090
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x1b70
movq %rax, %r13
movq %rax, %r15
subq %r14, %r15
leaq -0x100(%r15), %rax
cmpq $-0xfd, %rax
jb 0x1b70
leaq 0x1(%r15), %rdx
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1150
movb $0x0, 0x1(%rbp,%r15)
incq %r13
movq %r13, %r14
jmp 0x1a8f
leaq 0x1abd(%rip), %rsi      # 0x3513
movq %r14, %rdi
callq 0x10f0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0xff, %rax
ja 0x1b70
movq %rax, %r13
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1150
movb $0x0, (%rbp,%r13)
addq %r13, %r14
cmpb $0x3a, (%r14)
jne 0x1b26
incq %r14
leaq 0x1a6e(%rip), %rsi      # 0x3511
movq %r14, %rdi
callq 0x10f0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0x5, %rax
ja 0x1b70
movq %rax, %rbp
leaq 0x930(%rbx), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x1150
movb $0x0, (%r13,%rbp)
callq 0x1040
movq %rax, %r15
movl $0x0, (%rax)
leaq 0x10(%rsp), %rsi
movq %r13, %rdi
movl $0xa, %edx
callq 0x11a0
cmpl $0x0, (%r15)
jne 0x1b70
cmpb $0x0, (%r13)
je 0x1b70
movq 0x10(%rsp), %rcx
cmpb $0x0, (%rcx)
jne 0x1b70
addq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq $-0xffff, %rax          # imm = 0xFFFF0001
jb 0x1b70
addq %rbp, %r14
movq 0x8(%rsp), %rbp
addq $0x130, %rbx            # imm = 0x130
cmpb $0x0, (%rbp)
je 0x1b4c
leaq 0x19d7(%rip), %rsi      # 0x3511
movq %r14, %rdi
callq 0x10d0
addq %rax, %r14
movw $0x2f, (%rbx)
jmp 0x1b53
cmpl $0x0, 0x4(%rsp)
je 0x1b82
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
movq %r14, %rsi
callq 0x20ac
xorl %r12d, %r12d
cmpq $0x800, %rax            # imm = 0x800
adcl $-0x1, %r12d
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x1b70