// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
movq %rdi, -0x18(%rbp)
movq $0x0, -0x70(%rbp)
movq 0xb797(%rip), %rdi      # 0x1c298
leaq 0x2c9d(%rip), %rsi      # 0x137a5
xorl %edx, %edx
callq 0x5750
movq %rax, -0x68(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1f, (%rax)
jne 0x10b32
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x10b49
movq -0x18(%rbp), %rax
cmpl $0x1c, (%rax)
jne 0x10b47
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x10b49
cmpq $0x0, -0x70(%rbp)
jne 0x10b55
jmp 0x10df8
jmp 0x10b57
movq 0xb73a(%rip), %rdi      # 0x1c298
movq 0xb743(%rip), %rsi      # 0x1c2a8
movq -0x70(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x800, %r8d            # imm = 0x800
xorl %r9d, %r9d
xorl %eax, %eax
leaq -0x60(%rbp), %r14
leaq -0x34(%rbp), %rbx
leaq -0x20(%rbp), %r11
leaq -0x30(%rbp), %r10
leaq -0x40(%rbp), %rax
movq $0x0, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x51c0
cmpl $0x0, %eax
je 0x10bd4
movq 0x6432(%rip), %rax      # 0x16ff0
movq (%rax), %rdi
leaq 0x2be2(%rip), %rsi      # 0x137aa
movb $0x0, %al
callq 0x5870
jmp 0x10df8
movq -0x18(%rbp), %rax
cmpl $0x1c, (%rax)
jne 0x10c25
cmpq $0x0, -0x20(%rbp)
jne 0x10c25
cmpq $0x0, -0x30(%rbp)
jne 0x10c25
movq 0xb76e(%rip), %rax      # 0x1c360
andq $-0x400001, %rax        # imm = 0xFFBFFFFF
movq %rax, 0xb761(%rip)      # 0x1c360
movq 0xb692(%rip), %rdi      # 0x1c298
movq 0xb69b(%rip), %rsi      # 0x1c2a8
movl $0x800, %edx            # imm = 0x800
leaq 0xb67f(%rip), %rcx      # 0x1c298
addq $0x80, %rcx
callq 0x5920
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jne 0x10c88
movq 0xb72a(%rip), %rax      # 0x1c360
orq $0x400000, %rax         # imm = 0x400000
movq %rax, 0xb71d(%rip)      # 0x1c360
movq 0xb64e(%rip), %rdi      # 0x1c298
movq 0xb657(%rip), %rsi      # 0x1c2a8
movl $0x800, %edx            # imm = 0x800
leaq 0xb63b(%rip), %rcx      # 0x1c298
addq $0x80, %rcx
callq 0x5920
movq 0xb628(%rip), %rdi      # 0x1c298
movq 0xb631(%rip), %rsi      # 0x1c2a8
movq -0x70(%rbp), %rax
movslq %eax, %rdx
callq 0x5360
jmp 0x10dd3
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x34(%rbp), %rdx
imulq %rdx, %rcx
shrq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rax
subq %rax, %rdx
movl $0xa, %esi
callq 0x5120
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x10ce2
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x50(%rbp)
movb $0xd, (%rax)
jmp 0x10cab
movl 0xb6d8(%rip), %eax      # 0x1c3c0
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x10d45
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x10d3d
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x1b, %eax
je 0x10d2f
movq -0x58(%rbp), %rax
movb (%rax), %cl
movq -0x50(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x50(%rbp)
movb %cl, (%rax)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x10d02
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movl 0xb675(%rip), %eax      # 0x1c3c0
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x10d6f
cmpq $0x0, -0x28(%rbp)
jne 0x10d6f
leaq 0x2a64(%rip), %rdi      # 0x137c7
movl $0x6, %esi
xorl %edx, %edx
callq 0x6fb0
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rax
subq %rax, %rsi
movl $0x1, %edx
callq 0x6fb0
movl 0xb632(%rip), %eax      # 0x1c3c0
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x10db2
cmpq $0x0, -0x30(%rbp)
jne 0x10db2
leaq 0x2a28(%rip), %rdi      # 0x137ce
movl $0x6, %esi
xorl %edx, %edx
callq 0x6fb0
movq -0x40(%rbp), %rdi
callq 0x5090
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq %rcx, %rax
shrq $0x5, %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x30(%rbp)
ja 0x10b57
movq 0xb4b3(%rip), %rdi      # 0x1c298
movq 0xb4bc(%rip), %rsi      # 0x1c2a8
movq -0x70(%rbp), %rax
movslq %eax, %rdx
callq 0x5360
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)