// File: /workspace/github_c_makefile_star2_O0/jarun[P]nnn/src/nnn.c
// Function: save_session
static void save_session(const char *sname, int *presel)
{
	int fd, i;
	session_header_t header = {0};
	bool status = FALSE;
	char ssnpath[PATH_MAX];
	char spath[PATH_MAX];

	header.ver = SESSIONS_VERSION;

	for (i = 0; i < CTX_MAX; ++i) {
		if (g_ctx[i].c_cfg.ctxactive) {
			if (cfg.curctx == i && ndents)
				/* Update current file name, arrows don't update it */
				xstrsncpy(g_ctx[i].c_name, pdents[cur].name, NAME_MAX + 1);
			header.pathln[i] = MIN(xstrlen(g_ctx[i].c_path), PATH_MAX) + 1;
			header.lastln[i] = MIN(xstrlen(g_ctx[i].c_last), PATH_MAX) + 1;
			header.nameln[i] = MIN(xstrlen(g_ctx[i].c_name), NAME_MAX) + 1;
			header.fltrln[i] = REGEX_MAX;
		}
	}

	mkpath(cfgpath, toks[TOK_SSN], ssnpath);
	mkpath(ssnpath, sname, spath);

	fd = open(spath, O_CREAT | O_WRONLY | O_TRUNC, S_IWUSR | S_IRUSR);
	if (fd == -1) {
		printwait(messages[MSG_SEL_MISSING], presel);
		return;
	}

	if ((write(fd, &header, sizeof(header)) != (ssize_t)sizeof(header))
		|| (write(fd, &cfg, sizeof(cfg)) != (ssize_t)sizeof(cfg)))
		goto END;

	for (i = 0; i < CTX_MAX; ++i)
		if ((write(fd, &g_ctx[i].c_cfg, sizeof(settings)) != (ssize_t)sizeof(settings))
			|| (write(fd, &g_ctx[i].color, sizeof(uint_t)) != (ssize_t)sizeof(uint_t))
			|| (header.nameln[i] > 0
			    && write(fd, g_ctx[i].c_name, header.nameln[i]) != (ssize_t)header.nameln[i])
			|| (header.lastln[i] > 0
			    && write(fd, g_ctx[i].c_last, header.lastln[i]) != (ssize_t)header.lastln[i])
			|| (header.fltrln[i] > 0
			    && write(fd, g_ctx[i].c_fltr, header.fltrln[i]) != (ssize_t)header.fltrln[i])
			|| (header.pathln[i] > 0
			    && write(fd, g_ctx[i].c_path, header.pathln[i]) != (ssize_t)header.pathln[i]))
			goto END;

	status = TRUE;

END:
	close(fd);

	if (!status)
		printwait(messages[MSG_FAILED], presel);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20d0, %rsp           # imm = 0x20D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x88, %edx
callq 0x4380
movb $0x0, -0xa1(%rbp)
movq $0x1, -0xa0(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x4, -0x18(%rbp)
jge 0xc3cc
movslq -0x18(%rbp), %rcx
leaq 0x15cac(%rip), %rax     # 0x21e90
imulq $0x2138, %rcx, %rcx     # imm = 0x2138
addq %rcx, %rax
movl 0x2130(%rax), %eax
shrl $0x9, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xc3bc
movl 0x142c7(%rip), %eax     # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
cmpl -0x18(%rbp), %eax
jne 0xc25b
cmpl $0x0, 0x15c71(%rip)     # 0x21e8c
je 0xc25b
movslq -0x18(%rbp), %rax
leaq 0x15c68(%rip), %rdi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rdi
addq $0x2000, %rdi           # imm = 0x2000
movq 0x1e130(%rip), %rax     # 0x2a370
movslq 0x1e131(%rip), %rcx     # 0x2a378
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x6250
movslq -0x18(%rbp), %rax
leaq 0x15c2a(%rip), %rdi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rdi
callq 0x5cc0
cmpq $0x1000, %rax           # imm = 0x1000
jae 0xc2a0
movslq -0x18(%rbp), %rax
leaq 0x15c08(%rip), %rdi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rdi
callq 0x5cc0
movq %rax, -0x20b8(%rbp)
jmp 0xc2ae
movl $0x1000, %eax           # imm = 0x1000
movq %rax, -0x20b8(%rbp)
jmp 0xc2ae
movq -0x20b8(%rbp), %rcx
addq $0x1, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0x98(%rbp,%rax,8)
movslq -0x18(%rbp), %rax
leaq 0x15bc0(%rip), %rdi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rdi
addq $0x1000, %rdi           # imm = 0x1000
callq 0x5cc0
cmpq $0x1000, %rax           # imm = 0x1000
jae 0xc318
movslq -0x18(%rbp), %rax
leaq 0x15b97(%rip), %rdi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rdi
addq $0x1000, %rdi           # imm = 0x1000
callq 0x5cc0
movq %rax, -0x20c0(%rbp)
jmp 0xc326
movl $0x1000, %eax           # imm = 0x1000
movq %rax, -0x20c0(%rbp)
jmp 0xc326
movq -0x20c0(%rbp), %rcx
addq $0x1, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0x78(%rbp,%rax,8)
movslq -0x18(%rbp), %rax
leaq 0x15b4b(%rip), %rdi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rdi
addq $0x2000, %rdi           # imm = 0x2000
callq 0x5cc0
cmpq $0xff, %rax
jae 0xc38d
movslq -0x18(%rbp), %rax
leaq 0x15b22(%rip), %rdi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rdi
addq $0x2000, %rdi           # imm = 0x2000
callq 0x5cc0
movq %rax, -0x20c8(%rbp)
jmp 0xc39b
movl $0xff, %eax
movq %rax, -0x20c8(%rbp)
jmp 0xc39b
movq -0x20c8(%rbp), %rcx
addq $0x1, %rcx
movslq -0x18(%rbp), %rax
movq %rcx, -0x58(%rbp,%rax,8)
movslq -0x18(%rbp), %rax
movq $0x30, -0x38(%rbp,%rax,8)
jmp 0xc3be
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc1cf
movq 0x15895(%rip), %rdi     # 0x21c68
movq 0x138de(%rip), %rsi     # 0x1fcb8
leaq -0x10b0(%rbp), %rdx
callq 0x74c0
leaq -0x10b0(%rbp), %rdi
movq -0x8(%rbp), %rsi
leaq -0x20b0(%rbp), %rdx
callq 0x74c0
leaq -0x20b0(%rbp), %rdi
movl $0x241, %esi            # imm = 0x241
movl $0x180, %edx            # imm = 0x180
movb $0x0, %al
callq 0x46c0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0xc433
movq 0x136f3(%rip), %rdi     # 0x1fb18
movq -0x10(%rbp), %rsi
callq 0xd210
jmp 0xc639
movl -0x14(%rbp), %edi
leaq -0xa0(%rbp), %rsi
movl $0x88, %edx
callq 0x4210
cmpq $0x88, %rax
jne 0xc469
movl -0x14(%rbp), %edi
leaq 0x14077(%rip), %rsi     # 0x204d0
movl $0x4, %edx
callq 0x4210
cmpq $0x4, %rax
je 0xc46e
jmp 0xc618
movl $0x0, -0x18(%rbp)
cmpl $0x4, -0x18(%rbp)
jge 0xc611
movl -0x14(%rbp), %edi
movslq -0x18(%rbp), %rax
leaq 0x15a03(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x2130, %rsi           # imm = 0x2130
movl $0x4, %edx
callq 0x4210
cmpq $0x4, %rax
jne 0xc5ff
movl -0x14(%rbp), %edi
movslq -0x18(%rbp), %rax
leaq 0x159d0(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x2134, %rsi           # imm = 0x2134
movl $0x4, %edx
callq 0x4210
cmpq $0x4, %rax
jne 0xc5ff
movslq -0x18(%rbp), %rax
cmpq $0x0, -0x58(%rbp,%rax,8)
jbe 0xc52d
movl -0x14(%rbp), %edi
movslq -0x18(%rbp), %rax
leaq 0x15991(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x2000, %rsi           # imm = 0x2000
movslq -0x18(%rbp), %rax
movq -0x58(%rbp,%rax,8), %rdx
callq 0x4210
movslq -0x18(%rbp), %rcx
cmpq -0x58(%rbp,%rcx,8), %rax
jne 0xc5ff
movslq -0x18(%rbp), %rax
cmpq $0x0, -0x78(%rbp,%rax,8)
jbe 0xc575
movl -0x14(%rbp), %edi
movslq -0x18(%rbp), %rax
leaq 0x15949(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x1000, %rsi           # imm = 0x1000
movslq -0x18(%rbp), %rax
movq -0x78(%rbp,%rax,8), %rdx
callq 0x4210
movslq -0x18(%rbp), %rcx
cmpq -0x78(%rbp,%rcx,8), %rax
jne 0xc5ff
movslq -0x18(%rbp), %rax
cmpq $0x0, -0x38(%rbp,%rax,8)
jbe 0xc5b9
movl -0x14(%rbp), %edi
movslq -0x18(%rbp), %rax
leaq 0x15901(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x2100, %rsi           # imm = 0x2100
movslq -0x18(%rbp), %rax
movq -0x38(%rbp,%rax,8), %rdx
callq 0x4210
movslq -0x18(%rbp), %rcx
cmpq -0x38(%rbp,%rcx,8), %rax
jne 0xc5ff
movslq -0x18(%rbp), %rax
cmpq $0x0, -0x98(%rbp,%rax,8)
jbe 0xc601
movl -0x14(%rbp), %edi
movslq -0x18(%rbp), %rax
leaq 0x158ba(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
movslq -0x18(%rbp), %rax
movq -0x98(%rbp,%rax,8), %rdx
callq 0x4210
movslq -0x18(%rbp), %rcx
cmpq -0x98(%rbp,%rcx,8), %rax
je 0xc601
jmp 0xc618
jmp 0xc603
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc475
movb $0x1, -0xa1(%rbp)
movl -0x14(%rbp), %edi
callq 0x43c0
testb $0x1, -0xa1(%rbp)
jne 0xc639
movq 0x13458(%rip), %rdi     # 0x1fa88
movq -0x10(%rbp), %rsi
callq 0xd210
addq $0x20d0, %rsp           # imm = 0x20D0
popq %rbp
retq
nopw %cs:(%rax,%rax)