// File: /workspace/github_c_makefile_star2_O1/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
leaq 0x67ef(%rip), %rax      # 0xda48
movq (%rax), %rcx
movq 0x18(%rcx), %r9
leaq 0x67d1(%rip), %rax      # 0xda38
movq (%rax), %rax
movq 0x28(%rax), %r8
xorl %eax, %eax
cmpq %r8, %r9
je 0x7391
movq %r8, %rdx
movl %esi, -0xc(%rsp)
movl 0x20(%rcx), %r15d
movzbl (%rdi), %r8d
leal -0x41(%r8), %eax
movl %eax, -0x10(%rsp)
movl %r8d, %eax
orl $0x20, %eax
movl %eax, -0x14(%rsp)
leaq 0x2(%rdi), %rax
movq %rax, -0x8(%rsp)
movq %rdx, %rax
movq %r9, %r10
movl %r15d, %r11d
cmpl 0x14(%r9), %r15d
jne 0x72bf
movq (%r10), %r9
movl $0xa, %ebx
xorl %r15d, %r15d
jmp 0x72cf
leal 0x1(%r11), %r15d
movslq %r11d, %rsi
movzbl 0x18(%r10,%rsi), %ebx
movq %r10, %r9
cmpl %r8d, %ebx
je 0x72f8
leal -0x41(%rbx), %esi
cmpl $0x19, %esi
ja 0x72e4
orl $0x20, %ebx
cmpl %r8d, %ebx
jmp 0x72ef
cmpl $0x19, -0x10(%rsp)
ja 0x735d
cmpl -0x14(%rsp), %ebx
sete %sil
testb %sil, %sil
je 0x735d
movb 0x1(%rdi), %bl
testb %bl, %bl
je 0x736a
movq -0x8(%rsp), %r14
movl %r15d, %r13d
movq %r9, %r12
cmpl 0x14(%r12), %r13d
jne 0x731f
movq (%r12), %r12
xorl %r13d, %r13d
movl $0xa, %esi
jmp 0x732b
movslq %r13d, %rsi
incl %r13d
movzbl 0x18(%r12,%rsi), %esi
movzbl %bl, %ebx
cmpl %ebx, %esi
je 0x7351
leal -0x41(%rbx), %ebp
cmpl $0x1a, %ebp
jae 0x7340
movl %ebx, %ebp
movl %esi, %ebx
jmp 0x734a
leal -0x41(%rsi), %edx
movl %esi, %ebp
cmpl $0x19, %edx
ja 0x735d
orl $0x20, %ebp
cmpl %ebx, %ebp
jne 0x735d
movb (%r14), %bl
incq %r14
testb %bl, %bl
jne 0x730a
jmp 0x7370
cmpq %rax, %r9
jne 0x72a6
xorl %eax, %eax
jmp 0x7391
movq %r9, %r12
movl %r15d, %r13d
cmpl $0x2, -0xc(%rsp)
cmoveq %r12, %r10
cmovel %r13d, %r11d
movq %r10, 0x18(%rcx)
movslq %r11d, %rax
movq %rax, 0x20(%rcx)
orb $0x2, 0x3b(%rcx)
movl $0x1, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq