// File: /workspace/github_c_makefile_star2_O2/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 0x55b0(%rip), %rdi      # 0x9150
leaq 0x55ad(%rip), %rsi      # 0x9154
pushq $0x1
popq %rcx
callq 0x844c
testq %rax, %rax
je 0x3d57
movq %rax, %rbx
movaps 0x561e(%rip), %xmm0     # 0x91e0
leaq 0x40(%rsp), %rdi
movaps %xmm0, (%rdi)
callq 0x3560
testq %rax, %rax
je 0x3d4f
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3600
movl %eax, %ebp
testl %eax, %eax
js 0x3d40
leaq -0x150(%r14), %r12
movq %r12, %rdi
callq 0x780c
testq %rax, %rax
je 0x3c35
leaq -0x178(%r14), %rdi
callq 0x7c20
movq %r12, %rdi
movq %rax, %rsi
callq 0x66b1
leaq 0x553a(%rip), %rsi      # 0x915d
movl %ebp, %edi
movq %rax, %rdx
callq 0x8535
testb %al, %al
je 0x3d40
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x5ed8
cmpl $0xc, %eax
je 0x3d40
testl %eax, %eax
jne 0x3c7f
movq 0x10(%rsp), %rdx
leaq 0x550b(%rip), %rsi      # 0x9166
movl %ebp, %edi
callq 0x8581
movl %eax, %r12d
movq 0x10(%rsp), %rdi
movq 0x933f(%rip), %rsi      # 0xcfb0
callq 0x74d1
testb %r12b, %r12b
je 0x3d40
leaq -0x38(%r14), %rdi
callq 0x7dc8
leaq 0x54de(%rip), %rsi      # 0x916d
movl %ebp, %edi
movq %rax, %rdx
callq 0x8535
testb %al, %al
je 0x3d40
leaq -0x28(%r14), %rdi
movl %ebp, %esi
callq 0x5311
testb %al, %al
je 0x3d40
leaq 0x5490(%rip), %rax      # 0x914b
movq %rax, 0x20(%rsp)
movq %r15, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
xorl %eax, %eax
callq 0x8620
testb %al, %al
je 0x3d11
callq 0x36c0
addq $0x8, %r14
movq %rbx, %rdi
callq 0x7dc8
leaq 0x12c7(%rip), %r8       # 0x4fb5
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %r9
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rcx
callq 0x80aa
testl %eax, %eax
je 0x3d64
callq 0x3500
jmp 0x3d40
addq $0x8, %r14
movq %rbx, %rdi
callq 0x7dc8
leaq 0x12db(%rip), %r8       # 0x4fff
leaq 0x20(%rsp), %rdx
leaq 0xc(%rsp), %r9
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rcx
callq 0x80aa
testl %eax, %eax
je 0x3d48
movq %r15, %rdi
callq 0x8430
movl %ebp, %edi
callq 0x3320
movq %rbx, %rdi
callq 0x8047
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 0x819e
callq 0x3500
jmp 0x3d48