// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: kftp_connect_file
int kftp_connect_file(knetFile *fp)
{
	int ret;
	long long file_size;
	if (fp->fd != -1) {
		netclose(fp->fd);
		if (fp->no_reconnect) kftp_get_response(fp);
	}
	kftp_pasv_prep(fp);
    kftp_send_cmd(fp, fp->size_cmd, 1);
#ifndef _WIN32
    // If the file does not exist, the response will be "550 Could not get file
    // size". Be silent on failure, hts_idx_load can be trying the existence of .csi or .tbi.
    if ( sscanf(fp->response,"%*d %lld", &file_size) != 1 ) return -1;
#else
	const char *p = fp->response;
	while (*p != ' ') ++p;
	while (*p < '0' || *p > '9') ++p;
	file_size = strtoint64(p);
#endif
	fp->file_size = file_size;
	if (fp->offset>=0) {
		char tmp[32];
#ifndef _WIN32
		sprintf(tmp, "REST %lld\r\n", (long long)fp->offset);
#else
		strcpy(tmp, "REST ");
		int64tostr(tmp + 5, fp->offset);
		strcat(tmp, "\r\n");
#endif
		kftp_send_cmd(fp, tmp, 1);
	}
	kftp_send_cmd(fp, fp->retr, 0);
	kftp_pasv_connect(fp);
	ret = kftp_get_response(fp);
	if (ret != 150) {
		fprintf(stderr, "[kftp_connect_file] %s\n", fp->response);
		netclose(fp->fd);
		fp->fd = -1;
		return -1;
	}
	fp->is_ready = 1;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movl 0x4(%rdi), %edi
cmpl $-0x1, %edi
je 0x3fa51
callq 0x4a40
cmpl $0x0, 0x3c(%rbx)
je 0x3fa51
movq %rbx, %rdi
callq 0x3f746
leaq 0x802b(%rip), %rsi      # 0x47a83
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x3f86b
movq 0x48(%rbx), %rdi
incq %rdi
movzbl -0x1(%rdi), %eax
testl %eax, %eax
je 0x3fac5
cmpl $0x28, %eax
jne 0x3fa67
leaq 0x14(%rsp), %rcx
leaq 0x18(%rsp), %r8
leaq 0x1c(%rsp), %r9
leaq 0x20(%rsp), %r10
leaq 0x24(%rsp), %r11
leaq 0x7ff3(%rip), %rsi      # 0x47a8a
leaq 0x10(%rsp), %r14
movq %r14, %rdx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x4510
popq %rcx
popq %rdx
movaps (%r14), %xmm0
movups %xmm0, 0x24(%rbx)
movl 0x10(%r14), %eax
shll $0x8, %eax
movzwl %ax, %eax
addl 0x14(%r14), %eax
movl %eax, 0x34(%rbx)
movq 0x58(%rbx), %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x3f86b
movq 0x48(%rbx), %rdi
leaq 0x7e72(%rip), %rsi      # 0x47951
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x4510
pushq $-0x1
popq %rbp
cmpl $0x1, %eax
jne 0x3fba4
movq 0x8(%rsp), %rax
movq %rax, 0x68(%rbx)
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
js 0x3fb2d
leaq 0x7e4a(%rip), %rsi      # 0x4795a
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x4100
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3f86b
movq 0x50(%rbx), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3f86b
cmpl $0x0, 0x34(%rbx)
je 0x3fbb1
movl 0x24(%rbx), %edx
movl 0x28(%rbx), %ecx
movl 0x2c(%rbx), %r8d
movl 0x30(%rbx), %r9d
leaq 0x7f87(%rip), %rsi      # 0x47add
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x4100
movl 0x34(%rbx), %edx
leaq 0x7f2a(%rip), %rsi      # 0x47a99
leaq 0x6e(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x4100
movq %r14, %rdi
movq %r15, %rsi
callq 0x3f623
movl %eax, 0x4(%rbx)
movq %rbx, %rdi
callq 0x3f746
cmpl $0x96, %eax
jne 0x3fbcf
movl $0x1, 0x40(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x17418(%rip), %rax     # 0x56fd0
movq (%rax), %rcx
leaq 0x7eda(%rip), %rdi      # 0x47a9c
pushq $0x40
popq %rsi
pushq $0x1
popq %rdx
callq 0x4a20
jmp 0x3fb8c
movq 0x173fa(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
movq 0x48(%rbx), %rdx
leaq 0x7d82(%rip), %rsi      # 0x47966
xorl %eax, %eax
callq 0x4770
movl 0x4(%rbx), %edi
callq 0x4a40
orl $-0x1, 0x4(%rbx)
jmp 0x3fba4