// File: /workspace/github_c_makefile_star2_O1/uobikiemukot[P]yaft/./terminal.h
// Function: scroll
void scroll(struct terminal_t *term, int from, int to, int offset)
{
	int abs_offset, scroll_lines;

	if (offset == 0 || from >= to)
		return;

	logging(DEBUG, "scroll from:%d to:%d offset:%d\n", from, to, offset);

	for (int y = from; y <= to; y++)
		term->line_dirty[y] = true;

	abs_offset = abs(offset);
	scroll_lines = (to - from + 1) - abs_offset;

	if (offset > 0) { /* scroll down */
		for (int y = from; y < from + scroll_lines; y++)
			swap_lines(term, y, y + offset);
		for (int y = (to - offset + 1); y <= to; y++)
			for (int x = 0; x < term->cols; x++)
				erase_cell(term, y, x);
	}
	else {            /* scroll up */
		for (int y = to; y >= from + abs_offset; y--)
			swap_lines(term, y, y - abs_offset);
		for (int y = from; y < from + abs_offset; y++)
			for (int x = 0; x < term->cols; x++)
				erase_cell(term, y, x);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %ebp
movl %edx, %r15d
testl %ecx, %ecx
sete %al
subl %esi, %edx
setle %cl
orb %al, %cl
jne 0x3fe5
movl %esi, %r14d
movq %rdi, %rbx
movslq %esi, %r12
movq 0x28(%rdi), %rdi
addq %r12, %rdi
incq %rdx
movl $0x1, %esi
callq 0x2130
movl %ebp, %edx
negl %edx
cmovsl %ebp, %edx
leal (%rdx,%r14), %eax
testl %ebp, %ebp
jle 0x3f2f
leal (%r14,%r15), %edx
subl %eax, %edx
incl %edx
cmpl %r14d, %edx
jle 0x3ebd
movslq %r14d, %rax
movl %ebp, %ecx
movslq %edx, %rdx
addq %rax, %rcx
movq 0x18(%rbx), %rsi
movq (%rsi,%rax,8), %rdi
movq (%rsi,%rcx,8), %r8
movq %r8, (%rsi,%rax,8)
movq 0x18(%rbx), %rsi
movq %rdi, (%rsi,%rcx,8)
incq %rax
incq %rcx
cmpq %rdx, %rax
jl 0x3e9a
movslq %r15d, %rax
subl %ebp, %r15d
movslq %r15d, %rcx
movabsq $0x100000000, %rdx      # imm = 0x100000000
incq %rcx
cmpl $0x0, 0xc(%rbx)
jle 0x3f25
movl $0x14, %esi
xorl %edi, %edi
movq 0x18(%rbx), %r8
movq (%r8,%rcx,8), %r8
movq 0x588(%rbx), %r9
movq %r9, -0x14(%r8,%rsi)
movzwl 0x4c(%rbx), %r9d
movw %r9w, -0xc(%r8,%rsi)
movq %rdx, -0x8(%r8,%rsi)
movb $0x0, (%r8,%rsi)
movq 0x28(%rbx), %r8
movb $0x1, (%r8,%rcx)
incq %rdi
movslq 0xc(%rbx), %r8
addq $0x218, %rsi            # imm = 0x218
cmpq %r8, %rdi
jl 0x3ee0
cmpq %rax, %rcx
jl 0x3ed0
jmp 0x3fe5
cmpl %r15d, %eax
jg 0x3f71
movslq %r15d, %rcx
movl %edx, %edx
movslq %eax, %rsi
incq %rcx
shlq $0x3, %rdx
negq %rdx
movq 0x18(%rbx), %rdi
leaq (%rdi,%rcx,8), %r8
movq -0x8(%rdi,%rcx,8), %r9
movq -0x8(%rdx,%r8), %r8
movq %r8, -0x8(%rdi,%rcx,8)
movq 0x18(%rbx), %rdi
addq %rdx, %rdi
movq %r9, -0x8(%rdi,%rcx,8)
decq %rcx
cmpq %rsi, %rcx
jg 0x3f46
cmpl %r14d, %eax
jle 0x3fe5
movl %ebp, %eax
negl %eax
cmovsl %ebp, %eax
addl %r14d, %eax
cltq
movabsq $0x100000000, %rcx      # imm = 0x100000000
cmpl $0x0, 0xc(%rbx)
jle 0x3fdd
movl $0x14, %edx
xorl %esi, %esi
movq 0x18(%rbx), %rdi
movq (%rdi,%r12,8), %rdi
movq 0x588(%rbx), %r8
movq %r8, -0x14(%rdi,%rdx)
movzwl 0x4c(%rbx), %r8d
movw %r8w, -0xc(%rdi,%rdx)
movq %rcx, -0x8(%rdi,%rdx)
movb $0x0, (%rdi,%rdx)
movq 0x28(%rbx), %rdi
movb $0x1, (%rdi,%r12)
incq %rsi
movslq 0xc(%rbx), %rdi
addq $0x218, %rdx            # imm = 0x218
cmpq %rdi, %rsi
jl 0x3f99
incq %r12
cmpq %rax, %r12
jne 0x3f8c
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq