// File: /workspace/github_c_makefile_star2_O0/neovim[P]libvterm/src/state.c
// Function: on_resize
static int on_resize(int rows, int cols, void *user)
{
  VTermState *state = user;
  VTermPos oldpos = state->pos;

  if(cols != state->cols) {
    unsigned char *newtabstops = vterm_allocator_malloc(state->vt, (cols + 7) / 8);

    /* TODO: This can all be done much more efficiently bytewise */
    int col;
    for(col = 0; col < state->cols && col < cols; col++) {
      unsigned char mask = 1 << (col & 7);
      if(state->tabstops[col >> 3] & mask)
        newtabstops[col >> 3] |= mask;
      else
        newtabstops[col >> 3] &= ~mask;
      }

    for( ; col < cols; col++) {
      unsigned char mask = 1 << (col & 7);
      if(col % 8 == 0)
        newtabstops[col >> 3] |= mask;
      else
        newtabstops[col >> 3] &= ~mask;
    }

    vterm_allocator_free(state->vt, state->tabstops);
    state->tabstops = newtabstops;
  }

  state->rows = rows;
  state->cols = cols;

  if(state->scrollregion_bottom > -1)
    UBOUND(state->scrollregion_bottom, state->rows);
  if(state->scrollregion_right > -1)
    UBOUND(state->scrollregion_right, state->cols);

  VTermStateFields fields = {
    .pos       = state->pos,
    .lineinfos = { [0] = state->lineinfos[0], [1] = state->lineinfos[1] },
  };

  if(state->callbacks && state->callbacks->resize) {
    (*state->callbacks->resize)(rows, cols, &fields, state->cbdata);
    state->pos = fields.pos;

    state->lineinfos[0] = fields.lineinfos[0];
    state->lineinfos[1] = fields.lineinfos[1];
  }
  else {
    if(rows != state->rows) {
      for(int bufidx = BUFIDX_PRIMARY; bufidx <= BUFIDX_ALTSCREEN; bufidx++) {
        VTermLineInfo *oldlineinfo = state->lineinfos[bufidx];
        if(!oldlineinfo)
          continue;

        VTermLineInfo *newlineinfo = vterm_allocator_malloc(state->vt, rows * sizeof(VTermLineInfo));

        int row;
        for(row = 0; row < state->rows && row < rows; row++) {
          newlineinfo[row] = oldlineinfo[row];
        }

        for( ; row < rows; row++) {
          newlineinfo[row] = (VTermLineInfo){
            .doublewidth = 0,
          };
        }

        vterm_allocator_free(state->vt, state->lineinfos[bufidx]);
        state->lineinfos[bufidx] = newlineinfo;
      }
    }
  }

  state->lineinfo = state->lineinfos[state->mode.alt_screen ? BUFIDX_ALTSCREEN : BUFIDX_PRIMARY];

  if(state->at_phantom && state->pos.col < cols-1) {
    state->at_phantom = 0;
    state->pos.col++;
  }

  if(state->pos.row < 0)
    state->pos.row = 0;
  if(state->pos.row >= rows)
    state->pos.row = rows - 1;
  if(state->pos.col < 0)
    state->pos.col = 0;
  if(state->pos.col >= cols)
    state->pos.col = cols - 1;

  updatecursor(state, &oldpos, 1);

  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
movl -0x8(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x34(%rcx), %eax
je 0xf01d
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl -0x8(%rbp), %eax
addl $0x7, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movslq %eax, %rsi
callq 0x11a20
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpl 0x34(%rdx), %ecx
movb %al, -0x69(%rbp)
jge 0xef0b
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
setl %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0xef14
jmp 0xef8d
movl -0x2c(%rbp), %ecx
andl $0x7, %ecx
movl $0x1, %eax
shll %cl, %eax
movb %al, -0x2d(%rbp)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x2c(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movzbl -0x2d(%rbp), %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xef60
movzbl -0x2d(%rbp), %esi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0xef7d
movzbl -0x2d(%rbp), %esi
xorl $-0x1, %esi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
andl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0xef7f
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xeeee
jmp 0xef8f
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xeffd
movl -0x2c(%rbp), %ecx
andl $0x7, %ecx
movl $0x1, %eax
shll %cl, %eax
movb %al, -0x2e(%rbp)
movl -0x2c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0xefd3
movzbl -0x2e(%rbp), %esi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0xeff0
movzbl -0x2e(%rbp), %esi
xorl $-0x1, %esi
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
andl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0xeff2
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xef8f
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rsi
callq 0x11ae0
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movl -0x4(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x30(%rax)
movl -0x8(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x18(%rbp), %rax
cmpl $-0x1, 0x48(%rax)
jle 0xf05b
movq -0x18(%rbp), %rax
movl 0x48(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jle 0xf059
movq -0x18(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x48(%rax)
jmp 0xf05b
movq -0x18(%rbp), %rax
cmpl $-0x1, 0x50(%rax)
jle 0xf085
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x34(%rcx), %eax
jle 0xf083
movq -0x18(%rbp), %rax
movl 0x34(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x50(%rax)
jmp 0xf085
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf10c
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x48(%rax)
je 0xf10c
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x48(%rax), %rax
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
leaq -0x48(%rbp), %rdx
callq *%rax
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x68(%rax)
jmp 0xf233
movl -0x4(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x30(%rcx), %eax
je 0xf231
movl $0x0, -0x4c(%rbp)
cmpl $0x1, -0x4c(%rbp)
jg 0xf22f
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq 0x60(%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xf14a
jmp 0xf221
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movslq -0x4(%rbp), %rsi
shlq $0x2, %rsi
callq 0x11a20
movq %rax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %ecx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpl 0x30(%rdx), %ecx
movb %al, -0x6a(%rbp)
jge 0xf186
movl -0x64(%rbp), %eax
cmpl -0x4(%rbp), %eax
setl %al
movb %al, -0x6a(%rbp)
movb -0x6a(%rbp), %al
testb $0x1, %al
jne 0xf18f
jmp 0xf1b0
movq -0x60(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq -0x58(%rbp), %rdx
movslq -0x64(%rbp), %rsi
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xf169
jmp 0xf1b2
movl -0x64(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0xf1f7
movq -0x60(%rbp), %rax
movslq -0x64(%rbp), %rcx
movb -0x68(%rbp), %dl
andb $-0x2, %dl
orb $0x0, %dl
movb %dl, -0x68(%rbp)
movb -0x68(%rbp), %dl
andb $-0x7, %dl
orb $0x0, %dl
movb %dl, -0x68(%rbp)
movb -0x68(%rbp), %dl
andb $-0x9, %dl
orb $0x0, %dl
movb %dl, -0x68(%rbp)
movl -0x68(%rbp), %edx
movl %edx, (%rax,%rcx,4)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xf1b2
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq 0x60(%rax,%rcx,8), %rsi
callq 0x11ae0
movq -0x60(%rbp), %rdx
movq -0x18(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq %rdx, 0x60(%rax,%rcx,8)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xf123
jmp 0xf231
jmp 0xf233
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rcx
movw 0xac(%rcx), %cx
shrw $0x9, %cx
andw $0x1, %cx
movzwl %cx, %esi
xorl %ecx, %ecx
movl $0x1, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
movslq %ecx, %rcx
movq 0x60(%rax,%rcx,8), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0xf29d
movq -0x18(%rbp), %rax
movl 0x3c(%rax), %eax
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xf29d
movq -0x18(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x18(%rbp), %rax
movl 0x3c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x3c(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jge 0xf2b2
movq -0x18(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x18(%rbp), %rax
movl 0x38(%rax), %eax
cmpl -0x4(%rbp), %eax
jl 0xf2cb
movl -0x4(%rbp), %ecx
subl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
jge 0xf2e0
movq -0x18(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x18(%rbp), %rax
movl 0x3c(%rax), %eax
cmpl -0x8(%rbp), %eax
jl 0xf2f9
movl -0x8(%rbp), %ecx
subl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x3c(%rax)
movq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x1, %edx
callq 0xf9d0
movl $0x1, %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)