// File: /workspace/github_c_makefile_star2_O1/neovim[P]libvterm/src/screen.c
// Function: resize
static int resize(int new_rows, int new_cols, VTermStateFields *fields, void *user)
{
  VTermScreen *screen = user;

  int altscreen_active = (screen->buffers[BUFIDX_ALTSCREEN] && screen->buffer == screen->buffers[BUFIDX_ALTSCREEN]);

  int old_rows = screen->rows;
  int old_cols = screen->cols;

  if(new_cols > old_cols) {
    /* Ensure that ->sb_buffer is large enough for a new or and old row */
    if(screen->sb_buffer)
      vterm_allocator_free(screen->vt, screen->sb_buffer);

    screen->sb_buffer = vterm_allocator_malloc(screen->vt, sizeof(VTermScreenCell) * new_cols);
  }

  resize_buffer(screen, 0, new_rows, new_cols, !altscreen_active, fields);
  if(screen->buffers[BUFIDX_ALTSCREEN])
    resize_buffer(screen, 1, new_rows, new_cols, altscreen_active, fields);
  else if(new_rows != old_rows) {
    /* We don't need a full resize of the altscreen because it isn't enabled
     * but we should at least keep the lineinfo the right size */
    vterm_allocator_free(screen->vt, fields->lineinfos[BUFIDX_ALTSCREEN]);

    VTermLineInfo *new_lineinfo = vterm_allocator_malloc(screen->vt, sizeof(new_lineinfo[0]) * new_rows);
    for(int row = 0; row < new_rows; row++)
      new_lineinfo[row] = (VTermLineInfo){ 0 };

    fields->lineinfos[BUFIDX_ALTSCREEN] = new_lineinfo;
  }

  screen->buffer = altscreen_active ? screen->buffers[BUFIDX_ALTSCREEN] : screen->buffers[BUFIDX_PRIMARY];

  screen->rows = new_rows;
  screen->cols = new_cols;

  if(new_cols <= old_cols) {
    if(screen->sb_buffer)
      vterm_allocator_free(screen->vt, screen->sb_buffer);

    screen->sb_buffer = vterm_allocator_malloc(screen->vt, sizeof(VTermScreenCell) * new_cols);
  }

  /* TODO: Maaaaybe we can optimise this if there's no reflow happening */
  damagescreen(screen);

  if(screen->callbacks && screen->callbacks->resize)
    return (*screen->callbacks->resize)(new_rows, new_cols, screen->cbdata);

  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r15
movl %esi, %ebx
movl %edi, %ebp
movq 0x68(%rcx), %rax
testq %rax, %rax
je 0x569e
cmpq %rax, 0x70(%r14)
sete %r12b
jmp 0x56a1
xorl %r12d, %r12d
movl 0x50(%r14), %eax
movl %eax, 0x4(%rsp)
movl 0x54(%r14), %r13d
cmpl %ebx, %r13d
jge 0x56da
movq 0x78(%r14), %rsi
testq %rsi, %rsi
je 0x56c3
movq (%r14), %rdi
callq 0xa40a
movq (%r14), %rdi
movslq %ebx, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0xa39f
movq %rax, 0x78(%r14)
movl %r12d, %eax
xorb $0x1, %al
movzbl %al, %r8d
movq %r14, %rdi
xorl %esi, %esi
movl %ebp, %edx
movl %ebx, %ecx
movq %r15, %r9
callq 0x5c91
cmpq $0x0, 0x68(%r14)
movzbl %r12b, %r12d
je 0x5718
movq %r14, %rdi
movl $0x1, %esi
movl %ebp, %edx
movl %ebx, %ecx
movl %r12d, %r8d
movq %r15, %r9
callq 0x5c91
jmp 0x5751
cmpl %ebp, 0x4(%rsp)
je 0x5751
movq (%r14), %rdi
movq 0x10(%r15), %rsi
callq 0xa40a
movq (%r14), %rdi
movslq %ebp, %rsi
shlq $0x2, %rsi
callq 0xa39f
testl %ebp, %ebp
jle 0x574d
movl %ebp, %ecx
xorl %edx, %edx
movb $0x0, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x5741
movq %rax, 0x10(%r15)
movq 0x60(%r14,%r12,8), %rax
movq %rax, 0x70(%r14)
movl %ebp, 0x50(%r14)
movl %ebx, 0x54(%r14)
cmpl %ebx, %r13d
jl 0x578f
movq 0x78(%r14), %rsi
testq %rsi, %rsi
je 0x5778
movq (%r14), %rdi
callq 0xa40a
movq (%r14), %rdi
movslq %ebx, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0xa39f
movq %rax, 0x78(%r14)
movl 0x50(%r14), %esi
movl 0x54(%r14), %edx
shlq $0x20, %rsi
shlq $0x20, %rdx
movq %r14, %rdi
callq 0x5984
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x57d1
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x57d1
movq 0x18(%r14), %rdx
movl %ebp, %edi
movl %ebx, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq