// File: /workspace/github_c_makefile_star2_O1/hughbarney[P]pEmacs/line.c
// Function: linsert
int linsert (int n, int c)
{
  WINDOW *wp;
  LINE *lp1, *lp2, *lp3;
  char *cp1, *cp2;
  int i, doto;

  lchange (WFEDIT);
  lp1 = curwp->w_dotp;	       /* Current line */
  if (lp1 == curbp->b_linep)
    {			       /* At the end: special */
      if (curwp->w_doto != 0)
	{
	  mlwrite ("bug: linsert");
	  return (FALSE);
	}
      if ((lp2 = lalloc (n)) == NULL)	/* Allocate new line */
	return (FALSE);
      lp3 = lp1->l_bp;	       /* Previous line */
      lp3->l_fp = lp2;	       /* Link in */
      lp2->l_fp = lp1;
      lp1->l_bp = lp2;
      lp2->l_bp = lp3;
      for (i = 0; i < n; ++i)
	lp2->l_text[i] = c;
      curwp->w_dotp = lp2;
      curwp->w_doto = n;
      return (TRUE);
    }
  doto = curwp->w_doto;	       /* Save for later */
  if (lp1->l_used + n > lp1->l_size)
    {			       /* Hard: reallocate */
      if ((lp2 = lalloc (lp1->l_used + n)) == NULL)
	return (FALSE);
      cp1 = &lp1->l_text[0];
      cp2 = &lp2->l_text[0];
      while (cp1 != &lp1->l_text[doto])
	*cp2++ = *cp1++;
      cp2 += n;
      while (cp1 != &lp1->l_text[lp1->l_used])
	*cp2++ = *cp1++;
      lp1->l_bp->l_fp = lp2;
      lp2->l_fp = lp1->l_fp;
      lp1->l_fp->l_bp = lp2;
      lp2->l_bp = lp1->l_bp;
      free ((char *) lp1);
    }
  else
    {				/* Easy: in place */
      lp2 = lp1;		/* Pretend new line */
      lp2->l_used += n;
      cp2 = &lp1->l_text[lp1->l_used];
      cp1 = cp2 - n;
      while (cp1 != &lp1->l_text[doto])
	*--cp2 = *--cp1;
    }
  for (i = 0; i < n; ++i)	/* Add the characters */
    lp2->l_text[doto + i] = c;
  wp = wheadp;		       /* Update windows */
  while (wp != NULL)
    {
      if (wp->w_linep == lp1)
	wp->w_linep = lp2;
      if (wp->w_dotp == lp1)
	{
	  wp->w_dotp = lp2;
	  if (wp == curwp || wp->w_doto > doto)
	    wp->w_doto += n;
	}
      if (wp->w_markp == lp1)
	{
	  wp->w_markp = lp2;
	  if (wp->w_marko > doto)
	    wp->w_marko += n;
	}
      wp = wp->w_wndp;
    }
  return (TRUE);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %r14d
movl %edi, %ebp
movl $0x4, %edi
callq 0x512b
leaq 0x88ba(%rip), %r12      # 0xda48
movq (%r12), %rax
movq 0x18(%rax), %rbx
movq 0x20(%rax), %r13
leaq 0x8897(%rip), %rax      # 0xda38
movq (%rax), %rax
cmpq 0x28(%rax), %rbx
je 0x51fc
movslq 0x14(%rbx), %rax
movslq %ebp, %r12
leaq (%rax,%r12), %rdi
cmpl 0x10(%rbx), %edi
jle 0x5216
callq 0x503c
testq %rax, %rax
je 0x52ab
movq %rax, %r15
leaq 0x18(%rbx), %rax
leaq 0x18(%r15), %rcx
movq %r13, %rdx
shlq $0x20, %rdx
je 0x52b2
movslq %r13d, %rsi
movq %rax, %rdx
movb (%rdx), %dil
incq %rdx
movb %dil, (%rcx)
incq %rcx
decq %rsi
jne 0x51e6
jmp 0x52b5
testq %r13, %r13
je 0x525c
leaq 0x40fc(%rip), %rdi      # 0x9304
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x43cc
jmp 0x537f
movl %edi, 0x14(%rbx)
leaq (%rbx,%rdi), %rdx
addq $0x18, %rdx
subq %r12, %rdx
movslq %r13d, %rcx
leaq (%rbx,%rcx), %rsi
addq $0x18, %rsi
movq %rbx, %r15
cmpq %rsi, %rdx
je 0x5300
leaq (%r12,%rbx), %rdx
addq $0x17, %rdx
movb 0x17(%rbx,%rax), %sil
movb %sil, (%rdx,%rax)
decq %rax
cmpq %rax, %rcx
jne 0x5243
movq %rbx, %r15
jmp 0x5300
movl %ebp, %edi
callq 0x503c
testq %rax, %rax
je 0x52ab
movq %rax, %r15
movq 0x8(%rbx), %rax
movq %r15, (%rax)
movq %rbx, (%r15)
movq %r15, 0x8(%rbx)
movq %rax, 0x8(%r15)
testl %ebp, %ebp
jle 0x5292
movq %r15, %rdi
addq $0x18, %rdi
movl %ebp, %edx
movl %r14d, %esi
callq 0x2130
movq (%r12), %rax
movq %r15, 0x18(%rax)
movslq %ebp, %rcx
movq %rcx, 0x20(%rax)
movl $0x1, %ebp
jmp 0x537f
xorl %ebp, %ebp
jmp 0x537f
movq %rax, %rdx
movslq 0x14(%rbx), %rsi
addq %rax, %rsi
cmpq %rsi, %rdx
je 0x52dc
addq %r12, %rcx
movb (%rdx), %sil
incq %rdx
movb %sil, (%rcx)
incq %rcx
movslq 0x14(%rbx), %rsi
addq %rax, %rsi
cmpq %rsi, %rdx
jne 0x52c4
movq 0x8(%rbx), %rax
movq %r15, (%rax)
movq (%rbx), %rax
movq %rax, (%r15)
movq (%rbx), %rax
movq %r15, 0x8(%rax)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%r15)
movq %rbx, %rdi
callq 0x2040
testl %ebp, %ebp
jle 0x5319
movslq %r13d, %rax
leaq (%rax,%r15), %rdi
addq $0x18, %rdi
movl %ebp, %edx
movl %r14d, %esi
callq 0x2130
leaq 0x8740(%rip), %rax      # 0xda60
movq (%rax), %rax
movl $0x1, %ebp
testq %rax, %rax
je 0x537f
leaq 0x8714(%rip), %rcx      # 0xda48
movq (%rcx), %rcx
movslq %r13d, %rdx
cmpq %rbx, 0x10(%rax)
jne 0x5344
movq %r15, 0x10(%rax)
cmpq %rbx, 0x18(%rax)
jne 0x535d
movq %r15, 0x18(%rax)
cmpq %rcx, %rax
je 0x5359
cmpq %rdx, 0x20(%rax)
jle 0x535d
addq %r12, 0x20(%rax)
cmpq %rbx, 0x28(%rax)
jne 0x5377
movq %r15, 0x28(%rax)
movq 0x30(%rax), %rsi
cmpq %rdx, %rsi
jle 0x5377
addq %r12, %rsi
movq %rsi, 0x30(%rax)
movq (%rax), %rax
testq %rax, %rax
jne 0x533a
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq