// File: /workspace/github_c_makefile_star2_O1/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 0x11b84(%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 0xae75
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 0xadaa
testl %r15d, %r15d
jle 0xad43
movl %ebx, 0x4(%rsp)
movl 0x11ae8(%rip), %eax     # 0x1c780
movl 0xdc56(%rip), %edx      # 0x188f4
movl %r15d, %esi
movq %rdx, %rdi
shlq $0x4, %rdi
xorl %r8d, %r8d
leaq 0xdc3e(%rip), %r9       # 0x188f0
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 0xad12
xorl %ebp, %ebp
movl 0x11abf(%rip), %ebx     # 0x1c7a8
movl %ebx, 0x8(%r10,%rbp)
movl 0x11ab8(%rip), %ebx     # 0x1c7ac
movl %ebx, 0xc(%r10,%rbp)
movw $0x0, 0x4(%r10,%rbp)
movl $0x20, (%r10,%rbp)
addq $0x10, %rbp
cmpq %rbp, %rdi
jne 0xace3
movq 0xdbdf(%rip), %rbx      # 0x188f8
movq (%rbx,%r8,8), %rbx
movq %rbx, 0x10(%r9,%r11,8)
movq 0xdbcf(%rip), %r11      # 0x188f8
movq %r10, (%r11,%r8,8)
incq %r8
cmpq %rsi, %r8
jne 0xacb2
movl %eax, 0x11a41(%rip)     # 0x1c780
movl 0x4(%rsp), %ebx
movl 0x11a3b(%rip), %eax     # 0x1c784
addl %r15d, %eax
movl $0x7d0, %edx            # imm = 0x7D0
cmpl %edx, %eax
cmovgel %edx, %eax
movl %eax, 0x11a28(%rip)     # 0x1c784
movl 0x11a26(%rip), %esi     # 0x1c788
movl %r15d, %eax
testl %esi, %esi
je 0xad7b
addl %r15d, %esi
cmpl %edx, %esi
cmovll %esi, %edx
movl %edx, 0x11a11(%rip)     # 0x1c788
subl %edx, %esi
movl %esi, %eax
cmpl $-0x1, %ecx
je 0xadcf
cmpl $0x0, 0xdb69(%rip)      # 0x188f0
jle 0xadcf
movq 0x11a08(%rip), %rcx     # 0x1c798
xorl %edx, %edx
movl $0x1, (%rcx,%rdx,4)
incq %rdx
movslq 0xdb4d(%rip), %rsi      # 0x188f0
cmpq %rsi, %rdx
jl 0xad92
jmp 0xadcf
movl 0xdb44(%rip), %edx      # 0x188f4
decl %edx
leal (%r15,%r14), %ebp
leal (%r15,%r14), %ecx
decl %ecx
xorl %edi, %edi
movl %r14d, %esi
callq 0xab72
movl %ebp, %edi
movl %ebx, %esi
callq 0x642b
movl %ebx, %ecx
subl %r15d, %ecx
cmpl %r14d, %ecx
jl 0xae14
movslq %r14d, %rcx
movslq %r15d, %rdx
addq %rcx, %rdx
movl %ebx, %esi
notl %esi
addl %r15d, %esi
addl %r14d, %esi
movq 0xdb05(%rip), %rdi      # 0x188f8
movq (%rdi,%rcx,8), %r8
movq (%rdi,%rdx,8), %r9
movq %r9, (%rdi,%rcx,8)
movq 0xdaf2(%rip), %rdi      # 0x188f8
movq %r8, (%rdi,%rdx,8)
incq %rcx
incq %rdx
incl %esi
jne 0xadec
cmpl $-0x1, 0xdac1(%rip)     # 0x188dc
je 0xae75
cmpl %r12d, 0xdac8(%rip)     # 0x188ec
jne 0xae75
testb %r13b, %r13b
je 0xae84
testl %eax, %eax
jle 0xae75
subl %eax, 0xdaab(%rip)      # 0x188e0
movl 0xda95(%rip), %ecx      # 0x188d0
subl %eax, %ecx
movl %ecx, 0xda8d(%rip)      # 0x188d0
subl %eax, 0xda9f(%rip)      # 0x188e8
subl %eax, 0xda89(%rip)      # 0x188d8
subl 0x11933(%rip), %ecx     # 0x1c788
xorl %eax, %eax
subl 0x11927(%rip), %eax     # 0x1c784
cmpl %eax, %ecx
jge 0xae75
movl $0x0, 0xda55(%rip)      # 0x188c0
movl $0xffffffff, 0xda67(%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 0xb6c9