// File: /workspace/github_c_makefile_star2_O1/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
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xadc8(%rip), %r14      # 0x10738
movq (%r14), %rdi
callq 0x4110
leaq 0xafe9(%rip), %r15      # 0x10968
movl $0x1, (%r15)
cmpl $0x0, 0x68(%rbx)
je 0x59de
cmpq %rbx, 0xad9d(%rip)      # 0x10730
jne 0x59a9
movq (%r14), %rdi
movl $0x1, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x44c0
xorps %xmm0, %xmm0
movq %rsp, %rax
movaps %xmm0, (%rax)
movq (%rbx), %rsi
movq (%r14), %rdi
movq 0x8(%r14), %rcx
movq %rcx, %rdx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq $0x2
pushq %rax
callq 0x4640
addq $0x10, %rsp
movq %rbx, %rdi
callq 0x8217
jmp 0x59e6
movq %rbx, %rdi
callq 0x81fe
xorl %esi, %esi
subl 0x3c(%rbx), %esi
movq %rbx, %rdi
callq 0x57c7
movl 0x50(%rbx), %esi
movq %rbx, %rdi
callq 0x57c7
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 0x5a51
movq (%r14), %rdi
callq 0x4320
movq 0xacc0(%rip), %rdi      # 0x10718
movq %rbx, %rsi
callq 0x87d5
movq %rax, 0xacb1(%rip)      # 0x10718
movq 0xacb2(%rip), %rdi      # 0x10720
movq %rbx, %rsi
callq 0x87d5
movq %rax, 0xaca3(%rip)      # 0x10720
movq 0xaca4(%rip), %rdi      # 0x10728
movq %rbx, %rsi
callq 0x87d5
movq %rax, 0xac95(%rip)      # 0x10728
cmpl $0x0, 0x68(%rbx)
je 0x5aab
movq 0x10(%rbx), %rdi
callq 0x7e85
movq 0x10(%rbx), %rdi
callq 0x7f36
cmpq %rbx, 0xac7e(%rip)      # 0x10730
jne 0x5ac7
movq $0x0, 0xac71(%rip) # 0x10730
movq %rbx, %rdi
callq 0x8090
movq %rbx, %rdi
callq 0x42d0
movq (%r14), %rdi
callq 0x43a0
movq (%r14), %rdi
xorl %esi, %esi
callq 0x4500
movl $0x0, (%r15)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq