// File: /workspace/github_c_makefile_star2_O0/jarun[P]nnn/src/nnn.c
// Function: load_input
static char *load_input(int fd, const char *path)
{
	size_t i, chunk_count = 1, chunk = 512UL * 1024 /* 512 KiB chunk size */, entries = 0;
	char *input = malloc(sizeof(char) * chunk), *tmpdir = NULL;
	char cwd[PATH_MAX], *next;
	size_t offsets[LIST_FILES_MAX];
	char **paths = NULL;
	ssize_t input_read, total_read = 0, off = 0;
	int msgnum = 0;

	if (!input) {
		DPRINTF_S(strerror(errno));
		return NULL;
	}

	if (!path) {
		if (!getcwd(cwd, PATH_MAX)) {
			free(input);
			return NULL;
		}
	} else
		xstrsncpy(cwd, path, PATH_MAX);

	while (chunk_count < LIST_INPUT_MAX / chunk && !msgnum) {
		input_read = read(fd, input + total_read, chunk);
		if (input_read < 0) {
			if (errno == EINTR)
				continue;

			DPRINTF_S(strerror(errno));
			goto malloc_1;
		}

		if (input_read == 0)
			break;

		total_read += input_read;

		while (off < total_read) {
			next = memchr(input + off, '\0', total_read - off);
			if (!next)
				break;
			++next;

			if (next - input == off + 1) {
				off = next - input;
				continue;
			}

			if (entries == LIST_FILES_MAX) {
				msgnum = MSG_FILE_LIMIT;
				break;
			}

			offsets[entries++] = off;
			off = next - input;
		}

		/* We don't need to allocate another chunk */
		if (chunk_count > (total_read + chunk - 1) / chunk)
			continue;

		/* We can never need more than one additional chunk */
		++chunk_count;
		if (chunk_count > LIST_INPUT_MAX / chunk) {
			msgnum = MSG_SIZE_LIMIT;
			break;
		}

		input = xrealloc(input, chunk_count * chunk);
		if (!input)
			goto malloc_1;
	}

	/* We close fd outside this function. Any extra data is left to the kernel to handle */

	if (off != total_read) {
		if (entries == LIST_FILES_MAX)
			msgnum = MSG_FILE_LIMIT;
		else
			offsets[entries++] = off;
	}

	DPRINTF_D(entries);
	DPRINTF_D(total_read);
	DPRINTF_D(chunk_count);

	if (!entries) {
		msgnum = MSG_0_ENTRIES;
		goto malloc_1;
	}

	input[total_read] = '\0';

	paths = malloc(entries * sizeof(char *));
	if (!paths)
		goto malloc_1;

	for (i = 0; i < entries; ++i)
		paths[i] = input + offsets[i];

	listroot = malloc(sizeof(char) * PATH_MAX);
	if (!listroot)
		goto malloc_1;
	listroot[0] = '\0';

	DPRINTF_S(paths[0]);

	for (i = 0; i < entries; ++i) {
		if (paths[i][0] == '\n' || selforparent(paths[i])) {
			paths[i] = NULL;
			continue;
		}

		paths[i] = abspath(paths[i], cwd, NULL);
		if (!paths[i]) {
			entries = i; // free from the previous entry
			goto malloc_2;
		}

		DPRINTF_S(paths[i]);

		xstrsncpy(g_buf, paths[i], PATH_MAX);
		if (!common_prefix(xdirname(g_buf), listroot)) {
			entries = i + 1; // free from the current entry
			goto malloc_2;
		}

		DPRINTF_S(listroot);
	}

	DPRINTF_S(listroot);

	if (listroot[0])
		tmpdir = make_tmp_tree(paths, entries, listroot);

malloc_2:
	for (i = 0; i < entries; ++i)
		free(paths[i]);
malloc_1:
	if (msgnum) { /* Check if we are past init stage and show msg */
		if (home) {
			printmsg(messages[msgnum]);
			xdelay(XDELAY_INTERVAL_MS << 2);
		} else {
			msg(messages[msgnum]);
			usleep(XDELAY_INTERVAL_MS << 2);
		}
	}

	free(input);
	free(paths);
	return tmpdir;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210a0, %rsp          # imm = 0x210A0
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x1, -0x28(%rbp)
movq $0x80000, -0x30(%rbp)   # imm = 0x80000
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rdi
shlq $0x0, %rdi
callq 0x45e0
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x21068(%rbp)
movq $0x0, -0x21078(%rbp)
movq $0x0, -0x21080(%rbp)
movl $0x0, -0x21084(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x6552
movq $0x0, -0x8(%rbp)
jmp 0x6a97
cmpq $0x0, -0x18(%rbp)
jne 0x6588
leaq -0x1050(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x43a0
cmpq $0x0, %rax
jne 0x6586
movq -0x40(%rbp), %rdi
callq 0x4090
movq $0x0, -0x8(%rbp)
jmp 0x6a97
jmp 0x659d
leaq -0x1050(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x6250
jmp 0x659f
movq -0x28(%rbp), %rcx
movl $0x4000000, %eax        # imm = 0x4000000
xorl %edx, %edx
divq -0x30(%rbp)
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x21085(%rbp)
jae 0x65d0
cmpl $0x0, -0x21084(%rbp)
setne %al
xorb $-0x1, %al
movb %al, -0x21085(%rbp)
movb -0x21085(%rbp), %al
testb $0x1, %al
jne 0x65df
jmp 0x67ba
movl -0xc(%rbp), %edi
movq -0x40(%rbp), %rsi
addq -0x21078(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x4460
movq %rax, -0x21070(%rbp)
cmpq $0x0, -0x21070(%rbp)
jge 0x6618
callq 0x40c0
cmpl $0x4, (%rax)
jne 0x6613
jmp 0x659f
jmp 0x6a21
cmpq $0x0, -0x21070(%rbp)
jne 0x6627
jmp 0x67ba
movq -0x21070(%rbp), %rax
addq -0x21078(%rbp), %rax
movq %rax, -0x21078(%rbp)
movq -0x21080(%rbp), %rax
cmpq -0x21078(%rbp), %rax
jge 0x671e
movq -0x40(%rbp), %rdi
addq -0x21080(%rbp), %rdi
movq -0x21078(%rbp), %rdx
subq -0x21080(%rbp), %rdx
xorl %esi, %esi
callq 0x4450
movq %rax, -0x1058(%rbp)
cmpq $0x0, -0x1058(%rbp)
jne 0x6686
jmp 0x671e
movq -0x1058(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1058(%rbp)
movq -0x1058(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movq -0x21080(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x66d0
movq -0x1058(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x21080(%rbp)
jmp 0x663c
cmpq $0x4000, -0x38(%rbp)    # imm = 0x4000
jne 0x66e6
movl $0x9, -0x21084(%rbp)
jmp 0x671e
movq -0x21080(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movq %rcx, -0x21060(%rbp,%rax,8)
movq -0x1058(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x21080(%rbp)
jmp 0x663c
movq -0x28(%rbp), %rax
movq %rax, -0x21090(%rbp)
movq -0x21078(%rbp), %rax
addq -0x30(%rbp), %rax
subq $0x1, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x30(%rbp)
movq %rax, %rcx
movq -0x21090(%rbp), %rax
cmpq %rcx, %rax
jbe 0x6754
jmp 0x659f
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x21098(%rbp)
movl $0x4000000, %eax        # imm = 0x4000000
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x30(%rbp)
movq %rax, %rcx
movq -0x21098(%rbp), %rax
cmpq %rcx, %rax
jbe 0x6793
movl $0xa, -0x21084(%rbp)
jmp 0x67ba
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
imulq -0x30(%rbp), %rsi
callq 0xcb00
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x67b5
jmp 0x6a21
jmp 0x659f
movq -0x21080(%rbp), %rax
cmpq -0x21078(%rbp), %rax
je 0x6800
cmpq $0x4000, -0x38(%rbp)    # imm = 0x4000
jne 0x67e0
movl $0x9, -0x21084(%rbp)
jmp 0x67fe
movq -0x21080(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movq %rcx, -0x21060(%rbp,%rax,8)
jmp 0x6800
cmpq $0x0, -0x38(%rbp)
jne 0x6816
movl $0x1, -0x21084(%rbp)
jmp 0x6a21
movq -0x40(%rbp), %rax
movq -0x21078(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
shlq $0x3, %rdi
callq 0x45e0
movq %rax, -0x21068(%rbp)
cmpq $0x0, -0x21068(%rbp)
jne 0x6848
jmp 0x6a21
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x6887
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rax
addq -0x21060(%rbp,%rax,8), %rdx
movq -0x21068(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x6850
movl $0x1000, %edi           # imm = 0x1000
callq 0x45e0
movq %rax, 0x1b510(%rip)     # 0x21da8
cmpq $0x0, 0x1b508(%rip)     # 0x21da8
jne 0x68a7
jmp 0x6a21
movq 0x1b4fa(%rip), %rax     # 0x21da8
movb $0x0, (%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x69c2
movq -0x21068(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
je 0x68f8
movq -0x21068(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0xcb40
testb $0x1, %al
jne 0x68f8
jmp 0x6910
movq -0x21068(%rbp), %rax
movq -0x20(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x69b1
movq -0x21068(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x1050(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x5f00
movq %rax, %rdx
movq -0x21068(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x21068(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x6960
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x69eb
movq -0x21068(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x1a0da(%rip), %rdi     # 0x20a50
movl $0x1000, %edx           # imm = 0x1000
callq 0x6250
leaq 0x1a0c9(%rip), %rdi     # 0x20a50
callq 0x72a0
movq %rax, %rdi
movq 0x1b412(%rip), %rsi     # 0x21da8
callq 0xcbb0
cmpq $0x0, %rax
jne 0x69af
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x69eb
jmp 0x69b1
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x68b9
movq 0x1b3df(%rip), %rax     # 0x21da8
cmpb $0x0, (%rax)
je 0x69e9
movq -0x21068(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq 0x1b3c8(%rip), %rdx     # 0x21da8
callq 0xcd50
movq %rax, -0x48(%rbp)
jmp 0x69eb
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x6a1f
movq -0x21068(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x4090
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x69f3
jmp 0x6a21
cmpl $0x0, -0x21084(%rbp)
je 0x6a7a
cmpq $0x0, 0x19f0e(%rip)     # 0x20940
je 0x6a57
movslq -0x21084(%rbp), %rcx
leaq 0x1901e(%rip), %rax     # 0x1fa60
movq (%rax,%rcx,8), %rdi
callq 0xd020
movl $0x155cc0, %edi         # imm = 0x155CC0
callq 0xd0a0
jmp 0x6a78
movslq -0x21084(%rbp), %rcx
leaq 0x18ffb(%rip), %rax     # 0x1fa60
movq (%rax,%rcx,8), %rdi
callq 0x6ab0
movl $0x155cc0, %edi         # imm = 0x155CC0
callq 0x48f0
jmp 0x6a7a
movq -0x40(%rbp), %rdi
callq 0x4090
movq -0x21068(%rbp), %rdi
callq 0x4090
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x210a0, %rsp          # imm = 0x210A0
popq %rbp
retq
nopw %cs:(%rax,%rax)