// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x210d8, %rsp          # imm = 0x210D8
movq %rsi, %rbx
movl %edi, %ebp
movl $0x80000, %edi          # imm = 0x80000
callq 0x45c0
testq %rax, %rax
je 0x655b
movq %rax, %r15
leaq 0xd0(%rsp), %rdi
testq %rbx, %rbx
je 0x63f1
movl $0x1000, %ecx           # imm = 0x1000
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4860
testq %rax, %rax
jne 0x6404
movb $0x0, 0x10cf(%rsp)
jmp 0x6404
movl $0x1000, %esi           # imm = 0x1000
callq 0x43a0
testq %rax, %rax
je 0x6553
movq $0x0, 0x10(%rsp)
movl $0x1, %r12d
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %r15, 0x20(%rsp)
movq %r14, 0x18(%rsp)
addq %r14, %r15
cmpq $0x7f, %r12
ja 0x651a
testl %ebx, %ebx
jne 0x651a
movl $0x80000, %edx          # imm = 0x80000
movl %ebp, %edi
movq %r15, %rsi
callq 0x4460
testq %rax, %rax
jns 0x645f
callq 0x40c0
xorl %ebx, %ebx
cmpl $0x4, (%rax)
je 0x6428
jmp 0x6528
je 0x651a
movq %rax, %r14
addq 0x18(%rsp), %r14
movq %r13, %rcx
movq 0x20(%rsp), %r15
movq %rcx, %r13
movq %r14, %rdx
subq %rcx, %rdx
jle 0x64bd
leaq (%r15,%r13), %rdi
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x4450
testq %rax, %rax
je 0x64bf
subq %r15, %rax
leaq 0x1(%rax), %rcx
cmpq %r13, %rax
je 0x6475
movq 0x10(%rsp), %rax
cmpq $0x4000, %rax           # imm = 0x4000
je 0x64d5
movq %r13, 0x10d0(%rsp,%rax,8)
incq %rax
movq %rax, 0x10(%rsp)
jmp 0x6475
xorl %ebx, %ebx
leaq 0x7ffff(%r14), %rax
shrq $0x13, %rax
cmpq %rax, %r12
ja 0x6420
jmp 0x64e6
movl $0x9, %ebx
movl $0x4000, %eax           # imm = 0x4000
movq %rax, 0x10(%rsp)
jmp 0x64bf
incq %r12
movq %r12, %rsi
shlq $0x13, %rsi
movq %r15, %rdi
callq 0x4640
movq %r15, %rdi
movq %rax, %r15
testq %rax, %rax
jne 0x641b
callq 0x4090
xorl %r15d, %r15d
xorl %r13d, %r13d
xorl %r14d, %r14d
jmp 0x69a3
cmpq 0x18(%rsp), %r13
jne 0x6538
movq 0x10(%rsp), %r12
jmp 0x656e
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x20(%rsp), %r15
jmp 0x69df
movq 0x10(%rsp), %r12
cmpq $0x4000, %r12           # imm = 0x4000
jne 0x6563
movl $0x4000, %r12d          # imm = 0x4000
movl $0x9, %ebx
jmp 0x6577
movq %r15, %rdi
callq 0x4090
xorl %r13d, %r13d
jmp 0x69ef
movq %r13, 0x10d0(%rsp,%r12,8)
incq %r12
testq %r12, %r12
je 0x693e
movb $0x0, (%r15)
leaq (,%r12,8), %rdi
callq 0x45c0
testq %rax, %rax
je 0x6950
movq %rax, %r14
xorl %eax, %eax
movq 0x20(%rsp), %r15
movq 0x10d0(%rsp,%rax,8), %rcx
addq %r15, %rcx
movq %rcx, (%r14,%rax,8)
incq %rax
cmpq %rax, %r12
jne 0x659b
movl $0x1000, %edi           # imm = 0x1000
callq 0x45c0
movq %rax, 0x154e5(%rip)     # 0x1baa8
testq %rax, %rax
je 0x6958
movq %r12, 0x10(%rsp)
movb $0x0, (%rax)
xorl %r15d, %r15d
leaq 0x14172(%rip), %r12     # 0x1a750
movq (%r14,%r15,8), %rdi
movzbl (%rdi), %eax
cmpl $0xa, %eax
je 0x66fe
cmpl $0x2e, %eax
jne 0x660e
movzbl 0x1(%rdi), %eax
testl %eax, %eax
je 0x66fe
cmpl $0x2e, %eax
jne 0x660e
cmpb $0x0, 0x2(%rdi)
je 0x66fe
leaq 0xd0(%rsp), %rsi
xorl %edx, %edx
callq 0x6003
movq %rax, (%r14,%r15,8)
testq %rax, %rax
je 0x6967
movl $0x1000, %ecx           # imm = 0x1000
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x4860
testq %rax, %rax
jne 0x6648
movb $0x0, 0x15107(%rip)     # 0x1b74f
movq %r12, %rdi
xorl %esi, %esi
callq 0x4490
subq %r12, %rax
movq %r12, %rdi
movl $0x2f, %esi
movq %rax, %rdx
callq 0x46f0
cmpq %r12, %rax
leaq 0x140e2(%rip), %rcx     # 0x1a751
cmoveq %rcx, %rax
movb $0x0, (%rax)
movq 0x1542b(%rip), %r13     # 0x1baa8
testq %r13, %r13
je 0x6974
movb 0x140c4(%rip), %al      # 0x1a750
testb %al, %al
je 0x6974
cmpb $0x0, (%r13)
je 0x6708
xorl %ecx, %ecx
movq %r13, %rbp
movb (%rbp), %dl
cmpb %dl, %al
jne 0x672b
incq %rbp
movb 0x1(%rcx,%r12), %al
incq %rcx
testb %al, %al
jne 0x66a0
movzbl (%rbp), %eax
testl %eax, %eax
je 0x6756
cmpl $0x2f, %eax
jne 0x6731
movq %r13, %rax
subq %r12, %rax
movq %rax, 0x18(%rsp)
addq %rax, %rcx
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x4860
cmpq %r12, %rbp
je 0x6756
testq %rax, %rax
jne 0x6756
movq 0x18(%rsp), %rax
leaq (%rax,%rbp), %rcx
decq %rcx
jmp 0x6753
movq $0x0, (%r14,%r15,8)
jmp 0x6756
movl $0x1000, %ecx           # imm = 0x1000
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x4860
testq %rax, %rax
jne 0x6756
addq $0xfff, %r13            # imm = 0xFFF
movq %r13, %rcx
jmp 0x6753
xorb $0x2f, %al
orb %dl, %al
je 0x6756
movb $0x0, (%rbp)
subq %r13, %rbp
movq %r13, %rdi
movl $0x2f, %esi
movq %rbp, %rdx
callq 0x46f0
leaq 0x1(%r13), %rcx
cmpq %r13, %rax
cmovneq %rax, %rcx
movb $0x0, (%rcx)
incq %r15
cmpq 0x10(%rsp), %r15
jne 0x65de
movq 0x1533d(%rip), %r13     # 0x1baa8
cmpb $0x0, (%r13)
je 0x695d
movq %r13, %rdi
xorl %esi, %esi
callq 0x4490
movq %rax, %r12
movl $0x1000, %edi           # imm = 0x1000
callq 0x45c0
testq %rax, %rax
je 0x695d
movq %rax, %r15
movq %r12, 0x30(%rsp)
movzbl 0x13f9a(%rip), %r12d    # 0x1a740
movq %rax, %rbp
addq %r12, %rbp
leaq 0x13f4d(%rip), %rsi     # 0x1a700
movq %rax, %rdi
xorl %edx, %edx
movq %r12, %rcx
callq 0x4860
movabsq $0x585858586e6e6e2f, %rax # imm = 0x585858586E6E6E2F
movq %rax, -0x1(%r15,%r12)
movq %r15, 0x38(%rsp)
movl $0x585858, 0x6(%r15,%r12) # imm = 0x585858
movq %rbp, 0x28(%rsp)
cmpq $-0xa, %rbp
jne 0x67f1
movq 0x28(%rsp), %rax
movb $0x0, 0x9(%rax)
movq 0x30(%rsp), %rbp
subq %r13, %rbp
cmpb $0x0, 0x1(%r13)
movq 0x10(%rsp), %r12
jne 0x6810
xorl %eax, %eax
cmpb $0x2f, (%r13)
cmoveq %rax, %rbp
movq 0x38(%rsp), %r13
movq %r13, %rdi
callq 0x4670
testq %rax, %rax
je 0x697f
movq %rbp, 0x30(%rsp)
movq 0x28(%rsp), %rax
addq $0x9, %rax
movq %rax, 0x18(%rsp)
movq %r13, 0x15340(%rip)     # 0x1bb80
testq %r12, %r12
jle 0x6934
xorl %r15d, %r15d
movq (%r14,%r15,8), %rbp
testq %rbp, %rbp
je 0x6928
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
callq 0x4300
testl %eax, %eax
je 0x6878
callq 0x40c0
cmpl $0x2, (%rax)
je 0x6928
movq 0x30(%rsp), %rax
leaq (%rax,%rbp), %r12
movq %rbp, %rdi
xorl %esi, %esi
callq 0x4490
movq %rax, %r13
subq %r12, %r13
incq %r13
sete 0xf(%rsp)
movq 0x18(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x4860
testq %rax, %rax
jne 0x68c2
cmpb $0x0, 0xf(%rsp)
jne 0x68c2
movq 0x28(%rsp), %rax
movb $0x0, 0x8(%rax,%r13)
movq %rbp, %rdi
xorl %esi, %esi
callq 0x4490
subq %r12, %rax
movq 0x18(%rsp), %rdi
movl $0x2f, %esi
movq %rax, %rdx
callq 0x46f0
movq %rax, %r12
testq %rax, %rax
je 0x68ee
movb $0x0, (%r12)
movq 0x38(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x4710
testl %eax, %eax
je 0x690e
movq %r13, %rdi
movl $0x1, %esi
callq 0x6cab
testq %r12, %r12
je 0x6918
movb $0x2f, (%r12)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4910
movq 0x10(%rsp), %r12
incq %r15
cmpq %r15, %r12
jne 0x684c
movq 0x18(%rsp), %rax
movb $0x0, (%rax)
jmp 0x698a
movl $0x1, %ebx
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x20(%rsp), %r15
jmp 0x69a7
xorl %r13d, %r13d
xorl %r14d, %r14d
jmp 0x699e
xorl %r13d, %r13d
jmp 0x69a3
xorl %r13d, %r13d
movq 0x10(%rsp), %r12
jmp 0x698a
xorl %r13d, %r13d
movq %r15, %r12
testq %r15, %r15
jne 0x698a
jmp 0x699e
incq %r15
xorl %r13d, %r13d
movq %r15, %r12
jmp 0x698a
movq %r13, %rdi
callq 0x4090
xorl %r13d, %r13d
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x4090
incq %r15
cmpq %r15, %r12
jne 0x698d
movq 0x20(%rsp), %r15
testl %ebx, %ebx
je 0x69df
cmpq $0x0, 0x13c91(%rip)     # 0x1a640
movl %ebx, %eax
leaq 0x13158(%rip), %rcx     # 0x19b10
movq (%rcx,%rax,8), %rdx
je 0x6a04
movq %rdx, %rdi
callq 0xec60
movq 0x135c3(%rip), %rax     # 0x19f90
movq (%rax), %rdi
callq 0x4440
movl $0x155cc0, %edi         # imm = 0x155CC0
callq 0x48f0
movq %r15, %rdi
callq 0x4090
movq %r14, %rdi
callq 0x4090
movq %r13, %rax
addq $0x210d8, %rsp          # imm = 0x210D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x135ed(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xf38d(%rip), %rsi      # 0x15da2
xorl %eax, %eax
callq 0x4500
jmp 0x69d5