// File: /workspace/github_c_makefile_star2_O3/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 0x9ea0(%rip), %r14      # 0xf728
movq (%r14), %rdi
callq 0x4110
leaq 0xa0c1(%rip), %r15      # 0xf958
movl $0x1, (%r15)
cmpl $0x0, 0x68(%rbx)
je 0x58f6
cmpq %rbx, 0x9e75(%rip)      # 0xf720
jne 0x58c1
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 0x80be
jmp 0x58fe
movq %rbx, %rdi
callq 0x80a5
xorl %esi, %esi
subl 0x3c(%rbx), %esi
movq %rbx, %rdi
callq 0x56df
movl 0x50(%rbx), %esi
movq %rbx, %rdi
callq 0x56df
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 0x5969
movq (%r14), %rdi
callq 0x4320
movq 0x9d98(%rip), %rdi      # 0xf708
movq %rbx, %rsi
callq 0x867f
movq %rax, 0x9d89(%rip)      # 0xf708
movq 0x9d8a(%rip), %rdi      # 0xf710
movq %rbx, %rsi
callq 0x867f
movq %rax, 0x9d7b(%rip)      # 0xf710
movq 0x9d7c(%rip), %rdi      # 0xf718
movq %rbx, %rsi
callq 0x867f
movq %rax, 0x9d6d(%rip)      # 0xf718
cmpl $0x0, 0x68(%rbx)
je 0x59c3
movq 0x10(%rbx), %rdi
callq 0x7d21
movq 0x10(%rbx), %rdi
callq 0x7dd2
cmpq %rbx, 0x9d56(%rip)      # 0xf720
jne 0x59df
movq $0x0, 0x9d49(%rip) # 0xf720
movq %rbx, %rdi
callq 0x7f2c
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