// File: /workspace/github_c_makefile_star2_O3/ThomasMadappattu[P]Sandmacs/file.c
// Function: ifile
int ifile (char fname[])
{
  LINE *lp0, *lp1, *lp2;
  BUFFER *bp;
  char line[NLINE];
  int i, s, nbytes, nline;
  int lflag;			/* any lines longer than allowed? */

  bp = curbp;			/* Cheap */
  bp->b_flag |= BFCHG;		/* we have changed */
  bp->b_flag &= ~BFTEMP;	/* and are not temporary */
  if ((s = ffropen (fname)) == FIOERR) /* Hard file open */
    goto out;
  if (s == FIOFNF)
    {				/* File not found */
      mlwrite ("[No such file]");
      return (FALSE);
    }
  mlwrite ("[Inserting file]");

  /* back up a line and save the mark here */
  curwp->w_dotp = lback (curwp->w_dotp);
  curwp->w_doto = 0;
  curwp->w_markp = curwp->w_dotp;
  curwp->w_marko = 0;

  nline = 0;
  lflag = FALSE;
  while ((s = ffgetline (line, NLINE)) == FIOSUC || s == FIOLNG)
    {
      if (s == FIOLNG)
	lflag = TRUE;
      nbytes = strlen (line);
      if ((lp1 = lalloc (nbytes)) == NULL)
	{
	  s = FIOERR;		/* keep message on the */
	  break;		/* display */
	}
      lp0 = curwp->w_dotp;	/* line previous to insert */
      lp2 = lp0->l_fp;		/* line after insert */

      /* re-link new line between lp0 and lp2 */
      lp2->l_bp = lp1;
      lp0->l_fp = lp1;
      lp1->l_bp = lp0;
      lp1->l_fp = lp2;

      /* and advance and write out the current line */
      curwp->w_dotp = lp1;
      for (i = 0; i < nbytes; ++i)
	lputc (lp1, i, line[i]);
      ++nline;
    }
  ffclose ();			/* Ignore errors */
  curwp->w_markp = lforw (curwp->w_markp);
  if (s == FIOEOF)
    {				/* Don't zap message! */
      if (nline == 1)
	mlwrite ("[Inserted 1 line]");
      else
	mlwrite ("[Inserted %d lines]", nline);
    }
  if (lflag)
    mlwrite ("[Inserted %d line(s), Long lines wrapped]", nline);
 out:
  /* advance to the next line and mark the window for changes */
  curwp->w_dotp = lforw (curwp->w_dotp);
  curwp->w_flag |= WFHARD;

  /* copy window parameters back to the buffer structure */
  curbp->b_dotp = curwp->w_dotp;
  curbp->b_doto = curwp->w_doto;
  curbp->b_markp = curwp->w_markp;
  curbp->b_marko = curwp->w_marko;

  if (s == FIOERR)		/* False if error */
    return (FALSE);
  return (TRUE);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
leaq 0x905c(%rip), %rbx      # 0xd848
movq (%rbx), %rax
movb 0x32(%rax), %cl
andb $-0x4, %cl
orb $0x2, %cl
movb %cl, 0x32(%rax)
callq 0x4dfc
movl %eax, %ebp
cmpl $0x3, %eax
je 0x493b
cmpl $0x1, %ebp
jne 0x4825
leaq 0x49e8(%rip), %rdi      # 0x91ff
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4352
jmp 0x497b
leaq 0x49e2(%rip), %rdi      # 0x920e
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4352
leaq 0x901c(%rip), %r12      # 0xd858
movq (%r12), %rax
movq 0x18(%rax), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq %rbx, 0x20(%rax)
movq %rcx, 0x28(%rax)
movq %rbx, 0x30(%rax)
movq %rsp, %r14
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r14, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x4ee2
testl %eax, %eax
je 0x487e
movl %eax, %ebp
cmpl $0x4, %eax
jne 0x48df
movl $0x1, %r13d
movq %r14, %rdi
callq 0x20c0
movq %rax, %r15
movl %r15d, %edi
xorl %eax, %eax
callq 0x4f94
testq %rax, %rax
je 0x48da
movq (%r12), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx), %rdx
movq %rax, 0x8(%rdx)
movq %rax, (%rcx)
movq %rcx, 0x8(%rax)
movq %rdx, (%rax)
movq (%r12), %rcx
movq %rax, 0x18(%rcx)
testl %r15d, %r15d
jle 0x48d6
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movb (%rsp,%rcx), %dl
movb %dl, 0x18(%rax,%rcx)
incq %rcx
cmpq %rcx, %r15
jne 0x48c7
incl %ebx
jmp 0x4860
movl $0x3, %ebp
xorl %eax, %eax
callq 0x4e4f
movq (%r12), %rax
movq 0x28(%rax), %rcx
movq (%rcx), %rcx
movq %rcx, 0x28(%rax)
cmpl $0x2, %ebp
jne 0x491f
cmpl $0x1, %ebx
jne 0x490f
leaq 0x4919(%rip), %rdi      # 0x921f
xorl %eax, %eax
callq 0x4352
jmp 0x491f
leaq 0x491b(%rip), %rdi      # 0x9231
movl %ebx, %esi
xorl %eax, %eax
callq 0x4352
testl %r13d, %r13d
je 0x4934
leaq 0x491a(%rip), %rdi      # 0x9245
movl %ebx, %esi
xorl %eax, %eax
callq 0x4352
leaq 0x8f0d(%rip), %rbx      # 0xd848
leaq 0x8f16(%rip), %rax      # 0xd858
movq (%rax), %rax
movq 0x18(%rax), %rcx
movq (%rcx), %rcx
movq %rcx, 0x18(%rax)
orb $0x8, 0x3b(%rax)
movq (%rbx), %rdx
movq %rcx, 0x8(%rdx)
movq 0x20(%rax), %rcx
movq %rcx, 0x10(%rdx)
movq 0x28(%rax), %rcx
movq %rcx, 0x18(%rdx)
movq 0x30(%rax), %rax
movq %rax, 0x20(%rdx)
xorl %ebx, %ebx
cmpl $0x3, %ebp
setne %bl
movl %ebx, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq