// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movb $0x0, 0x930(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x130(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0x30(%rax)
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x1a9d
movl $0x0, -0x4(%rbp)
jmp 0x1e6b
movq -0x28(%rbp), %rdi
leaq 0x1add(%rip), %rsi      # 0x3585
movl $0x2, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x1ac8
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0x1c0c
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x49(%rbp)
je 0x1b69
callq 0x11d0
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movzbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x400, %ecx            # imm = 0x400
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x4a(%rbp)
jne 0x1b63
callq 0x11d0
movq (%rax), %rax
movq -0x28(%rbp), %rcx
movzbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %ecx
andl $0x800, %ecx            # imm = 0x800
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x4a(%rbp)
jne 0x1b63
movq -0x28(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x2b, %ecx
movb %al, -0x4a(%rbp)
je 0x1b63
movq -0x28(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x2d, %ecx
movb %al, -0x4a(%rbp)
je 0x1b63
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
sete %al
movb %al, -0x4a(%rbp)
movb -0x4a(%rbp), %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x1b72
jmp 0x1b85
jmp 0x1b74
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1ad0
movq -0x28(%rbp), %rdi
leaq 0x19f4(%rip), %rsi      # 0x3584
movl $0x3, %edx
callq 0x1050
cmpl $0x0, %eax
jne 0x1bf5
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
cmpq $0x30, %rax
jb 0x1bbc
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e6b
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x10(%rbp), %rax
subq %rax, %rdx
callq 0x1150
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rdx
subq %rdx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x28(%rbp)
jmp 0x1c0a
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x1c08
jmp 0x1ddb
jmp 0x1c0a
jmp 0x1c0c
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0x1ca6
movq -0x28(%rbp), %rdi
movl $0x5d, %esi
callq 0x1090
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x1c58
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
cmpq $0x3, %rax
jb 0x1c58
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
cmpq $0x100, %rax            # imm = 0x100
jb 0x1c64
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e6b
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x28(%rbp), %rax
subq %rax, %rdx
addq $0x1, %rdx
callq 0x1150
movq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rdx
subq %rdx, %rcx
movb $0x0, 0x31(%rax,%rcx)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1cfc
movq -0x28(%rbp), %rdi
leaq 0x18d7(%rip), %rsi      # 0x3588
callq 0x10f0
movq %rax, -0x40(%rbp)
cmpq $0x100, %rax            # imm = 0x100
jb 0x1cce
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e6b
movq -0x18(%rbp), %rdi
addq $0x30, %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x1150
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movb $0x0, 0x30(%rax,%rcx)
movq -0x28(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0x1dd9
movq -0x28(%rbp), %rdi
addq $0x1, %rdi
movq %rdi, -0x28(%rbp)
leaq 0x1867(%rip), %rsi      # 0x3586
callq 0x10f0
movq %rax, -0x40(%rbp)
cmpq $0x6, %rax
jb 0x1d3a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e6b
movq -0x18(%rbp), %rdi
addq $0x930, %rdi            # imm = 0x930
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x1150
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movb $0x0, 0x930(%rax,%rcx)
callq 0x1040
movl $0x0, (%rax)
movq -0x18(%rbp), %rdi
addq $0x930, %rdi            # imm = 0x930
leaq -0x38(%rbp), %rsi
movl $0xa, %edx
callq 0x11a0
movq %rax, -0x48(%rbp)
callq 0x1040
cmpl $0x0, (%rax)
jne 0x1dc1
movq -0x18(%rbp), %rax
movsbl 0x930(%rax), %eax
cmpl $0x0, %eax
je 0x1dc1
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x1dc1
cmpq $0x0, -0x48(%rbp)
je 0x1dc1
cmpq $0xffff, -0x48(%rbp)    # imm = 0xFFFF
jbe 0x1dcd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e6b
movq -0x28(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x1ddb
movq -0x18(%rbp), %rax
cmpb $0x0, 0x30(%rax)
je 0x1e29
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rdi
leaq 0x178e(%rip), %rsi      # 0x3586
callq 0x10d0
movq %rax, %rcx
movq -0x58(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
leaq 0x1769(%rip), %rsi      # 0x3586
movl $0x800, %edx            # imm = 0x800
callq 0x2860
jmp 0x1e3a
cmpl $0x0, -0x1c(%rbp)
jne 0x1e38
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e6b
jmp 0x1e3a
movq -0x18(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
movq -0x28(%rbp), %rsi
movl $0x800, %edx            # imm = 0x800
callq 0x2730
cmpq $0x800, %rax            # imm = 0x800
jb 0x1e64
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1e6b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)