// File: /workspace/github_c_makefile_star2_O1/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 0x55bd(%rip), %rdi      # 0x9160
leaq 0x55ba(%rip), %rsi      # 0x9164
movl $0x1, %ecx
callq 0x88e8
testq %rax, %rax
je 0x3d5f
movq %rax, %rbx
movaps 0x5629(%rip), %xmm0     # 0x91f0
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 0x7c0c
testq %rax, %rax
je 0x3c3a
leaq -0x178(%r14), %rdi
callq 0x8053
movq %r12, %rdi
movq %rax, %rsi
callq 0x6899
leaq 0x5545(%rip), %rsi      # 0x916d
movl %ebp, %edi
movq %rax, %rdx
callq 0x8a33
testb %al, %al
je 0x3d48
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x607c
cmpl $0xc, %eax
je 0x3d48
testl %eax, %eax
jne 0x3c84
movq 0x10(%rsp), %rdx
leaq 0x5516(%rip), %rsi      # 0x9176
movl %ebp, %edi
callq 0x8a81
movl %eax, %r12d
movq 0x10(%rsp), %rdi
movq 0x933a(%rip), %rsi      # 0xcfb0
callq 0x7896
testb %r12b, %r12b
je 0x3d48
leaq -0x38(%r14), %rdi
callq 0x81f0
leaq 0x54e9(%rip), %rsi      # 0x917d
movl %ebp, %edi
movq %rax, %rdx
callq 0x8a33
testb %al, %al
je 0x3d48
leaq -0x28(%r14), %rdi
movl %ebp, %esi
callq 0x53e1
testb %al, %al
je 0x3d48
leaq 0x549b(%rip), %rax      # 0x915b
movq %rax, 0x20(%rsp)
movq %r15, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
xorl %eax, %eax
callq 0x8b40
testb %al, %al
je 0x3d19
callq 0x36c0
addq $0x8, %r14
movq %rbx, %rdi
callq 0x81f0
leaq 0x138d(%rip), %r8       # 0x5083
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %r9
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rcx
callq 0x84ee
testl %eax, %eax
je 0x3d6c
callq 0x3500
jmp 0x3d48
addq $0x8, %r14
movq %rbx, %rdi
callq 0x81f0
leaq 0x13a9(%rip), %r8       # 0x50d5
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %r9
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rcx
callq 0x84ee
testl %eax, %eax
je 0x3d50
movq %r15, %rdi
callq 0x88c8
movl %ebp, %edi
callq 0x3320
movq %rbx, %rdi
callq 0x8489
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 0x85e9
callq 0x3500
jmp 0x3d50