// File: /workspace/github_c_makefile_star2_O0/jarun[P]nnn/src/nnn.c
// Function: load_session
static bool load_session(const char *sname, char **path, char **lastdir, char **lastname, bool restore)
{
	int fd, i = 0;
	session_header_t header;
	bool has_loaded_dynamically = !(sname || restore);
	bool status = (sname && g_state.picker); /* Picker mode with session program option */
	char ssnpath[PATH_MAX];
	char spath[PATH_MAX];

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

	if (!restore) {
		if (!sname || !sname[0])
			sname = xreadline(NULL, messages[MSG_SSN_NAME]);
		if (!sname[0])
			return FALSE;

		mkpath(ssnpath, sname, spath);

		/* If user is explicitly loading the "last session", skip auto-save */
		if ((sname[0] == '@') && !sname[1])
			has_loaded_dynamically = FALSE;
	} else
		mkpath(ssnpath, "@", spath);

	if (has_loaded_dynamically)
		save_session("@", NULL);

	fd = open(spath, O_RDONLY, S_IWUSR | S_IRUSR);
	if (fd == -1) {
		if (!status) {
			printmsg(messages[MSG_SEL_MISSING]);
			xdelay(XDELAY_INTERVAL_MS);
		}
		return FALSE;
	}

	status = FALSE;

	if ((read(fd, &header, sizeof(header)) != (ssize_t)sizeof(header))
		|| (header.ver != SESSIONS_VERSION)
		|| (read(fd, &cfg, sizeof(cfg)) != (ssize_t)sizeof(cfg)))
		goto END;

	g_ctx[cfg.curctx].c_name[0] = g_ctx[cfg.curctx].c_last[0]
		= g_ctx[cfg.curctx].c_fltr[0] = g_ctx[cfg.curctx].c_fltr[1] = '\0';

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

	*path = g_ctx[cfg.curctx].c_path;
	*lastdir = g_ctx[cfg.curctx].c_last;
	*lastname = g_ctx[cfg.curctx].c_name;
	/* Set correct sort and filter options */
	set_sort_flags('\0');
	filterfn = cfg.regex ? &visible_re : &visible_str;
	xstrsncpy(curssn, sname ? sname : "@", NAME_MAX);
	status = TRUE;

END:
	close(fd);

	if (!status) {
		printmsg(messages[MSG_FAILED]);
		xdelay(XDELAY_INTERVAL_MS);
	} else if (restore)
		unlink(spath);

	return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20e0, %rsp           # imm = 0x20E0
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
movl $0x0, -0x34(%rbp)
movb $0x1, %al
cmpq $0x0, -0x10(%rbp)
movb %al, -0x20d1(%rbp)
jne 0xe622
movb -0x29(%rbp), %al
movb %al, -0x20d1(%rbp)
movb -0x20d1(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0xc1(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x10(%rbp)
movb %al, -0x20d2(%rbp)
je 0xe659
movl 0x121dd(%rip), %eax     # 0x20824
shrl $0xc, %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x20d2(%rbp)
movb -0x20d2(%rbp), %al
andb $0x1, %al
movb %al, -0xc2(%rbp)
movq 0x135fa(%rip), %rdi     # 0x21c68
movq 0x11643(%rip), %rsi     # 0x1fcb8
leaq -0x10d0(%rbp), %rdx
callq 0x74c0
testb $0x1, -0x29(%rbp)
jne 0xe6f3
cmpq $0x0, -0x10(%rbp)
je 0xe697
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
jne 0xe6ab
movq 0x113f2(%rip), %rsi     # 0x1fa90
xorl %eax, %eax
movl %eax, %edi
callq 0x144a0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
jne 0xe6bd
movb $0x0, -0x1(%rbp)
jmp 0xeb3a
leaq -0x10d0(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x20d0(%rbp), %rdx
callq 0x74c0
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x40, %eax
jne 0xe6f1
movq -0x10(%rbp), %rax
cmpb $0x0, 0x1(%rax)
jne 0xe6f1
movb $0x0, -0xc1(%rbp)
jmp 0xe70d
leaq -0x10d0(%rbp), %rdi
leaq -0x20d0(%rbp), %rdx
leaq 0xdfa2(%rip), %rsi      # 0x1c6aa
callq 0x74c0
testb $0x1, -0xc1(%rbp)
je 0xe726
leaq 0xdf8d(%rip), %rdi      # 0x1c6aa
xorl %eax, %eax
movl %eax, %esi
callq 0xc190
leaq -0x20d0(%rbp), %rdi
xorl %esi, %esi
movl $0x180, %edx            # imm = 0x180
movb $0x0, %al
callq 0x46c0
movl %eax, -0x30(%rbp)
cmpl $-0x1, -0x30(%rbp)
jne 0xe76c
testb $0x1, -0xc2(%rbp)
jne 0xe763
movq 0x113c4(%rip), %rdi     # 0x1fb18
callq 0xd020
movl $0x55730, %edi          # imm = 0x55730
callq 0xd0a0
movb $0x0, -0x1(%rbp)
jmp 0xeb3a
movb $0x0, -0xc2(%rbp)
movl -0x30(%rbp), %edi
leaq -0xc0(%rbp), %rsi
movl $0x88, %edx
callq 0x4460
cmpq $0x88, %rax
jne 0xe7b3
cmpq $0x1, -0xc0(%rbp)
jne 0xe7b3
movl -0x30(%rbp), %edi
leaq 0x11d2d(%rip), %rsi     # 0x204d0
movl $0x4, %edx
callq 0x4460
cmpq $0x4, %rax
je 0xe7b8
jmp 0xeaf2
movl 0x11d12(%rip), %eax     # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x136c1(%rip), %rax     # 0x21e90
imulq $0x2138, %rcx, %rcx     # imm = 0x2138
addq %rcx, %rax
movb $0x0, 0x2101(%rax)
movl 0x11cea(%rip), %eax     # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x13699(%rip), %rax     # 0x21e90
imulq $0x2138, %rcx, %rcx     # imm = 0x2138
addq %rcx, %rax
movb $0x0, 0x2100(%rax)
movl 0x11cc2(%rip), %eax     # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x13671(%rip), %rax     # 0x21e90
imulq $0x2138, %rcx, %rcx     # imm = 0x2138
addq %rcx, %rax
movb $0x0, 0x1000(%rax)
movl 0x11c9a(%rip), %eax     # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
movl %eax, %eax
movl %eax, %ecx
leaq 0x13649(%rip), %rax     # 0x21e90
imulq $0x2138, %rcx, %rcx     # imm = 0x2138
addq %rcx, %rax
movb $0x0, 0x2000(%rax)
cmpl $0x4, -0x34(%rbp)
jge 0xea00
movl -0x30(%rbp), %edi
movslq -0x34(%rbp), %rax
leaq 0x13620(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x2130, %rsi           # imm = 0x2130
movl $0x4, %edx
callq 0x4460
cmpq $0x4, %rax
jne 0xe9eb
movl -0x30(%rbp), %edi
movslq -0x34(%rbp), %rax
leaq 0x135ed(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x2134, %rsi           # imm = 0x2134
movl $0x4, %edx
callq 0x4460
cmpq $0x4, %rax
jne 0xe9eb
movslq -0x34(%rbp), %rax
cmpq $0x0, -0x78(%rbp,%rax,8)
jbe 0xe910
movl -0x30(%rbp), %edi
movslq -0x34(%rbp), %rax
leaq 0x135ae(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x2000, %rsi           # imm = 0x2000
movslq -0x34(%rbp), %rax
movq -0x78(%rbp,%rax,8), %rdx
callq 0x4460
movslq -0x34(%rbp), %rcx
cmpq -0x78(%rbp,%rcx,8), %rax
jne 0xe9eb
movslq -0x34(%rbp), %rax
cmpq $0x0, -0x98(%rbp,%rax,8)
jbe 0xe961
movl -0x30(%rbp), %edi
movslq -0x34(%rbp), %rax
leaq 0x13563(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x1000, %rsi           # imm = 0x1000
movslq -0x34(%rbp), %rax
movq -0x98(%rbp,%rax,8), %rdx
callq 0x4460
movslq -0x34(%rbp), %rcx
cmpq -0x98(%rbp,%rcx,8), %rax
jne 0xe9eb
movslq -0x34(%rbp), %rax
cmpq $0x0, -0x58(%rbp,%rax,8)
jbe 0xe9a5
movl -0x30(%rbp), %edi
movslq -0x34(%rbp), %rax
leaq 0x13515(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
addq $0x2100, %rsi           # imm = 0x2100
movslq -0x34(%rbp), %rax
movq -0x58(%rbp,%rax,8), %rdx
callq 0x4460
movslq -0x34(%rbp), %rcx
cmpq -0x58(%rbp,%rcx,8), %rax
jne 0xe9eb
movslq -0x34(%rbp), %rax
cmpq $0x0, -0xb8(%rbp,%rax,8)
jbe 0xe9f0
movl -0x30(%rbp), %edi
movslq -0x34(%rbp), %rax
leaq 0x134ce(%rip), %rsi     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rsi
movslq -0x34(%rbp), %rax
movq -0xb8(%rbp,%rax,8), %rdx
callq 0x4460
movslq -0x34(%rbp), %rcx
cmpq -0xb8(%rbp,%rcx,8), %rax
je 0xe9f0
jmp 0xeaf2
jmp 0xe9f2
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xe858
movl 0x11aca(%rip), %eax     # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
movl %eax, %eax
leaq 0x1347b(%rip), %rcx     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl 0x11aa4(%rip), %eax     # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
movl %eax, %eax
leaq 0x13455(%rip), %rcx     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rcx
addq $0x1000, %rcx           # imm = 0x1000
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl 0x11a77(%rip), %eax     # 0x204d0
shrl $0xd, %eax
andl $0x7, %eax
movl %eax, %eax
leaq 0x13428(%rip), %rcx     # 0x21e90
imulq $0x2138, %rax, %rax     # imm = 0x2138
addq %rax, %rcx
addq $0x2000, %rcx           # imm = 0x2000
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
xorl %edi, %edi
callq 0x7960
movl 0x11a43(%rip), %edx     # 0x204d0
shrl $0x19, %edx
andl $0x1, %edx
leaq -0x204a(%rip), %rax     # 0xca50
leaq -0x8db1(%rip), %rcx     # 0x5cf0
cmpl $0x0, %edx
cmovneq %rcx, %rax
movq %rax, 0x119f1(%rip)     # 0x204a0
cmpq $0x0, -0x10(%rbp)
je 0xeac3
movq -0x10(%rbp), %rax
movq %rax, -0x20e0(%rbp)
jmp 0xead3
leaq 0xdbe0(%rip), %rax      # 0x1c6aa
movq %rax, -0x20e0(%rbp)
jmp 0xead3
movq -0x20e0(%rbp), %rsi
leaq 0x11d4f(%rip), %rdi     # 0x20830
movl $0xff, %edx
callq 0x6250
movb $0x1, -0xc2(%rbp)
movl -0x30(%rbp), %edi
callq 0x43c0
testb $0x1, -0xc2(%rbp)
jne 0xeb1b
movq 0x10f7e(%rip), %rdi     # 0x1fa88
callq 0xd020
movl $0x55730, %edi          # imm = 0x55730
callq 0xd0a0
jmp 0xeb2f
testb $0x1, -0x29(%rbp)
je 0xeb2d
leaq -0x20d0(%rbp), %rdi
callq 0x40d0
jmp 0xeb2f
movb -0xc2(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x20e0, %rsp           # imm = 0x20E0
popq %rbp
retq
nopl (%rax,%rax)