// File: /workspace/github_c_makefile_star2_O1/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 %eax, %eax
callq 0x7c21
testl %eax, %eax
je 0x372a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa137(%rip), %r9       # 0xd868
movslq (%r9), %rax
testq %rax, %rax
jle 0x3752
movq 0xa1c0(%rip), %rcx      # 0xd900
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
andw $-0x9, (%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x3742
leaq 0xa307(%rip), %r14      # 0xda60
movq (%r14), %rax
testq %rax, %rax
je 0x3786
movq 0xa198(%rip), %rcx      # 0xd900
movsbq 0x38(%rax), %rdx
movsbq 0x39(%rax), %rsi
leaq (%rcx,%rdx,8), %rdx
movq (%rdx,%rsi,8), %rdx
orw $0x8, (%rdx)
movq (%rax), %rax
testq %rax, %rax
jne 0x3768
movq (%r14), %rbx
testq %rbx, %rbx
je 0x39dd
xorl %r15d, %r15d
movb 0x3b(%rbx), %al
testb %al, %al
je 0x39b6
testb $0x1, %al
jne 0x37d4
movsbl 0x39(%rbx), %ecx
testl %ecx, %ecx
jle 0x37d4
leaq 0x10(%rbx), %rdx
movq 0x18(%rbx), %rsi
decl %ecx
movq (%rdx), %rdx
cmpq %rsi, %rdx
je 0x3839
movq 0x8(%rbx), %r8
subl $0x1, %ecx
setb %dil
cmpq 0x28(%r8), %rdx
je 0x37d4
testb %dil, %dil
je 0x37b6
movsbl 0x3a(%rbx), %ecx
movsbl 0x39(%rbx), %edx
testl %ecx, %ecx
jle 0x37e8
cmpb %dl, %cl
jle 0x37fa
decl %edx
jmp 0x3806
testb %cl, %cl
js 0x37fe
movl %edx, %ecx
shrb $0x7, %cl
addb %dl, %cl
sarb %cl
movsbl %cl, %ecx
jmp 0x3808
decl %ecx
jmp 0x3808
addl %ecx, %edx
testl %edx, %edx
cmovlel %r15d, %edx
movl %edx, %ecx
movq 0x18(%rbx), %rdx
testl %ecx, %ecx
je 0x382d
movq 0x8(%rbx), %rsi
movq 0x28(%rsi), %rsi
movq %rdx, %rdi
movq 0x8(%rdx), %rdx
cmpq %rsi, %rdx
je 0x3830
movq %rdx, %rdi
decl %ecx
jne 0x3818
jmp 0x3830
movq %rdx, %rdi
movq %rdi, 0x10(%rbx)
orb $0x8, %al
movb %al, 0x3b(%rbx)
movq 0x10(%rbx), %r12
movsbl 0x38(%rbx), %eax
movsbl 0x3b(%rbx), %ecx
movl %ecx, %edx
andl $-0x11, %edx
cmpl $0x4, %edx
jne 0x3864
movq 0x18(%rbx), %rcx
cmpq %rcx, %r12
je 0x3931
incl %eax
movq (%r12), %r12
jmp 0x3853
testb $0xc, %cl
je 0x39b6
movsbl 0x38(%rbx), %ecx
movsbl 0x39(%rbx), %edx
addl %ecx, %edx
cmpl %eax, %edx
jle 0x39b6
movslq %eax, %r13
movq 0xa077(%rip), %rax      # 0xd900
movq (%rax,%r13,8), %rax
orw $0x1, (%rax)
movl %r13d, 0xa058(%rip)     # 0xd8f0
movl $0x0, 0xa052(%rip)      # 0xd8f4
movq 0x8(%rbx), %rax
cmpq 0x28(%rax), %r12
je 0x38d9
cmpl $0x0, 0x14(%r12)
jle 0x38ce
xorl %ebp, %ebp
movzbl 0x18(%r12,%rbp), %edi
callq 0x359b
incq %rbp
movslq 0x14(%r12), %rax
cmpq %rax, %rbp
jl 0x38b6
movq (%r12), %r12
leaq 0x9f8f(%rip), %r9       # 0xd868
movl 0xa015(%rip), %eax      # 0xd8f4
cmpl 0x4(%r9), %eax
jge 0x3913
movq 0xa014(%rip), %rcx      # 0xd900
movslq 0x9ffd(%rip), %rdx      # 0xd8f0
movq (%rcx,%rdx,8), %rcx
leal 0x1(%rax), %edx
movl %edx, 0x9ff4(%rip)      # 0xd8f4
cltq
movb $0x20, 0x2(%rcx,%rax)
movl 0x9fe7(%rip), %eax      # 0xd8f4
cmpl 0x4(%r9), %eax
jl 0x38f7
incq %r13
movsbq 0x38(%rbx), %rax
movsbq 0x39(%rbx), %rcx
addq %rax, %rcx
cmpq %rcx, %r13
jl 0x3882
jmp 0x39b6
movq 0x9fc8(%rip), %rcx      # 0xd900
cltq
movq (%rcx,%rax,8), %rcx
orw $0x1, (%rcx)
movl %eax, 0x9fa8(%rip)      # 0xd8f0
movl $0x0, 0x9fa2(%rip)      # 0xd8f4
cmpl $0x0, 0x14(%r12)
jle 0x3975
xorl %r13d, %r13d
movzbl 0x18(%r12,%r13), %edi
callq 0x359b
incq %r13
movslq 0x14(%r12), %rax
cmpq %rax, %r13
jl 0x395d
movl 0x9f79(%rip), %eax      # 0xd8f4
leaq 0x9ee6(%rip), %r9       # 0xd868
cmpl 0x4(%r9), %eax
jge 0x39b6
movq 0x9f71(%rip), %rcx      # 0xd900
movslq 0x9f5a(%rip), %rdx      # 0xd8f0
movq (%rcx,%rdx,8), %rcx
leal 0x1(%rax), %edx
movl %edx, 0x9f51(%rip)      # 0xd8f4
cltq
movb $0x20, 0x2(%rcx,%rax)
movl 0x9f44(%rip), %eax      # 0xd8f4
cmpl 0x4(%r9), %eax
jl 0x399a
testb $0x10, 0x3b(%rbx)
je 0x39cb
movq %rbx, %rdi
callq 0x3d02
leaq 0x9e9d(%rip), %r9       # 0xd868
movw $0x0, 0x3a(%rbx)
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x3795
leaq 0xa064(%rip), %rbx      # 0xda48
movq (%rbx), %rcx
movq 0x10(%rcx), %rax
movsbl 0x38(%rcx), %edx
leaq 0xa12a(%rip), %r10      # 0xdb20
movl %edx, (%r10)
movq 0x18(%rcx), %rsi
cmpq %rsi, %rax
je 0x3a0f
incl %edx
movq (%rax), %rax
cmpq %rsi, %rax
jne 0x3a02
movl %edx, (%r10)
movq 0x20(%rcx), %rcx
leaq 0xa10a(%rip), %r12      # 0xdb24
movl $0x0, (%r12)
testq %rcx, %rcx
jle 0x3a66
xorl %esi, %esi
xorl %edx, %edx
movb 0x18(%rax,%rsi), %dil
cmpb $0x9, %dil
jne 0x3a3b
orl $0x7, %edx
jmp 0x3a52
cmpb $0x20, %dil
setae %r8b
cmpb $0x7f, %dil
setne %dil
testb %dil, %r8b
jne 0x3a56
incl %edx
movl %edx, (%r12)
incq %rsi
incl %edx
movl %edx, (%r12)
cmpq %rsi, %rcx
jne 0x3a2b
jmp 0x3a68
xorl %edx, %edx
movl 0x4(%r9), %eax
decl %eax
cmpl %eax, %edx
jge 0x3a81
movl $0x0, 0x9e7c(%rip)      # 0xd8f8
jmp 0x3b95
movq 0x9e78(%rip), %rax      # 0xd900
movslq (%r10), %rcx
movq (%rax,%rcx,8), %rax
orw $0x3, (%rax)
callq 0x425d
leaq 0x9dc9(%rip), %r9       # 0xd868
jmp 0x3b95
movsbl 0x38(%r14), %eax
movsbl 0x39(%r14), %ecx
addl %eax, %ecx
cmpl %eax, %ecx
jle 0x3b95
movslq %eax, %r13
leaq 0x10(%r14), %rbp
movq (%rbp), %rbp
movq 0x9e36(%rip), %rax      # 0xd900
movq (%rax,%r13,8), %rax
movzwl (%rax), %ecx
testb $0x2, %cl
je 0x3b7c
orl $0x1, %ecx
movw %cx, (%rax)
cmpq (%rbx), %r14
jne 0x3afb
cmpq 0x18(%r14), %rbp
jne 0x3afb
movl 0x4(%r9), %eax
decl %eax
cmpl %eax, (%r12)
jge 0x3b7c
movl %r13d, 0x9dee(%rip)     # 0xd8f0
movl $0x0, 0x9de8(%rip)      # 0xd8f4
cmpl $0x0, 0x14(%rbp)
jle 0x3b2c
xorl %r15d, %r15d
movzbl 0x18(%rbp,%r15), %edi
callq 0x359b
incq %r15
movslq 0x14(%rbp), %rax
cmpq %rax, %r15
jl 0x3b15
movl 0x9dc2(%rip), %eax      # 0xd8f4
leaq 0x9d2f(%rip), %r9       # 0xd868
cmpl 0x4(%r9), %eax
jge 0x3b6d
movq 0x9dba(%rip), %rcx      # 0xd900
movslq 0x9da3(%rip), %rdx      # 0xd8f0
movq (%rcx,%rdx,8), %rcx
leal 0x1(%rax), %edx
movl %edx, 0x9d9a(%rip)      # 0xd8f4
cltq
movb $0x20, 0x2(%rcx,%rax)
movl 0x9d8d(%rip), %eax      # 0xd8f4
cmpl 0x4(%r9), %eax
jl 0x3b51
movq 0x9d8c(%rip), %rax      # 0xd900
movq (%rax,%r13,8), %rax
andw $-0x3, (%rax)
incq %r13
movsbq 0x38(%r14), %rax
movsbq 0x39(%r14), %rcx
addq %rax, %rcx
cmpq %rcx, %r13
jl 0x3abf
movq (%r14), %r14
testq %r14, %r14
jne 0x3aa4
leaq 0x97cc(%rip), %rbx      # 0xd374
cmpl $0x0, (%rbx)
leaq 0x9f6e(%rip), %r15      # 0xdb20
je 0x3c4b
cmpl $0x0, (%r9)
jle 0x3bff
xorl %eax, %eax
movq 0x9d39(%rip), %rcx      # 0xd900
movq (%rcx,%rax,8), %rcx
orw $0x1, (%rcx)
cmpl $0x0, 0x4(%r9)
jle 0x3bf4
movq 0x9d2b(%rip), %rcx      # 0xd908
movq (%rcx,%rax,8), %rcx
xorl %edx, %edx
movb $0x20, 0x2(%rcx,%rdx)
incq %rdx
movslq 0x4(%r9), %rsi
cmpq %rsi, %rdx
jl 0x3be3
incq %rax
movslq (%r9), %rcx
cmpq %rcx, %rax
jl 0x3bc0
movl 0x955f(%rip), %eax      # 0xd164
orl 0x9555(%rip), %eax      # 0xd160
je 0x3c2b
xorl %eax, %eax
movl %eax, 0x954b(%rip)      # 0xd160
movl %eax, 0x9549(%rip)      # 0xd164
xorl %edi, %edi
xorl %esi, %esi
xorl %eax, %eax
leaq 0x9c40(%rip), %rcx      # 0xd868
callq *0x38(%rcx)
xorl %ebp, %ebp
xorl %eax, %eax
leaq 0x9c32(%rip), %rcx      # 0xd868
callq *0x48(%rcx)
leaq 0x9c28(%rip), %r9       # 0xd868
movl %ebp, (%rbx)
leaq 0x9deb(%rip), %rax      # 0xda34
movl %ebp, (%rax)
cmpl $0x0, (%r9)
jle 0x3cb2
xorl %ebx, %ebx
movq 0x9ca6(%rip), %rax      # 0xd900
movq (%rax,%rbx,8), %r14
movzwl (%r14), %eax
testb $0x1, %al
jne 0x3c74
movl %eax, %ecx
shrl $0x2, %ecx
shrl $0x3, %eax
xorl %ecx, %eax
testb $0x1, %al
je 0x3ca7
xorl %eax, %eax
callq 0x7c21
testl %eax, %eax
jne 0x371b
movq 0x9c7e(%rip), %rax      # 0xd908
movq (%rax,%rbx,8), %rdx
leaq 0x2(%r14), %rsi
addq $0x2, %rdx
movl %ebx, %edi
movq %r14, %rcx
callq 0x405c
leaq 0x9bc1(%rip), %r9       # 0xd868
incq %rbx
movslq (%r9), %rax
cmpq %rax, %rbx
jl 0x3c53
movl (%r15), %edi
movl (%r12), %esi
subl 0x9c39(%rip), %esi      # 0xd8f8
cmpl %edi, 0x949b(%rip)      # 0xd160
jne 0x3ccf
cmpl %esi, 0x9497(%rip)      # 0xd164
je 0x3cee
movl %edi, 0x948b(%rip)      # 0xd160
movl %esi, 0x9489(%rip)      # 0xd164
xorl %eax, %eax
leaq 0x9b84(%rip), %rcx      # 0xd868
callq *0x38(%rcx)
leaq 0x9b7a(%rip), %r9       # 0xd868
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *0x30(%r9)