// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, 0x8(%rsp)
xorl %eax, %eax
movb %al, 0x930(%rsi)
movb %al, 0x130(%rsi)
movb %al, 0x30(%rsi)
movb %al, (%rsi)
movzbl (%rdi), %r12d
testl %r12d, %r12d
je 0x1b90
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x30(%rsi), %rax
movq %rax, (%rsp)
cmpl $0x2f, %r12d
jne 0x1985
cmpb $0x2f, 0x1(%r15)
jne 0x1985
addq $0x2, %r15
jmp 0x1a54
callq 0x11c0
movq (%rax), %rax
leaq 0x3(%r15), %r14
xorl %r13d, %r13d
movzbl %r12b, %ecx
movzwl (%rax,%rcx,2), %edx
testl $0xc00, %edx            # imm = 0xC00
jne 0x19b1
leal -0x2d(%rcx), %edx
cmpl $0x2, %edx
jb 0x19b1
cmpl $0x2b, %ecx
jne 0x1a1b
movb -0x2(%r14), %r12b
incq %r14
incq %r13
testb %r12b, %r12b
jne 0x1994
testl %ebp, %ebp
je 0x1a54
addq $0x130, %rbx            # imm = 0x130
movq (%rsp), %rax
cmpb $0x0, (%rax)
je 0x19f1
leaq 0x1b62(%rip), %rsi      # 0x3541
movq %r15, %rdi
callq 0x10c0
addq %rax, %r15
movw $0x2f, (%rbx)
jmp 0x19f9
testl %ebp, %ebp
je 0x1b8a
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2134
xorl %r12d, %r12d
cmpq $0x800, %rax            # imm = 0x800
adcl $-0x1, %r12d
jmp 0x1b90
cmpl $0x3a, %ecx
jne 0x19c0
cmpb $0x2f, -0x2(%r14)
jne 0x19c0
cmpb $0x2f, -0x1(%r14)
jne 0x19c0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0x2f, %r13
ja 0x1b90
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x1140
movb $0x0, (%rbx,%r13)
movq %r14, %r15
cmpb $0x5b, (%r15)
jne 0x1ab3
movq %r15, %rdi
movl $0x5d, %esi
callq 0x1080
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x1b90
movq %rax, %r13
movq %rax, %r14
subq %r15, %r14
leaq -0x100(%r14), %rax
cmpq $-0xfd, %rax
jb 0x1b90
leaq 0x1(%r14), %rdx
movq (%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x1140
movb $0x0, 0x1(%r12,%r14)
incq %r13
movq %r13, %r15
jmp 0x1af1
leaq 0x1a86(%rip), %rsi      # 0x3540
movq %r15, %rdi
callq 0x10e0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0xff, %rax
ja 0x1b90
movq %rax, %r13
movq (%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1140
movb $0x0, (%r14,%r13)
addq %r13, %r15
cmpb $0x3a, (%r15)
jne 0x19c8
incq %r15
leaq 0x1a3c(%rip), %rsi      # 0x3541
movq %r15, %rdi
callq 0x10e0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0x5, %rax
ja 0x1b90
movq %rax, %r14
leaq 0x930(%rbx), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1140
movb $0x0, (%r13,%r14)
callq 0x1040
movq %rax, 0x10(%rsp)
movl $0x0, (%rax)
leaq 0x8(%rsp), %rsi
movq %r13, %rdi
movl $0xa, %edx
callq 0x1190
movq 0x10(%rsp), %rcx
cmpl $0x0, (%rcx)
jne 0x1b90
cmpb $0x0, (%r13)
je 0x1b90
movq 0x8(%rsp), %rcx
cmpb $0x0, (%rcx)
jne 0x1b90
addq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq $-0xffff, %rax          # imm = 0xFFFF0001
jb 0x1b90
addq %r14, %r15
jmp 0x19c8
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq