// File: /workspace/github_c_makefile_star2_O0/jarun[P]nnn/src/nnn.c
// Function: editselection
static int editselection(void)
{
	int ret = -1;
	int fd, lines = 0;
	ssize_t count;
	struct stat sb;
	time_t mtime;

	if (!selbufpos) /* External selection is only editable at source */
		return listselfile();

	fd = create_tmp_file();
	if (fd == -1) {
		DPRINTF_S("couldn't create tmp file");
		return -1;
	}

	seltofile(fd, NULL, NEWLINE);
	if (close(fd)) {
		DPRINTF_S(strerror(errno));
		return -1;
	}

	/* Save the last modification time */
	if (stat(g_tmpfpath, &sb)) {
		DPRINTF_S(strerror(errno));
		unlink(g_tmpfpath);
		return -1;
	}
	mtime = sb.st_mtime;

	spawn((cfg.waitedit ? enveditor : editor), g_tmpfpath, NULL, NULL, F_CLI);

	fd = open(g_tmpfpath, O_RDONLY);
	if (fd == -1) {
		DPRINTF_S(strerror(errno));
		unlink(g_tmpfpath);
		return -1;
	}

	fstat(fd, &sb);

	if (mtime == sb.st_mtime) {
		DPRINTF_S("selection is not modified");
		unlink(g_tmpfpath);
		return 1;
	}

	if (sb.st_size > selbufpos) {
		DPRINTF_S("edited buffer larger than previous");
		unlink(g_tmpfpath);
		goto emptyedit;
	}

	count = read(fd, pselbuf, selbuflen);
	if (count < 0) {
		DPRINTF_S(strerror(errno));
		printwarn(NULL);
		if (close(fd) || unlink(g_tmpfpath)) {
			DPRINTF_S(strerror(errno));
			printwarn(NULL);
		}
		goto emptyedit;
	}

	if (close(fd) || unlink(g_tmpfpath)) {
		DPRINTF_S(strerror(errno));
		printwarn(NULL);
		goto emptyedit;
	}

	if (!count) {
		ret = 1;
		goto emptyedit;
	}

	resetselind();
	selbufpos = count;
	/* The last character should be '\n' */
	pselbuf[--count] = '\0';
	for (--count; count > 0; --count) {
		/* Replace every '\n' that separates two paths */
		if (pselbuf[count] == '\n' && pselbuf[count + 1] == '/') {
			++lines;
			pselbuf[count] = '\0';
		}
	}

	/* Add a line for the last file */
	++lines;

	if (lines > nselected) {
		DPRINTF_S("files added to selection");
		goto emptyedit;
	}

	nselected = lines;
	writesel(pselbuf, selbufpos - 1);

	return 1;

emptyedit:
	resetselind();
	clearselection();
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x10(%rbp)
cmpl $0x0, 0xe120(%rip)      # 0x21d70
jne 0x13c64
callq 0x199f0
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4(%rbp)
jmp 0x13f5b
callq 0xddd0
movl %eax, -0xc(%rbp)
cmpl $-0x1, -0xc(%rbp)
jne 0x13c7e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13f5b
movl -0xc(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
leaq 0x8be2(%rip), %rdx      # 0x1c86e
callq 0xc650
movl -0xc(%rbp), %edi
callq 0x43c0
cmpl $0x0, %eax
je 0x13caa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13f5b
leaq 0xcd4f(%rip), %rdi      # 0x20a00
leaq -0xa8(%rbp), %rsi
callq 0x4300
cmpl $0x0, %eax
je 0x13cda
leaq 0xcd37(%rip), %rdi      # 0x20a00
callq 0x40d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13f5b
movq -0x50(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl 0xc7e5(%rip), %eax      # 0x204d0
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x13d06
movq 0xcca3(%rip), %rax      # 0x209a0
movq %rax, -0xb8(%rbp)
jmp 0x13d14
movq 0xccdb(%rip), %rax      # 0x209e8
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
leaq 0xccde(%rip), %rsi      # 0x20a00
xorl %eax, %eax
movl %eax, %ecx
movl $0x9, %r8d
movq %rcx, %rdx
callq 0xde30
leaq 0xccc5(%rip), %rdi      # 0x20a00
xorl %esi, %esi
movb $0x0, %al
callq 0x46c0
movl %eax, -0xc(%rbp)
cmpl $-0x1, -0xc(%rbp)
jne 0x13d65
leaq 0xccac(%rip), %rdi      # 0x20a00
callq 0x40d0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13f5b
movl -0xc(%rbp), %edi
leaq -0xa8(%rbp), %rsi
callq 0x4820
movq -0xb0(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x13d99
leaq 0xcc78(%rip), %rdi      # 0x20a00
callq 0x40d0
movl $0x1, -0x4(%rbp)
jmp 0x13f5b
movq -0x78(%rbp), %rax
movl 0xdfcd(%rip), %ecx      # 0x21d70
cmpq %rcx, %rax
jle 0x13db9
leaq 0xcc51(%rip), %rdi      # 0x20a00
callq 0x40d0
jmp 0x13f4b
movl -0xc(%rbp), %edi
movq 0xdfb5(%rip), %rsi      # 0x21d78
movl 0x16603(%rip), %eax     # 0x2a3cc
movl %eax, %edx
callq 0x4460
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jge 0x13e2e
callq 0x40c0
movl (%rax), %edi
callq 0x4870
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd210
movl -0xc(%rbp), %edi
callq 0x43c0
cmpl $0x0, %eax
jne 0x13e11
leaq 0xcbf9(%rip), %rdi      # 0x20a00
callq 0x40d0
cmpl $0x0, %eax
je 0x13e29
callq 0x40c0
movl (%rax), %edi
callq 0x4870
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd210
jmp 0x13f4b
movl -0xc(%rbp), %edi
callq 0x43c0
cmpl $0x0, %eax
jne 0x13e4c
leaq 0xcbbe(%rip), %rdi      # 0x20a00
callq 0x40d0
cmpl $0x0, %eax
je 0x13e69
callq 0x40c0
movl (%rax), %edi
callq 0x4870
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd210
jmp 0x13f4b
cmpq $0x0, -0x18(%rbp)
jne 0x13e7c
movl $0x1, -0x8(%rbp)
jmp 0x13f4b
callq 0x13260
movq -0x18(%rbp), %rax
movl %eax, 0xdee5(%rip)      # 0x21d70
movq 0xdee6(%rip), %rax      # 0x21d78
movq -0x18(%rbp), %rcx
movq %rcx, %rdx
addq $-0x1, %rdx
movq %rdx, -0x18(%rbp)
movb $0x0, -0x1(%rax,%rcx)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jle 0x13f0a
movq 0xdeb8(%rip), %rax      # 0x21d78
movq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x13efa
movq 0xdea4(%rip), %rax      # 0x21d78
movq -0x18(%rbp), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x13efa
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movq 0xde86(%rip), %rax      # 0x21d78
movq -0x18(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x13efc
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x13eb2
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x16690(%rip), %eax     # 0x2a5ac
jle 0x13f20
jmp 0x13f4b
movl -0x10(%rbp), %eax
movl %eax, 0x16683(%rip)     # 0x2a5ac
movq 0xde48(%rip), %rdi      # 0x21d78
movl 0xde3a(%rip), %eax      # 0x21d70
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0xe130
movl $0x1, -0x4(%rbp)
jmp 0x13f5b
callq 0x13260
callq 0x12c80
movl -0x8(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)