// File: /workspace/github_c_makefile_star2_O0/neovim[P]libvterm/src/screen.c
// Function: scrollrect
static int scrollrect(VTermRect rect, int downward, int rightward, void *user)
{
  VTermScreen *screen = user;

  if(screen->damage_merge != VTERM_DAMAGE_SCROLL) {
    vterm_scroll_rect(rect, downward, rightward,
        moverect_internal, erase_internal, screen);

    vterm_screen_flush_damage(screen);

    vterm_scroll_rect(rect, downward, rightward,
        moverect_user, erase_user, screen);

    return 1;
  }

  if(screen->damaged.start_row != -1 &&
     !rect_intersects(&rect, &screen->damaged)) {
    vterm_screen_flush_damage(screen);
  }

  if(screen->pending_scrollrect.start_row == -1) {
    screen->pending_scrollrect = rect;
    screen->pending_scroll_downward  = downward;
    screen->pending_scroll_rightward = rightward;
  }
  else if(rect_equal(&screen->pending_scrollrect, &rect) &&
     ((screen->pending_scroll_downward  == 0 && downward  == 0) ||
      (screen->pending_scroll_rightward == 0 && rightward == 0))) {
    screen->pending_scroll_downward  += downward;
    screen->pending_scroll_rightward += rightward;
  }
  else {
    vterm_screen_flush_damage(screen);

    screen->pending_scrollrect = rect;
    screen->pending_scroll_downward  = downward;
    screen->pending_scroll_rightward = rightward;
  }

  vterm_scroll_rect(rect, downward, rightward,
      moverect_internal, erase_internal, screen);

  if(screen->damaged.start_row == -1)
    return 1;

  if(rect_contains(&rect, &screen->damaged)) {
    /* Scroll region entirely contains the damage; just move it */
    vterm_rect_move(&screen->damaged, -downward, -rightward);
    rect_clip(&screen->damaged, &rect);
  }
  /* There are a number of possible cases here, but lets restrict this to only
   * the common case where we might actually gain some performance by
   * optimising it. Namely, a vertical scroll that neatly cuts the damage
   * region in half.
   */
  else if(rect.start_col <= screen->damaged.start_col &&
          rect.end_col   >= screen->damaged.end_col &&
          rightward == 0) {
    if(screen->damaged.start_row >= rect.start_row &&
       screen->damaged.start_row  < rect.end_row) {
      screen->damaged.start_row -= downward;
      if(screen->damaged.start_row < rect.start_row)
        screen->damaged.start_row = rect.start_row;
      if(screen->damaged.start_row > rect.end_row)
        screen->damaged.start_row = rect.end_row;
    }
    if(screen->damaged.end_row >= rect.start_row &&
       screen->damaged.end_row  < rect.end_row) {
      screen->damaged.end_row -= downward;
      if(screen->damaged.end_row < rect.start_row)
        screen->damaged.end_row = rect.start_row;
      if(screen->damaged.end_row > rect.end_row)
        screen->damaged.end_row = rect.end_row;
    }
  }
  else {
    DEBUG_LOG("TODO: Just flush and redo damaged=" STRFrect " rect=" STRFrect "\n",
        ARGSrect(screen->damaged), ARGSrect(rect));
  }

  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x14(%rbp)
movq %rsi, -0xc(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x3, 0x24(%rax)
je 0x7a83
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movq -0x14(%rbp), %rdi
movq -0xc(%rbp), %rsi
leaq 0xe5b(%rip), %r8        # 0x8890
leaq 0xf24(%rip), %r9        # 0x8960
movq %rax, (%rsp)
callq 0x2170
movq -0x30(%rbp), %rdi
callq 0x2040
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movq -0x14(%rbp), %rdi
movq -0xc(%rbp), %rsi
leaq -0xb37(%rip), %r8       # 0x6f30
leaq -0xa8e(%rip), %r9       # 0x6fe0
movq %rax, (%rsp)
callq 0x2170
movl $0x1, -0x4(%rbp)
jmp 0x7ccb
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x28(%rax)
je 0x7aac
movq -0x30(%rbp), %rsi
addq $0x28, %rsi
leaq -0x14(%rbp), %rdi
callq 0x8b60
cmpl $0x0, %eax
jne 0x7aac
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x38(%rax)
jne 0x7ae3
movq -0x30(%rbp), %rax
movq -0x14(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq -0xc(%rbp), %rcx
movq %rcx, 0x40(%rax)
movl -0x18(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x48(%rax)
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4c(%rax)
jmp 0x7b68
movq -0x30(%rbp), %rdi
addq $0x38, %rdi
leaq -0x14(%rbp), %rsi
callq 0x8bd0
cmpl $0x0, %eax
je 0x7b35
movq -0x30(%rbp), %rax
cmpl $0x0, 0x48(%rax)
jne 0x7b09
cmpl $0x0, -0x18(%rbp)
je 0x7b19
movq -0x30(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
jne 0x7b35
cmpl $0x0, -0x1c(%rbp)
jne 0x7b35
movl -0x18(%rbp), %ecx
movq -0x30(%rbp), %rax
addl 0x48(%rax), %ecx
movl %ecx, 0x48(%rax)
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
addl 0x4c(%rax), %ecx
movl %ecx, 0x4c(%rax)
jmp 0x7b66
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x30(%rbp), %rax
movq -0x14(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq -0xc(%rbp), %rcx
movq %rcx, 0x40(%rax)
movl -0x18(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x48(%rax)
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4c(%rax)
jmp 0x7b68
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movq -0x30(%rbp), %rax
movq -0x14(%rbp), %rdi
movq -0xc(%rbp), %rsi
leaq 0xd0f(%rip), %r8        # 0x8890
leaq 0xdd8(%rip), %r9        # 0x8960
movq %rax, (%rsp)
callq 0x2170
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x28(%rax)
jne 0x7ba7
movl $0x1, -0x4(%rbp)
jmp 0x7ccb
movq -0x30(%rbp), %rsi
addq $0x28, %rsi
leaq -0x14(%rbp), %rdi
callq 0x8c40
cmpl $0x0, %eax
je 0x7bea
movq -0x30(%rbp), %rdi
addq $0x28, %rdi
xorl %esi, %esi
subl -0x18(%rbp), %esi
xorl %edx, %edx
subl -0x1c(%rbp), %edx
callq 0x8cc0
movq -0x30(%rbp), %rdi
addq $0x28, %rdi
leaq -0x14(%rbp), %rsi
callq 0x8d10
jmp 0x7cc4
movl -0xc(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jg 0x7cc0
movl -0x8(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x34(%rcx), %eax
jl 0x7cc0
cmpl $0x0, -0x1c(%rbp)
jne 0x7cc0
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
cmpl -0x14(%rbp), %eax
jl 0x7c69
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
cmpl -0x10(%rbp), %eax
jge 0x7c69
movl -0x18(%rbp), %edx
movq -0x30(%rbp), %rax
movl 0x28(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x28(%rax)
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
cmpl -0x14(%rbp), %eax
jge 0x7c51
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x30(%rbp), %rax
movl 0x28(%rax), %eax
cmpl -0x10(%rbp), %eax
jle 0x7c67
movl -0x10(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x28(%rax)
jmp 0x7c69
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %eax
cmpl -0x14(%rbp), %eax
jl 0x7cbe
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %eax
cmpl -0x10(%rbp), %eax
jge 0x7cbe
movl -0x18(%rbp), %edx
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x2c(%rax)
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %eax
cmpl -0x14(%rbp), %eax
jge 0x7ca6
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x30(%rbp), %rax
movl 0x2c(%rax), %eax
cmpl -0x10(%rbp), %eax
jle 0x7cbc
movl -0x10(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x2c(%rax)
jmp 0x7cbe
jmp 0x7cc2
jmp 0x7cc2
jmp 0x7cc4
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)