// File: /workspace/github_c_makefile_star2_O0/doy[P]libvt100/src/screen.c
// Function: vt100_screen_set_window_size
void vt100_screen_set_window_size(VT100Screen *vt, int rows, int cols)
{
    struct vt100_loc old_size;
    int i;

    old_size.row = vt->grid->max.row;
    old_size.col = vt->grid->max.col;

    vt->grid->max.row = rows;
    vt->grid->max.col = cols;
    if (!vt->custom_scrollback_length)
        vt->scrollback_length = rows;

    if (vt->grid->max.row == 0) {
        vt->grid->max.row = 1;
    }
    if (vt->grid->max.col == 0) {
        vt->grid->max.col = 1;
    }

    if (vt->grid->max.row == old_size.row && vt->grid->max.col == old_size.col) {
        return;
    }

    if (vt->grid->cur.row >= vt->grid->max.row) {
        vt->grid->cur.row = vt->grid->max.row - 1;
    }
    if (vt->grid->cur.col > vt->grid->max.col) {
        vt->grid->cur.col = vt->grid->max.col;
    }

    vt100_screen_ensure_capacity(vt, vt->grid->max.row);

    for (i = 0; i < vt->grid->row_count; ++i) {
        vt->grid->rows[i].cells = realloc(
            vt->grid->rows[i].cells,
            vt->grid->max.col * sizeof(struct vt100_cell));
        if (old_size.col < vt->grid->max.col) {
            memset(
                &vt->grid->rows[i].cells[old_size.col], 0,
                (vt->grid->max.col - old_size.col) * sizeof(struct vt100_cell));
        }
    }

    for (i = vt->grid->row_count; i < vt->grid->max.row; ++i) {
        vt->grid->rows[i].cells = calloc(
            vt->grid->max.col, sizeof(struct vt100_cell));
    }

    if (vt->grid->row_count < vt->grid->max.row) {
        vt->grid->row_count = vt->grid->max.row;
        vt->grid->row_top = 0;
    }
    else {
        vt->grid->row_top = vt->grid->row_count - vt->grid->max.row;
    }

    vt->grid->scroll_top    = 0;
    vt->grid->scroll_bottom = vt->grid->max.row - 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x8(%rax)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rax
movw 0x49(%rax), %ax
shrw $0xe, %ax
andw $0x1, %ax
movzwl %ax, %eax
cmpl $0x0, %eax
jne 0x7b48
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x7b63
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl $0x1, 0x8(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x0, 0xc(%rax)
jne 0x7b7e
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl $0x1, 0xc(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x7ba1
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0xc(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x7ba1
jmp 0x7d9f
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jl 0x7bcc
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0xc(%rcx), %eax
jle 0x7bf6
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0xc(%rax), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %esi
callq 0x7db0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x20(%rcx), %eax
jge 0x7cca
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq 0xc(%rax), %rsi
shlq $0x5, %rsi
callq 0x35c0
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 -0x14(%rbp), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0xc(%rcx), %eax
jge 0x7cba
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movslq -0x14(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0xc(%rax), %eax
subl -0x14(%rbp), %eax
movslq %eax, %rdx
shlq $0x5, %rdx
xorl %esi, %esi
callq 0x32f0
jmp 0x7cbc
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x7c10
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x7d22
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 0x7cd7
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x20(%rax), %eax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x7d5c
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0x28(%rax)
jmp 0x7d7a
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x20(%rax), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
subl 0x8(%rax), %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl $0x0, 0x18(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x1c(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)