// File: /workspace/github_c_makefile_star2_O0/hughbarney[P]pEmacs/search.c
// Function: forscan
int forscan (char *patrn, int leavep)
{
  LINE *curline;		/* current line during scan */
  LINE *lastline;		/* last line position during scan */
  LINE *matchline;		/* current line during matching */
  char *patptr;			/* pointer into pattern */
  int curoff;			/* position within current line */
  int lastoff;			/* position within last line */
  int c;			/* character at current position */
  int matchoff;			/* position in matching line */

  /* setup local scan pointers to global "." */
  curline = curwp->w_dotp;
  curoff = curwp->w_doto;

  /* scan each character until we hit the head link record */
  while (curline != curbp->b_linep)
    {
      /* save the current position in case we need to restore it on a match */
      lastline = curline;
      lastoff = curoff;

      /* get the current character resolving EOLs */
      if (curoff == llength (curline))
	{			/* if at EOL */
	  curline = lforw (curline); /* skip to next line */
	  curoff = 0;
	  c = '\n';		/* and return a <NL> */
	}
      else
	c = lgetc (curline, curoff++); /* get the char */

      /* test it against first char in pattern */
      if (eq (c, patrn[0], 0) != FALSE) /* if we find it. */
	{
	  /* setup match pointers */
	  matchline = curline;
	  matchoff = curoff;
	  patptr = &patrn[0];

	  /* scan through patrn for a match */
	  while (*++patptr != 0)
	    {
	      /* advance all the pointers */
	      if (matchoff == llength (matchline))
		{
		  /* advance past EOL */
		  matchline = lforw (matchline);
		  matchoff = 0;
		  c = '\n';
		}
	      else
		c = lgetc (matchline, matchoff++);

	      /* and test it against the pattern */
	      if (eq (*patptr, c, 0) == FALSE)
		goto fail;
	    }

	  /* A SUCCESSFULL MATCH!!! */
	  /* reset the global "." pointers */
	  if (leavep == PTEND)
	    {			/* at end of string */
	      curwp->w_dotp = matchline;
	      curwp->w_doto = matchoff;
	    }
	  else
	    {			/* at begining of string */
	      curwp->w_dotp = lastline;
	      curwp->w_doto = lastoff;
	    }
	  curwp->w_flag |= WFMOVE; /* flag that we have moved */
	  return (TRUE);
	}
    fail:;			/* continue to search */
    }
  /* we could not find a match */
  return (FALSE);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
leaq 0x6bb2(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x20(%rbp)
leaq 0x6ba0(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq 0x20(%rax), %rax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
leaq 0x6b7b(%rip), %rcx      # 0x10a48
movq (%rcx), %rcx
cmpq 0x28(%rcx), %rax
je 0xa04a
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x9f0f
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0xa, -0x44(%rbp)
jmp 0x9f2e
movq -0x20(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x3c(%rbp)
movslq %ecx, %rcx
movsbl 0x18(%rax,%rcx), %eax
andl $0xff, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edi
movq -0x10(%rbp), %rax
movsbl (%rax), %esi
xorl %edx, %edx
callq 0xa2c0
cmpl $0x0, %eax
je 0xa043
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x9fd6
movl -0x48(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x9f9d
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x48(%rbp)
movl $0xa, -0x44(%rbp)
jmp 0x9fbc
movq -0x30(%rbp), %rax
movl -0x48(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x48(%rbp)
movslq %ecx, %rcx
movsbl 0x18(%rax,%rcx), %eax
andl $0xff, %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movsbl (%rax), %edi
movl -0x44(%rbp), %esi
xorl %edx, %edx
callq 0xa2c0
cmpl $0x0, %eax
jne 0x9fd4
jmp 0xa045
jmp 0x9f5e
cmpl $0x2, -0x14(%rbp)
jne 0xa002
movq -0x30(%rbp), %rcx
leaq 0x6a71(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x18(%rax)
movslq -0x48(%rbp), %rcx
leaq 0x6a5f(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x20(%rax)
jmp 0xa026
movq -0x28(%rbp), %rcx
leaq 0x6a4b(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x18(%rax)
movslq -0x40(%rbp), %rcx
leaq 0x6a39(%rip), %rax      # 0x10a58
movq (%rax), %rax
movq %rcx, 0x20(%rax)
leaq 0x6a2b(%rip), %rax      # 0x10a58
movq (%rax), %rax
movsbl 0x3b(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x3b(%rax)
movl $0x1, -0x4(%rbp)
jmp 0xa051
jmp 0xa045
jmp 0x9ec2
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)