// File: /workspace/github_c_makefile_star2_O0/mati75[P]evilwm/client.c
// Function: client_monitor
struct monitor *client_monitor(struct client *c, Bool *intersects) {
	int cx1 = c->x - c->border;
	int cy1 = c->y - c->border;
	int cx2 = cx1 + c->width + c->border*2;
	int cy2 = cy1 + c->height + c->border*2;
	int cmidx = (cx1 + cx2)/2;
	int cmidy = (cy1 + cy2)/2;

	struct monitor *best = NULL;
	Bool have_intersection = 0;
	double best_area_ratio = 0.0;
	double best_distance = 0.0;;

	for (int i = 0; i < c->screen->nmonitors; i++) {
		struct monitor *m = &c->screen->monitors[i];
		int mx2 = m->x + m->width;
		int my2 = m->y + m->height;

		int iw = imax(0, imin(mx2, cx2) - imax(m->x, cx1));
		int ih = imax(0, imin(my2, cy2) - imax(m->y, cy1));
		int iarea = iw * ih;

		// XXX if you're building on a platform without any floating
		// point, you could consider simply returning the first monitor
		// for which an intersection is found.

		if (iarea > 0) {
			// Found an intersection.  Higher ratio wins.
			double iarea_ratio = (double)iarea / (double)m->area;
			if (!have_intersection || iarea_ratio > best_area_ratio) {
				have_intersection = 1;
				best_area_ratio = iarea_ratio;
				best = m;
				continue;
			}
		}

		// Otherwise, any previous intersection trumps distance.
		if (have_intersection)
			continue;

#ifdef HAVE_MATH_H
		// No intersections yet, calculate distance between midpoints.
		int mmidx = (m->x + mx2)/2;
		int mmidy = (m->y + my2)/2;
		int dx = abs(cmidx - mmidx);
		int dy = abs(cmidy - mmidy);
		double d = sqrt(dx*dx + dy*dy);

		if (!best || d < best_distance) {
			best_distance = d;
			best = m;
		}
#endif
	}

	if (!best) {
		best = &c->screen->monitors[0];
	}
	if (intersects) {
		*intersects = have_intersection;
	}
	return best;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x8(%rbp), %rcx
subl 0x3c(%rcx), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x8(%rbp), %rcx
subl 0x3c(%rcx), %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
addl 0x30(%rcx), %eax
movq -0x8(%rbp), %rcx
movl 0x3c(%rcx), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
addl 0x34(%rcx), %eax
movq -0x8(%rbp), %rcx
movl 0x3c(%rcx), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x20(%rbp)
movl -0x14(%rbp), %eax
addl -0x1c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
addl -0x20(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpl 0x6c(%rcx), %eax
jge 0x5b0f
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x70(%rax), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %eax
movq -0x58(%rbp), %rcx
addl 0x8(%rcx), %eax
movl %eax, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x58(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0x5b80
movl %eax, -0x98(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %edi
movl -0x14(%rbp), %esi
callq 0x5b50
movl -0x98(%rbp), %esi
subl %eax, %esi
xorl %edi, %edi
callq 0x5b50
movl %eax, -0x64(%rbp)
movl -0x60(%rbp), %edi
movl -0x20(%rbp), %esi
callq 0x5b80
movl %eax, -0x94(%rbp)
movq -0x58(%rbp), %rax
movl 0x4(%rax), %edi
movl -0x18(%rbp), %esi
callq 0x5b50
movl -0x94(%rbp), %esi
subl %eax, %esi
xorl %edi, %edi
callq 0x5b50
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
imull -0x68(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jle 0x5a49
cvtsi2sdl -0x6c(%rbp), %xmm0
movq -0x58(%rbp), %rax
cvtsi2sdl 0x10(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x5a29
movsd -0x78(%rbp), %xmm0
ucomisd -0x40(%rbp), %xmm0
jbe 0x5a47
movl $0x1, -0x34(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x5b01
jmp 0x5a49
cmpl $0x0, -0x34(%rbp)
je 0x5a54
jmp 0x5b01
movq -0x58(%rbp), %rax
movl (%rax), %eax
addl -0x5c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x7c(%rbp)
movq -0x58(%rbp), %rax
movl 0x4(%rax), %eax
addl -0x60(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x80(%rbp)
movl -0x24(%rbp), %eax
subl -0x7c(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x84(%rbp)
movl -0x28(%rbp), %eax
subl -0x80(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x88(%rbp)
movl -0x84(%rbp), %eax
imull -0x84(%rbp), %eax
movl -0x88(%rbp), %ecx
imull -0x88(%rbp), %ecx
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
callq 0x4720
movsd %xmm0, -0x90(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5aea
movsd -0x90(%rbp), %xmm1
movsd -0x48(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5aff
movsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x5b01
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x593d
cmpq $0x0, -0x30(%rbp)
jne 0x5b26
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x70(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x5b36
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)