// File: /workspace/github_c_makefile_star2_O1/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 0x63e3
movq %rax, %r15
leaq 0xd0(%rsp), %rdi
testq %rbx, %rbx
je 0x63eb
movl $0x1000, %ecx           # imm = 0x1000
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4860
testq %rax, %rax
jne 0x63fe
movb $0x0, 0x10cf(%rsp)
jmp 0x63fe
xorl %r13d, %r13d
jmp 0x6581
movl $0x1000, %esi           # imm = 0x1000
callq 0x43a0
testq %rax, %rax
je 0x6596
movl $0x1, %ecx
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %eax, %eax
movq %r15, 0x20(%rsp)
movq %r12, %r14
cmpq $0x7f, %rcx
ja 0x659b
testl %eax, %eax
jne 0x659b
movq %rcx, %rbx
movl %eax, 0x4(%rsp)
addq %r14, %r15
movl $0x80000, %edx          # imm = 0x80000
movl %ebp, %edi
movq %r15, %rsi
callq 0x4460
testq %rax, %rax
jns 0x645b
callq 0x40c0
cmpl $0x4, (%rax)
je 0x6438
jmp 0x6529
movq %rax, %r12
movl 0x4(%rsp), %eax
movq 0x20(%rsp), %r15
je 0x659b
addq %r14, %r12
movq %r13, %rcx
movq %rcx, %r13
movq %r12, %rdx
subq %rcx, %rdx
jle 0x64cb
leaq (%r15,%r13), %rdi
xorl %esi, %esi
callq 0x4450
testq %rax, %rax
je 0x64cb
subq %r15, %rax
leaq 0x1(%rax), %rcx
cmpq %r13, %rax
je 0x6473
movq 0x8(%rsp), %rax
cmpq $0x4000, %rax           # imm = 0x4000
je 0x64b9
movq %r13, 0x10d0(%rsp,%rax,8)
incq %rax
movq %rax, 0x8(%rsp)
jmp 0x6473
movl $0x9, 0x4(%rsp)
movl $0x4000, %eax           # imm = 0x4000
movq %rax, 0x8(%rsp)
leaq 0x7ffff(%r12), %rax
shrq $0x13, %rax
movq %rbx, %rcx
cmpq %rax, %rbx
movl 0x4(%rsp), %eax
ja 0x6419
incq %rcx
movq %rcx, %rsi
shlq $0x13, %rsi
movq %r15, %rdi
movq %rcx, %rbx
callq 0x4640
movq %rbx, %rcx
movq %r15, %rdi
movq %rax, %r15
movl 0x4(%rsp), %eax
testq %r15, %r15
jne 0x6414
callq 0x4090
movl 0x4(%rsp), %eax
movq $0x0, 0x20(%rsp)
jmp 0x69f3
xorl %r15d, %r15d
movl 0x4(%rsp), %eax
xorl %r13d, %r13d
testl %eax, %eax
je 0x656f
cmpq $0x0, 0x14101(%rip)     # 0x1a640
movl %eax, %eax
leaq 0x135c8(%rip), %rcx     # 0x19b10
movq (%rcx,%rax,8), %rdx
je 0x65c2
movq %rdx, %rdi
callq 0xee6f
movq 0x13a33(%rip), %rax     # 0x19f90
movq (%rax), %rdi
callq 0x4440
movl $0x155cc0, %edi         # imm = 0x155CC0
callq 0x48f0
movq 0x20(%rsp), %rdi
callq 0x4090
movq %r15, %rdi
callq 0x4090
movq %r13, %rax
addq $0x210d8, %rsp          # imm = 0x210D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
jmp 0x6579
cmpq %r14, %r13
jne 0x65a7
movq 0x8(%rsp), %r12
jmp 0x65e7
movq 0x8(%rsp), %r12
cmpq $0x4000, %r12           # imm = 0x4000
jne 0x65dc
movl $0x9, %eax
movl $0x4000, %r12d          # imm = 0x4000
jmp 0x65e7
movq 0x13a2f(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xf7b5(%rip), %rsi      # 0x15d88
xorl %eax, %eax
callq 0x4500
jmp 0x6565
movq %r13, 0x10d0(%rsp,%r12,8)
incq %r12
testq %r12, %r12
je 0x69ee
movl %eax, 0x4(%rsp)
movb $0x0, (%r15,%r14)
leaq (,%r12,8), %rdi
callq 0x45c0
testq %rax, %rax
je 0x69fe
movq %rax, %r15
xorl %eax, %eax
movq 0x20(%rsp), %rdx
movq 0x10d0(%rsp,%rax,8), %rcx
addq %rdx, %rcx
movq %rcx, (%r15,%rax,8)
incq %rax
cmpq %rax, %r12
jne 0x6619
movl $0x1000, %edi           # imm = 0x1000
callq 0x45c0
movq %rax, 0x15467(%rip)     # 0x1baa8
testq %rax, %rax
je 0x6a06
movb $0x0, (%rax)
xorl %r13d, %r13d
leaq 0x140f9(%rip), %rbp     # 0x1a750
xorl %r14d, %r14d
movq %r12, 0x8(%rsp)
movq (%r15,%r14,8), %rdi
movzbl (%rdi), %eax
cmpl $0xa, %eax
je 0x6727
cmpl $0x2e, %eax
jne 0x668f
movzbl 0x1(%rdi), %eax
testl %eax, %eax
je 0x6727
cmpl $0x2e, %eax
jne 0x668f
cmpb $0x0, 0x2(%rdi)
je 0x6727
leaq 0xd0(%rsp), %rsi
xorl %edx, %edx
callq 0x6038
movq %rax, (%r15,%r14,8)
testq %rax, %rax
je 0x6a11
movl $0x1000, %ecx           # imm = 0x1000
movq %rbp, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0x4860
testq %rax, %rax
jne 0x66c9
movb $0x0, 0x15086(%rip)     # 0x1b74f
movq %rbp, %rdi
callq 0x6cbf
movq 0x153d0(%rip), %rdi     # 0x1baa8
movb 0x14072(%rip), %al      # 0x1a750
testb %al, %al
sete %cl
testq %rdi, %rdi
sete %r12b
orb %cl, %r12b
jne 0x6a0b
cmpb $0x0, (%rdi)
je 0x6734
cmpb (%rdi), %al
jne 0x6767
leaq 0x1(%rdi), %rbp
leaq 0x1404a(%rip), %rdx     # 0x1a751
movb (%rdx), %al
testb %al, %al
sete %cl
je 0x6770
incq %rdx
leaq 0x1(%rbp), %rsi
cmpb (%rbp), %al
movq %rsi, %rbp
je 0x6707
decq %rsi
movq %rsi, %rbp
jmp 0x676c
movq $0x0, (%r15,%r14,8)
jmp 0x6800
movl $0x1000, %ecx           # imm = 0x1000
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4860
movq 0x10(%rsp), %rcx
testq %rax, %rax
jne 0x67eb
addq $0xfff, %rcx            # imm = 0xFFF
jmp 0x67e8
xorl %ecx, %ecx
movq %rdi, %rbp
testb %cl, %cl
je 0x67bc
movb (%rbp), %dl
testb %dl, %dl
je 0x67eb
cmpb $0x2f, %dl
setne %dl
xorb $0x1, %cl
orb %dl, %cl
jne 0x67bc
movq %rbp, %rcx
leaq 0x13fc2(%rip), %rbx     # 0x1a750
subq %rbx, %rcx
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4860
movq 0x10(%rsp), %rcx
subq %rbx, %rbp
je 0x67eb
testq %rax, %rax
jne 0x67eb
addq %rbp, %rcx
decq %rcx
jmp 0x67e8
cmpb $0x2f, %al
jne 0x67c6
cmpb $0x0, (%rbp)
je 0x67eb
movb $0x0, (%rbp)
subq %rdi, %rbp
movq %rdi, %rbx
movl $0x2f, %esi
movq %rbp, %rdx
callq 0x46f0
leaq 0x1(%rbx), %rcx
cmpq %rbx, %rax
cmovneq %rax, %rcx
movb $0x0, (%rcx)
testb %r12b, %r12b
movq 0x8(%rsp), %r12
leaq 0x13f56(%rip), %rbp     # 0x1a750
jne 0x6a0b
incq %r14
cmpq %r12, %r14
jne 0x665f
movq 0x15295(%rip), %rbp     # 0x1baa8
cmpb $0x0, (%rbp)
je 0x6a3e
movq %rbp, %rdi
xorl %esi, %esi
callq 0x4490
movq %rax, %r13
movl $0x1000, %edi           # imm = 0x1000
callq 0x45c0
testq %rax, %rax
je 0x6a4c
movq %rax, %r14
movzbl 0x13ef8(%rip), %r12d    # 0x1a740
addq %r12, %rax
movq %rax, 0x18(%rsp)
leaq 0x13ea9(%rip), %rsi     # 0x1a700
movq %r14, %rdi
xorl %edx, %edx
movq %r12, %rcx
callq 0x4860
leaq (%r14,%r12), %rcx
decq %rcx
testq %r12, %r12
je 0x6878
testq %rax, %rax
jne 0x6878
movb $0x0, (%rcx)
movabsq $0x585858586e6e6e2f, %rax # imm = 0x585858586E6E6E2F
movq %rax, (%rcx)
movl $0x585858, 0x7(%rcx)    # imm = 0x585858
cmpq $-0xa, 0x18(%rsp)
jne 0x689d
movq 0x18(%rsp), %rax
movb $0x0, 0x9(%rax)
subq %rbp, %r13
cmpb $0x0, 0x1(%rbp)
jne 0x68b0
xorl %eax, %eax
cmpb $0x2f, (%rbp)
cmoveq %rax, %r13
movq 0x8(%rsp), %r12
movq %r14, %rdi
callq 0x4670
testq %rax, %rax
je 0x6a56
movq %r13, 0x30(%rsp)
movq 0x18(%rsp), %rax
addq $0x9, %rax
movq %rax, 0x28(%rsp)
movq %r14, 0x10(%rsp)
movq %r14, 0x1529b(%rip)     # 0x1bb80
testq %r12, %r12
jle 0x69df
xorl %r13d, %r13d
movq (%r15,%r13,8), %rbp
testq %rbp, %rbp
je 0x69ce
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
callq 0x4300
testl %eax, %eax
je 0x691d
callq 0x40c0
cmpl $0x2, (%rax)
je 0x69ce
movq 0x30(%rsp), %rax
leaq (%rax,%rbp), %rbx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x4490
movq %rax, %r12
subq %rbx, %r12
incq %r12
sete %r14b
movq 0x28(%rsp), %rdi
movq %rbx, 0x38(%rsp)
movq %rbx, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x4860
testq %rax, %rax
jne 0x6969
testb %r14b, %r14b
jne 0x6969
movq 0x18(%rsp), %rax
movb $0x0, 0x8(%rax,%r12)
movq %rbp, %rdi
xorl %esi, %esi
callq 0x4490
subq 0x38(%rsp), %rax
movq 0x28(%rsp), %rdi
movl $0x2f, %esi
movq %rax, %rdx
callq 0x46f0
movq %rax, %r12
testq %rax, %rax
je 0x6997
movb $0x0, (%r12)
movq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x4710
testl %eax, %eax
je 0x69b7
movq %r14, %rdi
movl $0x1, %esi
callq 0x6d24
testq %r12, %r12
je 0x69c1
movb $0x2f, (%r12)
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
callq 0x4910
incq %r13
movq 0x8(%rsp), %r12
cmpq %r13, %r12
jne 0x68f1
movq 0x28(%rsp), %rax
movb $0x0, (%rax)
movq 0x10(%rsp), %r13
jmp 0x6a14
movl $0x1, %eax
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x6533
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x6a35
xorl %r13d, %r13d
jmp 0x6a35
incq %r14
xorl %r13d, %r13d
movq %r14, %r12
movl 0x4(%rsp), %eax
testq %r12, %r12
je 0x6533
xorl %r14d, %r14d
movq (%r15,%r14,8), %rdi
callq 0x4090
incq %r14
cmpq %r14, %r12
jne 0x6a24
movl 0x4(%rsp), %eax
jmp 0x6533
xorl %r13d, %r13d
movl 0x4(%rsp), %eax
movq 0x8(%rsp), %r12
jmp 0x6a18
xorl %r13d, %r13d
movq 0x8(%rsp), %r12
jmp 0x6a14
movq %r14, %rdi
callq 0x4090
xorl %r13d, %r13d
jmp 0x6a14