// File: /workspace/github_c_makefile_star2_O2/anachronic[P]st/st.c
// Function: tscrollup
void
tscrollup(int top, int bot, int n, int mode)
{
	int i, j, s;
	int alt = IS_SET(MODE_ALTSCREEN);
	int savehist = !alt && top == 0 && mode != SCROLL_NOSAVEHIST;
	Line temp;

	if (n <= 0)
		return;
	n = MIN(n, bot-top+1);

	if (savehist) {
		for (i = 0; i < n; i++) {
			term.histi = (term.histi + 1) % HISTSIZE;
			temp = term.hist[term.histi];
			for (j = 0; j < term.col; j++)
				tclearglyph(&temp[j], 1);
			term.hist[term.histi] = term.line[i];
			term.line[i] = temp;
		}
		term.histf = MIN(term.histf + n, HISTSIZE);
		s = n;
		if (term.scr) {
			j = term.scr;
			term.scr = MIN(j + n, HISTSIZE);
			s = j + n - term.scr;
		}
		if (mode != SCROLL_RESIZE)
			tfulldirt();
	} else {
		tclearregion(0, top, term.col-1, top+n-1, 1);
		tsetdirt(top+n, bot);
	}

	for (i = top; i <= bot-n; i++) {
		temp = term.line[i];
		term.line[i] = term.line[i+n];
		term.line[i+n] = temp;
	}

	if (sel.ob.x != -1 && sel.alt == alt) {
		if (!savehist) {
			selscroll(top, bot, -n);
		} else if (s > 0) {
			selmove(-s);
			if (-term.scr + sel.nb.y < -term.histf)
				selremove();
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x122f8(%rip), %r12d    # 0x1c7cc
shrl $0x2, %r12d
andl $0x1, %r12d
movl %r12d, %eax
orl %edi, %eax
sete %al
testl %ecx, %ecx
setne %r13b
testl %edx, %edx
jle 0xa6a3
movl %edi, %r14d
andb %al, %r13b
movl %esi, %eax
subl %edi, %eax
leal 0x1(%rax), %r15d
cmpl %edx, %eax
cmovgel %edx, %r15d
testb %r13b, %r13b
movl %esi, %ebx
je 0xa5ab
movl %ebx, 0x4(%rsp)
movl 0xe3d9(%rip), %esi      # 0x188f4
xorl %edi, %edi
testl %esi, %esi
cmovlel %edi, %esi
testl %r15d, %r15d
movl $0x0, %r8d
cmovgl %r15d, %r8d
movl 0x1224b(%rip), %eax     # 0x1c780
shlq $0x4, %rsi
movl $0x7d0, %r9d            # imm = 0x7D0
leaq 0xe3aa(%rip), %r10      # 0x188f0
cmpq %r8, %rdi
je 0xa5d2
incl %eax
cltd
idivl %r9d
movl %edx, %eax
movl %edx, 0x12223(%rip)     # 0x1c780
movslq %edx, %r11
movq 0x10(%r10,%r11,8), %rdx
xorl %ebp, %ebp
cmpq %rbp, %rsi
je 0xa58b
movq 0x12235(%rip), %rbx     # 0x1c7a8
movq %rbx, 0x8(%rdx,%rbp)
andw $0x0, 0x4(%rdx,%rbp)
movl $0x20, (%rdx,%rbp)
addq $0x10, %rbp
jmp 0xa567
movq 0xe366(%rip), %rbx      # 0x188f8
movq (%rbx,%rdi,8), %rbx
movq %rbx, 0x10(%r10,%r11,8)
movq 0xe356(%rip), %r11      # 0x188f8
movq %rdx, (%r11,%rdi,8)
incq %rdi
jmp 0xa546
movl 0xe343(%rip), %edx      # 0x188f4
decl %edx
leal (%r15,%r14), %ebp
leal (%r15,%r14), %ecx
decl %ecx
xorl %edi, %edi
movl %r14d, %esi
callq 0xa40f
movl %ebp, %edi
movl %ebx, %esi
callq 0x5ec9
jmp 0xa618
movl 0x121ac(%rip), %edx     # 0x1c784
addl %r15d, %edx
movl $0x7d0, %eax            # imm = 0x7D0
cmpl %eax, %edx
cmovgel %eax, %edx
movl %edx, 0x12199(%rip)     # 0x1c784
movl 0x12197(%rip), %edx     # 0x1c788
movl %r15d, %ebp
testl %edx, %edx
je 0xa60a
addl %r15d, %edx
cmpl %eax, %edx
cmovll %edx, %eax
movl %eax, 0x12182(%rip)     # 0x1c788
subl %eax, %edx
movl %edx, %ebp
cmpl $-0x1, %ecx
je 0xa614
callq 0x700e
movl 0x4(%rsp), %ebx
movl %ebx, %ecx
subl %r15d, %ecx
movslq %r14d, %rax
movslq %ecx, %rcx
movslq %r15d, %rdx
shlq $0x3, %rdx
cmpq %rcx, %rax
jg 0xa659
movq 0xe2c2(%rip), %rsi      # 0x188f8
leaq (%rsi,%rax,8), %rdi
movq (%rsi,%rax,8), %r8
movq (%rdx,%rdi), %rdi
movq %rdi, (%rsi,%rax,8)
movq 0xe2ab(%rip), %rsi      # 0x188f8
addq %rdx, %rsi
movq %r8, (%rsi,%rax,8)
incq %rax
jmp 0xa62a
cmpl $-0x1, 0xe27c(%rip)     # 0x188dc
je 0xa6a3
cmpl %r12d, 0xe283(%rip)     # 0x188ec
jne 0xa6a3
testb %r13b, %r13b
je 0xa6b2
testl %ebp, %ebp
jle 0xa6a3
negl %ebp
movl %ebp, %edi
callq 0x6ff5
movl 0xe24d(%rip), %eax      # 0x188d0
subl 0x120ff(%rip), %eax     # 0x1c788
xorl %ecx, %ecx
subl 0x120f3(%rip), %ecx     # 0x1c784
cmpl %ecx, %eax
jge 0xa6a3
andl $0x0, 0xe224(%rip)      # 0x188c0
orl $-0x1, 0xe239(%rip)     # 0x188dc
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
negl %r15d
movl %r14d, %edi
movl %ebx, %esi
movl %r15d, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xab71