// File: /workspace/github_c_makefile_star2_O0/neovim[P]libvterm/src/state.c
// Function: scroll
static void scroll(VTermState *state, VTermRect rect, int downward, int rightward)
{
  if(!downward && !rightward)
    return;

  int rows = rect.end_row - rect.start_row;
  if(downward > rows)
    downward = rows;
  else if(downward < -rows)
    downward = -rows;

  int cols = rect.end_col - rect.start_col;
  if(rightward > cols)
    rightward = cols;
  else if(rightward < -cols)
    rightward = -cols;

  if(state->callbacks_has_premove && state->callbacks && state->callbacks->premove) {
    // TODO: technically this logic is wrong if both downward != 0 and rightward != 0

    /* Work out what subsection of the destination area is about to be destroyed */
    if(downward > 0)
      /* about to destroy the top */
      (*state->callbacks->premove)((VTermRect){
          .start_row = rect.start_row, .end_row = rect.start_row + downward,
          .start_col = rect.start_col, .end_col = rect.end_col}, state->cbdata);
    else if(downward < 0)
      /* about to destroy the bottom */
      (*state->callbacks->premove)((VTermRect){
          .start_row = rect.end_row + downward, .end_row = rect.end_row,
          .start_col = rect.start_col,          .end_col = rect.end_col}, state->cbdata);

    if(rightward > 0)
      /* about to destroy the left */
      (*state->callbacks->premove)((VTermRect){
          .start_row = rect.start_row, .end_row = rect.end_row,
          .start_col = rect.start_col, .end_col = rect.start_col + rightward}, state->cbdata);
    else if(rightward < 0)
      /* about to destroy the right */
      (*state->callbacks->premove)((VTermRect){
          .start_row = rect.start_row,           .end_row = rect.end_row,
          .start_col = rect.end_col + rightward, .end_col = rect.end_col}, state->cbdata);
  }

  // Update lineinfo if full line
  if(rect.start_col == 0 && rect.end_col == state->cols && rightward == 0) {
    int height = rect.end_row - rect.start_row - abs(downward);

    if(downward > 0) {
      memmove(state->lineinfo + rect.start_row,
              state->lineinfo + rect.start_row + downward,
              height * sizeof(state->lineinfo[0]));
      for(int row = rect.end_row - downward; row < rect.end_row; row++)
        state->lineinfo[row] = (VTermLineInfo){ 0 };
    }
    else {
      memmove(state->lineinfo + rect.start_row - downward,
              state->lineinfo + rect.start_row,
              height * sizeof(state->lineinfo[0]));
      for(int row = rect.start_row; row < rect.start_row - downward; row++)
        state->lineinfo[row] = (VTermLineInfo){ 0 };
    }
  }

  if(state->callbacks && state->callbacks->scrollrect)
    if((*state->callbacks->scrollrect)(rect, downward, rightward, state->cbdata))
      return;

  if(state->callbacks)
    vterm_scroll_rect(rect, downward, rightward,
        state->callbacks->moverect, state->callbacks->erase, state->cbdata);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rsi, -0x10(%rbp)
movq %rdx, -0x8(%rbp)
movq %rdi, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0xf62f
cmpl $0x0, -0x20(%rbp)
jne 0xf62f
jmp 0xf9bf
movl -0xc(%rbp), %eax
subl -0x10(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0xf648
movl -0x24(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0xf65e
movl -0x1c(%rbp), %eax
xorl %ecx, %ecx
subl -0x24(%rbp), %ecx
cmpl %ecx, %eax
jge 0xf65c
xorl %eax, %eax
subl -0x24(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0xf65e
movl -0x4(%rbp), %eax
subl -0x8(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jle 0xf677
movl -0x28(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0xf68d
movl -0x20(%rbp), %eax
xorl %ecx, %ecx
subl -0x28(%rbp), %ecx
cmpl %ecx, %eax
jge 0xf68b
xorl %eax, %eax
subl -0x28(%rbp), %eax
movl %eax, -0x20(%rbp)
jmp 0xf68d
movq -0x18(%rbp), %rax
testb $0x1, 0x18(%rax)
je 0xf7c3
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf7c3
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x60(%rax)
je 0xf7c3
cmpl $0x0, -0x1c(%rbp)
jle 0xf6fe
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x60(%rax), %rax
movl -0x10(%rbp), %ecx
movl %ecx, -0x38(%rbp)
movl -0x10(%rbp), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, -0x34(%rbp)
movl -0x8(%rbp), %ecx
movl %ecx, -0x30(%rbp)
movl -0x4(%rbp), %ecx
movl %ecx, -0x2c(%rbp)
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq *%rax
jmp 0xf73f
cmpl $0x0, -0x1c(%rbp)
jge 0xf73d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x60(%rax), %rax
movl -0xc(%rbp), %ecx
addl -0x1c(%rbp), %ecx
movl %ecx, -0x48(%rbp)
movl -0xc(%rbp), %ecx
movl %ecx, -0x44(%rbp)
movl -0x8(%rbp), %ecx
movl %ecx, -0x40(%rbp)
movl -0x4(%rbp), %ecx
movl %ecx, -0x3c(%rbp)
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq *%rax
jmp 0xf73f
cmpl $0x0, -0x20(%rbp)
jle 0xf780
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x60(%rax), %rax
movl -0x10(%rbp), %ecx
movl %ecx, -0x58(%rbp)
movl -0xc(%rbp), %ecx
movl %ecx, -0x54(%rbp)
movl -0x8(%rbp), %ecx
movl %ecx, -0x50(%rbp)
movl -0x8(%rbp), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, -0x4c(%rbp)
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq *%rax
jmp 0xf7c1
cmpl $0x0, -0x20(%rbp)
jge 0xf7bf
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x60(%rax), %rax
movl -0x10(%rbp), %ecx
movl %ecx, -0x68(%rbp)
movl -0xc(%rbp), %ecx
movl %ecx, -0x64(%rbp)
movl -0x4(%rbp), %ecx
addl -0x20(%rbp), %ecx
movl %ecx, -0x60(%rbp)
movl -0x4(%rbp), %ecx
movl %ecx, -0x5c(%rbp)
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq *%rax
jmp 0xf7c1
jmp 0xf7c3
cmpl $0x0, -0x8(%rbp)
jne 0xf936
movl -0x4(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x34(%rcx), %eax
jne 0xf936
cmpl $0x0, -0x20(%rbp)
jne 0xf936
movl -0xc(%rbp), %eax
subl -0x10(%rbp), %eax
movl -0x1c(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
subl %ecx, %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0xf89b
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rdi
movslq -0x10(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rsi
movslq -0x10(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movslq -0x1c(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movslq -0x6c(%rbp), %rdx
shlq $0x2, %rdx
callq 0x21b0
movl -0xc(%rbp), %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xf896
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x70(%rbp), %rcx
movb -0x74(%rbp), %dl
andb $-0x2, %dl
orb $0x0, %dl
movb %dl, -0x74(%rbp)
movb -0x74(%rbp), %dl
andb $-0x7, %dl
orb $0x0, %dl
movb %dl, -0x74(%rbp)
movb -0x74(%rbp), %dl
andb $-0x9, %dl
orb $0x0, %dl
movb %dl, -0x74(%rbp)
movl -0x74(%rbp), %edx
movl %edx, (%rax,%rcx,4)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0xf84d
jmp 0xf934
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rdi
movslq -0x10(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movslq -0x1c(%rbp), %rcx
xorl %eax, %eax
subq %rcx, %rax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rsi
movslq -0x10(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
movslq -0x6c(%rbp), %rdx
shlq $0x2, %rdx
callq 0x21b0
movl -0x10(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl -0x10(%rbp), %ecx
subl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jge 0xf932
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x78(%rbp), %rcx
movb -0x7c(%rbp), %dl
andb $-0x2, %dl
orb $0x0, %dl
movb %dl, -0x7c(%rbp)
movb -0x7c(%rbp), %dl
andb $-0x7, %dl
orb $0x0, %dl
movb %dl, -0x7c(%rbp)
movb -0x7c(%rbp), %dl
andb $-0x9, %dl
orb $0x0, %dl
movb %dl, -0x7c(%rbp)
movl -0x7c(%rbp), %edx
movl %edx, (%rax,%rcx,4)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0xf8e4
jmp 0xf934
jmp 0xf936
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf97d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0xf97d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movq -0x18(%rbp), %rsi
movq 0x10(%rsi), %r8
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq *%rax
cmpl $0x0, %eax
je 0xf97b
jmp 0xf9bf
jmp 0xf97d
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xf9bf
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %r8
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %r9
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq %rax, (%rsp)
callq 0x2170
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)