// File: karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: khttp_parse_url
knetFile *khttp_parse_url(const char *fn, const char *mode)
{
	knetFile *fp;
	char *p, *proxy, *q;
	int l;
	if (strstr(fn, "http://") != fn) return 0;
	// set ->http_host
	for (p = (char*)fn + 7; *p && *p != '/'; ++p);
	l = p - fn - 7;
	fp = (knetFile*)calloc(1, sizeof(knetFile));
	fp->http_host = (char*)calloc(l + 1, 1);
	strncpy(fp->http_host, fn + 7, l);
	fp->http_host[l] = 0;
	for (q = fp->http_host; *q && *q != ':'; ++q);
	if (*q == ':') *q++ = 0;
	// get http_proxy
	proxy = getenv("http_proxy");
	// set ->host, ->port and ->path
	if (proxy == 0) {
		fp->host = strdup(fp->http_host); // when there is no proxy, server name is identical to http_host name.
		fp->port = strdup(*q? q : "80");
		fp->path = strdup(*p? p : "/");
	} else {
		fp->host = (strstr(proxy, "http://") == proxy)? strdup(proxy + 7) : strdup(proxy);
		for (q = fp->host; *q && *q != ':'; ++q);
		if (*q == ':') *q++ = 0; 
		fp->port = strdup(*q? q : "80");
		fp->path = strdup(fn);
	}
	fp->type = KNF_TYPE_HTTP;
	fp->ctrl_fd = fp->fd = -1;
	fp->seek_offset = 0;
	return fp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x82ba(%rip), %rsi      # 0x7ee05
callq 0x4110
cmpq -0x10(%rbp), %rax
je 0x76b63
movq $0x0, -0x8(%rbp)
jmp 0x76e44
movq -0x10(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x3d(%rbp)
je 0x76b90
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
setne %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x76b99
jmp 0x76ba9
jmp 0x76b9b
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x76b6f
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
subq $0x7, %rax
movl %eax, -0x3c(%rbp)
movl $0x1, %edi
movl $0x80, %esi
callq 0x4370
movq %rax, -0x20(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x4370
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x7, %rsi
movslq -0x3c(%rbp), %rdx
callq 0x42c0
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rax
movslq -0x3c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x3e(%rbp)
je 0x76c42
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
setne %al
movb %al, -0x3e(%rbp)
movb -0x3e(%rbp), %al
testb $0x1, %al
jne 0x76c4b
jmp 0x76c5b
jmp 0x76c4d
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x76c21
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0x76c79
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x0, (%rax)
leaq 0x818d(%rip), %rdi      # 0x7ee0d
callq 0x46e0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x76d1f
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x4aa0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x76cc2
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x76ccf
leaq 0x814f(%rip), %rax      # 0x7ee18
movq %rax, -0x48(%rbp)
jmp 0x76ccf
movq -0x48(%rbp), %rdi
callq 0x4aa0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x76cf9
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x76d06
leaq 0x7c37(%rip), %rax      # 0x7e937
movq %rax, -0x50(%rbp)
jmp 0x76d06
movq -0x50(%rbp), %rdi
callq 0x4aa0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x76e10
movq -0x30(%rbp), %rdi
leaq 0x80db(%rip), %rsi      # 0x7ee05
callq 0x4110
cmpq -0x30(%rbp), %rax
jne 0x76d48
movq -0x30(%rbp), %rdi
addq $0x7, %rdi
callq 0x4aa0
movq %rax, -0x58(%rbp)
jmp 0x76d55
movq -0x30(%rbp), %rdi
callq 0x4aa0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x59(%rbp)
je 0x76d8e
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
setne %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x76d97
jmp 0x76da7
jmp 0x76d99
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x76d6d
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0x76dc5
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movb $0x0, (%rax)
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x76ddb
movq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x76de8
leaq 0x8036(%rip), %rax      # 0x7ee18
movq %rax, -0x68(%rbp)
jmp 0x76de8
movq -0x68(%rbp), %rdi
callq 0x4aa0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rdi
callq 0x4aa0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x20(%rbp), %rax
movl $0x3, (%rax)
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nop