// File: /workspace/github_c_makefile_star2_O3/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 0x401d
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 0x3f66
leal (%r14,%r15), %ecx
subl %eax, %ecx
incl %ecx
cmpl %r14d, %ecx
jle 0x3ef4
movl %ebp, %eax
movslq %ecx, %rcx
addq %r12, %rax
movq 0x18(%rbx), %rdx
movq (%rdx,%r12,8), %rsi
movq (%rdx,%rax,8), %rdi
movq %rdi, (%rdx,%r12,8)
movq 0x18(%rbx), %rdx
movq %rsi, (%rdx,%rax,8)
incq %r12
incq %rax
cmpq %rcx, %r12
jl 0x3ed1
movslq %r15d, %rax
subl %ebp, %r15d
movslq %r15d, %rcx
movl 0xc(%rbx), %esi
movabsq $0x100000000, %rdx      # imm = 0x100000000
incq %rcx
testl %esi, %esi
jle 0x3f5c
movl $0x14, %edi
xorl %r8d, %r8d
movq 0x18(%rbx), %rsi
movq (%rsi,%rcx,8), %rsi
movq 0x588(%rbx), %r9
movq %r9, -0x14(%rsi,%rdi)
movzwl 0x4c(%rbx), %r9d
movw %r9w, -0xc(%rsi,%rdi)
movq %rdx, -0x8(%rsi,%rdi)
movb $0x0, (%rsi,%rdi)
movq 0x28(%rbx), %rsi
movb $0x1, (%rsi,%rcx)
incq %r8
movslq 0xc(%rbx), %rsi
addq $0x218, %rdi            # imm = 0x218
cmpq %rsi, %r8
jl 0x3f19
cmpq %rax, %rcx
jl 0x3f0a
jmp 0x401d
cmpl %r15d, %eax
jg 0x3fa8
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 0x3f7d
cmpl %r14d, %eax
jle 0x401d
movl %ebp, %eax
negl %eax
cmovsl %ebp, %eax
addl %r14d, %eax
cltq
movl 0xc(%rbx), %edx
movabsq $0x100000000, %rcx      # imm = 0x100000000
testl %edx, %edx
jle 0x4015
movl $0x14, %esi
xorl %edi, %edi
movq 0x18(%rbx), %rdx
movq (%rdx,%r12,8), %rdx
movq 0x588(%rbx), %r8
movq %r8, -0x14(%rdx,%rsi)
movzwl 0x4c(%rbx), %r8d
movw %r8w, -0xc(%rdx,%rsi)
movq %rcx, -0x8(%rdx,%rsi)
movb $0x0, (%rdx,%rsi)
movq 0x28(%rbx), %rdx
movb $0x1, (%rdx,%r12)
incq %rdi
movslq 0xc(%rbx), %rdx
addq $0x218, %rsi            # imm = 0x218
cmpq %rdx, %rdi
jl 0x3fd1
incq %r12
cmpq %rax, %r12
jne 0x3fc6
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq