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

	if (sel.ob.x == -1 || sel.alt != IS_SET(MODE_ALTSCREEN))
		return NULL;

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

	/* append every set & selected glyph to the selection */
	for (y = sel.nb.y; y <= sel.ne.y; y++) {
		Line line = TLINE(y);

		if ((linelen = tlinelen(line)) == 0) {
			*ptr++ = '\n';
			continue;
		}

		if (sel.type == SEL_RECTANGULAR) {
			gp = &line[sel.nb.x];
			lastx = sel.ne.x;
		} else {
			gp = &line[sel.nb.y == y ? sel.nb.x : 0];
			lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
		}
		lgp = &line[MIN(lastx, linelen-1)];

		ptr = tgetglyphs(ptr, gp, lgp);
		/*
		 * 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) &&
		    (!(lgp->mode & ATTR_WRAP) || sel.type == SEL_RECTANGULAR))
			*ptr++ = '\n';
	}
	*ptr = '\0';
	return str;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
cmpl $-0x1, 0x169cd(%rip)    # 0x1cecc
je 0x6520
movl 0x169d5(%rip), %eax     # 0x1cedc
movl 0x1a8af(%rip), %ecx     # 0x20dbc
andl $0x4, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x652d
movq $0x0, -0x8(%rbp)
jmp 0x673c
movl 0x169b1(%rip), %eax     # 0x1cee4
addl $0x1, %eax
movl 0x1698c(%rip), %ecx     # 0x1cec8
subl 0x1697e(%rip), %ecx     # 0x1cec0
addl $0x1, %ecx
imull %ecx, %eax
shll $0x2, %eax
movslq %eax, %rdi
callq 0x5a30
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movl 0x1695b(%rip), %eax     # 0x1cec0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x16957(%rip), %eax     # 0x1cec8
jg 0x672d
movl -0x1c(%rbp), %eax
cmpl 0x1a7f8(%rip), %eax     # 0x20d78
jge 0x65b6
movl 0x1a7e8(%rip), %eax     # 0x20d70
addl -0x1c(%rbp), %eax
subl 0x1a7e7(%rip), %eax     # 0x20d78
addl $0x1, %eax
addl $0x7d0, %eax            # imm = 0x7D0
movl $0x7d0, %ecx            # imm = 0x7D0
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x16935(%rip), %rax     # 0x1cee0
movq 0x10(%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
jmp 0x65d1
movq 0x1692b(%rip), %rax     # 0x1cee8
movl -0x1c(%rbp), %ecx
subl 0x1a7b2(%rip), %ecx     # 0x20d78
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x6750
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
jne 0x6601
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movb $0xa, (%rax)
jmp 0x671f
cmpl $0x2, 0x168ac(%rip)     # 0x1ceb4
jne 0x662b
movq -0x40(%rbp), %rax
movslq 0x168a7(%rip), %rcx     # 0x1cebc
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl 0x1689e(%rip), %eax     # 0x1cec4
movl %eax, -0x20(%rbp)
jmp 0x668d
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movl 0x16887(%rip), %eax     # 0x1cec0
cmpl -0x1c(%rbp), %eax
jne 0x6649
movl 0x16878(%rip), %eax     # 0x1cebc
movl %eax, -0x54(%rbp)
jmp 0x6650
xorl %eax, %eax
movl %eax, -0x54(%rbp)
jmp 0x6650
movq -0x50(%rbp), %rax
movl -0x54(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl 0x1685d(%rip), %eax     # 0x1cec8
cmpl -0x1c(%rbp), %eax
jne 0x667b
movl 0x1684e(%rip), %eax     # 0x1cec4
movl %eax, -0x58(%rbp)
jmp 0x6687
movl 0x16863(%rip), %eax     # 0x1cee4
subl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x20(%rbp), %eax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x66aa
movl -0x20(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x66b3
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x64(%rbp)
movq -0x60(%rbp), %rax
movl -0x64(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x67b0
movq %rax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x167e2(%rip), %eax     # 0x1cec8
jl 0x66f0
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x671d
movq -0x38(%rbp), %rax
movzwl 0x4(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x670b
cmpl $0x2, 0x167ab(%rip)     # 0x1ceb4
jne 0x671d
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movb $0xa, (%rax)
jmp 0x671f
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6568
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
nopw %cs:(%rax,%rax)