// File: /workspace/github_c_makefile_star2_O3/cglindkamp[P]dfm/src/application.c
// Function: command_invoke_handler
static void command_invoke_handler(struct commandexecutor *commandexecutor, char *handler_name)
{
	struct application *app = container_of(commandexecutor, struct application, commandexecutor);
	struct path *handler_path = determine_usable_config_file(PROJECT, "handlers", handler_name, X_OK);
	if(handler_path == NULL)
		return;

	char path_template[] = "/tmp/"PROJECT".XXXXXX";
	char *path = mkdtemp(path_template);
	if(path == NULL)
		goto err_dir;

	int dir_fd = open(path, O_RDONLY);
	if(dir_fd < 0)
		goto err_dircreated;

	if(listmodel_count(&app->model.listmodel) > 0) {
		size_t index = listview_getindex(&app->view);
		const char *selected = dirmodel_getfilename(&app->model, index);
		if(!dump_string_to_file(dir_fd, "selected", selected))
			goto err_dircreated;
	}

	const struct list *list;
	int ret = dirmodel_getmarkedfilenames(&app->model, &list);
	if(ret == 0) {
		bool ret = dump_filelist_to_file(dir_fd, "marked", list);
		list_delete(list, free);
		if(!ret)
			goto err_dircreated;
	} else if(ret == ENOMEM) {
		goto err_dircreated;
	}

	if(!dump_string_to_file(dir_fd, "cwd", path_tocstr(&app->cwd)))
		goto err_dircreated;

	if(!clipboard_dump_contents_to_directory(&app->clipboard, dir_fd))
		goto err_dircreated;

	char * const args[] = {
		"open",
		path,
		NULL
	};
	pid_t pid;
	int status;
	bool foreground = run_in_foreground();

	if(foreground) {
		endwin();
		if(processmanager_spawn(&app->pm, path_tocstr(handler_path), args, path, unblock_signals, &pid) == 0) {
			processmanager_waitpid(&app->pm, pid, &status);
			doupdate();
			goto success;
		} else
			doupdate();
	} else if(processmanager_spawn(&app->pm, path_tocstr(handler_path), args, path, background_process_and_unblock_signals, &pid) == 0)
		goto success;

err_dircreated:
	remove_directory_recursively(path);
success:
	close(dir_fd);
err_dir:
	path_delete(handler_path);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rsi, %rdx
movq %rdi, %r14
leaq 0x55ad(%rip), %rdi      # 0x9150
leaq 0x55aa(%rip), %rsi      # 0x9154
movl $0x1, %ecx
callq 0x8770
testq %rax, %rax
je 0x3d5f
movq %rax, %rbx
movaps 0x5619(%rip), %xmm0     # 0x91e0
leaq 0x40(%rsp), %rdi
movaps %xmm0, (%rdi)
callq 0x3560
testq %rax, %rax
je 0x3d57
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3600
movl %eax, %ebp
testl %eax, %eax
js 0x3d48
leaq -0x150(%r14), %r12
movq %r12, %rdi
callq 0x7a7c
testq %rax, %rax
je 0x3c3a
leaq -0x178(%r14), %rdi
callq 0x7eb3
movq %r12, %rdi
movq %rax, %rsi
callq 0x6811
leaq 0x5535(%rip), %rsi      # 0x915d
movl %ebp, %edi
movq %rax, %rdx
callq 0x8867
testb %al, %al
je 0x3d48
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x6028
cmpl $0xc, %eax
je 0x3d48
testl %eax, %eax
jne 0x3c84
movq 0x10(%rsp), %rdx
leaq 0x5506(%rip), %rsi      # 0x9166
movl %ebp, %edi
callq 0x88b5
movl %eax, %r12d
movq 0x10(%rsp), %rdi
movq 0x933a(%rip), %rsi      # 0xcfb0
callq 0x7706
testb %r12b, %r12b
je 0x3d48
leaq -0x38(%r14), %rdi
callq 0x8050
leaq 0x54d9(%rip), %rsi      # 0x916d
movl %ebp, %edi
movq %rax, %rdx
callq 0x8867
testb %al, %al
je 0x3d48
leaq -0x28(%r14), %rdi
movl %ebp, %esi
callq 0x537d
testb %al, %al
je 0x3d48
leaq 0x548b(%rip), %rax      # 0x914b
movq %rax, 0x20(%rsp)
movq %r15, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
xorl %eax, %eax
callq 0x8993
testb %al, %al
je 0x3d19
callq 0x36c0
addq $0x8, %r14
movq %rbx, %rdi
callq 0x8050
leaq 0x1325(%rip), %r8       # 0x501b
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %r9
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rcx
callq 0x839e
testl %eax, %eax
je 0x3d6c
callq 0x3500
jmp 0x3d48
addq $0x8, %r14
movq %rbx, %rdi
callq 0x8050
leaq 0x1341(%rip), %r8       # 0x506d
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %r9
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rcx
callq 0x839e
testl %eax, %eax
je 0x3d50
movq %r15, %rdi
callq 0x8750
movl %ebp, %edi
callq 0x3320
movq %rbx, %rdi
callq 0x8337
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0xc(%rsp), %esi
leaq 0x1c(%rsp), %rdx
movq %r14, %rdi
callq 0x84a3
callq 0x3500
jmp 0x3d50