// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movl %esi, 0x28(%rsp)
movq %rdi, %rbx
leaq 0x761c(%rip), %r13      # 0xb978
movq (%r13), %rdi
movq (%rbx), %rsi
movl $0xe00010, %edx         # imm = 0xE00010
callq 0x23b0
movq (%r13), %rdi
movq (%rbx), %rsi
leaq 0x50(%rsp), %rdx
callq 0x2450
testl %eax, %eax
je 0x439c
movq 0x50(%rsp), %rax
movq %rax, 0xb8(%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0xc0(%rbx)
jmp 0x43a6
xorps %xmm0, %xmm0
movups %xmm0, 0xb8(%rbx)
movq (%rbx), %rdi
leaq 0x7640(%rip), %r15      # 0xb9f0
movq (%r15), %rdx
leaq 0x30(%rsp), %r8
movl $0x25, %esi
movl $0x64, %ecx
callq 0x4cdb
xorl %r14d, %r14d
movl $0x0, %ecx
testl %eax, %eax
jle 0x43d8
movq 0x30(%rsp), %rcx
movq %rcx, 0xd0(%rbx)
movq (%rbx), %rdi
movq (%r15), %rdx
leaq 0x30(%rsp), %rbp
movl $0x27, %esi
movl $0x64, %ecx
movq %rbp, %r8
callq 0x4cdb
testl %eax, %eax
jle 0x4405
movq 0x30(%rsp), %r14
movq %r14, 0xc8(%rbx)
movq %rbx, %rdi
callq 0x4c4c
movq (%r13), %rdi
movq (%rbx), %rsi
callq 0x2540
movq %rax, %r15
movq (%r13), %rdi
movq (%rbx), %rsi
leaq 0x40(%rbx), %r12
leaq 0x60(%rsp), %rcx
movq %r12, %rdx
callq 0x2120
testl %eax, %eax
je 0x4446
cmpq $0x0, (%r12)
jne 0x444e
movq $0x8, (%r12)
movq %rbx, %rdi
callq 0x4b13
movq %rbx, %rdi
callq 0x4e5e
movq %rbx, %rdi
callq 0x48b3
movq (%rbx), %rdi
leaq 0x2c(%rsp), %rsi
callq 0x4e12
testl %eax, %eax
jne 0x448b
testq %r15, %r15
je 0x4482
movl 0xc(%r15), %eax
jmp 0x4487
movl $0x1, %eax
movl %eax, 0x2c(%rsp)
movq (%r12), %rax
testb $0xa, %al
setne %dl
movl %eax, %ecx
notl %ecx
testb $0x30, %cl
jne 0x44b5
movl 0x58(%rbx), %ecx
cmpl 0x60(%rbx), %ecx
jne 0x44b5
testb $0xa, %al
setne %cl
movl 0x5c(%rbx), %edx
cmpl 0x64(%rbx), %edx
sete %dl
orb %cl, %dl
movl 0x2c(%rsp), %r12d
xorl %r14d, %r14d
cmpl $0x0, 0x28(%rsp)
sete %r14b
testb %dl, %dl
movb %dl, 0x27(%rsp)
je 0x44f4
xorl %ecx, %ecx
testb $0x1, %al
cmovnel %ecx, %r14d
testb $0x4, %al
movl $0x0, %edx
cmovel %r14d, %edx
cmpl $0x3, %r12d
cmovnel %r14d, %edx
cmpq $0x0, 0x10(%rbx)
cmovnel %ecx, %edx
movl %edx, %r14d
btl $0x8, %eax
jb 0x450b
testb $0x10, %al
jne 0x4514
movq $0x0, 0x90(%rbx)
jmp 0x451f
movq 0x80(%rbx), %rax
jmp 0x4518
movq 0x58(%rbx), %rax
movq %rax, 0x90(%rbx)
testq %r15, %r15
je 0x452c
movq %r15, %rdi
callq 0x2170
testl %r14d, %r14d
je 0x45e0
movl %r12d, 0x48(%rsp)
movq (%r13), %rax
movq 0xe8(%rax), %rax
movq 0xf8(%rbx), %rdx
movslq (%rdx), %rcx
shlq $0x7, %rcx
movl 0x18(%rax,%rcx), %ebp
movl 0x1c(%rax,%rcx), %r13d
leaq 0x30(%rsp), %r15
leaq 0x4c(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x6a25
movl (%r15), %esi
movl 0x30(%rbx), %ecx
movl 0x34(%rbx), %eax
movl %ecx, %edx
shrl $0x1f, %edx
addl %ecx, %edx
sarl %edx
subl %edx, %esi
movl %esi, 0x28(%rbx)
movl (%r12), %edx
movl %eax, %edi
shrl $0x1f, %edi
addl %eax, %edi
sarl %edi
subl %edi, %edx
movl %edx, 0x2c(%rbx)
addl %ecx, %esi
cmpl %ebp, %esi
jle 0x45a7
subl %ecx, %ebp
movl %ebp, 0x28(%rbx)
cmpl $0x0, 0x28(%rbx)
jns 0x45b4
movl $0x0, 0x28(%rbx)
addl %eax, %edx
cmpl %r13d, %edx
leaq 0x30(%rsp), %rbp
movl 0x48(%rsp), %r12d
jle 0x45cc
subl %eax, %r13d
movl %r13d, 0x2c(%rbx)
cmpl $0x0, 0x2c(%rbx)
jns 0x45d9
movl $0x0, 0x2c(%rbx)
leaq 0x7398(%rip), %r13      # 0xb978
movq %rbx, %rdi
xorl %esi, %esi
callq 0x49a1
movq (%r13), %rdi
movq 0xf8(%rbx), %rax
movq 0x8(%rax), %rsi
leaq 0x6d20(%rip), %r15      # 0xb320
movl (%r15), %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 0x2440
movq %rax, 0x8(%rbx)
movq (%r13), %rdi
movl $0x180000, %edx         # imm = 0x180000
movq %rax, %rsi
callq 0x23b0
cmpl $0x0, 0x28(%rsp)
je 0x465d
movl $0x1, 0xa0(%rbx)
testl %r14d, %r14d
sete %al
orb %al, 0x27(%rsp)
jne 0x467b
movq (%r13), %rdi
movq (%rbx), %rsi
movl 0x30(%rbx), %edx
movl 0x34(%rbx), %ecx
callq 0x20c0
movq (%r13), %rdi
movq (%rbx), %rsi
xorl %edx, %edx
callq 0x22d0
movq (%r13), %rdi
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movl (%r15), %ecx
decl %ecx
movl %ecx, %r8d
callq 0x2050
movq (%r13), %rdi
movq (%rbx), %rsi
callq 0x2430
cmpl $0x3, %r12d
jne 0x46c2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x5327
jmp 0x476b
movq (%r13), %rdi
movq (%rbx), %rsi
callq 0x24c0
movq (%r13), %rdi
movq 0x8(%rbx), %rsi
callq 0x24c0
testl %r14d, %r14d
je 0x46ec
movq %rbx, %rdi
xorl %eax, %eax
callq 0x56e6
jmp 0x4721
movq 0x10(%rbx), %rax
testq %rax, %rax
setne %dl
leaq 0x7433(%rip), %rcx      # 0xbb30
movq (%rcx), %rcx
testq %rcx, %rcx
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x4715
cmpq %rax, (%rcx)
je 0x46e0
movq %rbx, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x5580
movq $0x1, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movl $0x1, 0x98(%rbx)
movq (%r13), %rdi
movq (%rbx), %rsi
leaq 0x7255(%rip), %rax      # 0xb9a0
movq (%rax), %rcx
movq %rbp, (%rsp)
movl $0x2, 0x8(%rsp)
movq %rcx, %rdx
movl $0x20, %r8d
xorl %r9d, %r9d
callq 0x2360
leaq 0x73be(%rip), %rax      # 0xbb30
movq (%rax), %rdi
testq %rdi, %rdi
sete %al
cmpq %rbx, %rdi
sete %cl
orb %al, %cl
jne 0x478a
callq 0x4a43
movl $0x1, 0x9c(%rbx)
movl $0x1, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq