// File: /workspace/github_c_makefile_star2_O0/doy[P]libvt100/src/screen.c
// Function: vt100_screen_scroll_up
void vt100_screen_scroll_up(VT100Screen *vt, int count)
{
    struct vt100_row *row;
    int i;

    if (vt100_screen_scroll_region_is_active(vt) || vt->alternate) {
        int bottom = vt->grid->scroll_bottom, top = vt->grid->scroll_top;

        if (bottom - top + 1 > count) {
            for (i = 0; i < count; ++i) {
                row = vt100_screen_row_at(vt, top + i);
                free(row->cells);
            }
            row = vt100_screen_row_at(vt, top);
            memmove(
                row, row + count,
                (bottom - top + 1 - count) * sizeof(struct vt100_row));
            for (i = 0; i < count; ++i) {
                row = vt100_screen_row_at(vt, bottom - i);
                row->cells = calloc(
                    vt->grid->max.col, sizeof(struct vt100_cell));
                row->wrapped = 0;
            }
        }
        else {
            for (i = 0; i < bottom - top + 1; ++i) {
                row = vt100_screen_row_at(vt, top + i);
                memset(
                    row->cells, 0,
                    vt->grid->max.col * sizeof(struct vt100_cell));
                row->wrapped = 0;
            }
        }
    }
    else {
        int scrollback = vt->scrollback_length;
        int slack = scrollback / 10;
        int max_row_buffer_size = scrollback + slack;
        int overflow = vt->grid->row_count + count - max_row_buffer_size;

        if (overflow > 0) {
            int shift = overflow + slack;

            vt100_screen_ensure_capacity(vt, max_row_buffer_size);
            for (i = 0; i < shift; ++i) {
                free(vt->grid->rows[i].cells);
            }
            memmove(
                &vt->grid->rows[0], &vt->grid->rows[shift],
                (max_row_buffer_size - shift) * sizeof(struct vt100_row));
            for (i = scrollback - count; i < scrollback; ++i) {
                vt->grid->rows[i].cells = calloc(
                    vt->grid->max.col, sizeof(struct vt100_cell));
            }
            vt->grid->row_count = scrollback;
            vt->grid->row_top = scrollback - vt->grid->max.row;
        }
        else {
            vt100_screen_ensure_capacity(vt, vt->grid->row_count + count);
            for (i = 0; i < count; ++i) {
                row = vt100_screen_row_at(vt, i + vt->grid->max.row);
                row->cells = calloc(
                    vt->grid->max.col, sizeof(struct vt100_cell));
            }
            vt->grid->row_count += count;
            vt->grid->row_top += count;
        }
    }

    vt->dirty = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
callq 0x9a00
cmpl $0x0, %eax
jne 0x96bc
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x9823
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x18(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
subl -0x24(%rbp), %eax
addl $0x1, %eax
cmpl -0xc(%rbp), %eax
jle 0x97ba
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x9721
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
addl -0x1c(%rbp), %esi
callq 0x8a60
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3050
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x96ef
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x8a60
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0xc(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
movl -0x20(%rbp), %eax
subl -0x24(%rbp), %eax
addl $0x1, %eax
subl -0xc(%rbp), %eax
movslq %eax, %rdx
shlq $0x4, %rdx
callq 0x35f0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x97b8
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
subl -0x1c(%rbp), %esi
callq 0x8a60
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq 0xc(%rax), %rdi
movl $0x20, %esi
callq 0x33f0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movb 0x8(%rax), %cl
andb $-0x2, %cl
orb $0x0, %cl
movb %cl, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x9763
jmp 0x981e
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x20(%rbp), %ecx
subl -0x24(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x981c
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
addl -0x1c(%rbp), %esi
callq 0x8a60
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq 0xc(%rax), %rdx
shlq $0x5, %rdx
xorl %esi, %esi
callq 0x32f0
movq -0x18(%rbp), %rax
movb 0x8(%rax), %cl
andb $-0x2, %cl
orb $0x0, %cl
movb %cl, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x97c1
jmp 0x981e
jmp 0x99e2
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x20(%rax), %eax
addl -0xc(%rbp), %eax
subl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x9957
movl -0x34(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x7db0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x98ae
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x3050
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x987d
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rsi
movslq -0x38(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
movl -0x30(%rbp), %eax
subl -0x38(%rbp), %eax
movslq %eax, %rdx
shlq $0x4, %rdx
callq 0x35f0
movl -0x28(%rbp), %eax
subl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x992e
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq 0xc(%rax), %rdi
movl $0x20, %esi
callq 0x33f0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x98ea
movl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x20(%rax)
movl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
subl 0x8(%rax), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x28(%rax)
jmp 0x99e0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x20(%rax), %esi
addl -0xc(%rbp), %esi
callq 0x7db0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x99c0
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
movq -0x8(%rbp), %rax
movq (%rax), %rax
addl 0x8(%rax), %esi
callq 0x8a60
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq 0xc(%rax), %rdi
movl $0x20, %esi
callq 0x33f0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x9974
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
addl 0x20(%rax), %ecx
movl %ecx, 0x20(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
addl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
jmp 0x99e2
movq -0x8(%rbp), %rax
movw 0x49(%rax), %cx
andw $0xdfff, %cx            # imm = 0xDFFF
orw $0x2000, %cx            # imm = 0x2000
movw %cx, 0x49(%rax)
addq $0x40, %rsp
popq %rbp
retq
nop