// File: /workspace/github_c_makefile_star2_O0/odknt[P]st/st.c
// Function: getsel
char *
getsel(void)
{
	char *str, *ptr;
	int y, bufsize, lastx, linelen;
	const Glyph *gp, *last;

	if (sel.ob.x == -1)
		return NULL;

	bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZ;
	ptr = str = xmalloc(bufsize);

	/* append every set & selected glyph to the selection */
	for (y = sel.nb.y; y <= sel.ne.y; y++) {
		if ((linelen = tlinelen(y)) == 0) {
			*ptr++ = '\n';
			continue;
		}

		if (sel.type == SEL_RECTANGULAR) {
			gp = &TLINE(y)[sel.nb.x];
			lastx = sel.ne.x;
		} else {
			gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
			lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
		}
		last = &TLINE(y)[MIN(lastx, linelen-1)];
		while (last >= gp && last->u == ' ')
			--last;

		for ( ; gp <= last; ++gp) {
			if (gp->mode & ATTR_WDUMMY)
				continue;

			ptr += utf8encode(gp->u, ptr);
		}

		/*
		 * Copy and pasting of line endings is inconsistent
		 * in the inconsistent terminal and GUI world.
		 * The best solution seems like to produce '\n' when
		 * something is copied from st and convert '\n' to
		 * '\r', when something to be pasted is received by
		 * st.
		 * FIXME: Fix the computer world.
		 */
		if ((y < sel.ne.y || lastx >= linelen) &&
		    (!(last->mode & ATTR_WRAP) || sel.type == SEL_RECTANGULAR))
			*ptr++ = '\n';
	}
	*ptr = 0;
	return str;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
cmpl $-0x1, 0x14d1d(%rip)    # 0x1c1cc
jne 0x74be
movq $0x0, -0x8(%rbp)
jmp 0x77de
movl 0x14d20(%rip), %eax     # 0x1c1e4
addl $0x1, %eax
movl 0x14cfb(%rip), %ecx     # 0x1c1c8
subl 0x14ced(%rip), %ecx     # 0x1c1c0
addl $0x1, %ecx
imull %ecx, %eax
shll $0x2, %eax
movl %eax, -0x20(%rbp)
movslq -0x20(%rbp), %rdi
callq 0x6bd0
movq %rax, -0x10(%rbp)
movq %rax, -0x18(%rbp)
movl 0x14cca(%rip), %eax     # 0x1c1c0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x14cc6(%rip), %eax     # 0x1c1c8
jg 0x77cf
movl -0x1c(%rbp), %edi
callq 0x77f0
movl %eax, -0x28(%rbp)
cmpl $0x0, %eax
jne 0x752f
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movb $0xa, (%rax)
jmp 0x77c1
cmpl $0x2, 0x14c7e(%rip)     # 0x1c1b4
jne 0x75b6
movl -0x1c(%rbp), %eax
cmpl 0x18b3b(%rip), %eax     # 0x2007c
jge 0x7577
movl -0x1c(%rbp), %eax
addl 0x18b2c(%rip), %eax     # 0x20078
subl 0x18b2a(%rip), %eax     # 0x2007c
addl $0x7d0, %eax            # imm = 0x7D0
addl $0x1, %eax
movl $0x7d0, %ecx            # imm = 0x7D0
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x14c74(%rip), %rax     # 0x1c1e0
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
jmp 0x7592
movq 0x14c6a(%rip), %rax     # 0x1c1e8
movl -0x1c(%rbp), %ecx
subl 0x18af5(%rip), %ecx     # 0x2007c
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movslq 0x14c1f(%rip), %rcx     # 0x1c1bc
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl 0x14c16(%rip), %eax     # 0x1c1c4
movl %eax, -0x24(%rbp)
jmp 0x7672
movl -0x1c(%rbp), %eax
cmpl 0x18abd(%rip), %eax     # 0x2007c
jge 0x75f5
movl -0x1c(%rbp), %eax
addl 0x18aae(%rip), %eax     # 0x20078
subl 0x18aac(%rip), %eax     # 0x2007c
addl $0x7d0, %eax            # imm = 0x7D0
addl $0x1, %eax
movl $0x7d0, %ecx            # imm = 0x7D0
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x14bf6(%rip), %rax     # 0x1c1e0
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
jmp 0x7610
movq 0x14bec(%rip), %rax     # 0x1c1e8
movl -0x1c(%rbp), %ecx
subl 0x18a77(%rip), %ecx     # 0x2007c
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movl 0x14ba2(%rip), %eax     # 0x1c1c0
cmpl -0x1c(%rbp), %eax
jne 0x762e
movl 0x14b93(%rip), %eax     # 0x1c1bc
movl %eax, -0x54(%rbp)
jmp 0x7635
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0x7635
movq -0x50(%rbp), %rax
movl -0x54(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl 0x14b78(%rip), %eax     # 0x1c1c8
cmpl -0x1c(%rbp), %eax
jne 0x7660
movl 0x14b69(%rip), %eax     # 0x1c1c4
movl %eax, -0x58(%rbp)
jmp 0x766c
movl 0x14b7e(%rip), %eax     # 0x1c1e4
subl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x18a01(%rip), %eax     # 0x2007c
jge 0x76b1
movl -0x1c(%rbp), %eax
addl 0x189f2(%rip), %eax     # 0x20078
subl 0x189f0(%rip), %eax     # 0x2007c
addl $0x7d0, %eax            # imm = 0x7D0
addl $0x1, %eax
movl $0x7d0, %ecx            # imm = 0x7D0
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x14b3a(%rip), %rax     # 0x1c1e0
movq 0x18(%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
jmp 0x76cc
movq 0x14b30(%rip), %rax     # 0x1c1e8
movl -0x1c(%rbp), %ecx
subl 0x189bb(%rip), %ecx     # 0x2007c
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x24(%rbp), %eax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x76e9
movl -0x24(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x76f2
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq -0x68(%rbp), %rax
movl -0x6c(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
xorl %eax, %eax
cmpq -0x30(%rbp), %rcx
movb %al, -0x6d(%rbp)
jb 0x7723
movq -0x38(%rbp), %rax
cmpl $0x20, (%rax)
sete %al
movb %al, -0x6d(%rbp)
movb -0x6d(%rbp), %al
testb $0x1, %al
jne 0x772c
jmp 0x773a
movq -0x38(%rbp), %rax
addq $-0x10, %rax
movq %rax, -0x38(%rbp)
jmp 0x7707
jmp 0x773c
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
ja 0x777f
movq -0x30(%rbp), %rax
movzwl 0x4(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x775a
jmp 0x7771
movq -0x30(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rsi
callq 0x6d70
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
jmp 0x773c
movl -0x1c(%rbp), %eax
cmpl 0x14a40(%rip), %eax     # 0x1c1c8
jl 0x7792
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jl 0x77bf
movq -0x38(%rbp), %rax
movzwl 0x4(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x77ad
cmpl $0x2, 0x14a09(%rip)     # 0x1c1b4
jne 0x77bf
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movb $0xa, (%rax)
jmp 0x77c1
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x74f9
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)