// File: /workspace/github_c_makefile_star2_O2/hughbarney[P]pEmacs/display.c
// Function: update
void update ()
{
  VIDEO *vp1, *vp2;
  LINE *lp;
  WINDOW *wp;
  int i, j, c;

  if (typahead())
    return;

  /* update the reverse video flags for any mode lines out there */
  for (i = 0; i < term.t_nrow; ++i)
    vscreen[i]->v_flag &= ~VFREQ;

  wp = wheadp;
  while (wp != NULL)
    {
      vscreen[wp->w_toprow + wp->w_ntrows]->v_flag |= VFREQ;
      wp = wp->w_wndp;
    }

  wp = wheadp;
  while (wp != NULL)
    {
      /* Look at any window with update flags set on */
      if (wp->w_flag != 0)
	{
	  /* If not force reframe, check the framing */
	  if ((wp->w_flag & WFFORCE) == 0)
	    {
	      lp = wp->w_linep;
	      for (i = 0; i < wp->w_ntrows; ++i)
		{
		  if (lp == wp->w_dotp)
		    goto out;
		  if (lp == wp->w_bufp->b_linep)
		    break;
		  lp = lforw (lp);
		}
	    }
	  /* Not acceptable, better compute a new value for the line at the top
	   * of the window. Then set the "WFHARD" flag to force full redraw */
	  i = wp->w_force;
	  if (i > 0)
	    {
	      --i;
	      if (i >= wp->w_ntrows)
		i = wp->w_ntrows - 1;
	    }
	  else if (i < 0)
	    {
	      i += wp->w_ntrows;
	      if (i < 0)
		i = 0;
	    }
	  else
	    i = wp->w_ntrows / 2;
	  lp = wp->w_dotp;
	  while (i != 0 && lback (lp) != wp->w_bufp->b_linep)
	    {
	      --i;
	      lp = lback (lp);
	    }
	  wp->w_linep = lp;
	  wp->w_flag |= WFHARD;	   /* Force full */

	out:
	  /* Try to use reduced update. Mode line update has its own special
	   * flag. The fast update is used if the only thing to do is within
	   * the line editing */
	  lp = wp->w_linep;
	  i = wp->w_toprow;
	  if ((wp->w_flag & ~WFMODE) == WFEDIT)
	    {
	      while (lp != wp->w_dotp)
		{
		  ++i;
		  lp = lforw (lp);
		}
	      vscreen[i]->v_flag |= VFCHG;
	      vtmove (i, 0);
	      for (j = 0; j < llength (lp); ++j)
		vtputc (lgetc (lp, j));
	      vteeol ();
	    }
	  else if ((wp->w_flag & (WFEDIT | WFHARD)) != 0)
	    {
	      while (i < wp->w_toprow + wp->w_ntrows)
		{
		  vscreen[i]->v_flag |= VFCHG;
		  vtmove (i, 0);
		  /* if line has been changed */
		  if (lp != wp->w_bufp->b_linep)
		    {
		      for (j = 0; j < llength (lp); ++j)
			vtputc (lgetc (lp, j));
		      lp = lforw (lp);
		    }
		  vteeol ();
		  ++i;
		}
	    }
	}
      if (wp->w_flag & WFMODE)
	modeline(wp);
      wp->w_flag = 0;
      wp->w_force = 0;

      wp = wp->w_wndp;		/* and onward to the next window */
    }

  /* Always recompute the row and column number of the hardware cursor. This
   * is the only update for simple moves */
  lp = curwp->w_linep;
  currow = curwp->w_toprow;
  while (lp != curwp->w_dotp)
    {
      ++currow;
      lp = lforw (lp);
    }

  curcol = 0;
  i = 0;
  while (i < curwp->w_doto)
    {
      c = lgetc (lp, i++);
      if (c == '\t')
	curcol |= 0x07;
      else if (c < 0x20 || c == 0x7F)
	++curcol;
      ++curcol;
    }
  if (curcol >= term.t_ncol - 1)
    {				 /* extended line */
      /* flag we are extended and changed */
      vscreen[currow]->v_flag |= VFEXT | VFCHG;
      updext ();		 /* and output extended line */
    }
  else
    lbound = 0;			/* not extended line */

  /* make sure no lines need to be de-extended because the cursor is no
   * longer on them */

  wp = wheadp;

  while (wp != NULL)
    {
      lp = wp->w_linep;
      i = wp->w_toprow;

      while (i < wp->w_toprow + wp->w_ntrows)
	{
	  if (vscreen[i]->v_flag & VFEXT)
	    {
	      /* always flag extended lines as changed */
	      vscreen[i]->v_flag |= VFCHG;
	      if ((wp != curwp) || (lp != wp->w_dotp) ||
		  (curcol < term.t_ncol - 1))
		{
		  vtmove (i, 0);
		  for (j = 0; j < llength (lp); ++j)
		    vtputc (lgetc (lp, j));
		  vteeol ();
		  /* this line no longer is extended */
		  vscreen[i]->v_flag &= ~VFEXT;
		}
	    }
	  lp = lforw (lp);
	  ++i;
	}
      /* and onward to the next window */
      wp = wp->w_wndp;
    }

  /* Special hacking if the screen is garbage. Clear the hardware screen, and
   * update your copy to agree with it. Set all the virtual screen change
   * bits, to force a full update */
  if (sgarbf != FALSE)
    {
      for (i = 0; i < term.t_nrow; ++i)
	{
	  vscreen[i]->v_flag |= VFCHG;
	  vp1 = pscreen[i];
	  for (j = 0; j < term.t_ncol; ++j)
	    vp1->v_text[j] = ' ';
	}

      movecursor (0, 0);	 /* Erase the screen */
      (*term.t_eeop) ();
      sgarbf = FALSE;		 /* Erase-page clears */
      mpresf = FALSE;		 /* the message area */
    }
  /* Make sure that the physical and virtual displays agree. Unlike before,
   * the "updateline" code is only called with a line that has been updated
   * for sure */
  for (i = 0; i < term.t_nrow; ++i)
    {
      vp1 = vscreen[i];

      /* for each line that needs to be updated, or that needs its reverse
       * video status changed, call the line updater */
      j = vp1->v_flag;
      if (((j & VFCHG) != 0) || (((j & VFREV) == 0) != ((j & VFREQ) == 0)))
	{
	  if (typahead ())
	    return;
	  vp2 = pscreen[i];
	  updateline (i, &vp1->v_text[0], &vp2->v_text[0], &vp1->v_flag);
	}
    }

  /* Finally, update the hardware cursor and flush out buffers */
  movecursor (currow, curcol - lbound);
  (*term.t_flush) ();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x71e2
testl %eax, %eax
je 0x3523
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x932e(%rip), %rax      # 0xc858
movl (%rax), %eax
movq 0x93bd(%rip), %rcx      # 0xc8f0
testl %eax, %eax
cmovlel %ebx, %eax
cmpq %rbx, %rax
je 0x354a
movq (%rcx,%rbx,8), %rdx
andw $-0x9, (%rdx)
incq %rbx
jmp 0x3538
leaq 0x94ff(%rip), %rax      # 0xca50
movq 0x9398(%rip), %rcx      # 0xc8f0
movq (%rax), %rax
testq %rax, %rax
je 0x3578
movsbq 0x38(%rax), %rdx
movsbq 0x39(%rax), %rsi
leaq (%rcx,%rdx,8), %rdx
movq (%rdx,%rsi,8), %rdx
orw $0x8, (%rdx)
jmp 0x3558
leaq 0x94d1(%rip), %rbx      # 0xca50
xorl %r14d, %r14d
movb $0x2, %bpl
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x371c
movb 0x3b(%rbx), %dl
testb %dl, %dl
je 0x3704
testb $0x1, %dl
jne 0x35d0
movzbl 0x39(%rbx), %ecx
testb %cl, %cl
movl %ecx, %eax
cmovlel %r14d, %eax
leaq 0x10(%rbx), %rsi
movzbl %al, %edi
incl %edi
movq %rsi, %rax
decl %edi
je 0x35d0
movq (%rax), %rax
cmpq 0x18(%rbx), %rax
je 0x35fb
movq 0x8(%rbx), %r8
cmpq 0x28(%r8), %rax
jne 0x35b9
movsbl 0x3a(%rbx), %esi
movb 0x39(%rbx), %cl
movsbl %cl, %eax
testl %esi, %esi
jle 0x35e7
cmpb %cl, %sil
jle 0x35f7
decl %eax
jmp 0x3608
testb %sil, %sil
js 0x3600
movsbl %cl, %eax
idivb %bpl
movsbl %al, %esi
jmp 0x360a
decl %esi
jmp 0x360a
movq (%rsi), %r15
jmp 0x3632
addl %esi, %eax
testl %eax, %eax
cmovlel %r14d, %eax
movl %eax, %esi
movq 0x18(%rbx), %rax
incl %esi
movq %rax, %rdi
movq %rdi, %r15
decl %esi
je 0x3628
movq 0x8(%r15), %rdi
movq 0x8(%rbx), %r8
cmpq 0x28(%r8), %rdi
jne 0x3613
movq %r15, 0x10(%rbx)
orb $0x8, %dl
movb %dl, 0x3b(%rbx)
movb 0x38(%rbx), %sil
movsbq %sil, %r12
movsbl %dl, %edi
andl $-0x11, %edi
cmpl $0x4, %edi
jne 0x3652
cmpq %rax, %r15
je 0x36c6
movq (%r15), %r15
incq %r12
jmp 0x3645
testb $0xc, %dl
je 0x3704
movsbq %sil, %rax
movsbq %cl, %rcx
addq %rax, %rcx
cmpq %rcx, %r12
jge 0x3704
movq 0x927a(%rip), %rax      # 0xc8f0
movq (%rax,%r12,8), %rax
orw $0x1, (%rax)
andl $0x0, 0x925f(%rip)      # 0xc8e4
movl %r12d, 0x9254(%rip)     # 0xc8e0
movq 0x8(%rbx), %rax
cmpq 0x28(%rax), %r15
je 0x36b5
xorl %r13d, %r13d
movslq 0x14(%r15), %rax
cmpq %rax, %r13
jge 0x36b2
movzbl 0x18(%r15,%r13), %edi
callq 0x3398
incq %r13
jmp 0x3699
movq (%r15), %r15
callq 0x34c6
incq %r12
movb 0x38(%rbx), %sil
movb 0x39(%rbx), %cl
jmp 0x365b
movq 0x9223(%rip), %rax      # 0xc8f0
movq (%rax,%r12,8), %rax
orw $0x1, (%rax)
movl %r12d, 0x9204(%rip)     # 0xc8e0
andl $0x0, 0x9201(%rip)      # 0xc8e4
xorl %r12d, %r12d
movslq 0x14(%r15), %rax
cmpq %rax, %r12
jge 0x36ff
movzbl 0x18(%r15,%r12), %edi
callq 0x3398
incq %r12
jmp 0x36e6
callq 0x34c6
testb $0x10, 0x3b(%rbx)
je 0x3712
movq %rbx, %rdi
callq 0x3998
andw $0x0, 0x3a(%rbx)
jmp 0x3585
leaq 0x9315(%rip), %rbx      # 0xca38
movq (%rbx), %rdx
movq 0x10(%rdx), %rcx
movsbq 0x38(%rdx), %rax
leaq 0x93da(%rip), %rdi      # 0xcb10
movl %eax, (%rdi)
movq 0x18(%rdx), %rsi
cmpq %rsi, %rcx
je 0x374b
incq %rax
movl %eax, (%rdi)
movq (%rcx), %rcx
jmp 0x373c
movq 0x20(%rdx), %rdx
xorl %esi, %esi
testq %rdx, %rdx
cmovleq %rsi, %rdx
leaq 0x93b5(%rip), %r12      # 0xcb14
xorl %edi, %edi
movl %edi, (%r12)
cmpq %rsi, %rdx
je 0x379c
movb 0x18(%rcx,%rsi), %r8b
cmpb $0x9, %r8b
jne 0x377a
orl $0x7, %edi
jmp 0x3791
cmpb $0x20, %r8b
setae %r9b
cmpb $0x7f, %r8b
setne %r8b
testb %r8b, %r9b
jne 0x3795
incl %edi
movl %edi, (%r12)
incl %edi
incq %rsi
jmp 0x3761
leaq 0x90b5(%rip), %rcx      # 0xc858
movl 0x4(%rcx), %ecx
decl %ecx
cmpl %ecx, %edi
jge 0x37b5
andl $0x0, 0x9135(%rip)      # 0xc8e8
jmp 0x37c9
movq 0x9134(%rip), %rcx      # 0xc8f0
movq (%rcx,%rax,8), %rax
orw $0x3, (%rax)
callq 0x3cbd
leaq 0x9280(%rip), %r14      # 0xca50
movq (%r14), %r14
testq %r14, %r14
je 0x387c
leaq 0x10(%r14), %r13
movb 0x38(%r14), %al
movsbq %al, %rbp
movq (%r13), %r13
movsbq %al, %rcx
movsbq 0x39(%r14), %rdx
addq %rcx, %rdx
cmpq %rdx, %rbp
jge 0x37d0
movq 0x90ec(%rip), %rcx      # 0xc8f0
movq (%rcx,%rbp,8), %rcx
movzwl (%rcx), %edx
testb $0x2, %dl
je 0x3874
orl $0x1, %edx
movw %dx, (%rcx)
cmpq (%rbx), %r14
jne 0x3833
cmpq 0x18(%r14), %r13
jne 0x3833
leaq 0x9030(%rip), %rcx      # 0xc858
movl 0x4(%rcx), %ecx
decl %ecx
cmpl %ecx, (%r12)
jge 0x3874
movl %ebp, 0x90a7(%rip)      # 0xc8e0
andl $0x0, 0x90a4(%rip)      # 0xc8e4
xorl %r15d, %r15d
movslq 0x14(%r13), %rax
cmpq %rax, %r15
jge 0x385c
movzbl 0x18(%r13,%r15), %edi
callq 0x3398
incq %r15
jmp 0x3843
callq 0x34c6
movq 0x9088(%rip), %rax      # 0xc8f0
movq (%rax,%rbp,8), %rax
andw $-0x3, (%rax)
movb 0x38(%r14), %al
incq %rbp
jmp 0x37e8
leaq 0x8ae1(%rip), %rbx      # 0xc364
cmpl $0x0, (%rbx)
je 0x38f6
xorl %eax, %eax
leaq 0x8fc7(%rip), %rcx      # 0xc858
movslq (%rcx), %rcx
cmpq %rcx, %rax
jge 0x38d4
movq 0x9050(%rip), %rcx      # 0xc8f0
movq (%rcx,%rax,8), %rcx
orw $0x1, (%rcx)
movq 0x9049(%rip), %rcx      # 0xc8f8
movq (%rcx,%rax,8), %rcx
xorl %edx, %edx
leaq 0x8f9c(%rip), %rsi      # 0xc858
movslq 0x4(%rsi), %rsi
cmpq %rsi, %rdx
jge 0x38cf
movb $0x20, 0x2(%rcx,%rdx)
incq %rdx
jmp 0x38b5
incq %rax
jmp 0x388a
xorl %edi, %edi
xorl %esi, %esi
callq 0x3220
xorl %eax, %eax
leaq 0x8f72(%rip), %rcx      # 0xc858
callq *0x48(%rcx)
andl $0x0, (%rbx)
leaq 0x9131(%rip), %rax      # 0xca24
andl $0x0, (%rax)
leaq 0x8f5b(%rip), %rax      # 0xc858
movl (%rax), %eax
xorl %ebx, %ebx
movslq %eax, %rcx
cmpq %rcx, %rbx
jge 0x3966
movq 0x8fe0(%rip), %rcx      # 0xc8f0
movq (%rcx,%rbx,8), %r14
movzwl (%r14), %ecx
testb $0x1, %cl
jne 0x392c
movl %ecx, %edx
shrl $0x2, %edx
shrl $0x3, %ecx
xorl %edx, %ecx
testb $0x1, %cl
je 0x3961
xorl %eax, %eax
callq 0x71e2
testl %eax, %eax
jne 0x3514
movq 0x8fb6(%rip), %rax      # 0xc8f8
movq (%rax,%rbx,8), %rdx
leaq 0x2(%r14), %rsi
addq $0x2, %rdx
movl %ebx, %edi
movq %r14, %rcx
callq 0x3b1c
leaq 0x8ef9(%rip), %rax      # 0xc858
movl (%rax), %eax
incq %rbx
jmp 0x3901
leaq 0x91a3(%rip), %rax      # 0xcb10
movl (%rax), %edi
movl (%r12), %esi
subl 0x8f6f(%rip), %esi      # 0xc8e8
callq 0x3220
xorl %eax, %eax
leaq 0x8ed1(%rip), %rcx      # 0xc858
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *0x30(%rcx)