// File: /workspace/github_c_makefile_star2_O0/9wm[P]9wm/grab.c
// Function: menuhit
int
menuhit(XButtonEvent * e, Menu * m)
{
	XEvent ev;
	int i, n, cur, old, wide, high, status, drawn, warp;
	int x, y, dx, dy, xmax, ymax;
	int tx, ty;
	ScreenInfo *s;

	if (font == 0)
		return -1;
	s = getscreen(e->root);
	if (s == 0 || e->window == s->menuwin)	/* ugly event mangling */
		return -1;

	dx = 0;
	for (n = 0; m->item[n]; n++) {
		wide = XTextWidth(font, m->item[n], strlen(m->item[n])) + 4;
		if (wide > dx)
			dx = wide;
	}
	wide = dx;
	cur = m->lasthit;
	if (cur >= n)
		cur = n - 1;

	high = font->ascent + font->descent + 1;
	dy = n * high;
	x = e->x - wide / 2;
	y = e->y - cur * high - high / 2;
	warp = 0;
	xmax = DisplayWidth(dpy, s->num);
	ymax = DisplayHeight(dpy, s->num);
	if (x < 0) {
		e->x -= x;
		x = 0;
		warp++;
	}
	if (x + wide >= xmax) {
		e->x -= x + wide - xmax;
		x = xmax - wide;
		warp++;
	}
	if (y < 0) {
		e->y -= y;
		y = 0;
		warp++;
	}
	if (y + dy >= ymax) {
		e->y -= y + dy - ymax;
		y = ymax - dy;
		warp++;
	}
	if (warp)
		setmouse(e->x, e->y, s);
	XMoveResizeWindow(dpy, s->menuwin, x, y, dx, dy);
	XSelectInput(dpy, s->menuwin, MenuMask);
	XMapRaised(dpy, s->menuwin);
	status = grab(s->menuwin, None, MenuGrabMask, None, e->time);
	if (status != GrabSuccess) {
		/*
		 * graberror("menuhit", status); 
		 */
		XUnmapWindow(dpy, s->menuwin);
		return -1;
	}
	drawn = 0;
	for (;;) {
		XMaskEvent(dpy, MenuMask, &ev);
		switch (ev.type) {
		default:
			fprintf(stderr, "9wm: menuhit: unknown ev.type %d\n", ev.type);
			break;
		case ButtonPress:
			break;
		case ButtonRelease:
			if (ev.xbutton.button != e->button)
				break;
			x = ev.xbutton.x;
			y = ev.xbutton.y;
			i = y / high;
			if (cur >= 0 && y >= cur * high - 3 && y < (cur + 1) * high + 3)
				i = cur;
			if (x < 0 || x > wide || y < -3)
				i = -1;
			else if (i < 0 || i >= n)
				i = -1;
			else
				m->lasthit = i;
			if (!nobuttons(&ev.xbutton))
				i = -1;
			ungrab(&ev.xbutton);
			XUnmapWindow(dpy, s->menuwin);
			return i;
		case MotionNotify:
			if (!drawn)
				break;
			x = ev.xbutton.x;
			y = ev.xbutton.y;
			old = cur;
			cur = y / high;
			if (old >= 0 && y >= old * high - 3 && y < (old + 1) * high + 3)
				cur = old;
			if (x < 0 || x > wide || y < -3)
				cur = -1;
			else if (cur < 0 || cur >= n)
				cur = -1;
			if (cur == old)
				break;
			if (old >= 0 && old < n)
				XFillRectangle(dpy, s->menuwin, s->gc, 0, old * high, wide, high);
			if (cur >= 0 && cur < n)
				XFillRectangle(dpy, s->menuwin, s->gc, 0, cur * high, wide, high);
			break;
		case Expose:
			XClearWindow(dpy, s->menuwin);
			for (i = 0; i < n; i++) {
				char *item = m->item[i];

				if (i < 5) {
					tx = (wide - XTextWidth(font, item, strlen(item))) / 2;
				} else {
					tx = 1;
				}
				ty = i * high + font->ascent + 1;
				XDrawString(dpy, s->menuwin, s->gc, tx, ty, item, strlen(item));
			}
			if (cur >= 0 && cur < n)
				XFillRectangle(dpy, s->menuwin, s->gc, 0, cur * high, wide, high);
			drawn = 1;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x5526(%rip), %rax      # 0xc950
cmpq $0x0, (%rax)
jne 0x743c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7dcc
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movb $0x0, %al
callq 0x3350
movq %rax, -0x128(%rbp)
cmpq $0x0, -0x128(%rbp)
je 0x7471
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x128(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x747d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7dcc
movl $0x0, -0x108(%rbp)
movl $0x0, -0xe0(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0xe0(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x7539
leaq 0x549f(%rip), %rax      # 0xc950
movq (%rax), %rax
movq %rax, -0x140(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0xe0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x138(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0xe0(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2150
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rsi
movl %eax, %edx
callq 0x24d0
addl $0x4, %eax
movl %eax, -0xec(%rbp)
movl -0xec(%rbp), %eax
cmpl -0x108(%rbp), %eax
jle 0x7523
movl -0xec(%rbp), %eax
movl %eax, -0x108(%rbp)
jmp 0x7525
movl -0xe0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe0(%rbp)
jmp 0x7491
movl -0x108(%rbp), %eax
movl %eax, -0xec(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jl 0x756f
movl -0xe0(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xe4(%rbp)
leaq 0x53da(%rip), %rax      # 0xc950
movq (%rax), %rax
movl 0x58(%rax), %eax
leaq 0x53cd(%rip), %rcx      # 0xc950
movq (%rcx), %rcx
addl 0x5c(%rcx), %eax
addl $0x1, %eax
movl %eax, -0xf0(%rbp)
movl -0xe0(%rbp), %eax
imull -0xf0(%rbp), %eax
movl %eax, -0x10c(%rbp)
movq -0x10(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x148(%rbp)
movl -0xec(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x148(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x100(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %eax
movl -0xe4(%rbp), %ecx
imull -0xf0(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x144(%rbp)
movl -0xf0(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x144(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x104(%rbp)
movl $0x0, -0xfc(%rbp)
leaq 0x535d(%rip), %rax      # 0xc978
movq (%rax), %rax
movq 0xe8(%rax), %rax
movq -0x128(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x110(%rbp)
leaq 0x5332(%rip), %rax      # 0xc978
movq (%rax), %rax
movq 0xe8(%rax), %rax
movq -0x128(%rbp), %rcx
movslq (%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movl %eax, -0x114(%rbp)
cmpl $0x0, -0x100(%rbp)
jge 0x769e
movl -0x100(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x40(%rax)
movl $0x0, -0x100(%rbp)
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
movl -0x100(%rbp), %eax
addl -0xec(%rbp), %eax
cmpl -0x110(%rbp), %eax
jl 0x76f1
movl -0x100(%rbp), %edx
addl -0xec(%rbp), %edx
subl -0x110(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x40(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x40(%rax)
movl -0x110(%rbp), %eax
subl -0xec(%rbp), %eax
movl %eax, -0x100(%rbp)
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, -0x104(%rbp)
jge 0x7725
movl -0x104(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x44(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x44(%rax)
movl $0x0, -0x104(%rbp)
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
movl -0x104(%rbp), %eax
addl -0x10c(%rbp), %eax
cmpl -0x114(%rbp), %eax
jl 0x7778
movl -0x104(%rbp), %edx
addl -0x10c(%rbp), %edx
subl -0x114(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x44(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x44(%rax)
movl -0x114(%rbp), %eax
subl -0x10c(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
cmpl $0x0, -0xfc(%rbp)
je 0x779b
movq -0x10(%rbp), %rax
movl 0x40(%rax), %edi
movq -0x10(%rbp), %rax
movl 0x44(%rax), %esi
movq -0x128(%rbp), %rdx
callq 0x89a0
leaq 0x51d6(%rip), %rax      # 0xc978
movq (%rax), %rdi
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rsi
movl -0x100(%rbp), %edx
movl -0x104(%rbp), %ecx
movl -0x108(%rbp), %r8d
movl -0x10c(%rbp), %r9d
callq 0x21b0
leaq 0x51a2(%rip), %rax      # 0xc978
movq (%rax), %rdi
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rsi
movl $0xa00c, %edx           # imm = 0xA00C
callq 0x23b0
leaq 0x5183(%rip), %rax      # 0xc978
movq (%rax), %rdi
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2340
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %r8d
xorl %eax, %eax
movl %eax, %ecx
movl $0x2200c, %edx          # imm = 0x2200C
movq %rcx, %rsi
callq 0x72f0
movl %eax, -0xf4(%rbp)
cmpl $0x0, -0xf4(%rbp)
je 0x7864
leaq 0x5133(%rip), %rax      # 0xc978
movq (%rax), %rdi
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2420
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7dcc
movl $0x0, -0xf8(%rbp)
leaq 0x5103(%rip), %rax      # 0xc978
movq (%rax), %rdi
movl $0xa00c, %esi           # imm = 0xA00C
leaq -0xd8(%rbp), %rdx
callq 0x25e0
movl -0xd8(%rbp), %eax
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x150(%rbp)
subl $0x8, %eax
ja 0x78b7
movq -0x150(%rbp), %rax
leaq 0x1ea6(%rip), %rcx      # 0x9754
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x473a(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl -0xd8(%rbp), %edx
leaq 0x1eaa(%rip), %rsi      # 0x9778
movb $0x0, %al
callq 0x22b0
jmp 0x7dc7
jmp 0x7dc7
movl -0x84(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x54(%rcx), %eax
je 0x78f3
jmp 0x7dc7
movl -0x98(%rbp), %eax
movl %eax, -0x100(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0x104(%rbp), %eax
cltd
idivl -0xf0(%rbp)
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0xe4(%rbp)
jl 0x796a
movl -0x104(%rbp), %eax
movl -0xe4(%rbp), %ecx
imull -0xf0(%rbp), %ecx
subl $0x3, %ecx
cmpl %ecx, %eax
jl 0x796a
movl -0x104(%rbp), %eax
movl -0xe4(%rbp), %ecx
addl $0x1, %ecx
imull -0xf0(%rbp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jge 0x796a
movl -0xe4(%rbp), %eax
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0x100(%rbp)
jl 0x798a
movl -0x100(%rbp), %eax
cmpl -0xec(%rbp), %eax
jg 0x798a
cmpl $-0x3, -0x104(%rbp)
jge 0x7996
movl $0xffffffff, -0xdc(%rbp) # imm = 0xFFFFFFFF
jmp 0x79c8
cmpl $0x0, -0xdc(%rbp)
jl 0x79ad
movl -0xdc(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jl 0x79b9
movl $0xffffffff, -0xdc(%rbp) # imm = 0xFFFFFFFF
jmp 0x79c6
movl -0xdc(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x79c8
leaq -0xd8(%rbp), %rdi
callq 0x72a0
cmpl $0x0, %eax
jne 0x79e3
movl $0xffffffff, -0xdc(%rbp) # imm = 0xFFFFFFFF
leaq -0xd8(%rbp), %rdi
callq 0x7370
leaq 0x4f82(%rip), %rax      # 0xc978
movq (%rax), %rdi
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2420
movl -0xdc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7dcc
cmpl $0x0, -0xf8(%rbp)
jne 0x7a25
jmp 0x7dc7
movl -0x98(%rbp), %eax
movl %eax, -0x100(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0xe4(%rbp), %eax
movl %eax, -0xe8(%rbp)
movl -0x104(%rbp), %eax
cltd
idivl -0xf0(%rbp)
movl %eax, -0xe4(%rbp)
cmpl $0x0, -0xe8(%rbp)
jl 0x7aa8
movl -0x104(%rbp), %eax
movl -0xe8(%rbp), %ecx
imull -0xf0(%rbp), %ecx
subl $0x3, %ecx
cmpl %ecx, %eax
jl 0x7aa8
movl -0x104(%rbp), %eax
movl -0xe8(%rbp), %ecx
addl $0x1, %ecx
imull -0xf0(%rbp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jge 0x7aa8
movl -0xe8(%rbp), %eax
movl %eax, -0xe4(%rbp)
cmpl $0x0, -0x100(%rbp)
jl 0x7ac8
movl -0x100(%rbp), %eax
cmpl -0xec(%rbp), %eax
jg 0x7ac8
cmpl $-0x3, -0x104(%rbp)
jge 0x7ad4
movl $0xffffffff, -0xe4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7af7
cmpl $0x0, -0xe4(%rbp)
jl 0x7aeb
movl -0xe4(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jl 0x7af5
movl $0xffffffff, -0xe4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7af7
movl -0xe4(%rbp), %eax
cmpl -0xe8(%rbp), %eax
jne 0x7b0a
jmp 0x7dc7
cmpl $0x0, -0xe8(%rbp)
jl 0x7b67
movl -0xe8(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jge 0x7b67
leaq 0x4e50(%rip), %rax      # 0xc978
movq (%rax), %rdi
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rdx
movl -0xe8(%rbp), %r8d
imull -0xf0(%rbp), %r8d
movl -0xec(%rbp), %r9d
movl -0xf0(%rbp), %eax
xorl %ecx, %ecx
movl %eax, (%rsp)
callq 0x2160
cmpl $0x0, -0xe4(%rbp)
jl 0x7bc4
movl -0xe4(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jge 0x7bc4
leaq 0x4df3(%rip), %rax      # 0xc978
movq (%rax), %rdi
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rdx
movl -0xe4(%rbp), %r8d
imull -0xf0(%rbp), %r8d
movl -0xec(%rbp), %r9d
movl -0xf0(%rbp), %eax
xorl %ecx, %ecx
movl %eax, (%rsp)
callq 0x2160
jmp 0x7dc7
leaq 0x4da8(%rip), %rax      # 0xc978
movq (%rax), %rdi
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x2090
movl $0x0, -0xdc(%rbp)
movl -0xdc(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jge 0x7d60
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0xdc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x130(%rbp)
cmpl $0x5, -0xdc(%rbp)
jge 0x7c87
movl -0xec(%rbp), %eax
movl %eax, -0x154(%rbp)
leaq 0x4d1c(%rip), %rax      # 0xc950
movq (%rax), %rax
movq %rax, -0x168(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x130(%rbp), %rdi
callq 0x2150
movq -0x168(%rbp), %rdi
movq -0x160(%rbp), %rsi
movl %eax, %edx
callq 0x24d0
movl %eax, %ecx
movl -0x154(%rbp), %eax
subl %ecx, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x118(%rbp)
jmp 0x7c91
movl $0x1, -0x118(%rbp)
movl -0xdc(%rbp), %eax
imull -0xf0(%rbp), %eax
leaq 0x4cab(%rip), %rcx      # 0xc950
movq (%rcx), %rcx
addl 0x58(%rcx), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
leaq 0x4cbd(%rip), %rax      # 0xc978
movq (%rax), %rax
movq %rax, -0x190(%rbp)
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x188(%rbp)
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x180(%rbp)
movl -0x118(%rbp), %eax
movl %eax, -0x178(%rbp)
movl -0x11c(%rbp), %eax
movl %eax, -0x174(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x130(%rbp), %rdi
callq 0x2150
movq -0x190(%rbp), %rdi
movq -0x188(%rbp), %rsi
movq -0x180(%rbp), %rdx
movl -0x178(%rbp), %ecx
movl -0x174(%rbp), %r8d
movq -0x170(%rbp), %r9
movl %eax, (%rsp)
callq 0x23f0
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0x7bed
cmpl $0x0, -0xe4(%rbp)
jl 0x7dbd
movl -0xe4(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jge 0x7dbd
leaq 0x4bfa(%rip), %rax      # 0xc978
movq (%rax), %rdi
movq -0x128(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x128(%rbp), %rax
movq 0x20(%rax), %rdx
movl -0xe4(%rbp), %r8d
imull -0xf0(%rbp), %r8d
movl -0xec(%rbp), %r9d
movl -0xf0(%rbp), %eax
xorl %ecx, %ecx
movl %eax, (%rsp)
callq 0x2160
movl $0x1, -0xf8(%rbp)
jmp 0x786e
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopl (%rax,%rax)