// File: /workspace/github_c_makefile_star2_O3/Tharre[P]st-transparency/x.c
// Function: selnotify
void
selnotify(XEvent *e)
{
	ulong nitems, ofs, rem;
	int format;
	uchar *data, *last, *repl, *readpos;
	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';
		}

		/*
		 * In bracketed paste mode, we mark the pasted data by adding
		 * escape sequences around it (see below), but we also want to
		 * prevent the pasted data from prematurely signaling an end
		 * of paste. Therefore, strip escape characters from the
		 * pasted data.
		 */
		if (IS_SET(MODE_BRCKTPASTE)) {
			readpos = data;
			repl = data;
			while (readpos < last) {
				if (*readpos != '\033')
					*repl++ = *readpos;
				readpos++;
			}
			last = repl;
		}

		if (IS_SET(MODE_BRCKTPASTE) && ofs == 0)
			ttywrite("\033[200~", 6, 0);
		ttywrite((char *)data, last - data, 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 0xa461(%rip), %rdi      # 0x17ca8
leaq 0x1c6f(%rip), %rsi      # 0xf4bd
xorl %edx, %edx
callq 0x5740
movq %rax, %r14
movl (%rbx), %eax
cmpl $0x1f, %eax
je 0xd86f
cmpl $0x1c, %eax
jne 0xda8c
movl $0x28, %eax
jmp 0xd874
movl $0x38, %eax
movq (%rbx,%rax), %r12
testq %r12, %r12
je 0xda8c
movslq %r12d, %rax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
movq %rsp, %r15
leaq 0x10(%rsp), %rbp
movq %r12, 0x28(%rsp)
movq 0xa408(%rip), %rdi      # 0x17ca8
movq 0xa411(%rip), %rsi      # 0x17cb8
movl $0x800, %r8d            # imm = 0x800
movq %r12, %rdx
movq %r13, %rcx
xorl %r9d, %r9d
pushq %r15
pushq %rbp
leaq 0x28(%rsp), %rax
pushq %rax
leaq 0x24(%rsp), %rax
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
pushq $0x0
callq 0x51c0
addq $0x30, %rsp
testl %eax, %eax
jne 0xda9b
cmpl $0x1c, (%rbx)
jne 0xd919
cmpq $0x0, 0x18(%rsp)
jne 0xd919
cmpq $0x0, 0x10(%rsp)
jne 0xd919
andb $-0x41, 0xa478(%rip)    # 0x17d72
movq 0xa3a7(%rip), %rdi      # 0x17ca8
movq 0xa3b0(%rip), %rsi      # 0x17cb8
movl $0x800, %edx            # imm = 0x800
leaq 0xa414(%rip), %rcx      # 0x17d28
callq 0x5900
cmpq %r14, 0x30(%rsp)
jne 0xd963
orb $0x40, 0xa44b(%rip)     # 0x17d72
movq 0xa37a(%rip), %rdi      # 0x17ca8
movq 0xa383(%rip), %rsi      # 0x17cb8
movl $0x800, %edx            # imm = 0x800
leaq 0xa3e7(%rip), %rcx      # 0x17d28
callq 0x5900
movq 0xa35b(%rip), %rdi      # 0x17ca8
movq 0xa364(%rip), %rsi      # 0x17cb8
movq 0x20(%rsp), %rdx
callq 0x5360
jmp 0xda68
movq %rbx, %r12
movq %r14, %rbx
movq %rbp, %r14
movq (%rsp), %rdi
movslq 0xc(%rsp), %rdx
imulq 0x18(%rsp), %rdx
shrq $0x3, %rdx
leaq (%rdi,%rdx), %rbp
movl $0xa, %esi
callq 0x5120
testq %rax, %rax
je 0xd9a3
movb $0xd, (%rax)
incq %rax
movq %rbp, %rdx
subq %rax, %rdx
movq %rax, %rdi
jmp 0xd983
testb $0x1, 0xa428(%rip)      # 0x17dd2
jne 0xd9b7
movq %rbp, %r15
movq %r14, %rbp
movq %rbx, %r14
jmp 0xda0a
movq (%rsp), %rax
movb $0x1, %cl
cmpq %rbp, %rax
jae 0xd9e5
movq %rax, %r15
movb (%rax), %cl
cmpb $0x1b, %cl
je 0xd9d2
movb %cl, (%r15)
incq %r15
incq %rax
cmpq %rbp, %rax
jb 0xd9c5
movb 0xa3f2(%rip), %cl       # 0x17dd2
andb $0x1, %cl
jmp 0xd9e8
movq %rax, %r15
testq %r13, %r13
movq %r14, %rbp
jne 0xd9b2
testb %cl, %cl
movq %rbx, %r14
je 0xda0a
movl $0x6, %esi
leaq 0x1adc(%rip), %rdi      # 0xf4df
xorl %edx, %edx
callq 0x6d10
movq %r12, %rbx
movq (%rsp), %rdi
subq %rdi, %r15
movq %r15, %rsi
movl $0x1, %edx
callq 0x6d10
testb $0x1, 0xa3aa(%rip)      # 0x17dd2
movq 0x28(%rsp), %r12
je 0xda4a
cmpq $0x0, 0x10(%rsp)
jne 0xda4a
movl $0x6, %esi
leaq 0x1aa3(%rip), %rdi      # 0xf4e6
xorl %edx, %edx
callq 0x6d10
movq (%rsp), %rdi
callq 0x5090
movslq 0xc(%rsp), %rax
imulq 0x18(%rsp), %rax
shrq $0x5, %rax
addq %rax, %r13
movq %rsp, %r15
cmpq $0x0, 0x10(%rsp)
jne 0xd899
movq 0xa22d(%rip), %rdi      # 0x17ca8
movq 0xa236(%rip), %rsi      # 0x17cb8
movq 0x20(%rsp), %rdx
callq 0x5360
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5d7d
jmp 0xda8c