// File: /workspace/github_c_makefile_star2_O2/TurkeyMcMac[P]ts3d/src/read-lines.c
// Function: read_lines
struct string *read_lines(FILE *file, size_t *nlines)
{
	int errnum;
	size_t lines_cap;
	struct string *lines;
	*nlines = 0;
	lines_cap = 16;
	lines = xmalloc(lines_cap * sizeof(*lines));
	char buf[BUFSIZ];
	size_t nread = sizeof(buf);
	char *head = buf + nread;
	errno = 0;
	do {
		size_t line_cap = 16;
		struct string *line = GROWE(lines, *nlines, lines_cap);
		line->len = 0;
		line->text = xmalloc(line_cap);
		for (bool last_one = false; !last_one;) {
			if (head >= buf + nread) {
				nread = fread(buf, 1, sizeof(buf), file);
				last_one = nread < sizeof(buf);
				head = buf;
			}
			char *nl = memchr(head, '\n', nread + buf - head);
			if (nl) {
				last_one = true;
			} else if (head == buf + nread
			        && line->len == 0
				&& feof(file))
			{
				--*nlines;
				free(line->text);
				goto done;
			} else {
				nl = buf + nread;
			}
			char *added = string_grow(line, &line_cap, nl - head);
			memcpy(added, head, nl - head);
			head = nl + 1;
		}
		if (line->len != 0) string_shrink_to_fit(line);
	} while (!errno && !(feof(file) && head >= buf + nread));
done:
	if (errno) {
		for (size_t i = 0; i < *nlines; ++i) {
			free(lines[i].text);
		}
		free(lines);
		lines = NULL;
	}
	errnum = errno;
	fclose(file);
	errno = errnum;
	return lines;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2038, %rsp           # imm = 0x2038
movq %rsi, 0x10(%rsp)
andq $0x0, (%rsi)
movq %rdi, (%rsp)
leaq 0x28(%rsp), %rax
movq $0x10, (%rax)
movl $0x100, %edi            # imm = 0x100
callq 0xa7d0
leaq 0x8(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x2030(%rsp), %r14
callq 0x2330
andl $0x0, (%rax)
movl $0x2000, %r15d          # imm = 0x2000
movq %rax, 0x18(%rsp)
movq $0x10, 0x20(%rsp)
leaq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
leaq 0x28(%rsp), %rdx
pushq $0x10
popq %rcx
callq 0x4954
movq %rax, %rbx
andq $0x0, (%rax)
movq 0x20(%rsp), %rdi
callq 0xa7d0
movq %rax, 0x8(%rbx)
xorl %r12d, %r12d
testb $0x1, %r12b
jne 0x99d5
leaq (%rsp,%r15), %rax
addq $0x30, %rax
cmpq %rax, %r14
jae 0x993f
xorl %r12d, %r12d
jmp 0x9965
movl $0x2000, %edx           # imm = 0x2000
leaq 0x30(%rsp), %r14
movq %r14, %rdi
pushq $0x1
popq %rsi
movq (%rsp), %rcx
callq 0x22f0
movq %rax, %r15
cmpq $0x2000, %rax           # imm = 0x2000
setb %r12b
leaq (%rsp,%r15), %r13
addq $0x30, %r13
movq %r13, %rbp
subq %r14, %rbp
movq %r14, %rdi
pushq $0xa
popq %rsi
movq %rbp, %rdx
callq 0x20d0
testq %rax, %rax
je 0x9994
movq %rax, %rbp
subq %r14, %rbp
movb $0x1, %r12b
movq %rax, %r13
jmp 0x99ac
cmpq %r13, %r14
jne 0x99ac
cmpq $0x0, (%rbx)
jne 0x99ac
movq (%rsp), %rdi
callq 0x23e0
testl %eax, %eax
jne 0x9a13
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
movq %rbp, %rdx
callq 0x9d86
movq %rax, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x2510
incq %r13
movq %r13, %r14
jmp 0x9923
cmpq $0x0, (%rbx)
movq 0x18(%rsp), %r12
je 0x99e8
movq %rbx, %rdi
callq 0x9d98
cmpl $0x0, (%r12)
jne 0x9a30
movq (%rsp), %rdi
callq 0x23e0
testl %eax, %eax
je 0x98eb
leaq (%rsp,%r15), %rax
addq $0x30, %rax
cmpq %rax, %r14
jb 0x98eb
jmp 0x9a29
movq 0x10(%rsp), %rax
decq (%rax)
movq 0x8(%rbx), %rdi
callq 0x2580
movq 0x18(%rsp), %r12
cmpl $0x0, (%r12)
je 0x9a68
pushq $0x8
popq %rbx
xorl %r14d, %r14d
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %rdi
cmpq (%r15), %r14
jae 0x9a57
movq (%rdi,%rbx), %rdi
callq 0x2580
incq %r14
addq $0x10, %rbx
jmp 0x9a3b
callq 0x2580
andq $0x0, 0x8(%rsp)
movl (%r12), %ebx
jmp 0x9a6a
xorl %ebx, %ebx
movq (%rsp), %rdi
callq 0x23f0
movl %ebx, (%r12)
movq 0x8(%rsp), %rax
addq $0x2038, %rsp           # imm = 0x2038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop