// File: /workspace/github_c_makefile_star2_O3/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 0x67a3(%rip), %rax      # 0xda48
movq (%rax), %rcx
movq 0x18(%rcx), %r9
leaq 0x6785(%rip), %rax      # 0xda38
movq (%rax), %rax
movq 0x28(%rax), %rdx
xorl %eax, %eax
cmpq %rdx, %r9
je 0x73d9
movl %esi, -0xc(%rsp)
movl 0x20(%rcx), %r15d
movzbl (%rdi), %r8d
leal -0x41(%r8), %esi
movl %esi, -0x10(%rsp)
movl %r8d, %esi
orl $0x20, %esi
movl %esi, -0x14(%rsp)
leaq 0x2(%rdi), %rsi
movq %rsi, -0x8(%rsp)
movq %r9, %r10
movl %r15d, %r11d
cmpl 0x14(%r9), %r15d
jne 0x7305
movq (%r10), %r9
movl $0xa, %esi
xorl %r15d, %r15d
jmp 0x7315
leal 0x1(%r11), %r15d
movslq %r11d, %rsi
movzbl 0x18(%r10,%rsi), %esi
movq %r10, %r9
cmpl %r8d, %esi
jne 0x7384
movb 0x1(%rdi), %bl
testb %bl, %bl
je 0x73b2
movq -0x8(%rsp), %r14
movl %r15d, %r13d
movq %r9, %r12
cmpl 0x14(%r12), %r13d
jne 0x7345
movq (%r12), %r12
xorl %r13d, %r13d
movl $0xa, %esi
jmp 0x7351
movslq %r13d, %rsi
incl %r13d
movzbl 0x18(%r12,%rsi), %esi
movzbl %bl, %ebx
cmpl %ebx, %esi
je 0x7378
leal -0x41(%rbx), %ebp
cmpl $0x19, %ebp
ja 0x7369
orl $0x20, %ebx
cmpl %esi, %ebx
je 0x7378
jmp 0x73a7
leal -0x41(%rsi), %ebp
cmpl $0x19, %ebp
ja 0x73a7
orl $0x20, %esi
cmpl %ebx, %esi
jne 0x73a7
movb (%r14), %bl
incq %r14
testb %bl, %bl
jne 0x7330
jmp 0x73b8
leal -0x41(%rsi), %ebx
cmpl $0x19, %ebx
ja 0x7396
orl $0x20, %esi
cmpl %r8d, %esi
je 0x731a
jmp 0x73a7
cmpl $0x19, -0x10(%rsp)
ja 0x73a7
cmpl -0x14(%rsp), %esi
je 0x731a
cmpq %rdx, %r9
jne 0x72ec
jmp 0x73d9
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