// File: /workspace/github_c_makefile_star2_O1/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 $0x2048, %rsp           # imm = 0x2048
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
movq $0x0, (%rsi)
leaq 0x38(%rsp), %rax
movq $0x10, (%rax)
movl $0x100, %edi            # imm = 0x100
callq 0xb1ac
movq %rsp, %rcx
movq %rax, (%rcx)
leaq 0x2040(%rsp), %rbx
callq 0x2320
movq %rax, 0x10(%rsp)
movl $0x0, (%rax)
movl $0x2000, %r13d          # imm = 0x2000
movq %r15, 0x20(%rsp)
movq $0x10, 0x28(%rsp)
movl $0x10, %ecx
movq %rsp, %rdi
movq %r15, %rsi
leaq 0x38(%rsp), %rdx
callq 0x4c08
movq %rax, %r14
movq $0x0, (%rax)
movq 0x28(%rsp), %rdi
callq 0xb1ac
movq %r14, 0x18(%rsp)
movq %rax, 0x8(%r14)
xorl %r12d, %r12d
testb $0x1, %r12b
jne 0xa260
leaq (%rsp,%r13), %rax
addq $0x40, %rax
cmpq %rax, %rbx
jb 0xa1b1
movl $0x1, %esi
movl $0x2000, %edx           # imm = 0x2000
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rcx
callq 0x22e0
movq %rax, %r13
cmpq $0x2000, %rax           # imm = 0x2000
setb %r12b
movq %r13, 0x30(%rsp)
leaq (%rsp,%r13), %r14
addq $0x40, %r14
movq %r14, %rdx
subq %rbx, %rdx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x20d0
movq %rax, %r15
movb $0x1, %bpl
movb $0x1, %r13b
testq %rax, %rax
jne 0xa1f5
cmpq %r14, %rbx
jne 0xa1ef
movq 0x18(%rsp), %r15
cmpq $0x0, (%r15)
je 0xa237
movl %r12d, %r13d
movq %r14, %r15
movq %r15, %r12
subq %rbx, %r12
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq %r12, %rdx
callq 0xa665
movq %rax, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2500
incq %r15
xorl %r14d, %r14d
movq %r15, %rbx
movl %r13d, %r12d
testb %bpl, %bpl
movq 0x30(%rsp), %r13
jne 0xa171
jmp 0xa266
movq 0x8(%rsp), %rdi
callq 0x23d0
testl %eax, %eax
je 0xa1ef
movq 0x20(%rsp), %rax
decq (%rax)
movq 0x8(%r15), %rdi
callq 0x2570
movl $0x6, %r14d
xorl %ebp, %ebp
jmp 0xa227
movl $0x4, %r14d
cmpl $0x4, %r14d
movq 0x20(%rsp), %r15
jne 0xa284
xorl %r14d, %r14d
movq 0x18(%rsp), %rdi
cmpq $0x0, (%rdi)
je 0xa284
callq 0xa677
testl %r14d, %r14d
jne 0xa2b8
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jne 0xa2be
movq 0x8(%rsp), %rdi
callq 0x23d0
testl %eax, %eax
je 0xa133
leaq (%rsp,%r13), %rax
addq $0x40, %rax
cmpq %rax, %rbx
jb 0xa133
jmp 0xa2be
cmpl $0x6, %r14d
jne 0xa31b
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
je 0xa300
cmpq $0x0, (%r15)
je 0xa2ef
movl $0x8, %ebx
xorl %r14d, %r14d
movq (%rsp), %rax
movq (%rax,%rbx), %rdi
callq 0x2570
incq %r14
addq $0x10, %rbx
cmpq (%r15), %r14
jb 0xa2d6
movq (%rsp), %rdi
callq 0x2570
movq $0x0, (%rsp)
movq 0x10(%rsp), %r14
movl (%r14), %ebx
movq 0x8(%rsp), %rdi
callq 0x23e0
movl %ebx, (%r14)
movq (%rsp), %rax
jmp 0xa31b
addq $0x2048, %rsp           # imm = 0x2048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)