// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, 0x4(%rsp)
movq %rdi, %rbx
leaq 0x619e(%rip), %rax      # 0xca38
movq (%rax), %rax
movq 0x18(%rax), %r15
movq %rax, 0x20(%rsp)
movl 0x20(%rax), %ecx
leaq 0x6178(%rip), %rax      # 0xca28
movq (%rax), %rax
movq 0x28(%rax), %r14
leaq 0x1(%rdi), %r12
movq %rdi, 0x18(%rsp)
movq %r14, 0x10(%rsp)
movq %r12, 0x8(%rsp)
cmpq %r14, %r15
je 0x6999
movl %ecx, %r13d
movq %r15, %rbp
cmpl 0x14(%r15), %ecx
jne 0x68ef
movq (%rbp), %r15
movl $0x0, (%rsp)
pushq $0xa
popq %rdi
jmp 0x6901
leal 0x1(%r13), %eax
movl %eax, (%rsp)
movslq %r13d, %rax
movzbl 0x18(%rbp,%rax), %edi
movq %rbp, %r15
movsbl (%rbx), %esi
xorl %edx, %edx
callq 0x6ab6
testl %eax, %eax
movl (%rsp), %ecx
je 0x68ca
movq %r12, %rbx
movq %r15, %r12
movl %ecx, %r14d
movsbl (%rbx), %edi
testl %edi, %edi
je 0x6966
cmpl 0x14(%r12), %r14d
jne 0x6935
movq (%r12), %r12
xorl %r14d, %r14d
pushq $0xa
popq %rsi
jmp 0x6941
movslq %r14d, %rax
incl %r14d
movzbl 0x18(%r12,%rax), %esi
xorl %edx, %edx
callq 0x6ab6
incq %rbx
testl %eax, %eax
jne 0x691b
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r12
movl (%rsp), %ecx
jmp 0x68ca
cmpl $0x2, 0x4(%rsp)
cmoveq %r12, %rbp
cmovel %r14d, %r13d
movq 0x20(%rsp), %rcx
movq %rbp, 0x18(%rcx)
movslq %r13d, %rax
movq %rax, 0x20(%rcx)
orb $0x2, 0x3b(%rcx)
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x698a