// File: /workspace/github_c_makefile_star2_O1/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 0xa923(%rip), %rdi      # 0x17ca8
leaq 0x2111(%rip), %rsi      # 0xf49d
xorl %r14d, %r14d
xorl %edx, %edx
callq 0x5750
movq %rax, %r15
movl (%rbx), %eax
cmpl $0x1f, %eax
je 0xd3ac
cmpl $0x1c, %eax
jne 0xd3b5
movl $0x28, %eax
jmp 0xd3b1
movl $0x38, %eax
movq (%rbx,%rax), %r14
testq %r14, %r14
je 0xd5b2
movslq %r14d, %rax
movq %rax, 0x28(%rsp)
xorl %r13d, %r13d
leaq 0x8(%rsp), %r12
leaq 0x18(%rsp), %rbp
movq 0xa8ce(%rip), %rdi      # 0x17ca8
movq 0xa8d7(%rip), %rsi      # 0x17cb8
movl $0x800, %r8d            # imm = 0x800
movq %r14, %rdx
movq %r13, %rcx
xorl %r9d, %r9d
pushq %r12
pushq %rbp
leaq 0x30(%rsp), %rax
pushq %rax
leaq 0x2c(%rsp), %rax
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
pushq $0x0
callq 0x51c0
addq $0x30, %rsp
testl %eax, %eax
jne 0xd5c1
cmpl $0x1c, (%rbx)
jne 0xd453
cmpq $0x0, 0x20(%rsp)
jne 0xd453
cmpq $0x0, 0x18(%rsp)
jne 0xd453
andb $-0x41, 0xa93e(%rip)    # 0x17d72
movq 0xa86d(%rip), %rdi      # 0x17ca8
movq 0xa876(%rip), %rsi      # 0x17cb8
movl $0x800, %edx            # imm = 0x800
leaq 0xa8da(%rip), %rcx      # 0x17d28
callq 0x5910
cmpq %r15, 0x30(%rsp)
jne 0xd49d
orb $0x40, 0xa911(%rip)     # 0x17d72
movq 0xa840(%rip), %rdi      # 0x17ca8
movq 0xa849(%rip), %rsi      # 0x17cb8
movl $0x800, %edx            # imm = 0x800
leaq 0xa8ad(%rip), %rcx      # 0x17d28
callq 0x5910
movq 0xa821(%rip), %rdi      # 0x17ca8
movq 0xa82a(%rip), %rsi      # 0x17cb8
movq 0x28(%rsp), %rdx
callq 0x5360
jmp 0xd590
movq 0x8(%rsp), %rdi
movslq 0x14(%rsp), %rdx
imulq 0x20(%rsp), %rdx
shrq $0x3, %rdx
leaq (%rdi,%rdx), %r12
movl $0xa, %esi
callq 0x5120
testq %rax, %rax
je 0xd4d5
movb $0xd, (%rax)
incq %rax
movq %r12, %rdx
subq %rax, %rdx
movq %rax, %rdi
jmp 0xd4b5
testb $0x1, 0xa8f6(%rip)      # 0x17dd2
jne 0xd4e3
movq %r12, %rbp
jmp 0xd50a
movq 0x8(%rsp), %rax
cmpq %r12, %rax
jae 0xd507
movq %rax, %rbp
movb (%rax), %cl
cmpb $0x1b, %cl
je 0xd4fd
movb %cl, (%rbp)
incq %rbp
incq %rax
cmpq %r12, %rax
jb 0xd4f0
jmp 0xd50a
movq %rax, %rbp
testq %r13, %r13
jne 0xd531
movl 0xa8bb(%rip), %eax      # 0x17dd0
movl $0x10000, %ecx          # imm = 0x10000
andl %ecx, %eax
je 0xd531
movl $0x6, %esi
leaq 0x1f95(%rip), %rdi      # 0xf4bf
xorl %edx, %edx
callq 0x6c23
movq 0x8(%rsp), %rdi
subq %rdi, %rbp
movq %rbp, %rsi
movl $0x1, %edx
callq 0x6c23
testb $0x1, 0xa885(%rip)      # 0x17dd2
je 0xd56a
cmpq $0x0, 0x18(%rsp)
jne 0xd56a
movl $0x6, %esi
leaq 0x1f63(%rip), %rdi      # 0xf4c6
xorl %edx, %edx
callq 0x6c23
movq 0x8(%rsp), %rdi
callq 0x5090
movslq 0x14(%rsp), %rax
imulq 0x20(%rsp), %rax
shrq $0x5, %rax
addq %rax, %r13
leaq 0x8(%rsp), %r12
leaq 0x18(%rsp), %rbp
cmpq $0x0, 0x18(%rsp)
jne 0xd3d3
movq 0xa705(%rip), %rdi      # 0x17ca8
movq 0xa70e(%rip), %rsi      # 0x17cb8
movslq %r14d, %rdx
callq 0x5360
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5d8d
jmp 0xd5b2