// File: /workspace/github_c_makefile_star2_O2/9wm[P]9wm/manage.c
// Function: manage
int
manage(Client * c, int mapped)
{
	int fixsize, dohide, doreshape, state;
	long msize;
	XClassHint class;
	XWMHints *hints;

	trace("manage", c, 0);
	XSelectInput(dpy, c->window, ColormapChangeMask | EnterWindowMask | PropertyChangeMask | FocusChangeMask);

	/*
	 * Get loads of hints 
	 */

	if (XGetClassHint(dpy, c->window, &class) != 0) {	/* ``Success'' */
		c->instance = class.res_name;
		c->class = class.res_class;
	} else {
		c->instance = 0;
		c->class = 0;
	}
	c->iconname = getprop(c->window, XA_WM_ICON_NAME);
	c->name = getprop(c->window, XA_WM_NAME);
	setlabel(c);

	hints = XGetWMHints(dpy, c->window);
	if (XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0)
		c->size.flags = PSize;	/* not specified - punt */

	getcmaps(c);
	getproto(c);
	gettrans(c);

	/*
	 * Figure out what to do with the window from hints 
	 */

	if (!getwstate(c->window, &state))
		state = hints ? hints->initial_state : NormalState;
	dohide = (state == IconicState);

	fixsize = 0;
	if ((c->size.flags & (USSize | PSize)))
		fixsize = 1;
	if ((c->size.flags & (PMinSize | PMaxSize)) == (PMinSize | PMaxSize) && c->size.min_width == c->size.max_width
	    && c->size.min_height == c->size.max_height)
		fixsize = 1;
	doreshape = !mapped;
	if (fixsize) {
		if (c->size.flags & USPosition)
			doreshape = 0;
		if (dohide && (c->size.flags & PPosition))
			doreshape = 0;
		if (c->trans != None)
			doreshape = 0;
	}
	if (c->size.flags & PBaseSize) {
		c->min_dx = c->size.base_width;
		c->min_dy = c->size.base_height;
	} else if (c->size.flags & PMinSize) {
		c->min_dx = c->size.min_width;
		c->min_dy = c->size.min_height;
	} else
		c->min_dx = c->min_dy = 0;

	if (hints)
		XFree(hints);

	/*
	 * Now do it!!! 
	 */

	if (doreshape) {
		int xmax = DisplayWidth(dpy, c->screen->num);
		int ymax = DisplayHeight(dpy, c->screen->num);
		int x, y;

		getmouse(&x, &y, c->screen);

		c->x = x - (c->dx / 2);
		c->y = y - (c->dy / 2);

		if (c->x + c->dx > xmax) {
			c->x = xmax - c->dx;
		}
		if (c->x < 0) {
			c->x = 0;
		}

		if (c->y + c->dy > ymax) {
			c->y = ymax - c->dy;
		}
		if (c->y < 0) {
			c->y = 0;
		}
	}
	gravitate(c, 0);

	c->parent = XCreateSimpleWindow(dpy, c->screen->root,
					c->x - BORDER, c->y - BORDER,
					c->dx + 2 * (BORDER - 1), c->dy + 2 * (BORDER - 1), 1, c->screen->black, c->screen->white);
	XSelectInput(dpy, c->parent, SubstructureRedirectMask | SubstructureNotifyMask);
	if (mapped)
		c->reparenting = 1;
	if (doreshape && !fixsize)
		XResizeWindow(dpy, c->window, c->dx, c->dy);
	XSetWindowBorderWidth(dpy, c->window, 0);
	XReparentWindow(dpy, c->window, c->parent, BORDER - 1, BORDER - 1);
#ifdef	SHAPE
	if (shape) {
		XShapeSelectInput(dpy, c->window, ShapeNotifyMask);
		ignore_badwindow = 1;	/* magic */
		setshape(c);
		ignore_badwindow = 0;
	}
#endif
	XAddToSaveSet(dpy, c->window);
	if (dohide)
		hide(c);
	else {
		XMapWindow(dpy, c->window);
		XMapWindow(dpy, c->parent);
		if (doreshape)
			active(c);
		else if (c->trans != None && current && current->window == c->trans)
			active(c);
		else
			setactive(c, 0);
		setwstate(c, NormalState);
	}
	if (current && (current != c))
		cmapfocus(current);
	c->init = 1;
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x7932(%rip), %r12      # 0xb988
movq (%r12), %rdi
movq (%rbx), %rsi
movl $0xe00010, %edx         # imm = 0xE00010
callq 0x23c0
movq (%r12), %rdi
movq (%rbx), %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdx
callq 0x2460
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
movd %ecx, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
pslld $0x1f, %xmm0
psrad $0x1f, %xmm0
pandn (%r14), %xmm0
movdqu %xmm0, 0xb8(%rbx)
movq (%rbx), %rdi
pushq $0x25
popq %rsi
callq 0x4980
movq %rax, 0xd0(%rbx)
movq (%rbx), %rdi
pushq $0x27
popq %rsi
callq 0x4980
movq %rax, 0xc8(%rbx)
movq %rbx, %rdi
callq 0x4878
movq (%r12), %rdi
movq (%rbx), %rsi
callq 0x2550
movq %rax, %r14
movq (%r12), %rdi
movq (%rbx), %rsi
leaq 0x40(%rbx), %r15
leaq 0x38(%rsp), %rcx
movq %r15, %rdx
callq 0x2120
testl %eax, %eax
je 0x40ff
cmpq $0x0, (%r15)
jne 0x4106
movq $0x8, (%r15)
movq %rbx, %rdi
callq 0x4749
movq %rbx, %rdi
callq 0x4a77
movq %rbx, %rdi
callq 0x4516
movq (%rbx), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4a32
testl %eax, %eax
je 0x4135
movl 0x30(%rsp), %esi
jmp 0x4143
testq %r14, %r14
je 0x4140
movl 0xc(%r14), %esi
jmp 0x4143
pushq $0x1
popq %rsi
movq (%r15), %rax
movl %eax, %ecx
notl %ecx
testb $0x30, %cl
jne 0x4174
movl 0x58(%rbx), %ecx
cmpl 0x60(%rbx), %ecx
jne 0x4174
xorl %r13d, %r13d
testl %ebp, %ebp
sete %bpl
movb %bpl, %r13b
testb $0xa, %al
jne 0x4184
movl 0x64(%rbx), %ecx
cmpl %ecx, 0x5c(%rbx)
je 0x4184
xorl %r15d, %r15d
jmp 0x41ac
xorl %r13d, %r13d
testl %ebp, %ebp
sete %bpl
movb %bpl, %r13b
testb $0xa, %al
je 0x416f
xorl %ecx, %ecx
testb $0x1, %al
cmovnel %ecx, %r13d
testb $0x4, %al
movl $0x0, %edx
cmovel %r13d, %edx
cmpl $0x3, %esi
cmovnel %r13d, %edx
cmpq $0x0, 0x10(%rbx)
cmovnel %ecx, %edx
movb $0x1, %r15b
movl %edx, %r13d
btl $0x8, %eax
movl %esi, 0x28(%rsp)
jb 0x41c4
testb $0x10, %al
jne 0x41cd
andq $0x0, 0x90(%rbx)
jmp 0x41d8
movq 0x80(%rbx), %rax
jmp 0x41d1
movq 0x58(%rbx), %rax
movq %rax, 0x90(%rbx)
testq %r14, %r14
je 0x41e5
movq %r14, %rdi
callq 0x2170
testl %r13d, %r13d
je 0x42a5
movl %r15d, 0x24(%rsp)
movb %bpl, 0x23(%rsp)
movq (%r12), %rax
movq 0xe8(%rax), %rax
movq 0xf8(%rbx), %rdx
movslq (%rdx), %rcx
shlq $0x7, %rcx
movl 0x18(%rax,%rcx), %r15d
movl 0x1c(%rax,%rcx), %r12d
xorl %ebp, %ebp
leaq 0x34(%rsp), %r14
leaq 0x2c(%rsp), %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x6419
movl 0x30(%rbx), %esi
movl 0x34(%rbx), %ecx
pushq $-0x2
popq %r8
movl %esi, %eax
cltd
idivl %r8d
movl %eax, %edi
addl (%r14), %edi
movl %edi, 0x28(%rbx)
movl %ecx, %eax
cltd
idivl %r8d
leaq 0x2c(%rsp), %rdx
addl (%rdx), %eax
movl %eax, 0x2c(%rbx)
leal (%rdi,%rsi), %r8d
movl %r15d, %edx
subl %esi, %edx
cmpl %r15d, %r8d
cmovlel %edi, %edx
jg 0x426e
testl %edx, %edx
jns 0x4276
testl %edx, %edx
cmovgl %edx, %ebp
movl %ebp, 0x28(%rbx)
leal (%rax,%rcx), %esi
movl %r12d, %edx
subl %ecx, %edx
cmpl %r12d, %esi
cmovlel %eax, %edx
jg 0x428a
testl %edx, %edx
jns 0x4294
xorl %eax, %eax
testl %edx, %edx
cmovgl %edx, %eax
movl %eax, 0x2c(%rbx)
leaq 0x76ed(%rip), %r12      # 0xb988
movb 0x23(%rsp), %bpl
movl 0x24(%rsp), %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x45d3
movq (%r12), %rdi
movq 0xf8(%rbx), %rax
movq 0x8(%rax), %rsi
leaq 0x706b(%rip), %r14      # 0xb330
movl (%r14), %r8d
movl 0x28(%rbx), %edx
movl 0x2c(%rbx), %ecx
subl %r8d, %edx
subl %r8d, %ecx
leal -0x2(,%r8,2), %r9d
movl 0x30(%rbx), %r8d
addl %r9d, %r8d
addl 0x34(%rbx), %r9d
movups 0x28(%rax), %xmm0
movups %xmm0, 0x8(%rsp)
movl $0x1, (%rsp)
callq 0x2450
movq %rax, 0x8(%rbx)
movq (%r12), %rdi
movl $0x180000, %edx         # imm = 0x180000
movq %rax, %rsi
callq 0x23c0
testb %bpl, %bpl
jne 0x4320
movl $0x1, 0xa0(%rbx)
testl %r13d, %r13d
sete %al
orb %al, %r15b
jne 0x433d
movq (%r12), %rdi
movq (%rbx), %rsi
movl 0x30(%rbx), %edx
movl 0x34(%rbx), %ecx
callq 0x20c0
movq (%r12), %rdi
movq (%rbx), %rsi
xorl %edx, %edx
callq 0x22e0
movq (%r12), %rdi
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movl (%r14), %ecx
decl %ecx
movl %ecx, %r8d
callq 0x2050
movq (%r12), %rdi
movq (%rbx), %rsi
callq 0x2440
cmpl $0x3, 0x28(%rsp)
jne 0x4382
movq %rbx, %rdi
xorl %eax, %eax
callq 0x4f68
jmp 0x43ec
movq (%r12), %rdi
movq (%rbx), %rsi
callq 0x24d0
movq (%r12), %rdi
movq 0x8(%rbx), %rsi
callq 0x24d0
testl %r13d, %r13d
je 0x43ac
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5367
jmp 0x43e1
movq 0x10(%rbx), %rax
testq %rax, %rax
setne %dl
leaq 0x7783(%rip), %rcx      # 0xbb40
movq (%rcx), %rcx
testq %rcx, %rcx
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x43d5
cmpq %rax, (%rcx)
je 0x43a0
movq %rbx, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x5208
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x49e8
leaq 0x774d(%rip), %rax      # 0xbb40
movq (%rax), %rdi
testq %rdi, %rdi
sete %al
cmpq %rbx, %rdi
sete %cl
orb %al, %cl
jne 0x440b
callq 0x467f
movl $0x1, 0x9c(%rbx)
pushq $0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq