// File: /workspace/github_c_makefile_star2_O1/dxwc[P]sfeed/util.c
// Function: absuri
int
absuri(char *buf, size_t bufsiz, const char *link, const char *base)
{
	struct uri ulink, ubase;
	char tmp[4096], *host, *p, *port;
	int c, r;
	size_t i;

	buf[0] = '\0';
	if (parseuri(base, &ubase, 0) == -1 ||
	    parseuri(link, &ulink, 1) == -1 ||
	    (!ulink.host[0] && !ubase.host[0]))
		return -1;

	if (!strncmp(link, "//", 2)) {
		host = ulink.host;
		port = ulink.port;
	} else {
		host = ulink.host[0] ? ulink.host : ubase.host;
		port = ulink.port[0] ? ulink.port : ubase.port;
	}
	r = snprintf(tmp, sizeof(tmp), "%s://%s%s%s",
		ulink.proto[0] ?
			ulink.proto :
			(ubase.proto[0] ? ubase.proto : "http"),
		host,
		port[0] ? ":" : "",
		port);
	if (r < 0 || (size_t)r >= sizeof(tmp))
		return -1; /* error or truncation */

	/* relative to root */
	if (!ulink.host[0] && ulink.path[0] != '/') {
		/* relative to base url path */
		if (ulink.path[0]) {
			if ((p = strrchr(ubase.path, '/'))) {
				/* temporary null-terminate */
				c = *(++p);
				*p = '\0';
				i = strlcat(tmp, ubase.path, sizeof(tmp));
				*p = c; /* restore */
				if (i >= sizeof(tmp))
					return -1;
			}
		} else if (strlcat(tmp, ubase.path, sizeof(tmp)) >=
		           sizeof(tmp)) {
			return -1;
		}
	}
	if (strlcat(tmp, ulink.path, sizeof(tmp)) >= sizeof(tmp))
		return -1;

	return encodeuri(buf, bufsiz, tmp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2288, %rsp           # imm = 0x2288
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movb $0x0, (%rdi)
leaq 0x94a(%rsp), %r13
movq %rcx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x18ec
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x1d68
leaq 0x14(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x18ec
cmpl $-0x1, %eax
je 0x1d68
movq %r15, 0x8(%rsp)
movb 0x44(%rsp), %r15b
movb 0x97a(%rsp), %al
orb %r15b, %al
je 0x1d68
leaq 0x44(%rsp), %rbp
leaq 0x1902(%rip), %rsi      # 0x3510
movl $0x2, %edx
movq %rbx, %rdi
callq 0x1050
testl %eax, %eax
je 0x1c48
leaq 0x97a(%rsp), %rax
testb %r15b, %r15b
cmoveq %rax, %rbp
movl $0x930, %eax            # imm = 0x930
leaq (%r12,%rax), %rcx
addq %r13, %rax
cmpb $0x0, 0x944(%rsp)
cmovneq %rcx, %rax
jmp 0x1c50
leaq 0x944(%rsp), %rax
movq 0x8(%rsp), %r15
cmpb $0x0, 0x94a(%rsp)
leaq 0x18be(%rip), %rcx      # 0x3522
cmoveq %rcx, %r13
cmpb $0x0, 0x14(%rsp)
cmoveq %r13, %r12
cmpb $0x0, (%rax)
leaq 0x17ef(%rip), %rcx      # 0x346a
leaq 0x18a5(%rip), %r9       # 0x3527
cmoveq %rcx, %r9
movq %rax, (%rsp)
leaq 0x1885(%rip), %rdx      # 0x3516
leaq 0x1280(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r12, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x10a0
cmpl $0xfff, %eax            # imm = 0xFFF
jbe 0x1cbc
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1d68
cmpb $0x0, 0x44(%rsp)
sete %cl
movb 0x144(%rsp), %al
cmpb $0x2f, %al
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jne 0x1d43
leaq 0xa7a(%rsp), %rbx
testb %al, %al
je 0x1d26
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x10b0
testq %rax, %rax
je 0x1d43
movq %rax, %r12
movb 0x1(%rax), %bpl
movb $0x0, 0x1(%rax)
leaq 0x1280(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rsi
callq 0x20ac
movb %bpl, 0x1(%r12)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x1d3b
leaq 0x1280(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rsi
callq 0x20ac
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0x1d68
leaq 0x144(%rsp), %rsi
leaq 0x1280(%rsp), %r12
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
callq 0x20ac
cmpq $0xfff, %rax            # imm = 0xFFF
jbe 0x1d7c
movl %ebp, %eax
addq $0x2288, %rsp           # imm = 0x2288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
leaq 0x17c5(%rip), %r13      # 0x354a
movzbl (%r12), %ebp
cmpl $0x20, %ebp
je 0x1db8
testl %ebp, %ebp
je 0x1ded
testb %bpl, %bpl
js 0x1db8
callq 0x11d0
movq (%rax), %rax
testb $0x2, (%rax,%rbp,2)
jne 0x1db8
cmpq %r15, %rbx
jae 0x1cb2
movb %bpl, (%r14,%rbx)
incq %rbx
jmp 0x1de8
leaq 0x3(%rbx), %rax
cmpq %r15, %rax
jae 0x1cb2
movb $0x25, (%r14,%rbx)
movl %ebp, %ecx
shrl $0x4, %ecx
movb (%rcx,%r13), %cl
movb %cl, 0x1(%r14,%rbx)
andl $0xf, %ebp
movb (%rbp,%r13), %cl
movb %cl, 0x2(%r14,%rbx)
movq %rax, %rbx
incq %r12
jmp 0x1d85
cmpq %r15, %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jae 0x1d68
movb $0x0, (%r14,%rbx)
xorl %ebp, %ebp
jmp 0x1d68