// File: /workspace/github_c_makefile_star2_O0/mrdotx[P]st/x.c
// Function: run
void
run(void)
{
	XEvent ev;
	int w = win.w, h = win.h;
	fd_set rfd;
	int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing;
	struct timespec seltv, *tv, now, lastblink, trigger;
	double timeout;

	/* Waiting for window mapping */
	do {
		XNextEvent(xw.dpy, &ev);
		/*
		 * This XFilterEvent call is required because of XOpenIM. It
		 * does filter out the key event and some client message for
		 * the input method too.
		 */
		if (XFilterEvent(&ev, None))
			continue;
		if (ev.type == ConfigureNotify) {
			w = ev.xconfigure.width;
			h = ev.xconfigure.height;
		}
	} while (ev.type != MapNotify);

	ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
	cresize(w, h);

	for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) {
		FD_ZERO(&rfd);
		FD_SET(ttyfd, &rfd);
		FD_SET(xfd, &rfd);

		if (XPending(xw.dpy) || ttyread_pending())
			timeout = 0;  /* existing events might not set xfd */

		seltv.tv_sec = timeout / 1E3;
		seltv.tv_nsec = 1E6 * (timeout - 1E3 * seltv.tv_sec);
		tv = timeout >= 0 ? &seltv : NULL;

		if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
			if (errno == EINTR)
				continue;
			die("select failed: %s\n", strerror(errno));
		}
		clock_gettime(CLOCK_MONOTONIC, &now);

		int ttyin = FD_ISSET(ttyfd, &rfd) || ttyread_pending();
		if (ttyin)
			ttyread();

		xev = 0;
		while (XPending(xw.dpy)) {
			xev = 1;
			XNextEvent(xw.dpy, &ev);
			if (XFilterEvent(&ev, None))
				continue;
			if (handler[ev.type])
				(handler[ev.type])(&ev);
		}

		/*
		 * To reduce flicker and tearing, when new content or event
		 * triggers drawing, we first wait a bit to ensure we got
		 * everything, and if nothing new arrives - we draw.
		 * We start with trying to wait minlatency ms. If more content
		 * arrives sooner, we retry with shorter and shorter periods,
		 * and eventually draw even without idle after maxlatency ms.
		 * Typically this results in low latency while interacting,
		 * maximum latency intervals during `cat huge.txt`, and perfect
		 * sync with periodic updates from animations/key-repeats/etc.
		 */
		if (ttyin || xev) {
			if (!drawing) {
				trigger = now;
				drawing = 1;
			}
			timeout = (maxlatency - TIMEDIFF(now, trigger))
			          / maxlatency * minlatency;
			if (timeout > 0)
				continue;  /* we have time, try to find idle */
		}

		if (tinsync(su_timeout)) {
			/*
			 * on synchronized-update draw-suspension: don't reset
			 * drawing so that we draw ASAP once we can (just after
			 * ESU). it won't be too soon because we already can
			 * draw now but we skip. we set timeout > 0 to draw on
			 * SU-timeout even without new content.
			 */
			timeout = minlatency;
			continue;
		}

		/* idle detected or maxlatency exhausted -> draw */
		timeout = -1;
		if (blinktimeout && tattrset(ATTR_BLINK)) {
			timeout = blinktimeout - TIMEDIFF(now, lastblink);
			if (timeout <= 0) {
				if (-timeout > blinktimeout) /* start visible */
					win.mode |= MODE_BLINK;
				win.mode ^= MODE_BLINK;
				tsetdirtattr(ATTR_BLINK);
				lastblink = now;
				timeout = blinktimeout;
			}
		}

		draw();
		XFlush(xw.dpy);
		drawing = 0;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movl 0xfab7(%rip), %eax      # 0x219c8
movl %eax, -0xc4(%rbp)
movl 0xfaaf(%rip), %eax      # 0x219cc
movl %eax, -0xc8(%rbp)
movq 0xf986(%rip), %rdi      # 0x218b0
callq 0x62b0
movl %eax, -0x14c(%rbp)
movq 0xf974(%rip), %rdi      # 0x218b0
leaq -0xc0(%rbp), %rsi
callq 0x6420
leaq -0xc0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6350
cmpl $0x0, %eax
je 0x11f5f
jmp 0x11f82
cmpl $0x16, -0xc0(%rbp)
jne 0x11f80
movl -0x88(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0xc8(%rbp)
jmp 0x11f82
cmpl $0x13, -0xc0(%rbp)
jne 0x11f35
movq 0xfa7e(%rip), %rdi      # 0x21a10
movq 0xa07f(%rip), %rsi      # 0x1c018
movq 0xfa68(%rip), %rdx      # 0x21a08
movq 0xfa79(%rip), %rcx      # 0x21a20
callq 0x78c0
movl %eax, -0x150(%rbp)
movl -0xc4(%rbp), %edi
movl -0xc8(%rbp), %esi
callq 0x134c0
movsd 0x4fa5(%rip), %xmm0     # 0x16f70
movsd %xmm0, -0x1a8(%rbp)
movl $0x0, -0x158(%rbp)
movq $0x0, -0x1b8(%rbp)
movq $0x0, -0x1b0(%rbp)
movq -0x1b8(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x1b0(%rbp), %rax
movq %rax, -0x188(%rbp)
jmp 0x12011
leaq -0x148(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movl $0x0, -0x1bc(%rbp)
movl -0x1bc(%rbp), %eax
cmpq $0x10, %rax
jae 0x1205b
movq -0x1c8(%rbp), %rax
movl -0x1bc(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0x1bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1bc(%rbp)
jmp 0x12029
jmp 0x1205d
movl -0x150(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl -0x150(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x148(%rbp,%rax,8), %rcx
movq %rcx, -0x148(%rbp,%rax,8)
movl -0x14c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movl -0x14c(%rbp), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0x148(%rbp,%rax,8), %rcx
movq %rcx, -0x148(%rbp,%rax,8)
movq 0xf7d2(%rip), %rdi      # 0x218b0
callq 0x6990
cmpl $0x0, %eax
jne 0x120f4
movb $0x0, %al
callq 0x8050
cmpl $0x0, %eax
je 0x120ff
xorps %xmm0, %xmm0
movsd %xmm0, -0x1a8(%rbp)
movsd -0x1a8(%rbp), %xmm0
movsd 0x4e71(%rip), %xmm1     # 0x16f80
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x168(%rbp)
movsd -0x1a8(%rbp), %xmm0
cvtsi2sdq -0x168(%rbp), %xmm1
movsd 0x4e40(%rip), %xmm2     # 0x16f78
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x3ec0(%rip), %xmm0     # 0x16008
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x160(%rbp)
movsd -0x1a8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x12179
leaq -0x168(%rbp), %rax
movq %rax, -0x1d8(%rbp)
jmp 0x12184
xorl %eax, %eax
movq %rax, -0x1d8(%rbp)
jmp 0x12184
movq -0x1d8(%rbp), %rax
movq %rax, -0x170(%rbp)
movl -0x14c(%rbp), %eax
cmpl -0x150(%rbp), %eax
jge 0x121ae
movl -0x150(%rbp), %eax
movl %eax, -0x1dc(%rbp)
jmp 0x121ba
movl -0x14c(%rbp), %eax
movl %eax, -0x1dc(%rbp)
movl -0x1dc(%rbp), %edi
addl $0x1, %edi
movq -0x170(%rbp), %r8
leaq -0x148(%rbp), %rsi
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rdx
movq %r9, %rcx
callq 0x6310
cmpl $0x0, %eax
jge 0x12212
callq 0x65d0
cmpl $0x4, (%rax)
jne 0x121f5
jmp 0x1200f
callq 0x65d0
movl (%rax), %edi
callq 0x6470
movq %rax, %rsi
leaq 0x4907(%rip), %rdi      # 0x16b12
movb $0x0, %al
callq 0x6bb0
movl $0x1, %edi
leaq -0x180(%rbp), %rsi
callq 0x6130
movl -0x150(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x148(%rbp,%rax,8), %rax
movq %rax, -0x1e8(%rbp)
movl -0x150(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq -0x1e8(%rbp), %rcx
andq %rax, %rcx
movb $0x1, %al
cmpq $0x0, %rcx
movb %al, -0x1dd(%rbp)
jne 0x12287
movb $0x0, %al
callq 0x8050
cmpl $0x0, %eax
setne %al
movb %al, -0x1dd(%rbp)
movb -0x1dd(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1cc(%rbp)
cmpl $0x0, -0x1cc(%rbp)
je 0x122a6
callq 0x8060
movl $0x0, -0x154(%rbp)
movq 0xf5f9(%rip), %rdi      # 0x218b0
callq 0x6990
cmpl $0x0, %eax
je 0x12324
movl $0x1, -0x154(%rbp)
movq 0xf5de(%rip), %rdi      # 0x218b0
leaq -0xc0(%rbp), %rsi
callq 0x6420
leaq -0xc0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x6350
cmpl $0x0, %eax
je 0x122f5
jmp 0x122b0
movslq -0xc0(%rbp), %rcx
leaq 0xa0ed(%rip), %rax      # 0x1c3f0
cmpq $0x0, (%rax,%rcx,8)
je 0x12322
movslq -0xc0(%rbp), %rcx
leaq -0xc0(%rbp), %rdi
leaq 0xa0d1(%rip), %rax      # 0x1c3f0
callq *(%rax,%rcx,8)
jmp 0x122b0
cmpl $0x0, -0x1cc(%rbp)
jne 0x1233a
cmpl $0x0, -0x154(%rbp)
je 0x123e2
cmpl $0x0, -0x158(%rbp)
jne 0x12369
movq -0x180(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x198(%rbp)
movl $0x1, -0x158(%rbp)
movsd 0x9cb7(%rip), %xmm0     # 0x1c028
movq -0x180(%rbp), %rax
subq -0x1a0(%rbp), %rax
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
cvtsi2sd %rax, %xmm1
movq -0x178(%rbp), %rax
subq -0x198(%rbp), %rax
cvtsi2sd %rax, %xmm2
movsd 0x3c62(%rip), %xmm3     # 0x16008
divsd %xmm3, %xmm2
addsd %xmm2, %xmm1
subsd %xmm1, %xmm0
divsd 0x9c6e(%rip), %xmm0     # 0x1c028
mulsd 0x9c5e(%rip), %xmm0     # 0x1c020
movsd %xmm0, -0x1a8(%rbp)
movsd -0x1a8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x123e0
jmp 0x1200f
jmp 0x123e2
movl 0xa128(%rip), %edi      # 0x1c510
callq 0x6ad0
cmpl $0x0, %eax
je 0x12407
movsd 0x9c26(%rip), %xmm0     # 0x1c020
movsd %xmm0, -0x1a8(%rbp)
jmp 0x1200f
movsd 0x4b61(%rip), %xmm0     # 0x16f70
movsd %xmm0, -0x1a8(%rbp)
cmpl $0x0, 0x9c12(%rip)      # 0x1c030
je 0x12508
movl $0x10, %edi
callq 0x8810
cmpl $0x0, %eax
je 0x12508
movl 0x9bf3(%rip), %eax      # 0x1c030
cvtsi2sd %rax, %xmm0
movq -0x180(%rbp), %rax
subq -0x190(%rbp), %rax
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
cvtsi2sd %rax, %xmm1
movq -0x178(%rbp), %rax
subq -0x188(%rbp), %rax
cvtsi2sd %rax, %xmm2
movsd 0x3b91(%rip), %xmm3     # 0x16008
divsd %xmm3, %xmm2
addsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x1a8(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x1a8(%rbp), %xmm0
jb 0x12506
movaps 0x4b01(%rip), %xmm1     # 0x16fa0
movsd -0x1a8(%rbp), %xmm0
pxor %xmm1, %xmm0
movl 0x9b7f(%rip), %eax      # 0x1c030
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x124cd
movl 0xf516(%rip), %eax      # 0x219d8
orl $0x800, %eax            # imm = 0x800
movl %eax, 0xf50b(%rip)      # 0x219d8
movb 0xf506(%rip), %al       # 0x219d9
xorb $0x8, %al
movb %al, 0xf4fe(%rip)       # 0x219d9
movl $0x10, %edi
callq 0x88a0
movups -0x180(%rbp), %xmm0
movaps %xmm0, -0x190(%rbp)
movl 0x9b37(%rip), %eax      # 0x1c030
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x1a8(%rbp)
jmp 0x12508
callq 0xa1c0
movq 0xf39c(%rip), %rdi      # 0x218b0
callq 0x65e0
movl $0x0, -0x158(%rbp)
jmp 0x1200f
nopl (%rax,%rax)