// File: /workspace/github_c_makefile_star2_O0/jarun[P]nnn/src/nnn.c
// Function: seltofile
static size_t seltofile(int fd, uint_t *pcount, const char *separator)
{
	uint_t lastpos, count = 0;
	char *pbuf = pselbuf;
	size_t pos = 0;
	ssize_t len, prefixlen = 0, initlen = 0;

	if (pcount)
		*pcount = 0;

	if (!selbufpos)
		return 0;

	lastpos = selbufpos - 1;

	if (listpath) {
		prefixlen = (ssize_t)xstrlen(listroot);
		initlen = (ssize_t)xstrlen(listpath);
	}

	while (pos <= lastpos) {
		DPRINTF_S(pbuf);
		len = (ssize_t)xstrlen(pbuf);

		if (!listpath || !is_prefix(pbuf, listpath, initlen)) {
			if (write(fd, pbuf, len) != len)
				return pos;
		} else {
			if (write(fd, listroot, prefixlen) != prefixlen)
				return pos;
			if (write(fd, pbuf + initlen, len - initlen) != (len - initlen))
				return pos;
		}

		pos += len;
		if (pos <= lastpos) {
			if (write(fd, separator, 1) != 1)
				return pos;
			pbuf += len + 1;
		}
		++pos;
		++count;
	}

	if (pcount)
		*pcount = count;

	return pos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movq 0x15707(%rip), %rax     # 0x21d78
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xc69e
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
cmpl $0x0, 0x156cb(%rip)     # 0x21d70
jne 0xc6b4
movq $0x0, -0x8(%rbp)
jmp 0xc822
movl 0x156b6(%rip), %eax     # 0x21d70
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpq $0x0, 0x157b8(%rip)     # 0x21e80
je 0xc6ea
movq 0x156d7(%rip), %rdi     # 0x21da8
callq 0x5cc0
movq %rax, -0x48(%rbp)
movq 0x1579f(%rip), %rdi     # 0x21e80
callq 0x5cc0
movq %rax, -0x50(%rbp)
jmp 0xc6ec
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
cmpq %rcx, %rax
ja 0xc80a
movq -0x30(%rbp), %rdi
callq 0x5cc0
movq %rax, -0x40(%rbp)
cmpq $0x0, 0x1576f(%rip)     # 0x21e80
je 0xc72b
movq -0x30(%rbp), %rdi
movq 0x15762(%rip), %rsi     # 0x21e80
movq -0x50(%rbp), %rdx
callq 0x7200
testb $0x1, %al
jne 0xc750
movl -0xc(%rbp), %edi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x4210
cmpq -0x40(%rbp), %rax
je 0xc74e
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc822
jmp 0xc7a7
movl -0xc(%rbp), %edi
movq 0x1564e(%rip), %rsi     # 0x21da8
movq -0x48(%rbp), %rdx
callq 0x4210
cmpq -0x48(%rbp), %rax
je 0xc776
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc822
movl -0xc(%rbp), %edi
movq -0x30(%rbp), %rsi
addq -0x50(%rbp), %rsi
movq -0x40(%rbp), %rdx
subq -0x50(%rbp), %rdx
callq 0x4210
movq -0x40(%rbp), %rcx
subq -0x50(%rbp), %rcx
cmpq %rcx, %rax
je 0xc7a5
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc822
jmp 0xc7a7
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
cmpq %rcx, %rax
ja 0xc7f0
movl -0xc(%rbp), %edi
movq -0x20(%rbp), %rsi
movl $0x1, %edx
callq 0x4210
cmpq $0x1, %rax
je 0xc7e0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xc822
movq -0x40(%rbp), %rax
addq $0x1, %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xc6ec
cmpq $0x0, -0x18(%rbp)
je 0xc81a
movl -0x28(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)