// File: /workspace/github_c_makefile_star2_O0/jarun[P]nnn/src/nnn.c
// Function: endselection
static void endselection(bool endselmode)
{
	int fd;
	ssize_t count;
	char buf[sizeof(patterns[P_REPLACE]) + PATH_MAX + (TMP_LEN_MAX << 1)];

	if (endselmode && g_state.selmode)
		g_state.selmode = 0;

	/* The code below is only for listing mode */
	if (!listpath || !selbufpos)
		return;

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

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

	snprintf(buf, sizeof(buf), patterns[P_REPLACE], listpath, listroot, g_tmpfpath);
	spawn(utils[UTIL_SH_EXEC], buf, NULL, NULL, F_CLI);

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

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

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

	selbufpos = count;
	pselbuf[--count] = '\0';
	for (--count; count > 0; --count)
		if (pselbuf[count] == '\n' && pselbuf[count+1] == '/')
			pselbuf[count] = '\0';

	writesel(pselbuf, selbufpos - 1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10a0, %rsp           # imm = 0x10A0
movb %dil, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
testb $0x1, -0x1(%rbp)
je 0xdb4e
movl 0x12cf5(%rip), %eax     # 0x20824
shrl $0x15, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xdb4e
movl 0x12ce4(%rip), %eax     # 0x20824
andl $0xffdfffff, %eax       # imm = 0xFFDFFFFF
orl $0x0, %eax
movl %eax, 0x12cd6(%rip)     # 0x20824
cmpq $0x0, 0x1432a(%rip)     # 0x21e80
je 0xdb61
cmpl $0x0, 0x14211(%rip)     # 0x21d70
jne 0xdb66
jmp 0xdd97
callq 0xddd0
movl %eax, -0x8(%rbp)
cmpl $-0x1, -0x8(%rbp)
jne 0xdb79
jmp 0xdd97
movl -0x8(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
leaq 0xece7(%rip), %rdx      # 0x1c86e
callq 0xc650
movl -0x8(%rbp), %edi
callq 0x43c0
cmpl $0x0, %eax
je 0xdbb6
callq 0x40c0
movl (%rax), %edi
callq 0x4870
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd210
jmp 0xdd97
leaq -0x10a0(%rbp), %rdi
movq 0x12014(%rip), %rdx     # 0x1fbd8
movq 0x142b5(%rip), %rcx     # 0x21e80
movq 0x141d6(%rip), %r8      # 0x21da8
movl $0x1088, %esi           # imm = 0x1088
leaq 0x12e22(%rip), %r9      # 0x20a00
movb $0x0, %al
callq 0x4350
movq 0x11dfc(%rip), %rdi     # 0x1f9e8
leaq -0x10a0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movl $0x9, %r8d
movq %rcx, %rdx
callq 0xde30
leaq 0x12df4(%rip), %rdi     # 0x20a00
xorl %esi, %esi
movb $0x0, %al
callq 0x46c0
movl %eax, -0x8(%rbp)
cmpl $-0x1, -0x8(%rbp)
jne 0xdc64
callq 0x40c0
movl (%rax), %edi
callq 0x4870
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd210
leaq 0x12dc3(%rip), %rdi     # 0x20a00
callq 0x40d0
cmpl $0x0, %eax
je 0xdc5f
callq 0x40c0
movl (%rax), %edi
callq 0x4870
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd210
jmp 0xdd97
movl -0x8(%rbp), %edi
movq 0x1410a(%rip), %rsi     # 0x21d78
movl 0x1c758(%rip), %eax     # 0x2a3cc
movl %eax, %edx
callq 0x4460
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jge 0xdcc3
callq 0x40c0
movl (%rax), %edi
callq 0x4870
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd210
movl -0x8(%rbp), %edi
callq 0x43c0
cmpl $0x0, %eax
jne 0xdcbc
leaq 0x12d4e(%rip), %rdi     # 0x20a00
callq 0x40d0
cmpl $0x0, %eax
je 0xdcbe
jmp 0xdcbe
jmp 0xdd97
movl -0x8(%rbp), %edi
callq 0x43c0
cmpl $0x0, %eax
jne 0xdce1
leaq 0x12d29(%rip), %rdi     # 0x20a00
callq 0x40d0
cmpl $0x0, %eax
je 0xdcfe
callq 0x40c0
movl (%rax), %edi
callq 0x4870
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd210
jmp 0xdd97
movq -0x10(%rbp), %rax
movl %eax, 0x14068(%rip)     # 0x21d70
movq 0x14069(%rip), %rax     # 0x21d78
movq -0x10(%rbp), %rcx
movq %rcx, %rdx
addq $-0x1, %rdx
movq %rdx, -0x10(%rbp)
movb $0x0, -0x1(%rax,%rcx)
movq -0x10(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jle 0xdd7e
movq 0x1403b(%rip), %rax     # 0x21d78
movq -0x10(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0xdd6e
movq 0x14027(%rip), %rax     # 0x21d78
movq -0x10(%rbp), %rcx
movsbl 0x1(%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0xdd6e
movq 0x14012(%rip), %rax     # 0x21d78
movq -0x10(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xdd70
movq -0x10(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0xdd2f
movq 0x13ff3(%rip), %rdi     # 0x21d78
movl 0x13fe5(%rip), %eax     # 0x21d70
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0xe130
addq $0x10a0, %rsp           # imm = 0x10A0
popq %rbp
retq