// File: /workspace/github_c_makefile_star2_O2/mati75[P]evilwm/client.c
// Function: remove_client
void remove_client(struct client *c) {
	LOG_ENTER("remove_client(window=%lx, %s)", (unsigned long)c->window, c->remove ? "withdrawing" : "wm quitting");

	// Grab the server so any X errors are guaranteed to come from our actions.
	XGrabServer(display.dpy);

	// Flag to ignore any X errors we trigger.  The window may well already
	// have been deleted from the server, so anything we try to do to it
	// here would raise one.
	ignore_xerror = 1;

	// ICCCM 4.1.3.1
	// "When the window is withdrawn, the window manager will either change
	//  the state field's value to WithdrawnState or it will remove the
	//  WM_STATE property entirely."
	//
	// EWMH 1.3
	// "The Window Manager should remove the property whenever a window is
	//  withdrawn but it should leave the property in place when it is
	//  shutting down." (both _NET_WM_DESKTOP and _NET_WM_STATE)

	if (c->remove) {
		LOG_DEBUG("setting WithdrawnState\n");
		if (c == current) {
			XSetInputFocus(display.dpy, PointerRoot, RevertToPointerRoot,
			               CurrentTime);
		}
		set_wm_state(c, WithdrawnState);
		ewmh_withdraw_client(c);
	} else {
		ewmh_remove_allowed_actions(c);
	}

	// Undo the geometry changes applied when we managed the client
	client_gravitate(c, -c->border);
	client_gravitate(c, c->old_border);
	c->x -= c->old_border;
	c->y -= c->old_border;

	// Reparent window back to the root
	XReparentWindow(display.dpy, c->window, c->screen->root, c->x, c->y);

	// Restore any old border
	XSetWindowBorderWidth(display.dpy, c->window, c->old_border);

	// Remove window from "save set": we are no longer its parent, so if we
	// die now, the window should be fine.
	XRemoveFromSaveSet(display.dpy, c->window);

	// Destroy parent window
	if (c->parent) {
		XDestroyWindow(display.dpy, c->parent);
	}

	// Remove from the client lists
	clients_tab_order = list_delete(clients_tab_order, c);
	clients_mapping_order = list_delete(clients_mapping_order, c);
	clients_stacking_order = list_delete(clients_stacking_order, c);

	// If the wm is quitting, we'll remove the client list properties
	// soon enough, otherwise, update them:
	if (c->remove) {
		ewmh_set_net_client_list(c->screen);
		ewmh_set_net_client_list_stacking(c->screen);
	}

	// Deselect if this client were previously selected
	if (current == c) {
		current = NULL;
		// Remove _NET_WM_STATE_FOCUSED from client window and
		// _NET_ACTIVE_WINDOW from screen if necessary.
		ewmh_set_net_wm_state(c);
	}
	free(c);

#ifdef DEBUG
	{
		int i = 0;
		for (struct list *iter = clients_tab_order; iter; iter = iter->next)
			i++;
		LOG_DEBUG("free(), window count now %d\n", i);
	}
#endif

	XUngrabServer(display.dpy);
	XSync(display.dpy, False);
	ignore_xerror = 0;
	LOG_LEAVE();
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
leaq 0xa157(%rip), %r14      # 0xf728
movq (%r14), %rdi
callq 0x4110
leaq 0xa378(%rip), %r15      # 0xf958
movl $0x1, (%r15)
cmpl $0x0, 0x68(%rbx)
je 0x561a
cmpq %rbx, 0xa12c(%rip)      # 0xf720
jne 0x5606
movq (%r14), %rdi
pushq $0x1
popq %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x44c0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5302
movq %rbx, %rdi
callq 0x7cdc
jmp 0x5622
movq %rbx, %rdi
callq 0x7cc3
xorl %esi, %esi
subl 0x3c(%rbx), %esi
movq %rbx, %rdi
callq 0x542e
movl 0x50(%rbx), %esi
movq %rbx, %rdi
callq 0x542e
movl 0x50(%rbx), %eax
movl 0x28(%rbx), %ecx
subl %eax, %ecx
movl %ecx, 0x28(%rbx)
movl 0x2c(%rbx), %r8d
subl %eax, %r8d
movl %r8d, 0x2c(%rbx)
movq (%r14), %rdi
movq (%rbx), %rsi
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rdx
callq 0x46d0
movq (%r14), %rdi
movq (%rbx), %rsi
movl 0x50(%rbx), %edx
callq 0x45a0
movq (%r14), %rdi
movq (%rbx), %rsi
callq 0x4290
movq 0x8(%rbx), %rsi
testq %rsi, %rsi
je 0x568d
movq (%r14), %rdi
callq 0x4320
movq 0xa074(%rip), %rdi      # 0xf708
movq %rbx, %rsi
callq 0x824d
movq %rax, 0xa065(%rip)      # 0xf708
movq 0xa066(%rip), %rdi      # 0xf710
movq %rbx, %rsi
callq 0x824d
movq %rax, 0xa057(%rip)      # 0xf710
movq 0xa058(%rip), %rdi      # 0xf718
movq %rbx, %rsi
callq 0x824d
movq %rax, 0xa049(%rip)      # 0xf718
cmpl $0x0, 0x68(%rbx)
je 0x56e7
movq 0x10(%rbx), %rdi
callq 0x7991
movq 0x10(%rbx), %rdi
callq 0x7a29
cmpq %rbx, 0xa032(%rip)      # 0xf720
jne 0x5700
andq $0x0, 0xa028(%rip)      # 0xf720
movq %rbx, %rdi
callq 0x7b5e
movq %rbx, %rdi
callq 0x42d0
movq (%r14), %rdi
callq 0x43a0
movq (%r14), %rdi
xorl %esi, %esi
callq 0x4500
andl $0x0, (%r15)
popq %rbx
popq %r14
popq %r15
retq