// File: /workspace/github_c_makefile_star2_O1/gitluin[P]sara/src/sara.c
// Function: manipulate
void
manipulate(const Arg arg){
	int x, y, ocx, ocy, nx, ny, nw, nh;
	client* c;
	XEvent ev;
	int doresize = (arg.i == WantResize), trytoggle = 0;
	monitor* m = NULL;
	Time lasttime = 0;

	if ( !(c = curmon->current) || c->isfull )
		return;

	restack(curmon);

	if (XGrabPointer(dis, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
		None, cursor, CurrentTime) != GrabSuccess)
		return;

	if (!getptrcoords(&x, &y))
		return;

	if (doresize){
		if ( !(m = c->mon) )
			return;
		XWarpPointer(dis, None, c->win, 0, 0, 0, 0, c->w + 1, c->h + 1);
	}

	ocx = c->x;
	ocy = c->y;
	do {
		XMaskEvent(dis, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
		switch(ev.type){
		case ConfigureRequest:
		case Expose:
		case MapRequest:
			events[ev.type](&ev);
			break;
		case MotionNotify:
			if ((ev.xmotion.time - lasttime) <= (1000 / 60))
				continue;
			lasttime = ev.xmotion.time;

			/* Only adjust if moving */
			nx = doresize ? c->x : ocx + (ev.xmotion.x - x);
			ny = doresize ? c->y : ocy + (ev.xmotion.y - y);
			/* Only adjust if resizing */
			nw = doresize ? MAX(ev.xmotion.x - ocx + 1, 1) : c->w;
			nh = doresize ? MAX(ev.xmotion.y - ocy + 1, 1) : c->h;

			/* if c extends beyond the boundaries of its monitor, make it a float */
			if (doresize && (m->mx + nw >= curmon->mx
						&& m->mx + nw <= curmon->mx + curmon->mw
						&& m->wy + nh >= curmon->wy
						&& m->wy + nh <= curmon->wy + curmon->wh)){
				trytoggle = 1;

			} else {
				/* if c is within snappx of the monitor borders,
				 * then snap and make it a float
				 */
				nx = (abs(curmon->mx - nx) < snappx) ? curmon->mx : nx;
				nx = (abs((curmon->mx + curmon->mw) - (nx + c->w)) < snappx)
					? curmon->mx + curmon->mw - c->w : nx;
				ny = (abs(curmon->wy - ny) < snappx) ? curmon->wy : ny;
				ny = (abs((curmon->wy + curmon->wh) - (ny + c->h)) < snappx)
					? curmon->wy + curmon->wh - c->h : ny;
				trytoggle = 1;
			}
			/* don't toggle if floating layout, do resize if floating */
			if (!c->isfloat && trytoggle && !(curmon->curlayout->arrange == &floaty))
				togglefloat(dumbarg);
			if (c->isfloat || (curmon->curlayout->arrange == &floaty))
				resizeclient(c, nx, ny, nw, nh);
			XFlush(dis);
			break;
		}
	} while (ev.type != ButtonRelease);

	if (doresize)
		XWarpPointer(dis, None, c->win, 0, 0, 0, 0, c->w + 1, c->h + 1);
	XUngrabPointer(dis, CurrentTime);

	if (doresize)
		while (XCheckMaskEvent(dis, EnterWindowMask, &ev));

	if ( (m = coordstomon(c->x, c->y)) && m != curmon){
		sendmon(c, m);
		changemon(m, YesFocus);
		outputstats();
	}
#ifdef _SHAPE_H_
	roundcorners(c);
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %r14
movq 0x510b(%rip), %rdi      # 0x94e8
movq 0x28(%rdi), %rbx
testq %rbx, %rbx
je 0x47ac
cmpl $0x0, 0x18(%rbx)
jne 0x47ac
callq 0x3ded
movq 0x50c0(%rip), %rdi      # 0x94c0
movq 0x51a9(%rip), %rsi      # 0x95b0
subq $0x8, %rsp
xorl %eax, %eax
xorl %edx, %edx
movl $0x4c, %ecx
movl $0x1, %r8d
movl $0x1, %r9d
pushq %rax
pushq 0x5191(%rip)            # 0x95b8
pushq %rax
callq 0x2170
addq $0x20, %rsp
testl %eax, %eax
jne 0x47ac
movq 0x5080(%rip), %rdi      # 0x94c0
movq 0x5169(%rip), %rsi      # 0x95b0
subq $0x8, %rsp
leaq 0x38(%rsp), %rax
leaq 0x3c(%rsp), %r10
leaq 0x40(%rsp), %rcx
leaq 0x24(%rsp), %r8
leaq 0x20(%rsp), %r9
movq %rcx, %rdx
pushq %rax
pushq %r10
pushq %r10
callq 0x23d0
addq $0x20, %rsp
testl %eax, %eax
je 0x47ac
movl %r14d, %r13d
cmpl $0x1, %r13d
jne 0x44cd
movq 0x30(%rbx), %rcx
movq %rcx, 0x10(%rsp)
testq %rcx, %rcx
je 0x47ac
movq 0x5021(%rip), %rdi      # 0x94c0
movq 0x38(%rbx), %rdx
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %r10d
incl %eax
incl %r10d
subq $0x8, %rsp
xorl %esi, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r10
pushq %rax
pushq $0x0
callq 0x2360
addq $0x20, %rsp
jmp 0x44d6
movq $0x0, 0x10(%rsp)
movl (%rbx), %eax
movl %eax, 0xc(%rsp)
movl 0x4(%rbx), %eax
movl %eax, 0x8(%rsp)
leaq 0x38(%rsp), %r14
leaq 0x4da1(%rip), %r12      # 0x9290
xorl %r15d, %r15d
movq %r13, 0x20(%rsp)
movq 0x4fc2(%rip), %rdi      # 0x94c0
movl $0x10804c, %esi         # imm = 0x10804C
movq %r14, %rdx
callq 0x2340
movslq 0x38(%rsp), %rax
cmpq $0x13, %rax
jg 0x4522
cmpl $0x6, %eax
je 0x453f
cmpl $0xc, %eax
je 0x452c
jmp 0x4533
cmpl $0x17, %eax
je 0x452c
cmpl $0x14, %eax
jne 0x4533
movq %r14, %rdi
callq *(%r12,%rax,8)
cmpl $0x5, 0x38(%rsp)
jne 0x44f7
jmp 0x46ff
movq 0x70(%rsp), %rcx
movq %rcx, %rax
subq %r15, %rax
cmpq $0x11, %rax
jb 0x4533
cmpl $0x1, %r13d
jne 0x455a
movl (%rbx), %eax
jmp 0x4566
movl 0x78(%rsp), %eax
addl 0xc(%rsp), %eax
subl 0x1c(%rsp), %eax
cmpl $0x1, %r13d
jne 0x4572
movl 0x4(%rbx), %r15d
jmp 0x4581
movl 0x7c(%rsp), %r15d
addl 0x8(%rsp), %r15d
subl 0x18(%rsp), %r15d
cmpl $0x1, %r13d
movq %rcx, 0x28(%rsp)
jne 0x45a2
movl 0x78(%rsp), %ebp
subl 0xc(%rsp), %ebp
testl %ebp, %ebp
movl $0x0, %ecx
cmovlel %ecx, %ebp
incl %ebp
jmp 0x45a5
movl 0x8(%rbx), %ebp
cmpl $0x1, %r13d
jne 0x45c6
movl 0x7c(%rsp), %r12d
subl 0x8(%rsp), %r12d
testl %r12d, %r12d
movl $0x0, %ecx
cmovlel %ecx, %r12d
incl %r12d
jmp 0x45ca
movl 0xc(%rbx), %r12d
cmpl $0x1, %r13d
jne 0x460c
movq 0x10(%rsp), %rcx
movl 0x8(%rcx), %edx
addl %ebp, %edx
movq 0x4f07(%rip), %rcx      # 0x94e8
movl 0x8(%rcx), %esi
cmpl %esi, %edx
jl 0x460c
addl 0x14(%rcx), %esi
cmpl %esi, %edx
jg 0x460c
movq 0x10(%rsp), %rdx
movl 0x18(%rdx), %edx
addl %r12d, %edx
movl 0x18(%rcx), %esi
cmpl %esi, %edx
jl 0x460c
addl 0x1c(%rcx), %esi
cmpl %esi, %edx
jle 0x46fa
movq 0x4ed5(%rip), %rcx      # 0x94e8
movl 0x8(%rcx), %edx
movl %edx, %esi
subl %eax, %esi
movl %esi, %edi
negl %edi
cmovsl %esi, %edi
movl %edx, %r13d
cmpl $0x20, %edi
jb 0x462c
movl %eax, %r13d
addl 0x14(%rcx), %edx
movl 0x8(%rbx), %eax
movl %edx, %edi
subl %eax, %edi
subl %r13d, %edi
movl %edi, %esi
negl %esi
cmovsl %edi, %esi
cmpl $0x20, %esi
jae 0x464a
subl %eax, %edx
movl %edx, %r13d
movl 0x18(%rcx), %eax
movl %eax, %edx
subl %r15d, %edx
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
movl %eax, %edx
cmpl $0x20, %esi
jb 0x4663
movl %r15d, %edx
movl 0xc(%rbx), %esi
addl 0x1c(%rcx), %eax
movl %eax, %edi
subl %esi, %edi
subl %edx, %edi
movl %edi, %ecx
negl %ecx
cmovsl %edi, %ecx
cmpl $0x20, %ecx
jae 0x467f
subl %esi, %eax
movl %eax, %edx
movl %edx, %r15d
cmpl $0x0, 0x10(%rbx)
jne 0x46a5
movq 0x4e59(%rip), %rax      # 0x94e8
movq 0x40(%rax), %rax
leaq 0x124(%rip), %rcx       # 0x47be
cmpq %rcx, 0x8(%rax)
je 0x46a5
callq 0x31a8
cmpl $0x0, 0x10(%rbx)
je 0x46c0
movq %rbx, %rdi
movl %r13d, %esi
movl %r15d, %edx
movl %ebp, %ecx
movl %r12d, %r8d
callq 0x3eb9
jmp 0x46d8
movq 0x4e21(%rip), %rax      # 0x94e8
movq 0x40(%rax), %rax
leaq 0xec(%rip), %rcx        # 0x47be
cmpq %rcx, 0x8(%rax)
je 0x46ab
movq 0x4de1(%rip), %rdi      # 0x94c0
callq 0x2320
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %r13
leaq 0x4b9b(%rip), %r12      # 0x9290
jmp 0x4533
movl %eax, %r13d
jmp 0x4682
movq 0x4dba(%rip), %rdi      # 0x94c0
cmpl $0x1, %r13d
jne 0x4765
movq 0x38(%rbx), %rdx
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %r10d
incl %eax
incl %r10d
subq $0x8, %rsp
xorl %esi, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r10
pushq %rax
pushq $0x0
callq 0x2360
addq $0x20, %rsp
movq 0x4d81(%rip), %rdi      # 0x94c0
xorl %esi, %esi
callq 0x2100
leaq 0x38(%rsp), %r14
movq 0x4d6e(%rip), %rdi      # 0x94c0
movl $0x10, %esi
movq %r14, %rdx
callq 0x22c0
testl %eax, %eax
jne 0x474b
jmp 0x476c
xorl %esi, %esi
callq 0x2100
movl (%rbx), %edi
movl 0x4(%rbx), %esi
callq 0x4808
testq %rax, %rax
je 0x47a4
movq %rax, %r14
cmpq 0x4d63(%rip), %rax      # 0x94e8
je 0x47a4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4843
movq %r14, %rdi
movl $0x1, %esi
callq 0x48ff
callq 0x4a48
movq %rbx, %rdi
callq 0x3f12
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq