// File: /workspace/github_c_makefile_star2_O2/mati75[P]evilwm/client_new.c
// Function: client_manage_new
void client_manage_new(Window w, struct screen *s) {
	struct client *c;
	char *name;
	XClassHint *class;
	unsigned window_type;

	LOG_ENTER("client_manage_new(window=%lx)", (unsigned long)w);

	XGrabServer(display.dpy);

	// First a bit of interaction with the error handler due to X's
	// tendency to batch event notifications.  We set a global variable to
	// the id of the window we're initialising then do simple X call on
	// that window.  If an error is raised by this (and nothing else should
	// do so as we've grabbed the server), the error handler resets the
	// variable indicating the window has already disappeared, so we stop
	// trying to manage it.

	initialising = w;
	XFetchName(display.dpy, w, &name);
	XSync(display.dpy, False);

	// If 'initialising' is now set to None, that means doing the
	// XFetchName raised BadWindow - the window has been removed before
	// we got a chance to grab the server. */

	if (initialising == None) {
		LOG_DEBUG("XError occurred for initialising window - aborting...\n");
		XUngrabServer(display.dpy);
		LOG_LEAVE();
		return;
	}
	initialising = None;
	LOG_DEBUG("screen=%d\n", s->screen);
	LOG_DEBUG("name=%s\n", name ? name : "Untitled");
	if (name)
		XFree(name);

	window_type = ewmh_get_net_wm_window_type(w);
	// Don't manage DESKTOP type windows
	if (window_type & EWMH_WINDOW_TYPE_DESKTOP) {
		XMapWindow(display.dpy, w);
		XUngrabServer(display.dpy);
		return;
	}

	// If allocation fails, don't crash the window manager.  Just don't
	// manage the window.
	c = malloc(sizeof(struct client));
	if (!c) {
		LOG_ERROR("out of memory allocating new client\n");
		XMapWindow(display.dpy, w);
		XUngrabServer(display.dpy);
		LOG_LEAVE();
		return;
	}
	clients_tab_order = list_prepend(clients_tab_order, c);
	clients_mapping_order = list_append(clients_mapping_order, c);
	clients_stacking_order = list_append(clients_stacking_order, c);

	c->screen = s;
	c->window = w;
	c->ignore_unmap = 0;
	c->remove = 0;

	// Ungrab the X server as soon as possible. Now that the client is
	// malloc()ed and attached to the list, it is safe for any subsequent
	// X calls to raise an X error and thus flag it for removal.

	XUngrabServer(display.dpy);

	update_window_type_flags(c, window_type);
	init_geometry(c);

#ifdef DEBUG
	{
		int i = 0;
		for (struct list *iter = clients_tab_order; iter; iter = iter->next)
			i++;
		LOG_DEBUG("new window %dx%d+%d+%d, wincount=%d\n", c->width, c->height, c->x, c->y, i);
	}
#endif

	XSelectInput(display.dpy, c->window, ColormapChangeMask | EnterWindowMask | PropertyChangeMask);

	reparent(c);

#ifdef SHAPE
	if (display.have_shape) {
		XShapeSelectInput(display.dpy, c->window, ShapeNotifyMask);
		set_shape(c);
	}
#endif

	// Read name/class information for client and check against list built
	// with -app options.
	class = XAllocClassHint();
	if (class) {
		XGetClassHint(display.dpy, w, class);
		for (struct list *iter = applications; iter; iter = iter->next) {
			struct application *a = iter->data;
			// Does resource name and class match?
			if ((!a->res_name || (class->res_name && !strcmp(class->res_name, a->res_name)))
					&& (!a->res_class || (class->res_class && !strcmp(class->res_class, a->res_class)))) {

				// Override width or height?
				if (a->geometry_mask & WidthValue)
					c->width = a->width * c->width_inc;
				if (a->geometry_mask & HeightValue)
					c->height = a->height * c->height_inc;

				// Override X or Y?
				if (a->geometry_mask & XValue) {
					if (a->geometry_mask & XNegative)
						c->x = a->x + DisplayWidth(display.dpy, s->screen)-c->width-c->border;
					else
						c->x = a->x + c->border;
				}
				if (a->geometry_mask & YValue) {
					if (a->geometry_mask & YNegative)
						c->y = a->y + DisplayHeight(display.dpy, s->screen)-c->height-c->border;
					else
						c->y = a->y + c->border;
				}

				// XXX better way of updating window geometry?
				client_moveresizeraise(c);

				// Force treating this app as a dock?
				if (a->is_dock)
					c->is_dock = 1;

				// Force app to specific vdesk?
				if (a->vdesk != VDESK_NONE)
					c->vdesk = a->vdesk;
			}
		}
		XFree(class->res_name);
		XFree(class->res_class);
		XFree(class);
	}

	// Set EWMH property on client advertising WM features
	ewmh_set_allowed_actions(c);

	// Update EWMH client list hints for screen
	ewmh_set_net_client_list(c->screen);
	ewmh_set_net_client_list_stacking(c->screen);

	// Only map the window frame (and thus the window) if it's supposed
	// to be visible on this virtual desktop.  Otherwise, set it to
	// IconicState (hidden).
	if (is_fixed(c) || c->vdesk == s->vdesk) {
		client_show(c);
		client_raise(c);
		// Don't focus windows that aren't on the same display as the
		// pointer.
		if (get_pointer_root_xy(c->window, NULL, NULL) &&
		    !(window_type & (EWMH_WINDOW_TYPE_DOCK|EWMH_WINDOW_TYPE_NOTIFICATION))) {
			select_client(c);
#ifdef WARP_POINTER
			setmouse(c->window, c->width + c->border - 1,
				 c->height + c->border - 1);
#endif
			discard_enter_events(c);
		}
	} else {
		set_wm_state(c, IconicState);
	}

	// Ensure whichever vdesk it ended up on is reflected in the EWMH hints
	ewmh_set_net_wm_desktop(c);

	LOG_LEAVE();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
leaq 0x8fa0(%rip), %rbx      # 0xf728
movq (%rbx), %rdi
callq 0x4110
leaq 0x91c9(%rip), %r14      # 0xf960
movq %r15, (%r14)
movq (%rbx), %rdi
leaq 0x20(%rsp), %rdx
movq %r15, %rsi
callq 0x45b0
movq (%rbx), %rdi
xorl %esi, %esi
callq 0x4500
cmpq $0x0, (%r14)
je 0x6d71
movq $0x0, (%r14)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x67d4
callq 0x4050
movq %r15, %rdi
callq 0x7d4a
movl %eax, %r13d
testb $0x1, %r13b
jne 0x6d66
movl $0x98, %edi
callq 0x41e0
testq %rax, %rax
je 0x6d4a
movq %rax, %r14
leaq 0x8f02(%rip), %r12      # 0xf708
movq (%r12), %rdi
movq %rax, %rsi
callq 0x8238
movq %rax, (%r12)
leaq 0x8ef3(%rip), %r12      # 0xf710
movq (%r12), %rdi
movq %r14, %rsi
callq 0x8243
movq %rax, (%r12)
leaq 0x8ee4(%rip), %r12      # 0xf718
movq (%r12), %rdi
movq %r14, %rsi
callq 0x8243
movq %rax, (%r12)
movq 0x10(%rsp), %rax
movq %rax, 0x10(%r14)
movq %r15, (%r14)
andl $0x0, 0x24(%r14)
andl $0x0, 0x68(%r14)
movq (%rbx), %rdi
callq 0x43a0
movq %r14, %rdi
movl %r13d, %esi
callq 0x50f0
movq (%r14), %rdi
callq 0x931b
movl %eax, 0x38(%r14)
movq (%r14), %rdi
movq 0x10(%r14), %rax
movl 0x60(%rax), %eax
movl %eax, 0x20(%r14)
movq 0xb8(%rbx), %rsi
pushq $0x6
popq %rdx
movq %rsp, %rcx
callq 0x929b
testq %rax, %rax
je 0x68cb
cmpq $0x0, (%rsp)
je 0x68c3
movl (%rax), %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpq %rdx, %rcx
je 0x68bf
leaq 0x9038(%rip), %rdx      # 0xf8f0
movl 0x2c(%rdx), %edx
cmpl %edx, %ecx
jae 0x68c3
movl %ecx, 0x20(%r14)
movq %rax, %rdi
callq 0x4050
movq (%rbx), %rdi
movq (%r14), %rsi
leaq 0x30(%rsp), %r12
movq %r12, %rdx
callq 0x4630
movl 0x10(%r12), %eax
movl %eax, 0x50(%r14)
movq 0x50(%r12), %rax
movq %rax, 0x18(%r14)
andq $0x0, 0x48(%r14)
movq (%r14), %rdi
movq 0x30(%rbx), %rsi
pushq $0x6
popq %rdx
movq %rsp, %rcx
callq 0x929b
testq %rax, %rax
je 0x6928
cmpq $0x2, (%rsp)
jne 0x6920
movl (%rax), %ecx
movl %ecx, 0x40(%r14)
movl 0x8(%rax), %ecx
movl %ecx, 0x48(%r14)
movq %rax, %rdi
callq 0x4050
movq (%r14), %rdi
movq 0x38(%rbx), %rsi
pushq $0x6
popq %rdx
movq %rsp, %rcx
callq 0x929b
testq %rax, %rax
je 0x695b
cmpq $0x2, (%rsp)
jne 0x6953
movl (%rax), %ecx
movl %ecx, 0x44(%r14)
movl 0x8(%rax), %ecx
movl %ecx, 0x4c(%r14)
movq %rax, %rdi
callq 0x4050
cmpl $0x0, 0x48(%r14)
je 0x696b
xorl %eax, %eax
cmpl $0x0, 0x4c(%r14)
jne 0x696f
movl 0x38(%r14), %eax
movl %eax, 0x3c(%r14)
movq %r14, %rdi
callq 0x4fe4
movl 0x38(%rsp), %edi
movl 0x6c(%r14), %edx
cmpl %edx, %edi
jge 0x698f
movl 0x70(%r14), %esi
movb $0x1, %cl
jmp 0x69a7
movl 0x3c(%rsp), %esi
movl 0x70(%r14), %r8d
cmpl %r8d, %esi
jge 0x69a3
movb $0x1, %cl
movl %r8d, %esi
jmp 0x69a7
xorl %ecx, %ecx
movl %edi, %edx
movl %edx, 0x30(%r14)
movl %esi, 0x34(%r14)
cmpl $0x2, 0x8c(%rsp)
movl %r13d, 0xc(%rsp)
je 0x6a31
andl $0x1, %eax
jne 0x6a31
movq (%rbx), %rax
movq 0xe8(%rax), %rax
movq 0x10(%r14), %rcx
movslq (%rcx), %rdx
shlq $0x7, %rdx
movl 0x18(%rax,%rdx), %ebp
movl 0x1c(%rax,%rdx), %r12d
movq 0x10(%rcx), %rdi
leaq 0x2c(%rsp), %r13
leaq 0x1c(%rsp), %rdx
movq %r13, %rsi
callq 0x9241
movl 0x3c(%r14), %ecx
movl 0x30(%r14), %edx
addl %ecx, %edx
movl %ebp, %eax
subl %edx, %eax
imull (%r13), %eax
cltd
idivl %ebp
movl 0xc(%rsp), %r13d
movl %eax, 0x28(%r14)
addl 0x34(%r14), %ecx
movl %r12d, %eax
subl %ecx, %eax
leaq 0x1c(%rsp), %rcx
imull (%rcx), %eax
cltd
idivl %r12d
movl %eax, 0x2c(%r14)
jmp 0x6a3e
movq 0x30(%rsp), %rax
movq %rax, 0x28(%r14)
testb %cl, %cl
je 0x6a46
movq %r14, %rdi
callq 0x53ce
movq (%r14), %rdi
movslq 0x3c(%r14), %rsi
callq 0x7dd8
cmpl $0x2, 0x8c(%rsp)
jne 0x6a60
incl 0x24(%r14)
movl 0x50(%r14), %esi
movq 0x28(%r14), %xmm0
movd %esi, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, 0x28(%r14)
negl %esi
movq %r14, %rdi
callq 0x542e
movl 0x3c(%r14), %esi
movq %r14, %rdi
callq 0x542e
movq (%rbx), %rdi
movq (%r14), %rsi
movl $0xc00010, %edx         # imm = 0xC00010
callq 0x44b0
movq 0x10(%r14), %r10
movq 0x40(%r10), %rax
movq %rax, 0x48(%rsp)
movl $0x1, 0x88(%rsp)
movq $0x180014, 0x78(%rsp)   # imm = 0x180014
movq (%rbx), %rdi
movq 0x10(%r10), %rsi
movl 0x3c(%r14), %eax
movl 0x28(%r14), %edx
movl 0x2c(%r14), %ecx
subl %eax, %edx
subl %eax, %ecx
movl 0x30(%r14), %r8d
movl 0x34(%r14), %r9d
movq 0xe8(%rdi), %r11
movslq (%r10), %r10
shlq $0x7, %r10
movl 0x38(%r11,%r10), %r12d
leaq 0x30(%rsp), %rbp
pushq %rbp
pushq $0xa08                  # imm = 0xA08
pushq 0x40(%r11,%r10)
pushq $0x0
pushq %r12
pushq %rax
callq 0x4250
addq $0x30, %rsp
movq %rax, 0x8(%r14)
movq (%rbx), %rdi
movq (%r14), %rsi
callq 0x4350
movq (%rbx), %rdi
movq (%r14), %rsi
xorl %edx, %edx
callq 0x45a0
movq (%rbx), %rdi
movq (%r14), %rsi
movq 0x8(%r14), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x46d0
movq (%rbx), %rdi
movq (%r14), %rsi
callq 0x4440
movq %r14, %rdi
callq 0x4d6a
cmpl $0x0, 0x178(%rbx)
je 0x6b76
movq (%rbx), %rdi
movq (%r14), %rsi
pushq $0x1
popq %rdx
callq 0x4750
movq %r14, %rdi
callq 0x57fb
callq 0x40f0
testq %rax, %rax
je 0x6cd0
movq %rax, %r12
movq (%rbx), %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x4370
leaq 0x8d44(%rip), %r15      # 0xf8e0
movq (%r15), %r15
testq %r15, %r15
je 0x6cb0
movq 0x8(%r15), %r13
movq (%r13), %rsi
testq %rsi, %rsi
je 0x6bc7
movq (%r12), %rdi
testq %rdi, %rdi
je 0x6b9c
callq 0x4540
testl %eax, %eax
jne 0x6b9c
movq 0x8(%r13), %rsi
testq %rsi, %rsi
je 0x6be3
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x6b9c
callq 0x4540
testl %eax, %eax
jne 0x6b9c
movl 0x10(%r13), %eax
testb $0x4, %al
je 0x6bf8
movl 0x7c(%r14), %ecx
imull 0x1c(%r13), %ecx
movl %ecx, 0x30(%r14)
testb $0x8, %al
je 0x6c0c
movl 0x80(%r14), %ecx
imull 0x20(%r13), %ecx
movl %ecx, 0x34(%r14)
testb $0x1, %al
je 0x6c46
movl 0x14(%r13), %ecx
testb $0x10, %al
jne 0x6c1e
addl 0x3c(%r14), %ecx
jmp 0x6c42
movq (%rbx), %rdx
movq 0xe8(%rdx), %rdx
movq 0x10(%rsp), %rsi
movslq (%rsi), %rsi
shlq $0x7, %rsi
addl 0x18(%rdx,%rsi), %ecx
movl 0x30(%r14), %edx
addl 0x3c(%r14), %edx
subl %edx, %ecx
movl %ecx, 0x28(%r14)
testb $0x2, %al
je 0x6c80
movl 0x18(%r13), %ecx
testb $0x20, %al
jne 0x6c58
addl 0x3c(%r14), %ecx
jmp 0x6c7c
movq (%rbx), %rax
movq 0xe8(%rax), %rax
movq 0x10(%rsp), %rdx
movslq (%rdx), %rdx
shlq $0x7, %rdx
addl 0x1c(%rax,%rdx), %ecx
movl 0x34(%r14), %eax
addl 0x3c(%r14), %eax
subl %eax, %ecx
movl %ecx, 0x2c(%r14)
movq %r14, %rdi
callq 0x5e5f
cmpl $0x0, 0x24(%r13)
je 0x6c9a
movl $0x1, 0x94(%r14)
movl 0x28(%r13), %eax
cmpl $-0x2, %eax
je 0x6b9c
movl %eax, 0x20(%r14)
jmp 0x6b9c
movq (%r12), %rdi
callq 0x4050
movq 0x8(%r12), %rdi
callq 0x4050
movq %r12, %rdi
callq 0x4050
movl 0xc(%rsp), %r13d
movq %r14, %rdi
callq 0x7abd
movq 0x10(%r14), %rdi
callq 0x7991
movq 0x10(%r14), %rdi
callq 0x7a29
movl 0x20(%r14), %eax
cmpl $-0x1, %eax
je 0x6cfd
movq 0x10(%rsp), %rcx
cmpl 0x60(%rcx), %eax
jne 0x6d35
movq %r14, %rdi
callq 0x533d
movq %r14, %rdi
callq 0x5360
movq (%r14), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x9241
testb $0x6, %r13b
jne 0x6d40
testl %eax, %eax
je 0x6d40
movq %r14, %rdi
callq 0x54cf
movq %r14, %rdi
callq 0x9438
jmp 0x6d40
pushq $0x3
popq %rsi
movq %r14, %rdi
callq 0x5302
movq %r14, %rdi
callq 0x7d15
jmp 0x6d79
movq 0x829f(%rip), %rax      # 0xeff0
movq (%rax), %rcx
leaq 0x36e1(%rip), %rdi      # 0xa43c
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x46b0
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x4440
movq (%rbx), %rdi
callq 0x43a0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop