// File: /workspace/github_c_makefile_star2_O0/neovim[P]libvterm/src/vterm.c
// Function: vterm_scroll_rect
void vterm_scroll_rect(VTermRect rect,
    int downward,
    int rightward,
    int (*moverect)(VTermRect src, VTermRect dest, void *user),
    int (*eraserect)(VTermRect rect, int selective, void *user),
    void *user)
{
  VTermRect src;
  VTermRect dest;

  if(abs(downward)  >= rect.end_row - rect.start_row ||
     abs(rightward) >= rect.end_col - rect.start_col) {
    /* Scroll more than area; just erase the lot */
    (*eraserect)(rect, 0, user);
    return;
  }

  if(rightward >= 0) {
    /* rect: [XXX................]
     * src:     [----------------]
     * dest: [----------------]
     */
    dest.start_col = rect.start_col;
    dest.end_col   = rect.end_col   - rightward;
    src.start_col  = rect.start_col + rightward;
    src.end_col    = rect.end_col;
  }
  else {
    /* rect: [................XXX]
     * src:  [----------------]
     * dest:    [----------------]
     */
    int leftward = -rightward;
    dest.start_col = rect.start_col + leftward;
    dest.end_col   = rect.end_col;
    src.start_col  = rect.start_col;
    src.end_col    = rect.end_col - leftward;
  }

  if(downward >= 0) {
    dest.start_row = rect.start_row;
    dest.end_row   = rect.end_row   - downward;
    src.start_row  = rect.start_row + downward;
    src.end_row    = rect.end_row;
  }
  else {
    int upward = -downward;
    dest.start_row = rect.start_row + upward;
    dest.end_row   = rect.end_row;
    src.start_row  = rect.start_row;
    src.end_row    = rect.end_row - upward;
  }

  if(moverect)
    (*moverect)(dest, src, user);

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

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

  (*eraserect)(rect, 0, user);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x8(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl -0xc(%rbp), %ecx
subl -0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1244a
movl -0x18(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl -0x4(%rbp), %ecx
subl -0x8(%rbp), %ecx
cmpl %ecx, %eax
jl 0x12463
movq -0x28(%rbp), %rax
movq 0x10(%rbp), %rcx
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
xorl %edx, %edx
callq *%rax
jmp 0x12574
cmpl $0x0, -0x18(%rbp)
jl 0x12489
movl -0x8(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x4(%rbp), %eax
subl -0x18(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x8(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x124af
xorl %eax, %eax
subl -0x18(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x8(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x4(%rbp), %eax
subl -0x4c(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x124d5
movl -0x10(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0xc(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x10(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x124fb
xorl %eax, %eax
subl -0x14(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x10(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0xc(%rbp), %eax
subl -0x50(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1251c
movq -0x20(%rbp), %rax
movq 0x10(%rbp), %r8
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq *%rax
cmpl $0x0, -0x14(%rbp)
jle 0x1252d
movl -0xc(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x1253e
cmpl $0x0, -0x14(%rbp)
jge 0x1253c
movl -0x10(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x1253e
cmpl $0x0, -0x18(%rbp)
jle 0x1254f
movl -0x4(%rbp), %eax
subl -0x18(%rbp), %eax
movl %eax, -0x8(%rbp)
jmp 0x12560
cmpl $0x0, -0x18(%rbp)
jge 0x1255e
movl -0x8(%rbp), %eax
subl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x12560
movq -0x28(%rbp), %rax
movq 0x10(%rbp), %rcx
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
xorl %edx, %edx
callq *%rax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)