// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, 0x10(%rsp)
xorl %eax, %eax
movb %al, 0x930(%rsi)
movb %al, 0x130(%rsi)
movb %al, 0x30(%rsi)
movb %al, (%rsi)
movzbl (%rdi), %ebx
testl %ebx, %ebx
je 0x1944
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %r12
leaq 0x30(%rsi), %rax
movq %rax, 0x8(%rsp)
pushq $-0x1
popq %rbp
cmpl $0x2f, %ebx
jne 0x1905
cmpb $0x2f, 0x1(%r12)
jne 0x1905
addq $0x2, %r12
jmp 0x19bf
movl %r15d, (%rsp)
callq 0x11c0
movq (%rax), %rax
leaq 0x3(%r12), %r15
xorl %r13d, %r13d
testb %bl, %bl
je 0x1984
movzbl %bl, %ecx
movzwl (%rax,%rcx,2), %edx
testw $0xc00, %dx             # imm = 0xC00
jne 0x1938
leal -0x2d(%rcx), %edx
cmpl $0x2, %edx
jb 0x1938
cmpl $0x2b, %ecx
jne 0x194b
movb -0x2(%r15), %bl
incq %r15
incq %r13
jmp 0x1919
movl %ebx, %ebp
jmp 0x1b00
cmpl $0x3a, %ecx
jne 0x1984
cmpb $0x2f, -0x2(%r15)
jne 0x1984
cmpb $0x2f, -0x1(%r15)
jne 0x1984
cmpq $0x2f, %r13
ja 0x1b00
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1140
movb $0x0, (%r14,%r13)
movq %r15, %r12
movl (%rsp), %r15d
jmp 0x19bf
movl (%rsp), %r15d
testl %r15d, %r15d
je 0x19bf
addq $0x130, %r14            # imm = 0x130
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x1ae0
leaq 0x1b83(%rip), %rsi      # 0x352c
movq %r12, %rdi
callq 0x10c0
addq %rax, %r12
movw $0x2f, (%r14)
jmp 0x1ae5
cmpb $0x5b, (%r12)
jne 0x1a19
pushq $0x5d
popq %rsi
movq %r12, %rdi
callq 0x1080
testq %rax, %rax
je 0x1b00
movq %rax, %r13
movq %rax, %rbx
subq %r12, %rbx
leaq -0x100(%rbx), %rax
cmpq $-0xfd, %rax
jb 0x1b00
leaq 0x1(%rbx), %rdx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x1140
movq 0x8(%rsp), %rax
movb $0x0, 0x1(%rax,%rbx)
incq %r13
movq %r13, %r12
jmp 0x1a52
leaq 0x1b0b(%rip), %rsi      # 0x352b
movq %r12, %rdi
callq 0x10e0
cmpq $0xff, %rax
ja 0x1b00
movq %rax, %r13
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x1140
movb $0x0, (%rbx,%r13)
addq %r13, %r12
cmpb $0x3a, (%r12)
jne 0x198d
incq %r12
leaq 0x1ac5(%rip), %rsi      # 0x352c
movq %r12, %rdi
callq 0x10e0
cmpq $0x5, %rax
ja 0x1b00
movq %rax, %r13
leaq 0x930(%r14), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x1140
movb $0x0, (%rbx,%r13)
callq 0x1040
movq %rax, (%rsp)
andl $0x0, (%rax)
leaq 0x10(%rsp), %rsi
pushq $0xa
popq %rdx
movq %rbx, %rdi
callq 0x1190
movq (%rsp), %rcx
cmpl $0x0, (%rcx)
jne 0x1b00
cmpb $0x0, (%rbx)
je 0x1b00
movq 0x10(%rsp), %rcx
cmpb $0x0, (%rcx)
jne 0x1b00
addq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq $-0xffff, %rax          # imm = 0xFFFF0001
jb 0x1b00
addq %r13, %r12
jmp 0x198d
testl %r15d, %r15d
je 0x1b00
movl $0x800, %edx            # imm = 0x800
movq %r14, %rdi
movq %r12, %rsi
callq 0x1f9c
xorl %ebp, %ebp
cmpq $0x800, %rax            # imm = 0x800
adcl $-0x1, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq