// File: conchoecia[P]fasta_stats/src/open_compressed.cc
// Function: pfgets(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
ssize_t pfgets(const int fd, std::string &line) {
	if (fd < 0 || local.open_max <= fd) {
		fprintf(stderr, "Error: pfgets: fd out of range: %d\n", fd);
		return -1;
	}
	if (local.buffers[fd].empty()) {
		fprintf(stderr, "Error: pfgets: buffer unallocated\n");
		return -1;
	}
	line.clear();
	char * const buf = local.buffers[fd].array();
	ssize_t &i = local.buffer_start[fd];
	ssize_t &j = local.buffer_length[fd];
	for (;;) {
		char * const end_of_line = strchr(buf + i, '\n');
		if (end_of_line != NULL) {
			*end_of_line = '\0';
			line += buf + i;
			i = end_of_line - buf + 1;
			return (ssize_t)line.size();
		}
		line += buf + i;
		i = 0;
		j = read(fd, buf, BUFSIZE);
		if (j <= 0) {
			if (j == -1) {
				fprintf(stderr, "Error: read(%d): %s\n", fd, strerror(errno));
			}
			buf[j = 0] = '\0';
			/* only return -1 if we don't return anything else */
			return line.empty() ? -1 : (ssize_t)line.size();
		}
		buf[j] = '\0';
	}
}

// Assembly:
subq $0x58, %rsp
movl %edi, 0x4c(%rsp)
movq %rsi, 0x40(%rsp)
cmpl $0x0, 0x4c(%rsp)
jl 0xaf55
movq 0xb385(%rip), %rax      # 0x162d0
movslq 0x4c(%rsp), %rcx
cmpq %rcx, %rax
jg 0xaf7f
movq 0xb074(%rip), %rax      # 0x15fd0
movq (%rax), %rdi
movl 0x4c(%rsp), %edx
leaq 0x486b(%rip), %rsi      # 0xf7d5
movb $0x0, %al
callq 0x2380
movq $-0x1, 0x50(%rsp)
jmp 0xb185
movq 0xb352(%rip), %rdi      # 0x162d8
movslq 0x4c(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0xbcc0
testb $0x1, %al
jne 0xaf9d
jmp 0xafc3
movq 0xb02c(%rip), %rax      # 0x15fd0
movq (%rax), %rdi
leaq 0x484b(%rip), %rsi      # 0xf7f9
movb $0x0, %al
callq 0x2380
movq $-0x1, 0x50(%rsp)
jmp 0xb185
movq 0x40(%rsp), %rdi
callq 0x2310
movq 0xb304(%rip), %rdi      # 0x162d8
movslq 0x4c(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
callq 0xbce0
movq %rax, 0x38(%rsp)
movq 0xb2ef(%rip), %rax      # 0x162e0
movslq 0x4c(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0xb2df(%rip), %rax      # 0x162e8
movslq 0x4c(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rax
addq (%rax), %rdi
movl $0xa, %esi
callq 0x20f0
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0xb08a
movq 0x20(%rsp), %rax
movb $0x0, (%rax)
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rax
addq (%rax), %rsi
movq 0x40(%rsp), %rdi
callq 0x2270
movq 0x20(%rsp), %rcx
movq 0x38(%rsp), %rax
subq %rax, %rcx
addq $0x1, %rcx
movq 0x30(%rsp), %rax
movq %rcx, (%rax)
movq 0x40(%rsp), %rdi
callq 0x21e0
movq %rax, 0x50(%rsp)
jmp 0xb185
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rax
addq (%rax), %rsi
movq 0x40(%rsp), %rdi
callq 0x2270
movq 0x30(%rsp), %rax
movq $0x0, (%rax)
movl 0x4c(%rsp), %edi
movq 0x38(%rsp), %rsi
movl $0x8000, %edx           # imm = 0x8000
callq 0x2390
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, (%rax)
jg 0xb16f
movq 0x28(%rsp), %rax
cmpq $-0x1, (%rax)
jne 0xb122
movq 0xaee4(%rip), %rax      # 0x15fd0
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x1c(%rsp)
callq 0x2040
movl (%rax), %edi
callq 0x20d0
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %edx
movq %rax, %rcx
leaq 0x4701(%rip), %rsi      # 0xf81c
movb $0x0, %al
callq 0x2380
movq 0x38(%rsp), %rax
movq 0x28(%rsp), %rcx
movq $0x0, (%rcx)
movb $0x0, (%rax)
movq 0x40(%rsp), %rdi
callq 0x23f0
testb $0x1, %al
jne 0xb146
jmp 0xb154
movq $-0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0xb163
movq 0x40(%rsp), %rdi
callq 0x21e0
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0xb185
movq 0x38(%rsp), %rax
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xb01a
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nop