// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
movq %rdi, -0x18(%rbp)
movq $0x0, -0x68(%rbp)
movq 0xf7cf(%rip), %rdi      # 0x22590
leaq 0x2bc9(%rip), %rsi      # 0x15991
xorl %edx, %edx
callq 0x6870
movq %rax, -0x60(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1f, (%rax)
jne 0x12df2
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x12e09
movq -0x18(%rbp), %rax
cmpl $0x1c, (%rax)
jne 0x12e07
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x12e09
cmpq $0x0, -0x68(%rbp)
jne 0x12e15
jmp 0x1305a
jmp 0x12e17
movq 0xf772(%rip), %rdi      # 0x22590
movq 0xf77b(%rip), %rsi      # 0x225a0
movq -0x68(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x800, %r8d            # imm = 0x800
xorl %r9d, %r9d
xorl %eax, %eax
leaq -0x58(%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 0x6200
cmpl $0x0, %eax
je 0x12e94
movq 0x6172(%rip), %rax      # 0x18ff0
movq (%rax), %rdi
leaq 0x2b0e(%rip), %rsi      # 0x15996
movb $0x0, %al
callq 0x69d0
jmp 0x1305a
movq -0x18(%rbp), %rax
cmpl $0x1c, (%rax)
jne 0x12ee5
cmpq $0x0, -0x20(%rbp)
jne 0x12ee5
cmpq $0x0, -0x30(%rbp)
jne 0x12ee5
movq 0xf7a6(%rip), %rax      # 0x22658
andq $-0x400001, %rax        # imm = 0xFFBFFFFF
movq %rax, 0xf799(%rip)      # 0x22658
movq 0xf6ca(%rip), %rdi      # 0x22590
movq 0xf6d3(%rip), %rsi      # 0x225a0
movl $0x800, %edx            # imm = 0x800
leaq 0xf6b7(%rip), %rcx      # 0x22590
addq $0x80, %rcx
callq 0x6aa0
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jne 0x12f48
movq 0xf762(%rip), %rax      # 0x22658
orq $0x400000, %rax         # imm = 0x400000
movq %rax, 0xf755(%rip)      # 0x22658
movq 0xf686(%rip), %rdi      # 0x22590
movq 0xf68f(%rip), %rsi      # 0x225a0
movl $0x800, %edx            # imm = 0x800
leaq 0xf673(%rip), %rcx      # 0x22590
addq $0x80, %rcx
callq 0x6aa0
movq 0xf660(%rip), %rdi      # 0x22590
movq 0xf669(%rip), %rsi      # 0x225a0
movq -0x68(%rbp), %rax
movslq %eax, %rdx
callq 0x6400
jmp 0x13035
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 0x6130
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x12fa2
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x50(%rbp)
movb $0xd, (%rax)
jmp 0x12f6b
movl 0xf72c(%rip), %eax      # 0x226d4
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x12fcc
cmpq $0x0, -0x28(%rbp)
jne 0x12fcc
leaq 0x29f3(%rip), %rdi      # 0x159b3
movl $0x6, %esi
xorl %edx, %edx
callq 0x8350
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movslq -0x34(%rbp), %rax
imulq %rax, %rsi
shrq $0x3, %rsi
movl $0x1, %edx
callq 0x8350
movl 0xf6e4(%rip), %eax      # 0x226d4
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0x13014
cmpq $0x0, -0x30(%rbp)
jne 0x13014
leaq 0x29b2(%rip), %rdi      # 0x159ba
movl $0x6, %esi
xorl %edx, %edx
callq 0x8350
movq -0x40(%rbp), %rdi
callq 0x6090
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 0x12e17
movq 0xf549(%rip), %rdi      # 0x22590
movq 0xf552(%rip), %rsi      # 0x225a0
movq -0x68(%rbp), %rax
movslq %eax, %rdx
callq 0x6400
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)