// File: /workspace/github_c_makefile_star2_O3/odknt[P]st/x.c
// Function: selnotify
void
selnotify(XEvent *e)
{
	ulong nitems, ofs, rem;
	int format;
	uchar *data, *last, *repl;
	Atom type, incratom, property = None;

	incratom = XInternAtom(xw.dpy, "INCR", 0);

	ofs = 0;
	if (e->type == SelectionNotify)
		property = e->xselection.property;
	else if (e->type == PropertyNotify)
		property = e->xproperty.atom;

	if (property == None)
		return;

	do {
		if (XGetWindowProperty(xw.dpy, xw.win, property, ofs,
					BUFSIZ/4, False, AnyPropertyType,
					&type, &format, &nitems, &rem,
					&data)) {
			fprintf(stderr, "Clipboard allocation failed\n");
			return;
		}

		if (e->type == PropertyNotify && nitems == 0 && rem == 0) {
			/*
			 * If there is some PropertyNotify with no data, then
			 * this is the signal of the selection owner that all
			 * data has been transferred. We won't need to receive
			 * PropertyNotify events anymore.
			 */
			MODBIT(xw.attrs.event_mask, 0, PropertyChangeMask);
			XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask,
					&xw.attrs);
		}

		if (type == incratom) {
			/*
			 * Activate the PropertyNotify events so we receive
			 * when the selection owner does send us the next
			 * chunk of data.
			 */
			MODBIT(xw.attrs.event_mask, 1, PropertyChangeMask);
			XChangeWindowAttributes(xw.dpy, xw.win, CWEventMask,
					&xw.attrs);

			/*
			 * Deleting the property is the transfer start signal.
			 */
			XDeleteProperty(xw.dpy, xw.win, (int)property);
			continue;
		}

		/*
		 * As seen in getsel:
		 * Line endings are inconsistent in the terminal and GUI world
		 * copy and pasting. When receiving some selection data,
		 * replace all '\n' with '\r'.
		 * FIXME: Fix the computer world.
		 */
		repl = data;
		last = data + nitems * format / 8;
		while ((repl = memchr(repl, '\n', last - repl))) {
			*repl++ = '\r';
		}

		if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)
			ttywrite("\033[200~", 6, 0);
		ttywrite((char *)data, nitems * format / 8, 1);
		if (IS_SET(MODE_BRCKTPASTE) && rem == 0)
			ttywrite("\033[201~", 6, 0);
		XFree(data);
		/* number of 32-bit chunks returned */
		ofs += nitems * format / 32;
	} while (rem > 0);

	/*
	 * Deleting the property again tells the selection owner to send the
	 * next data chunk in the property.
	 */
	XDeleteProperty(xw.dpy, xw.win, (int)property);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq 0xfbec(%rip), %rdi      # 0x1f7f0
leaq 0x2b1e(%rip), %rsi      # 0x12729
xorl %edx, %edx
callq 0x6850
movq %rax, %r14
movl (%rbx), %eax
cmpl $0x1f, %eax
je 0xfc2c
cmpl $0x1c, %eax
jne 0xfe31
movl $0x28, %eax
jmp 0xfc31
movl $0x38, %eax
movq (%rbx,%rax), %r12
testq %r12, %r12
je 0xfe31
movslq %r12d, %rax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
leaq 0x18(%rsp), %r15
leaq 0x8(%rsp), %rbp
movq %r12, 0x28(%rsp)
movq 0xfb91(%rip), %rdi      # 0x1f7f0
movq 0xfb9a(%rip), %rsi      # 0x1f800
movl $0x800, %r8d            # imm = 0x800
movq %r12, %rdx
movq %r13, %rcx
xorl %r9d, %r9d
pushq %r15
pushq %rbp
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x1c(%rsp), %rax
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
pushq $0x0
callq 0x6200
addq $0x30, %rsp
testl %eax, %eax
jne 0xfe40
cmpl $0x1c, (%rbx)
jne 0xfcd8
cmpq $0x0, 0x10(%rsp)
jne 0xfcd8
cmpq $0x0, 0x8(%rsp)
jne 0xfcd8
andb $-0x41, 0xfc01(%rip)    # 0x1f8ba
movq 0xfb30(%rip), %rdi      # 0x1f7f0
movq 0xfb39(%rip), %rsi      # 0x1f800
movl $0x800, %edx            # imm = 0x800
leaq 0xfb9d(%rip), %rcx      # 0x1f870
callq 0x6a90
cmpq %r14, 0x30(%rsp)
jne 0xfd22
orb $0x40, 0xfbd4(%rip)     # 0x1f8ba
movq 0xfb03(%rip), %rdi      # 0x1f7f0
movq 0xfb0c(%rip), %rsi      # 0x1f800
movl $0x800, %edx            # imm = 0x800
leaq 0xfb70(%rip), %rcx      # 0x1f870
callq 0x6a90
movq 0xfae4(%rip), %rdi      # 0x1f7f0
movq 0xfaed(%rip), %rsi      # 0x1f800
movq 0x20(%rsp), %rdx
callq 0x6400
jmp 0xfe0d
movq %rbx, %r12
movq %r14, %rbx
movq %r15, %r14
movq 0x18(%rsp), %rbp
movslq 0x4(%rsp), %r15
imulq 0x10(%rsp), %r15
shrq $0x3, %r15
movq %rbp, %rdi
movl $0xa, %esi
movq %r15, %rdx
callq 0x6130
testq %rax, %rax
je 0xfd75
addq %r15, %rbp
movb $0xd, (%rax)
incq %rax
movq %rbp, %rdx
subq %rax, %rdx
movq %rax, %rdi
movl $0xa, %esi
callq 0x6130
testq %rax, %rax
jne 0xfd57
testq %r13, %r13
jne 0xfd9c
movl 0xfbb4(%rip), %eax      # 0x1f934
movl $0x10000, %ecx          # imm = 0x10000
andl %ecx, %eax
je 0xfd9c
movl $0x6, %esi
leaq 0x29b6(%rip), %rdi      # 0x1274b
xorl %edx, %edx
callq 0x8127
movq 0x18(%rsp), %rdi
movslq 0x4(%rsp), %rsi
imulq 0x10(%rsp), %rsi
shrq $0x3, %rsi
movl $0x1, %edx
callq 0x8127
testb $0x1, 0xfb75(%rip)      # 0x1f936
movq %r14, %r15
leaq 0x8(%rsp), %rbp
je 0xfde6
cmpq $0x0, 0x8(%rsp)
jne 0xfde6
movl $0x6, %esi
leaq 0x2973(%rip), %rdi      # 0x12752
xorl %edx, %edx
callq 0x8127
movq 0x18(%rsp), %rdi
callq 0x6090
movslq 0x4(%rsp), %rax
imulq 0x10(%rsp), %rax
shrq $0x5, %rax
addq %rax, %r13
movq %rbx, %r14
movq %r12, %rbx
movq 0x28(%rsp), %r12
cmpq $0x0, 0x8(%rsp)
jne 0xfc58
movq 0xf9d0(%rip), %rdi      # 0x1f7f0
movq 0xf9d9(%rip), %rsi      # 0x1f800
movq 0x20(%rsp), %rdx
callq 0x6400
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x6f6b
jmp 0xfe31