// File: /workspace/github_c_makefile_star2_O2/seanpringle[P]xoat/./client.c
// Function: window_build_client
Client* window_build_client(Window win)
{
	int i, j; XClassHint chint; XWMHints *hints; Monitor *m;
	if (win == None) return NULL;

	Client *c = calloc(1, sizeof(Client));
	c->window = win;

	if (XGetWindowAttributes(display, c->window, &c->attr))
	{
		c->visible = c->attr.map_state == IsViewable ? 1:0;
		if (!GETPROP_ATOM(win, atoms[_NET_WM_WINDOW_TYPE], &c->type, 1)) c->type = 0;

		c->manage = !c->attr.override_redirect
			&& c->type != atoms[_NET_WM_WINDOW_TYPE_DESKTOP]
			&& c->type != atoms[_NET_WM_WINDOW_TYPE_NOTIFICATION]
			&& c->type != atoms[_NET_WM_WINDOW_TYPE_DOCK]
			&& c->type != atoms[_NET_WM_WINDOW_TYPE_SPLASH]
			? 1:0;

		// detect our own title bars
		if (settings.title)
			for_monitors(i, m) for_spots(j)
				if (m->bars[j] && m->bars[j]->window == c->window)
					{ c->ours = 1; c->bar = 1; c->manage = 0; break; }

		// detect our own menus
		if (menu && menu->mb && menu->mb->window == c->window)
			{ c->ours = 1; c->menu = 1; c->manage = 0; }

		if (c->manage)
		{
			XGetTransientForHint(display, c->window, &c->transient);
			if (!GETPROP_WIND(win, atoms[WM_CLIENT_LEADER], &c->leader, 1)) c->leader = None;
			c->spot = SPOT1; m = &monitors[0];

			for_monitors(i, m)
				if (INTERSECT(m->x, m->y, m->w, m->h, c->attr.x + c->attr.width/2, c->attr.y+c->attr.height/2, 1, 1))
					{ c->monitor = i; break; }

			int intersect_1 = INTERSECT(c->attr.x, c->attr.y, c->attr.width, c->attr.height,
				m->spots[SPOT1].x + m->spots[SPOT1].w/2, m->spots[SPOT1].y + m->spots[SPOT1].h/2, 1, 1);

			int intersect_2 = INTERSECT(c->attr.x, c->attr.y, c->attr.width, c->attr.height,
				m->spots[SPOT2].x + m->spots[SPOT2].w/2, m->spots[SPOT2].y + m->spots[SPOT2].h/2, 1, 1);

			int intersect_3 = INTERSECT(c->attr.x, c->attr.y, c->attr.width, c->attr.height,
				m->spots[SPOT3].x + m->spots[SPOT3].w/2, m->spots[SPOT3].y + m->spots[SPOT3].h/2, 1, 1);

			     if (intersect_3) c->spot = SPOT3;
			else if (intersect_2) c->spot = SPOT2;
			else if (intersect_1) c->spot = SPOT1;

			if (c->visible)
			{
				if (!GETPROP_ATOM(c->window, atoms[_NET_WM_STATE], c->states, ATOMLIST))
					memset(c->states, 0, sizeof(Atom) * ATOMLIST);

				c->urgent = client_has_state(c, atoms[_NET_WM_STATE_DEMANDS_ATTENTION]);
				c->full   = client_has_state(c, atoms[_NET_WM_STATE_FULLSCREEN]);
				c->maxv   = client_has_state(c, atoms[_NET_WM_STATE_MAXIMIZE_VERT]);
				c->maxh   = client_has_state(c, atoms[_NET_WM_STATE_MAXIMIZE_HORZ]);
				c->above  = client_has_state(c, atoms[_NET_WM_STATE_ABOVE]);

				GETPROP_LONG(win, atoms[XOAT_MAXIMIZE], &c->max, 1);

				// proper spot detection based on toggled atoms.
				// XOAT_MAXIMIZE may apply to spot1 windows. Detect...
				if (c->max && intersect_1)
				{
					c->spot = SPOT1;
				}
				else
				// _NET_WM_STATE_MAXIMIZE_VERT may apply to spot2 windows. Detect...
				if (c->maxv && c->type != atoms[_NET_WM_WINDOW_TYPE_DIALOG]
					&& !intersect_1 && intersect_2)
				{
					c->spot = SPOT2;
				}
				else
				// _NET_WM_STATE_MAXIMIZE_HORZ may apply to spot3 windows with c->max. Detect...
				if (c->maxh && c->type != atoms[_NET_WM_WINDOW_TYPE_DIALOG]
					&& !intersect_1 && !intersect_2 && intersect_3)
				{
					c->spot = SPOT3;
				}
				if ((hints = XGetWMHints(display, c->window)))
				{
					c->input  = hints->flags & InputHint && hints->input ? 1:0;
					c->urgent = c->urgent || hints->flags & XUrgencyHint ? 1:0;
					XFree(hints);
				}
				if (XGetClassHint(display, c->window, &chint))
				{
					c->class = strdup(chint.res_class);
					XFree(chint.res_class); XFree(chint.res_name);
				}
			}
		}
		return c;
	}
	free(c);
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testq %rdi, %rdi
je 0x578a
movq %rdi, %r15
pushq $0x1
popq %r14
movl $0x130, %esi            # imm = 0x130
movq %r14, %rdi
callq 0x3500
movq %rax, %rbx
movq %r15, (%rax)
movq 0x94a2(%rip), %rdi      # 0xebb0
leaq 0x8(%rax), %rdx
movq %r15, %rsi
callq 0x35c0
testl %eax, %eax
je 0x5782
xorl %eax, %eax
cmpl $0x2, 0x64(%rbx)
sete %al
movw %ax, 0x102(%rbx)
movq 0x95db(%rip), %rsi      # 0xed10
leaq 0xa0(%rbx), %r12
leaq 0x9a6d(%rip), %rdx      # 0xf1b0
leaq 0x9a6e(%rip), %rcx      # 0xf1b8
pushq $0x8
popq %r9
movq %r15, %rdi
movq %r12, %r8
callq 0x5324
testl %eax, %eax
je 0x5770
cmpq $0x4, 0x9a4b(%rip)      # 0xf1b0
jne 0x5770
cmpl $0x0, 0x9a4a(%rip)      # 0xf1b8
jne 0x5775
andq $0x0, (%r12)
cmpl $0x0, 0x80(%rbx)
je 0x579e
xorl %eax, %eax
jmp 0x57cb
movq %rbx, %rdi
callq 0x3220
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rcx
xorl %eax, %eax
cmpq 0x956d(%rip), %rcx      # 0xed18
je 0x57cb
cmpq 0x957c(%rip), %rcx      # 0xed30
je 0x57cb
cmpq 0x9563(%rip), %rcx      # 0xed20
je 0x57cb
xorl %eax, %eax
cmpq 0x9560(%rip), %rcx      # 0xed28
setne %al
movw %ax, 0x104(%rbx)
cmpq $0x0, 0x9a0e(%rip)      # 0xf1e8
je 0x583a
movl 0x8f8e(%rip), %ecx      # 0xe770
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
leaq 0x9400(%rip), %rsi      # 0xebf0
movw $0x1, %di
cmpq %rcx, %rdx
je 0x583a
xorl %r8d, %r8d
cmpq $0x3, %r8
je 0x5831
movq (%rsi,%r8,8), %r9
testq %r9, %r9
je 0x5814
movq 0x8(%r9), %r9
cmpq (%rbx), %r9
je 0x5819
incq %r8
jmp 0x57fc
movw %di, 0x10c(%rbx)
movw %di, 0x112(%rbx)
andw $0x0, 0x104(%rbx)
xorl %eax, %eax
incq %rdx
addq $0x48, %rsi
jmp 0x57f4
movq 0x99ff(%rip), %rcx      # 0xf240
testq %rcx, %rcx
je 0x587a
movq 0x648(%rcx), %rcx
testq %rcx, %rcx
je 0x587a
movq 0x8(%rcx), %rcx
cmpq (%rbx), %rcx
jne 0x587a
movw $0x1, %ax
movw %ax, 0x10c(%rbx)
movw %ax, 0x114(%rbx)
andw $0x0, 0x104(%rbx)
jmp 0x578c
testw %ax, %ax
je 0x578c
movq %r12, 0x10(%rsp)
movq 0x9321(%rip), %rdi      # 0xebb0
movq (%rbx), %rsi
leaq 0x90(%rbx), %rdx
callq 0x3620
movq 0x94db(%rip), %rsi      # 0xed80
leaq 0x98(%rbx), %r13
leaq 0x98fd(%rip), %rdx      # 0xf1b0
leaq 0x98fe(%rip), %rcx      # 0xf1b8
pushq $0x8
popq %r9
movq %r15, %rdi
movq %r13, %r8
callq 0x5324
testl %eax, %eax
je 0x58e0
cmpq $0x21, 0x98db(%rip)     # 0xf1b0
jne 0x58e0
cmpl $0x0, 0x98da(%rip)      # 0xf1b8
jne 0x58e5
andq $0x0, (%r13)
movl 0x8e84(%rip), %r9d      # 0xe770
xorl %r8d, %r8d
testl %r9d, %r9d
cmovlel %r8d, %r9d
movq $0x1, 0x118(%rbx)
leaq 0x92b8(%rip), %rcx      # 0xebc0
pushq $0x2
popq %r10
movq %rcx, %rax
cmpq %r8, %r9
je 0x59b9
movq %rcx, %rsi
movswl (%rcx), %r11d
movl 0x8(%rbx), %edi
movl 0x10(%rbx), %ecx
movl %ecx, %eax
cltd
idivl %r10d
addl %edi, %eax
cmpl %r11d, %eax
sete %bpl
movzwl 0x4(%rsi), %edx
cmpw $0x1, %dx
sete %r12b
testb %r12b, %bpl
jne 0x595f
movswl %dx, %edx
addl %r11d, %edx
leal 0x1(%rax), %ebp
cmpl %eax, %edx
cmovlel %edx, %ebp
cmpl %r11d, %eax
cmovgl %eax, %r11d
cmpl %r11d, %ebp
jle 0x59a0
movswl 0x2(%rsi), %r11d
movl 0x14(%rbx), %eax
cltd
idivl %r10d
addl 0xc(%rbx), %eax
cmpl %r11d, %eax
sete %bpl
movzwl 0x6(%rsi), %edx
cmpw $0x1, %dx
sete %r12b
testb %r12b, %bpl
jne 0x59af
movswl %dx, %edx
addl %r11d, %edx
leal 0x1(%rax), %ebp
cmpl %eax, %edx
cmovlel %edx, %ebp
cmpl %r11d, %eax
cmovgl %eax, %r11d
cmpl %r11d, %ebp
jg 0x59af
incq %r8
leaq 0x48(%rsi), %rcx
movq %rsi, %rax
jmp 0x590f
movw %r8w, 0x100(%rbx)
jmp 0x59c2
movl 0x8(%rbx), %edi
movl 0x10(%rbx), %ecx
movq %rax, %rsi
movswl 0x10(%rsi), %r8d
movzwl 0x14(%rsi), %eax
movw $0x2, %r9w
cwtd
idivw %r9w
cwtl
addl %r8d, %eax
movl %edi, %edx
xorl %eax, %edx
movl %ecx, %r8d
xorl $0x1, %r8d
orl %r8d, %edx
je 0x5a01
leal (%rcx,%rdi), %edx
leal 0x1(%rax), %r10d
cmpl %eax, %edx
cmovlel %edx, %r10d
cmpl %eax, %edi
cmovgl %edi, %eax
cmpl %eax, %r10d
jle 0x5a4a
movl 0xc(%rbx), %r10d
movl 0x14(%rbx), %r11d
movswl 0x12(%rsi), %ebp
movzwl 0x16(%rsi), %eax
cwtd
idivw %r9w
cwtl
addl %ebp, %eax
movl %r10d, %edx
xorl %eax, %edx
movl %r11d, %r9d
xorl $0x1, %r9d
movb $0x1, %r13b
orl %edx, %r9d
je 0x5a4d
addl %r10d, %r11d
leal 0x1(%rax), %edx
cmpl %eax, %r11d
cmovlel %r11d, %edx
cmpl %eax, %r10d
cmovgl %r10d, %eax
cmpl %eax, %edx
setg %r13b
jmp 0x5a4d
xorl %r13d, %r13d
movswl 0x18(%rsi), %r10d
movzwl 0x1c(%rsi), %eax
cwtd
movw $0x2, %r9w
idivw %r9w
cwtl
addl %r10d, %eax
movl %edi, %edx
xorl %eax, %edx
orl %r8d, %edx
je 0x5a85
leal (%rcx,%rdi), %edx
leal 0x1(%rax), %r10d
cmpl %eax, %edx
cmovlel %edx, %r10d
cmpl %eax, %edi
cmovgl %edi, %eax
cmpl %eax, %r10d
jle 0x5ace
movl 0xc(%rbx), %r10d
movl 0x14(%rbx), %r11d
movswl 0x1a(%rsi), %ebp
movzwl 0x1e(%rsi), %eax
cwtd
idivw %r9w
cwtl
addl %ebp, %eax
movl %r10d, %edx
xorl %eax, %edx
movl %r11d, %r9d
xorl $0x1, %r9d
movb $0x1, %r12b
orl %edx, %r9d
je 0x5ad1
addl %r10d, %r11d
leal 0x1(%rax), %edx
cmpl %eax, %r11d
cmovlel %r11d, %edx
cmpl %eax, %r10d
cmovgl %r10d, %eax
cmpl %eax, %edx
setg %r12b
jmp 0x5ad1
xorl %r12d, %r12d
movswl 0x20(%rsi), %r10d
movzwl 0x24(%rsi), %eax
cwtd
movw $0x2, %r9w
idivw %r9w
cwtl
addl %r10d, %eax
movl %edi, %edx
xorl %eax, %edx
orl %r8d, %edx
je 0x5b05
addl %edi, %ecx
leal 0x1(%rax), %edx
cmpl %eax, %ecx
cmovlel %ecx, %edx
cmpl %eax, %edi
cmovgl %edi, %eax
cmpl %eax, %edx
jle 0x5b6b
movl 0xc(%rbx), %ecx
movl 0x14(%rbx), %edi
movswl 0x22(%rsi), %r8d
movzwl 0x26(%rsi), %eax
cwtd
idivw %r9w
cwtl
addl %r8d, %eax
movl %ecx, %edx
xorl %eax, %edx
movl %edi, %esi
xorl $0x1, %esi
orl %edx, %esi
jne 0x5b32
pushq $0x3
popq %rcx
xorl %eax, %eax
jmp 0x5b83
addl %ecx, %edi
leal 0x1(%rax), %edx
cmpl %eax, %edi
cmovlel %edi, %edx
cmpl %eax, %ecx
cmovgl %ecx, %eax
movzbl %r12b, %esi
incq %rsi
cmpl %eax, %edx
setle %al
setg %dl
pushq $0x3
popq %rcx
cmovleq %rsi, %rcx
movl %r12d, %esi
orb %r13b, %sil
orb %dl, %sil
movb $0x1, %bpl
testb $0x1, %sil
jne 0x5b83
jmp 0x5b8c
movl %r12d, %ecx
orb %r13b, %cl
movb $0x1, %al
testb $0x1, %cl
je 0x5da6
movzbl %r12b, %ecx
incq %rcx
movq %rcx, 0x118(%rbx)
movl %eax, %ebp
cmpw $0x0, 0x102(%rbx)
je 0x578c
movq %r14, 0x8(%rsp)
movl %r13d, %r14d
movq (%rbx), %rdi
movq 0x9194(%rip), %rsi      # 0xed40
leaq 0xa8(%rbx), %r13
leaq 0x95f6(%rip), %rdx      # 0xf1b0
leaq 0x95f7(%rip), %rcx      # 0xf1b8
pushq $0x50
popq %r9
movq %r13, %r8
callq 0x5324
testl %eax, %eax
je 0x5be4
cmpq $0x4, 0x95d7(%rip)      # 0xf1b0
jne 0x5be4
cmpl $0x0, 0x95d6(%rip)      # 0xf1b8
jne 0x5c00
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%r13)
movups %xmm0, 0x30(%r13)
movups %xmm0, 0x20(%r13)
movups %xmm0, 0x10(%r13)
movups %xmm0, (%r13)
movq 0x9159(%rip), %rsi      # 0xed60
movq %rbx, %rdi
callq 0x5eb6
movw %ax, 0x108(%rbx)
movq 0x912b(%rip), %rsi      # 0xed48
movq %rbx, %rdi
callq 0x5eb6
movw %ax, 0x10a(%rbx)
movq 0x911d(%rip), %rsi      # 0xed50
movq %rbx, %rdi
callq 0x5eb6
movw %ax, 0x10e(%rbx)
movq 0x910f(%rip), %rsi      # 0xed58
movq %rbx, %rdi
callq 0x5eb6
movw %ax, 0x110(%rbx)
movq 0x9109(%rip), %rsi      # 0xed68
movq %rbx, %rdi
callq 0x5eb6
movw %ax, 0x116(%rbx)
movq 0x9043(%rip), %rsi      # 0xecb8
movq %rbx, %r8
addq $0x120, %r8             # imm = 0x120
leaq 0x952a(%rip), %rdx      # 0xf1b0
leaq 0x952b(%rip), %rcx      # 0xf1b8
pushq $0x8
popq %r9
movq %r15, %rdi
callq 0x5324
cmpq $0x0, 0x120(%rbx)
setne %al
testb %r14b, %al
jne 0x5d04
cmpw $0x0, 0x10e(%rbx)
movq 0x10(%rsp), %rdx
je 0x5cd6
movq (%rdx), %rax
cmpq 0x9076(%rip), %rax      # 0xed38
setne %al
movl %r14d, %ecx
xorb $0x1, %cl
andb %al, %cl
testb %r12b, %cl
je 0x5cd6
pushq $0x2
jmp 0x5cfe
cmpw $0x0, 0x110(%rbx)
je 0x5d10
movq (%rdx), %rax
cmpq 0x904e(%rip), %rax      # 0xed38
sete %al
orb %r12b, %r14b
orb %r14b, %bpl
orb %al, %bpl
testb $0x1, %bpl
jne 0x5d10
pushq $0x3
popq %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x118(%rbx)
movq 0x8e99(%rip), %rdi      # 0xebb0
movq (%rbx), %rsi
callq 0x3370
testq %rax, %rax
je 0x5d5f
movq (%rax), %rcx
xorl %edx, %edx
testb $0x1, %cl
je 0x5d35
cmpl $0x0, 0x8(%rax)
setne %dl
movw %dx, 0x106(%rbx)
shrl $0x8, %ecx
andl $0x1, %ecx
cmpw $0x0, 0x108(%rbx)
pushq $0x1
popq %rdx
cmovel %ecx, %edx
movw %dx, 0x108(%rbx)
movq %rax, %rdi
callq 0x3050
movq 0x8e4a(%rip), %rdi      # 0xebb0
movq (%rbx), %rsi
leaq 0x18(%rsp), %rdx
callq 0x32b0
testl %eax, %eax
je 0x578c
movq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x3430
movq %rax, 0x128(%rbx)
movq %r14, %rdi
callq 0x3050
movq 0x18(%rsp), %rdi
callq 0x3050
jmp 0x578c
movb $0x1, %bpl
jmp 0x5b8c