// File: /workspace/github_c_makefile_star2_O2/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, %rbp
movq %rsi, %r15
movq %rdi, %r14
movb $0x0, (%rdi)
leaq 0x94a(%rsp), %r13
movq %rcx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x18ac
pushq $-0x1
popq %rbx
cmpl $-0x1, %eax
je 0x1d3d
leaq 0x14(%rsp), %r12
pushq $0x1
popq %rdx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x18ac
cmpl $-0x1, %eax
je 0x1d3d
movb 0x44(%rsp), %al
movb 0x97a(%rsp), %cl
orb %al, %cl
je 0x1d3d
leaq 0x44(%rsp), %r8
cmpb $0x2f, (%rbp)
jne 0x1b99
cmpb $0x2f, 0x1(%rbp)
jne 0x1b99
leaq 0x944(%rsp), %rax
jmp 0x1bbf
leaq 0x97a(%rsp), %rcx
testb %al, %al
cmoveq %rcx, %r8
movl $0x930, %eax            # imm = 0x930
leaq (%r12,%rax), %rcx
addq %r13, %rax
cmpb $0x0, 0x944(%rsp)
cmovneq %rcx, %rax
cmpb $0x0, 0x94a(%rsp)
leaq 0x196c(%rip), %rcx      # 0x353a
cmoveq %rcx, %r13
cmpb $0x0, 0x14(%rsp)
cmoveq %r13, %r12
cmpb $0x0, (%rax)
leaq 0x18a1(%rip), %rcx      # 0x3486
leaq 0x1953(%rip), %r9       # 0x353f
cmoveq %rcx, %r9
movq %rax, (%rsp)
leaq 0x1933(%rip), %rdx      # 0x352e
leaq 0x1280(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movq %r12, %rcx
xorl %eax, %eax
callq 0x1090
cmpl $0xfff, %eax            # imm = 0xFFF
ja 0x1d3d
cmpb $0x0, 0x44(%rsp)
sete %cl
movb 0x144(%rsp), %al
cmpb $0x2f, %al
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x1c9e
leaq 0xa7a(%rsp), %r12
testb %al, %al
je 0x1c7d
pushq $0x2f
popq %rsi
movq %r12, %rdi
callq 0x10a0
testq %rax, %rax
je 0x1c9e
movq %rax, %r13
movl %ebx, %ebp
movb 0x1(%rax), %bl
movb $0x0, 0x1(%rax)
leaq 0x1280(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rsi
callq 0x1f9c
movb %bl, 0x1(%r13)
movl %ebp, %ebx
jmp 0x1c92
leaq 0x1280(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rsi
callq 0x1f9c
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0x1d3d
leaq 0x144(%rsp), %rsi
leaq 0x1280(%rsp), %r12
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
callq 0x1f9c
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0x1d3d
xorl %r13d, %r13d
leaq 0x1895(%rip), %rbp      # 0x3562
movzbl (%r12), %ebx
cmpl $0x20, %ebx
je 0x1cfb
testl %ebx, %ebx
je 0x1d2e
testb %bl, %bl
js 0x1cfb
callq 0x11c0
movq (%rax), %rax
testb $0x2, (%rax,%rbx,2)
jne 0x1cfb
cmpq %r15, %r13
jae 0x1d29
movb %bl, (%r14,%r13)
incq %r13
jmp 0x1d24
leaq 0x3(%r13), %rax
cmpq %r15, %rax
jae 0x1d29
movb $0x25, (%r14,%r13)
movl %ebx, %ecx
shrl $0x4, %ecx
movb (%rcx,%rbp), %cl
movb %cl, 0x1(%r14,%r13)
andl $0xf, %ebx
movb (%rbx,%rbp), %cl
movb %cl, 0x2(%r14,%r13)
movq %rax, %r13
incq %r12
jmp 0x1ccd
pushq $-0x1
popq %rbx
jmp 0x1d3d
cmpq %r15, %r13
pushq $-0x1
popq %rbx
jae 0x1d3d
movb $0x0, (%r14,%r13)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x2288, %rsp           # imm = 0x2288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq