// File: /workspace/github_c_makefile_star2_O1/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 0x8f58(%rip), %rbx      # 0xd848
movq (%rbx), %rax
movb 0x32(%rax), %cl
andb $-0x4, %cl
orb $0x2, %cl
movb %cl, 0x32(%rax)
callq 0x4ee4
movl %eax, %ebp
cmpl $0x3, %eax
je 0x4a3f
cmpl $0x1, %ebp
jne 0x4929
leaq 0x48e4(%rip), %rdi      # 0x91ff
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x446e
jmp 0x4a7f
leaq 0x48de(%rip), %rdi      # 0x920e
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x446e
leaq 0x8f18(%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 0x4fca
testl %eax, %eax
je 0x4982
movl %eax, %ebp
cmpl $0x4, %eax
jne 0x49e3
movl $0x1, %r13d
movq %r14, %rdi
callq 0x20c0
movq %rax, %r15
movl %r15d, %edi
xorl %eax, %eax
callq 0x507c
testq %rax, %rax
je 0x49de
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 0x49da
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movb (%rsp,%rcx), %dl
movb %dl, 0x18(%rax,%rcx)
incq %rcx
cmpq %rcx, %r15
jne 0x49cb
incl %ebx
jmp 0x4964
movl $0x3, %ebp
xorl %eax, %eax
callq 0x4f37
movq (%r12), %rax
movq 0x28(%rax), %rcx
movq (%rcx), %rcx
movq %rcx, 0x28(%rax)
cmpl $0x2, %ebp
jne 0x4a23
cmpl $0x1, %ebx
jne 0x4a13
leaq 0x4815(%rip), %rdi      # 0x921f
xorl %eax, %eax
callq 0x446e
jmp 0x4a23
leaq 0x4817(%rip), %rdi      # 0x9231
movl %ebx, %esi
xorl %eax, %eax
callq 0x446e
testl %r13d, %r13d
je 0x4a38
leaq 0x4816(%rip), %rdi      # 0x9245
movl %ebx, %esi
xorl %eax, %eax
callq 0x446e
leaq 0x8e09(%rip), %rbx      # 0xd848
leaq 0x8e12(%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