// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
addq $-0x178, %rax           # imm = 0xFE88
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdx
leaq 0x93a8(%rip), %rdi      # 0xd134
leaq 0x93a5(%rip), %rsi      # 0xd138
movl $0x1, %ecx
callq 0xbed0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3dad
jmp 0x4004
movq 0x940c(%rip), %rax      # 0xd1c0
movq %rax, -0x30(%rbp)
movq 0x9409(%rip), %rax      # 0xd1c8
movq %rax, -0x28(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3560
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x3ddc
jmp 0x3ffb
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x3600
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x3df7
jmp 0x3fea
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
callq 0xa660
cmpq $0x0, %rax
jbe 0x3e4a
movq -0x18(%rbp), %rdi
callq 0xafa0
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
movq -0x48(%rbp), %rsi
callq 0x8250
movq %rax, -0x50(%rbp)
movl -0x3c(%rbp), %edi
movq -0x50(%rbp), %rdx
leaq 0x9307(%rip), %rsi      # 0xd141
callq 0xc000
testb $0x1, %al
jne 0x3e48
jmp 0x3fea
jmp 0x3e4a
movq -0x18(%rbp), %rdi
addq $0x28, %rdi
leaq -0x58(%rbp), %rsi
callq 0x7790
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jne 0x3e99
movl -0x3c(%rbp), %edi
movq -0x58(%rbp), %rdx
leaq 0x92d8(%rip), %rsi      # 0xd14a
callq 0xc0a0
andb $0x1, %al
movb %al, -0x5d(%rbp)
movq -0x58(%rbp), %rdi
movq 0xd131(%rip), %rsi      # 0x10fb8
callq 0xa010
testb $0x1, -0x5d(%rbp)
jne 0x3e97
jmp 0x3fea
jmp 0x3ea6
cmpl $0xc, -0x5c(%rbp)
jne 0x3ea4
jmp 0x3fea
jmp 0x3ea6
movl -0x3c(%rbp), %eax
movl %eax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
callq 0xb310
movl -0x90(%rbp), %edi
movq %rax, %rdx
leaq 0x9282(%rip), %rsi      # 0xd151
callq 0xc000
testb $0x1, %al
jne 0x3edd
jmp 0x3fea
movq -0x18(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
movl -0x3c(%rbp), %esi
callq 0x6150
testb $0x1, %al
jne 0x3ef9
jmp 0x3fea
leaq 0x922f(%rip), %rax      # 0xd12f
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movb $0x0, %al
callq 0xc1a0
andb $0x1, %al
movb %al, -0x89(%rbp)
testb $0x1, -0x89(%rbp)
je 0x3fa0
callq 0x36c0
movq -0x18(%rbp), %rax
addq $0x180, %rax            # imm = 0x180
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb310
movq -0x98(%rbp), %rdi
movq %rax, %rsi
leaq -0x80(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x1a6c(%rip), %r8       # 0x59d0
leaq -0x84(%rbp), %r9
callq 0xb8f0
cmpl $0x0, %eax
jne 0x3f99
movq -0x18(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
movl -0x84(%rbp), %esi
leaq -0x88(%rbp), %rdx
callq 0xba50
callq 0x3500
jmp 0x3ff3
callq 0x3500
jmp 0x3fe8
movq -0x18(%rbp), %rax
addq $0x180, %rax            # imm = 0x180
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rdi
callq 0xb310
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
leaq -0x80(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0x1a5d(%rip), %r8       # 0x5a30
leaq -0x84(%rbp), %r9
callq 0xb8f0
cmpl $0x0, %eax
jne 0x3fe6
jmp 0x3ff3
jmp 0x3fe8
jmp 0x3fea
movq -0x38(%rbp), %rdi
callq 0xbe70
movl -0x3c(%rbp), %edi
callq 0x3320
movq -0x20(%rbp), %rdi
callq 0xb7f0
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)