// File: /workspace/github_c_makefile_star2_O1/ThomasMadappattu[P]Sandmacs/main.c
// Function: main
int main (int argc, char *argv[])
{
  BUFFER *bp;
  char bname[NBUFN];		/* buffer name of file to read */
  int c, f, n, mflag;
  int ffile;			/* first file flag */
  int carg;			/* current arg to scan */
  int basec;			/* c stripped of meta character */

  /* initialize the editor and process the startup file */
  getwinsize();			/* find out the "real" screen size */
  strncpy (bname, "main", 5);	/* default buffer name */
  edinit (bname);		/* Buffers, windows */
  vtinit ();			/* Displays */
  ffile = TRUE;			/* no file to edit yet */
  update ();			/* let the user know we are here */

  /* scan through the command line and get the files to edit */
  for (carg = 1; carg < argc; ++carg)
    {
      /* set up a buffer for this file */
      makename (bname, argv[carg]);

      /* if this is the first file, read it in */
      if (ffile)
	{
	  bp = curbp;
	  makename (bname, argv[carg]);
	  strncpy (bp->b_bname, bname, NBUFN);
	  strncpy (bp->b_fname, argv[carg], NFILEN);
	  if (readin (argv[carg]) == ABORT)
	    {
	      strncpy (bp->b_bname, "main", 5);
	      strncpy (bp->b_fname, "", 1);
	    }
	  bp->b_dotp = bp->b_linep;
	  bp->b_doto = 0;
	  ffile = FALSE;
	}
      else
	{
	  /* set this to inactive */
	  bp = bfind (bname, TRUE, 0);
	  strncpy (bp->b_fname, argv[carg], NFILEN);
	  bp->b_active = FALSE;
	}
    }

  /* setup to process commands */
  lastflag = 0;			/* Fake last flags */
  curwp->w_flag |= WFMODE;	/* and force an update */

 loop:
  update ();			/* Fix up the screen */
  c = getkey ();
  if (mpresf != FALSE)
    {
      mlerase ();
      update ();
    }
  f = FALSE;
  n = 1;

  /* do META-# processing if needed */

  basec = c & ~META;		/* strip meta char off if there */
  if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-'))
    {
      f = TRUE;			/* there is a # arg */
      n = 0;			/* start with a zero default */
      mflag = 1;		/* current minus flag */
      c = basec;		/* strip the META */
      while ((c >= '0' && c <= '9') || (c == '-'))
	{
	  if (c == '-')
	    {
	      /* already hit a minus or digit? */
	      if ((mflag == -1) || (n != 0))
		break;
	      mflag = -1;
	    }
	  else
	    n = n * 10 + (c - '0');
	  if ((n == 0) && (mflag == -1)) /* lonely - */
	    mlwrite ("Arg:");
	  else
	    mlwrite ("Arg: %d", n * mflag);

	  c = getkey ();	/* get the next key */
	}
      n = n * mflag;		/* figure in the sign */
    }
  /* do ^U repeat argument processing */

  if (c == (CTRL | 'U'))
    {				/* ^U, start argument */
      f = TRUE;
      n = 4;			/* with argument of 4 */
      mflag = 0;		 /* that can be discarded */
      mlwrite ("Arg: 4");
      while (((c = getkey ()) >= '0')
	     && ((c <= '9') || (c == (CTRL | 'U')) || (c == '-')))
	{
	  if (c == (CTRL | 'U'))
	    n = n * 4;
	  /*
	   * If dash, and start of argument string, set arg.
	   * to -1.  Otherwise, insert it.
	   */
	  else if (c == '-')
	    {
	      if (mflag)
		break;
	      n = 0;
	      mflag = -1;
	    }
	  /*
	   * If first digit entered, replace previous argument
	   * with digit and set sign.  Otherwise, append to arg.
	   */
	  else
	    {
	      if (!mflag)
		{
		  n = 0;
		  mflag = 1;
		}
	      n = 10 * n + c - '0';
	    }
	  mlwrite ("Arg: %d", (mflag >= 0) ? n : (n ? -n : -1));
	}
      /*
       * Make arguments preceded by a minus sign negative and change
       * the special argument "^U -" to an effective "^U -1".
       */
      if (mflag == -1)
	{
	  if (n == 0)
	    n++;
	  n = -n;
	}
    }

  if (c == (CTRL | 'X'))       /* ^X is a prefix */
    c = CTLX | getctl ();
  if (kbdmip != NULL)
    {				 /* Save macro strokes */
      if (c != (CTLX | ')') && kbdmip > &kbdm[NKBDM - 6])
	{
	  ctrlg (FALSE, 0);
	  goto loop;
	}
      if (f != FALSE)
	{
	  *kbdmip++ = (CTRL | 'U');
	  *kbdmip++ = n;
	}
      *kbdmip++ = c;
    }
  execute (c, f, n);	       /* Do it */
  goto loop;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorl %eax, %eax
callq 0x7174
leaq 0x10(%rsp), %rdi
movb $0x0, 0x4(%rdi)
movl $0x6e69616d, (%rdi)     # imm = 0x6E69616D
callq 0x5cb1
xorl %eax, %eax
callq 0x3204
xorl %eax, %eax
callq 0x346d
cmpl $0x2, %ebp
jl 0x5a0c
movl %ebp, %r12d
movl $0x1, %ebp
leaq 0x10(%rsp), %r14
xorl %r15d, %r15d
movq %r12, 0x8(%rsp)
movq (%rbx,%rbp,8), %rsi
movq %r14, %rdi
callq 0x4c80
testb $0x1, %r15b
je 0x5985
movq %r14, %rdi
movl $0x1, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2a45
movq %rax, %r15
leaq 0x33(%rax), %rdi
movq (%rbx,%rbp,8), %rsi
movl $0x50, %edx
callq 0x2060
movb $0x0, 0x30(%r15)
jmp 0x59fd
movq 0x7ebc(%rip), %r13      # 0xd848
movq (%rbx,%rbp,8), %rsi
movq %r14, %rdi
callq 0x4c80
leaq 0x83(%r13), %r15
movl $0x10, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2060
leaq 0x33(%r13), %r12
movq (%rbx,%rbp,8), %rsi
movl $0x50, %edx
movq %r12, %rdi
callq 0x2060
movq (%rbx,%rbp,8), %rdi
callq 0x46ee
cmpl $0x2, %eax
jne 0x59e3
xorl %eax, %eax
movb %al, 0x4(%r15)
movl $0x6e69616d, (%r15)     # imm = 0x6E69616D
movb %al, (%r12)
movq 0x28(%r13), %rax
movq %rax, 0x8(%r13)
movq $0x0, 0x10(%r13)
movq 0x8(%rsp), %r12
leaq 0x10(%rsp), %r14
incq %rbp
movb $0x1, %r15b
cmpq %rbp, %r12
jne 0x5946
movl $0x0, 0x7e3a(%rip)      # 0xd850
movq 0x7e3b(%rip), %rax      # 0xd858
orb $0x10, 0x3b(%rax)
leaq 0x394e(%rip), %rbx      # 0x9376
leaq 0x393f(%rip), %r14      # 0x936e
leaq 0x7d5a(%rip), %r12      # 0xd790
leaq 0x76e3(%rip), %rax      # 0xd120
addq $0x1f4, %rax            # imm = 0x1F4
movq %rax, 0x8(%rsp)
xorl %eax, %eax
callq 0x346d
callq 0x5e12
movl %eax, %r15d
cmpl $0x0, 0x7de6(%rip)      # 0xd844
je 0x5a6e
xorl %eax, %eax
callq 0x3130
xorl %eax, %eax
callq 0x346d
movl $0x1, %r13d
xorl %ebp, %ebp
btl $0x9, %r15d
jae 0x5b34
movl %r15d, %eax
andl $0xfffffdff, %eax       # imm = 0xFFFFFDFF
leal -0x30(%rax), %ecx
cmpl $0xa, %ecx
setae %dl
cmpl $0x2d, %eax
setne %sil
testb %dl, %sil
jne 0x5b34
cmpl $0xa, %ecx
setae %sil
cmpl $0x2d, %eax
sete %dl
setne %dil
xorl %r13d, %r13d
testb %sil, %dil
jne 0x5b2c
movl $0x1, %ebp
leaq 0x38a2(%rip), %r15      # 0x9369
testb $0x1, %dl
je 0x5ae0
testl %r13d, %r13d
jne 0x5b28
cmpl $-0x1, %ebp
je 0x5b28
xorl %r13d, %r13d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x5ae9
leal (%r13,%r13,4), %eax
leal (%rcx,%rax,2), %r13d
movl %ebp, %eax
notl %eax
orl %r13d, %eax
jne 0x5afe
movq %r15, %rdi
xorl %eax, %eax
callq 0x446e
jmp 0x5b0e
movl %ebp, %esi
imull %r13d, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x446e
callq 0x5e12
leal -0x30(%rax), %ecx
cmpl $0xa, %ecx
setb %sil
cmpl $0x2d, %eax
sete %dl
orb %dl, %sil
jne 0x5ac7
imull %ebp, %r13d
movl $0x1, %ebp
movl %eax, %r15d
cmpl $0x155, %r15d           # imm = 0x155
jne 0x5bd0
movq %rbx, %rdi
xorl %eax, %eax
callq 0x446e
callq 0x5e12
movl %eax, %r15d
movl $0x4, %r13d
movl $0x1, %ebp
cmpl $0x30, %eax
jl 0x5bd0
movq %rbx, %r12
movl $0x4, %r13d
xorl %ebx, %ebx
cmpl $0x3a, %r15d
setae %al
cmpl $0x155, %r15d           # imm = 0x155
setne %cl
testb %cl, %al
jne 0x5bc6
cmpl $0x155, %r15d           # imm = 0x155
jne 0x5b92
shll $0x2, %r13d
jmp 0x5bac
addl %r13d, %r13d
testl %ebx, %ebx
leal (%r13,%r13,4), %eax
cmovel %ebx, %eax
leal (%r15,%rax), %r13d
addl $-0x30, %r13d
movl $0x1, %ebx
movq %r14, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x446e
callq 0x5e12
movl %eax, %r15d
cmpl $0x2f, %eax
jg 0x5b6e
movq %r12, %rbx
leaq 0x7bc0(%rip), %r12      # 0xd790
cmpl $0x158, %r15d           # imm = 0x158
jne 0x5c04
xorl %eax, %eax
callq *0x20(%r12)
leal -0x61(%rax), %ecx
leal -0x20(%rax), %edx
cmpl $0x1a, %ecx
cmovael %eax, %edx
movl %edx, %r15d
orl $0x140, %r15d           # imm = 0x140
cmpl $0x20, %edx
cmovael %edx, %r15d
orl $0x400, %r15d           # imm = 0x400
movq 0x7c55(%rip), %rax      # 0xd860
testq %rax, %rax
je 0x5c9f
cmpl $0x429, %r15d           # imm = 0x429
setne %cl
cmpq 0x8(%rsp), %rax
seta %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x5c65
xorl %eax, %eax
callq *0x50(%r12)
cmpq $0x0, 0x7c24(%rip)      # 0xd860
je 0x5c52
movw $0x429, 0x74d9(%rip)    # imm = 0x429
movq $0x0, 0x7c0e(%rip) # 0xd860
leaq 0x37a0(%rip), %rdi      # 0x93f9
xorl %eax, %eax
callq 0x446e
jmp 0x5a48
testl %ebp, %ebp
je 0x5c89
leaq 0x2(%rax), %rcx
movq %rcx, 0x7bec(%rip)      # 0xd860
movw $0x155, (%rax)          # imm = 0x155
leaq 0x4(%rax), %rcx
movq %rcx, 0x7bdc(%rip)      # 0xd860
movw %r13w, 0x2(%rax)
movq 0x7bd0(%rip), %rax      # 0xd860
leaq 0x2(%rax), %rcx
movq %rcx, 0x7bc5(%rip)      # 0xd860
movw %r15w, (%rax)
movl %r15d, %edi
movl %ebp, %esi
movl %r13d, %edx
callq 0x5d62
jmp 0x5a48