// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/sdlayer2.c
// Function: handleevents
int handleevents(void)
{
	int code, rv=0, j, control;
	SDL_Event ev;
	static int firstcall = 1;
	int eattextinput = 0;

#define SetKey(key,state) { \
	keystatus[key] = state; \
		if (state) { \
	keyfifo[keyfifoend] = key; \
	keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = state; \
	keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1)); \
		} \
}

	while (SDL_PollEvent(&ev)) {
		switch (ev.type) {
			case SDL_TEXTINPUT:
				if (eattextinput) {
					eattextinput = 0;
					break;
				}
				for (j = 0; j < SDL_TEXTINPUTEVENT_TEXT_SIZE && ev.text.text[j]; j++) {
					if (ev.text.text[j] & 0x80) {
						continue;   // UTF8 character byte
					}
					code = ev.text.text[j];
					if (OSD_HandleChar(code)) {
						if (((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) {
							keyasciififo[keyasciififoend] = code;
							keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
						}
					}
				}
				break;

			case SDL_KEYUP:
				// (un)grab mouse with ctrl-g
				if (ev.key.keysym.sym == SDLK_g
					&& (ev.key.keysym.mod & KMOD_CTRL)) {
					grabmouse(!mouseacquired);
					break;
				}
				// else, fallthrough
			case SDL_KEYDOWN:
#ifdef __APPLE__
				// For Mac keyboards that removed the Help key, which shared a scancode
				// with PC Insert, pretend Cmd+Delete is insert when in the editor.
				if (ev.key.keysym.sym == SDLK_DELETE && ev.key.keysym.mod == KMOD_RGUI) {
					extern short editstatus;
					if (editstatus) {
						ev.key.keysym.sym = SDLK_INSERT;
						ev.key.keysym.scancode = SDL_SCANCODE_INSERT;
						ev.key.keysym.mod &= ~KMOD_RGUI;
					}
				}
#endif
				code = keytranslation[ev.key.keysym.scancode].normal;
				control = keytranslation[ev.key.keysym.scancode].controlchar;

				if (control && ev.key.type == SDL_KEYDOWN) {
					int needcontrol = (control & WITH_CONTROL_KEY) == WITH_CONTROL_KEY;
					int mod = ev.key.keysym.mod & ~(KMOD_CAPS|KMOD_NUM);
					control &= ~WITH_CONTROL_KEY;

					// May need to insert a control character into the ascii input
					// FIFO depending on what the state of the control keys are.
					if ((needcontrol  && mod && (mod & KMOD_CTRL) == mod) ||
						(!needcontrol && (mod == KMOD_NONE))) {
						if (OSD_HandleChar(control)) {
							if (((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) {
								keyasciififo[keyasciififoend] = control;
								keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
							}
						}
					}
				}

				// hook in the osd
				if (code == OSD_CaptureKey(-1)) {
					if (ev.key.type == SDL_KEYDOWN) {
						// The character produced by the OSD toggle key needs to be ignored.
						eattextinput = 1;

						OSD_ShowDisplay(-1);
					}
					break;
				} else if (OSD_HandleKey(code, (ev.key.type == SDL_KEYDOWN)) == 0)
					break;

				if (ev.key.type == SDL_KEYDOWN) {
					if (!keystatus[code]) {
						SetKey(code, 1);
					}
				} else {
					SetKey(code, 0);
				}
				break;

			case SDL_WINDOWEVENT:
				if (ev.window.event == SDL_WINDOWEVENT_FOCUS_GAINED ||
						ev.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
					appactive = ev.window.event == SDL_WINDOWEVENT_FOCUS_GAINED;
					if (mouseacquired && moustat) {
						SDL_SetRelativeMouseMode(appactive ? SDL_TRUE : SDL_FALSE);
					}
					rv=-1;
				}
				break;

			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				switch (ev.button.button) {
					case SDL_BUTTON_LEFT: j = 0; break;
					case SDL_BUTTON_RIGHT: j = 1; break;
					case SDL_BUTTON_MIDDLE: j = 2; break;
					default: j = -1; break;
				}
				if (j<0) break;

				if (ev.button.state == SDL_PRESSED)
					mouseb |= (1<<j);
				else
					mouseb &= ~(1<<j);
				break;

			case SDL_MOUSEWHEEL:
				if (ev.wheel.y > 0) {   // Up
					j = 5;
				} else if (ev.wheel.y < 0) {    // Down
					j = 4;
				} else {
					break;
				}
				mouseb |= 1<<j;
				// 'release' is done in readmousebstatus()
				break;

			case SDL_MOUSEMOTION:
				if (!firstcall) {
					if (appactive) {
						mousex += ev.motion.xrel;
						mousey += ev.motion.yrel;
					}
				}
				break;

			case SDL_CONTROLLERAXISMOTION:
				if (appactive) {
					joyaxis[ ev.caxis.axis ] = ev.caxis.value;
				}
				break;

			case SDL_CONTROLLERBUTTONDOWN:
			case SDL_CONTROLLERBUTTONUP:
				if (appactive) {
					if (ev.cbutton.state == SDL_PRESSED)
						joyb |= 1 << ev.cbutton.button;
					else
						joyb &= ~(1 << ev.cbutton.button);
				}
				break;

			case SDL_QUIT:
				quitevent = 1;
				rv=-1;
				break;

			default:
				//buildprintf("Got event (%d)\n", ev.type);
				break;
		}
	}

	sampletimer();
	startwin_idle(NULL);
	wm_idle(NULL);
#undef SetKey

	firstcall = 0;

	return rv;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x8(%rbp)
movl $0x0, -0x4c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x6af0
cmpl $0x0, %eax
je 0xa708c
movl -0x48(%rbp), %eax
movl %eax, -0x58(%rbp)
subl $0x100, %eax            # imm = 0x100
je 0xa7072
jmp 0xa6aeb
movl -0x58(%rbp), %eax
subl $0x200, %eax            # imm = 0x200
je 0xa6e5c
jmp 0xa6afb
movl -0x58(%rbp), %eax
subl $0x300, %eax            # imm = 0x300
je 0xa6c83
jmp 0xa6b0b
movl -0x58(%rbp), %eax
subl $0x301, %eax            # imm = 0x301
je 0xa6c52
jmp 0xa6b1b
movl -0x58(%rbp), %eax
subl $0x303, %eax            # imm = 0x303
je 0xa6b80
jmp 0xa6b27
movl -0x58(%rbp), %eax
subl $0x400, %eax            # imm = 0x400
je 0xa6fae
jmp 0xa6b37
movl -0x58(%rbp), %eax
addl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
subl $0x2, %eax
jb 0xa6ec8
jmp 0xa6b4a
movl -0x58(%rbp), %eax
subl $0x403, %eax            # imm = 0x403
je 0xa6f66
jmp 0xa6b5a
movl -0x58(%rbp), %eax
subl $0x650, %eax            # imm = 0x650
je 0xa6ff4
jmp 0xa6b6a
movl -0x58(%rbp), %eax
addl $0xfffff9af, %eax       # imm = 0xFFFFF9AF
subl $0x2, %eax
jb 0xa7016
jmp 0xa7085
cmpl $0x0, -0x4c(%rbp)
je 0xa6b92
movl $0x0, -0x4c(%rbp)
jmp 0xa7087
movl $0x0, -0xc(%rbp)
xorl %eax, %eax
cmpl $0x20, -0xc(%rbp)
movb %al, -0x59(%rbp)
jge 0xa6bb6
movslq -0xc(%rbp), %rax
movsbl -0x3c(%rbp,%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0xa6bc2
jmp 0xa6c4d
movslq -0xc(%rbp), %rax
movsbl -0x3c(%rbp,%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xa6bd7
jmp 0xa6c3f
movslq -0xc(%rbp), %rax
movsbl -0x3c(%rbp,%rax), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %edi
callq 0x6ccc0
cmpl $0x0, %eax
je 0xa6c3d
leaq 0x114059(%rip), %rax    # 0x1bac50
movl (%rax), %eax
addl $0x1, %eax
andl $0x3f, %eax
leaq 0x114046(%rip), %rcx    # 0x1bac4c
cmpl (%rcx), %eax
je 0xa6c3b
movl -0x4(%rbp), %eax
movb %al, %dl
leaq 0x11403a(%rip), %rax    # 0x1bac50
movslq (%rax), %rcx
leaq 0x114040(%rip), %rax    # 0x1bac60
movb %dl, (%rax,%rcx)
leaq 0x114026(%rip), %rax    # 0x1bac50
movl (%rax), %ecx
addl $0x1, %ecx
andl $0x3f, %ecx
leaq 0x114017(%rip), %rax    # 0x1bac50
movl %ecx, (%rax)
jmp 0xa6c3d
jmp 0xa6c3f
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xa6b99
jmp 0xa7087
cmpl $0x67, -0x34(%rbp)
jne 0xa6c81
movzwl -0x30(%rbp), %eax
andl $0xc0, %eax
cmpl $0x0, %eax
je 0xa6c81
cmpb $0x0, 0x61963b(%rip)    # 0x6c02a8
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
callq 0xa5460
jmp 0xa7087
jmp 0xa6c83
movl -0x38(%rbp), %eax
movl %eax, %ecx
leaq 0x61af21(%rip), %rax    # 0x6c1bb0
movzbl (%rax,%rcx,2), %eax
movl %eax, -0x4(%rbp)
movl -0x38(%rbp), %eax
movl %eax, %ecx
leaq 0x61af0e(%rip), %rax    # 0x6c1bb0
movzbl 0x1(%rax,%rcx,2), %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0xa6d73
cmpl $0x300, -0x48(%rbp)     # imm = 0x300
jne 0xa6d73
movl -0x10(%rbp), %eax
andl $0x80, %eax
cmpl $0x80, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
movzwl -0x30(%rbp), %eax
andl $0xffffcfff, %eax       # imm = 0xFFFFCFFF
movl %eax, -0x54(%rbp)
movl -0x10(%rbp), %eax
andl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0xa6d09
cmpl $0x0, -0x54(%rbp)
je 0xa6d09
movl -0x54(%rbp), %eax
andl $0xc0, %eax
cmpl -0x54(%rbp), %eax
je 0xa6d15
cmpl $0x0, -0x50(%rbp)
jne 0xa6d71
cmpl $0x0, -0x54(%rbp)
jne 0xa6d71
movl -0x10(%rbp), %edi
callq 0x6ccc0
cmpl $0x0, %eax
je 0xa6d6f
leaq 0x113f27(%rip), %rax    # 0x1bac50
movl (%rax), %eax
addl $0x1, %eax
andl $0x3f, %eax
leaq 0x113f14(%rip), %rcx    # 0x1bac4c
cmpl (%rcx), %eax
je 0xa6d6d
movl -0x10(%rbp), %eax
movb %al, %dl
leaq 0x113f08(%rip), %rax    # 0x1bac50
movslq (%rax), %rcx
leaq 0x113f0e(%rip), %rax    # 0x1bac60
movb %dl, (%rax,%rcx)
leaq 0x113ef4(%rip), %rax    # 0x1bac50
movl (%rax), %ecx
addl $0x1, %ecx
andl $0x3f, %ecx
leaq 0x113ee5(%rip), %rax    # 0x1bac50
movl %ecx, (%rax)
jmp 0xa6d6f
jmp 0xa6d71
jmp 0xa6d73
movl -0x4(%rbp), %eax
movl %eax, -0x60(%rbp)
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x6cc90
movl %eax, %ecx
movl -0x60(%rbp), %eax
cmpl %ecx, %eax
jne 0xa6dab
cmpl $0x300, -0x48(%rbp)     # imm = 0x300
jne 0xa6da6
movl $0x1, -0x4c(%rbp)
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x6dea0
jmp 0xa7087
movl -0x4(%rbp), %edi
cmpl $0x300, -0x48(%rbp)     # imm = 0x300
sete %al
andb $0x1, %al
movzbl %al, %esi
callq 0x6db60
cmpl $0x0, %eax
jne 0xa6dcc
jmp 0xa7087
jmp 0xa6dce
cmpl $0x300, -0x48(%rbp)     # imm = 0x300
jne 0xa6e48
movslq -0x4(%rbp), %rcx
leaq 0x11400e(%rip), %rax    # 0x1badf0
cmpb $0x0, (%rax,%rcx)
jne 0xa6e46
movslq -0x4(%rbp), %rcx
leaq 0x113ffd(%rip), %rax    # 0x1badf0
movb $0x1, (%rax,%rcx)
movl -0x4(%rbp), %edx
leaq 0x113ea3(%rip), %rax    # 0x1baca4
movslq (%rax), %rcx
leaq 0x113ea5(%rip), %rax    # 0x1bacb0
movl %edx, (%rax,%rcx,4)
leaq 0x113e8f(%rip), %rax    # 0x1baca4
movl (%rax), %eax
addl $0x1, %eax
andl $0x3f, %eax
movslq %eax, %rcx
leaq 0x113e89(%rip), %rax    # 0x1bacb0
movl $0x1, (%rax,%rcx,4)
leaq 0x113e6f(%rip), %rax    # 0x1baca4
movl (%rax), %ecx
addl $0x2, %ecx
andl $0x3f, %ecx
leaq 0x113e60(%rip), %rax    # 0x1baca4
movl %ecx, (%rax)
jmp 0xa6e57
movslq -0x4(%rbp), %rcx
leaq 0x113f9d(%rip), %rax    # 0x1badf0
movb $0x0, (%rax,%rcx)
jmp 0xa7087
movzbl -0x3c(%rbp), %eax
cmpl $0xc, %eax
je 0xa6e6e
movzbl -0x3c(%rbp), %eax
cmpl $0xd, %eax
jne 0xa6ec3
movzbl -0x3c(%rbp), %eax
cmpl $0xc, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
leaq 0x3956a(%rip), %rax     # 0xe03f0
movb %cl, (%rax)
movsbl 0x619419(%rip), %eax    # 0x6c02a8
cmpl $0x0, %eax
je 0xa6ebc
movsbl 0x61940e(%rip), %eax    # 0x6c02a9
cmpl $0x0, %eax
je 0xa6ebc
leaq 0x39549(%rip), %rax     # 0xe03f0
movsbl (%rax), %ecx
xorl %edi, %edi
movl $0x1, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edi
callq 0x64e0
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
jmp 0xa7087
movzbl -0x38(%rbp), %eax
movl %eax, -0x64(%rbp)
subl $0x1, %eax
je 0xa6eea
jmp 0xa6ed6
movl -0x64(%rbp), %eax
subl $0x2, %eax
je 0xa6efc
jmp 0xa6ee0
movl -0x64(%rbp), %eax
subl $0x3, %eax
je 0xa6ef3
jmp 0xa6f05
movl $0x0, -0xc(%rbp)
jmp 0xa6f0c
movl $0x1, -0xc(%rbp)
jmp 0xa6f0c
movl $0x2, -0xc(%rbp)
jmp 0xa6f0c
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0xc(%rbp)
jge 0xa6f17
jmp 0xa7087
movzbl -0x37(%rbp), %eax
cmpl $0x1, %eax
jne 0xa6f40
movl -0xc(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
leaq 0x113d09(%rip), %rax    # 0x1bac3c
orl (%rax), %ecx
leaq 0x113d00(%rip), %rax    # 0x1bac3c
movl %ecx, (%rax)
jmp 0xa6f61
movl -0xc(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
xorl $-0x1, %ecx
leaq 0x113ce6(%rip), %rax    # 0x1bac3c
andl (%rax), %ecx
leaq 0x113cdd(%rip), %rax    # 0x1bac3c
movl %ecx, (%rax)
jmp 0xa7087
cmpl $0x0, -0x34(%rbp)
jle 0xa6f75
movl $0x5, -0xc(%rbp)
jmp 0xa6f8b
cmpl $0x0, -0x34(%rbp)
jge 0xa6f84
movl $0x4, -0xc(%rbp)
jmp 0xa6f89
jmp 0xa7087
jmp 0xa6f8b
movl -0xc(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
leaq 0x113c9e(%rip), %rax    # 0x1bac3c
orl (%rax), %ecx
leaq 0x113c95(%rip), %rax    # 0x1bac3c
movl %ecx, (%rax)
jmp 0xa7087
cmpl $0x0, 0x3ae3b(%rip)     # 0xe1df0
jne 0xa6fef
leaq 0x39432(%rip), %rax     # 0xe03f0
cmpb $0x0, (%rax)
je 0xa6fed
movl -0x2c(%rbp), %ecx
leaq 0x113c67(%rip), %rax    # 0x1bac34
addl (%rax), %ecx
leaq 0x113c5e(%rip), %rax    # 0x1bac34
movl %ecx, (%rax)
movl -0x28(%rbp), %ecx
leaq 0x113c56(%rip), %rax    # 0x1bac38
addl (%rax), %ecx
leaq 0x113c4d(%rip), %rax    # 0x1bac38
movl %ecx, (%rax)
jmp 0xa6fef
jmp 0xa7087
leaq 0x393f5(%rip), %rax     # 0xe03f0
cmpb $0x0, (%rax)
je 0xa7014
movswl -0x38(%rbp), %edx
movzbl -0x3c(%rbp), %eax
movl %eax, %ecx
leaq 0x113edf(%rip), %rax    # 0x1baef0
movl %edx, (%rax,%rcx,4)
jmp 0xa7087
leaq 0x393d3(%rip), %rax     # 0xe03f0
cmpb $0x0, (%rax)
je 0xa7070
movzbl -0x3b(%rbp), %eax
cmpl $0x1, %eax
jne 0xa704c
movzbl -0x3c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
leaq 0x113c01(%rip), %rax    # 0x1bac40
orl (%rax), %ecx
leaq 0x113bf8(%rip), %rax    # 0x1bac40
movl %ecx, (%rax)
jmp 0xa706e
movzbl -0x3c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
xorl $-0x1, %ecx
leaq 0x113bdd(%rip), %rax    # 0x1bac40
andl (%rax), %ecx
leaq 0x113bd4(%rip), %rax    # 0x1bac40
movl %ecx, (%rax)
jmp 0xa7070
jmp 0xa7087
leaq 0x113b87(%rip), %rax    # 0x1bac00
movb $0x1, (%rax)
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
jmp 0xa7087
jmp 0xa7087
jmp 0xa6ac6
callq 0xa5650
xorl %eax, %eax
movl %eax, %edi
callq 0x2d0f0
xorl %eax, %eax
movl %eax, %edi
callq 0xa47e0
movl $0x0, 0x3ad43(%rip)     # 0xe1df0
movl -0x8(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)