// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
leaq 0xccad(%rip), %rax      # 0x12d80
movq (%rax), %rdi
callq 0x4120
leaq 0xcece(%rip), %rax      # 0x12fb0
movl $0x1, (%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x6132
movq -0x8(%rbp), %rax
cmpq 0xcc7b(%rip), %rax      # 0x12d78
jne 0x611c
leaq 0xcc7a(%rip), %rax      # 0x12d80
movq (%rax), %rdi
movl $0x1, %esi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x44d0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x5c00
movq -0x8(%rbp), %rdi
callq 0xa340
jmp 0x613b
movq -0x8(%rbp), %rdi
callq 0xa300
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
xorl %esi, %esi
subl 0x3c(%rax), %esi
callq 0x5e00
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x50(%rax), %esi
callq 0x5e00
movq -0x8(%rbp), %rax
movl 0x50(%rax), %edx
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movl 0x50(%rax), %edx
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x2c(%rax)
leaq 0xcbf6(%rip), %rax      # 0x12d80
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rdx
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %r8d
callq 0x46d0
leaq 0xcbc5(%rip), %rax      # 0x12d80
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x50(%rax), %edx
callq 0x45b0
leaq 0xcba8(%rip), %rax      # 0x12d80
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
callq 0x42a0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x6209
leaq 0xcb87(%rip), %rax      # 0x12d80
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x4330
movq 0xcb50(%rip), %rdi      # 0x12d60
movq -0x8(%rbp), %rsi
callq 0xaf90
movq %rax, 0xcb40(%rip)      # 0x12d60
movq 0xcb41(%rip), %rdi      # 0x12d68
movq -0x8(%rbp), %rsi
callq 0xaf90
movq %rax, 0xcb31(%rip)      # 0x12d68
movq 0xcb32(%rip), %rdi      # 0x12d70
movq -0x8(%rbp), %rsi
callq 0xaf90
movq %rax, 0xcb22(%rip)      # 0x12d70
movq -0x8(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x6272
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x9d50
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x9ea0
movq 0xcaff(%rip), %rax      # 0x12d78
cmpq -0x8(%rbp), %rax
jne 0x6293
movq $0x0, 0xcaee(%rip) # 0x12d78
movq -0x8(%rbp), %rdi
callq 0xa0f0
movq -0x8(%rbp), %rdi
callq 0x42e0
leaq 0xcadd(%rip), %rax      # 0x12d80
movq (%rax), %rdi
callq 0x43b0
leaq 0xcace(%rip), %rax      # 0x12d80
movq (%rax), %rdi
xorl %esi, %esi
callq 0x4510
leaq 0xcced(%rip), %rax      # 0x12fb0
movl $0x0, (%rax)
addq $0x10, %rsp
popq %rbp
retq
nop