// File: /workspace/github_c_makefile_star2_O3/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 0x11a53(%rip), %r12d    # 0x1c7bc
shrl $0x2, %r12d
andl $0x1, %r12d
movl %r12d, %eax
orl %edi, %eax
sete %al
testl %ecx, %ecx
setne %r13b
testl %edx, %edx
jle 0xaf88
movl %esi, %ebx
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
je 0xaebd
testl %r15d, %r15d
jle 0xae56
movl %ebx, 0x4(%rsp)
movl 0x119b7(%rip), %eax     # 0x1c770
movl 0xdb25(%rip), %edx      # 0x188e4
movl %r15d, %esi
movq %rdx, %rdi
shlq $0x4, %rdi
xorl %r8d, %r8d
leaq 0xdb0d(%rip), %r9       # 0x188e0
incl %eax
cltq
imulq $0x10624dd3, %rax, %r10 # imm = 0x10624DD3
movq %r10, %r11
shrq $0x3f, %r11
sarq $0x27, %r10
addl %r11d, %r10d
imull $0x7d0, %r10d, %r10d    # imm = 0x7D0
subl %r10d, %eax
movslq %eax, %r11
movq 0x10(%r9,%r11,8), %r10
testl %edx, %edx
jle 0xae29
xorl %ebp, %ebp
movq 0x1198d(%rip), %rbx     # 0x1c798
movq %rbx, 0x8(%r10,%rbp)
movw $0x0, 0x4(%r10,%rbp)
movl $0x20, (%r10,%rbp)
addq $0x10, %rbp
cmpq %rbp, %rdi
jne 0xae04
movq 0xdab8(%rip), %rbx      # 0x188e8
movq (%rbx,%r8,8), %rbx
movq %rbx, 0x10(%r9,%r11,8)
movq 0xdaa8(%rip), %r11      # 0x188e8
movq %r10, (%r11,%r8,8)
incq %r8
cmpq %rsi, %r8
jne 0xadd3
movl %eax, 0x1191e(%rip)     # 0x1c770
movl 0x4(%rsp), %ebx
movl 0x11918(%rip), %eax     # 0x1c774
addl %r15d, %eax
movl $0x7d0, %edx            # imm = 0x7D0
cmpl %edx, %eax
cmovgel %edx, %eax
movl %eax, 0x11905(%rip)     # 0x1c774
movl 0x11903(%rip), %esi     # 0x1c778
movl %r15d, %eax
testl %esi, %esi
je 0xae8e
addl %r15d, %esi
cmpl %edx, %esi
cmovll %esi, %edx
movl %edx, 0x118ee(%rip)     # 0x1c778
subl %edx, %esi
movl %esi, %eax
cmpl $-0x1, %ecx
je 0xaee2
cmpl $0x0, 0xda46(%rip)      # 0x188e0
jle 0xaee2
movq 0x118e5(%rip), %rcx     # 0x1c788
xorl %edx, %edx
movl $0x1, (%rcx,%rdx,4)
incq %rdx
movslq 0xda2a(%rip), %rsi      # 0x188e0
cmpq %rsi, %rdx
jl 0xaea5
jmp 0xaee2
movl 0xda21(%rip), %edx      # 0x188e4
decl %edx
leal (%r15,%r14), %ebp
leal (%r15,%r14), %ecx
decl %ecx
xorl %edi, %edi
movl %r14d, %esi
callq 0xac9e
movl %ebp, %edi
movl %ebx, %esi
callq 0x641b
movl %ebx, %ecx
subl %r15d, %ecx
cmpl %r14d, %ecx
jl 0xaf27
movslq %r14d, %rcx
movslq %r15d, %rdx
addq %rcx, %rdx
movl %ebx, %esi
notl %esi
addl %r15d, %esi
addl %r14d, %esi
movq 0xd9e2(%rip), %rdi      # 0x188e8
movq (%rdi,%rcx,8), %r8
movq (%rdi,%rdx,8), %r9
movq %r9, (%rdi,%rcx,8)
movq 0xd9cf(%rip), %rdi      # 0x188e8
movq %r8, (%rdi,%rdx,8)
incq %rcx
incq %rdx
incl %esi
jne 0xaeff
cmpl $-0x1, 0xd99e(%rip)     # 0x188cc
je 0xaf88
cmpl %r12d, 0xd9a5(%rip)     # 0x188dc
jne 0xaf88
testb %r13b, %r13b
je 0xaf97
testl %eax, %eax
jle 0xaf88
subl %eax, 0xd988(%rip)      # 0x188d0
movl 0xd972(%rip), %ecx      # 0x188c0
subl %eax, %ecx
movl %ecx, 0xd96a(%rip)      # 0x188c0
subl %eax, 0xd97c(%rip)      # 0x188d8
subl %eax, 0xd966(%rip)      # 0x188c8
subl 0x11810(%rip), %ecx     # 0x1c778
xorl %eax, %eax
subl 0x11804(%rip), %eax     # 0x1c774
cmpl %eax, %ecx
jge 0xaf88
movl $0x0, 0xd932(%rip)      # 0x188b0
movl $0xffffffff, 0xd944(%rip) # imm = 0xFFFFFFFF
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 0xb802