// File: /workspace/github_cpp_makefile_star2_O3/Alcaro[P]bridges/arlib/game-x11.cpp
// Function: gameview_x11::process_event(_XEvent*)
void process_event(XEvent* ev)
{
	got_event = true;
	switch (ev->type)
	{
		case Expose: break; // just set got_event, nothing else needed
		case FocusIn:
			focus = true;
			set_all_keys();
			break;
		case FocusOut:
			focus = false;
			break;
		case KeyPress:
		case KeyRelease:
			set_key(ev->xkey.keycode, (ev->type == KeyPress));
			break;
		case ButtonPress:
		case ButtonRelease:
			static_assert(Button1Mask == 256); // guaranteed by X11 spec
			static_assert(Button2Mask == 512);
			static_assert(Button3Mask == 1024);
			if (ev->xbutton.button >= 1 && ev->xbutton.button <= 3)
				send_mouse(ev->xbutton.x, ev->xbutton.y, ev->xbutton.state^(Button1Mask >> 1 << ev->xbutton.button));
			break;
		case MotionNotify:
			send_mouse(ev->xmotion.x, ev->xmotion.y, ev->xmotion.state);
			break;
		case LeaveNotify:
			if (!(ev->xcrossing.state & (Button1Mask | Button2Mask | Button3Mask))) // if a button is held, we'll get a MotionNotify soon
				send_mouse(-0x8000000, -0x8000000, ev->xcrossing.state);
			break;
		case ClientMessage:
			if (ev->xclient.message_type == atoms.WM_PROTOCOLS && ev->xclient.format == 32)
			{
				Atom subtype = ev->xclient.data.l[0];
				if (subtype == atoms.WM_DELETE_WINDOW)
				{
					cb_exit();
				}
				else if (subtype == atoms._NET_WM_PING)
				{
					ev->xclient.window = XRootWindow(display, window_x11.screen);
					XSendEvent(display, ev->xclient.window, false, SubstructureRedirectMask|SubstructureNotifyMask, ev);
				}
#ifndef ARLIB_OPT
				else puts("AAAAA unknown WM_PROTOCOLS");
#endif
			}
#ifndef ARLIB_OPT
			else puts("AAAAA unknown ClientMessage");
#endif
			break;
#ifndef ARLIB_OPT
		default:
			printf("AAAAA unknown event %d\n",ev->type);
			break;
#endif
	}
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r9
movb $0x1, 0x1a(%rdi)
movl (%rsi), %esi
leal -0x2(%rsi), %eax
cmpl $0xa, %eax
ja 0xaa10
leaq 0x24ba3(%rip), %rcx     # 0x2f544
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl 0x54(%rbx), %eax
xorl %edx, %edx
cmpl $0x2, %esi
sete %dl
movq %r9, %rdi
movl %eax, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xaba4
movl 0x54(%rbx), %ecx
leal -0x1(%rcx), %eax
cmpl $0x2, %eax
ja 0xaab3
movl $0x80, %eax
shll %cl, %eax
xorl 0x50(%rbx), %eax
movl 0x40(%rbx), %esi
shrl $0x6, %eax
andb $0x1c, %al
movl $0x76325410, %r8d       # imm = 0x76325410
movl %eax, %ecx
shrl %cl, %r8d
movl 0x44(%rbx), %edx
movq 0x2b0(%r9), %rdi
movq 0x2b8(%r9), %rax
andl $0x7, %r8d
movl %r8d, %ecx
jmp 0xaae8
cmpl $0x21, %esi
jne 0xaa4a
movq 0x28(%rbx), %rax
cmpq 0x20(%r9), %rax
jne 0xaabb
cmpl $0x20, 0x30(%rbx)
jne 0xaabb
movq 0x38(%rbx), %rax
cmpq 0x28(%r9), %rax
jne 0xaaf1
movq 0x60(%r9), %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *0x68(%r9)
leaq 0x24b99(%rip), %rdi     # 0x2f5ea
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x3050
movb $0x1, 0x18(%r9)
movq %r9, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0xab34
movb $0x0, 0x18(%r9)
jmp 0xaab3
movl 0x40(%rbx), %esi
movl 0x50(%rbx), %ecx
shrl $0x6, %ecx
andb $0x1c, %cl
movl $0x76325410, %eax       # imm = 0x76325410
shrl %cl, %eax
movl 0x44(%rbx), %edx
movq 0x2b0(%r9), %rdi
movq 0x2b8(%r9), %r8
andl $0x7, %eax
movl %eax, %ecx
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *%r8
testb $0x7, 0x61(%rbx)
je 0xaace
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x24b0c(%rip), %rdi     # 0x2f5ce
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x3590
movq 0x2b0(%r9), %rdi
movq 0x2b8(%r9), %rax
movl $0xf8000000, %esi       # imm = 0xF8000000
movl $0xf8000000, %edx       # imm = 0xF8000000
xorl %ecx, %ecx
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *%rax
cmpq 0x30(%r9), %rax
jne 0xab2a
movq 0x8(%r9), %rdi
movl 0x3b84f(%rip), %esi     # 0x46350
movq %r9, %r14
callq 0x35d0
movq %rax, 0x20(%rbx)
movq 0x8(%r14), %rdi
movl $0x180000, %ecx         # imm = 0x180000
movq %rax, %rsi
xorl %edx, %edx
movq %rbx, %r8
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x30c0
leaq 0x24a82(%rip), %rdi     # 0x2f5b3
jmp 0xaac2
nop