// File: karel-brinda[P]ococo/ext/htslib/knetfile.c
// Function: kftp_get_response
static int kftp_get_response(knetFile *ftp)
{
#ifndef _WIN32
	unsigned char c;
#else
	char c;
#endif
	int n = 0;
	char *p;
	if (socket_wait(ftp->ctrl_fd, 1) <= 0) return 0;
	while (netread(ftp->ctrl_fd, &c, 1)) { // FIXME: this is *VERY BAD* for unbuffered I/O
		//fputc(c, stderr);
		if (n >= ftp->max_response) {
			ftp->max_response = ftp->max_response? ftp->max_response<<1 : 256;
			ftp->response = (char*)realloc(ftp->response, ftp->max_response);
		}
		ftp->response[n++] = c;
		if (c == '\n') {
			if (n >= 4 && isdigit(ftp->response[0]) && isdigit(ftp->response[1]) && isdigit(ftp->response[2])
				&& ftp->response[3] != '-') break;
			n = 0;
			continue;
		}
	}
	if (n < 2) return -1;
	ftp->response[n-2] = 0;
	return strtol(ftp->response, &p, 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %edi
movl $0x1, %esi
callq 0x778a0
cmpl $0x0, %eax
jg 0x763b5
movl $0x0, -0x4(%rbp)
jmp 0x7652d
jmp 0x763b7
movq -0x10(%rbp), %rax
movl 0x20(%rax), %edi
leaq -0x11(%rbp), %rsi
movl $0x1, %edx
callq 0x4840
cmpq $0x0, %rax
je 0x764f3
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jl 0x7642e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x763fa
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
shll %eax
movl %eax, -0x24(%rbp)
jmp 0x76404
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x24(%rbp)
jmp 0x76404
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x38(%rax), %rsi
callq 0x4990
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movb -0x11(%rbp), %dl
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x18(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzbl -0x11(%rbp), %eax
cmpl $0xa, %eax
jne 0x764ee
cmpl $0x4, -0x18(%rbp)
jl 0x764e2
callq 0x4610
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x764e2
callq 0x4610
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movsbl 0x1(%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x764e2
callq 0x4610
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movsbl 0x2(%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x764e2
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movsbl 0x3(%rax), %eax
cmpl $0x2d, %eax
je 0x764e2
jmp 0x764f3
movl $0x0, -0x18(%rbp)
jmp 0x763b7
jmp 0x763b7
cmpl $0x2, -0x18(%rbp)
jge 0x76502
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7652d
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x18(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
leaq -0x20(%rbp), %rsi
xorl %edx, %edx
callq 0x4820
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)