// File: /workspace/github_c_makefile_star2_O1/ThomasMadappattu[P]Sandmacs/search.c
// Function: bsearch
int bsearch (int f, int n)
{
  LINE *clp, *tlp;
  char *epp, *pp;
  int cbo, tbo, c;

  /* find a pointer to the end of the pattern */
  for (epp = &pat[0]; epp[1] != 0; ++epp)
    ;

  /* make local copies of the starting location */
  clp = curwp->w_dotp;
  cbo = curwp->w_doto;

  while (n-- > 0)
    {
      for (;;)
	{
	  /* if we are at the begining of the line, wrap back around */
	  if (cbo == 0)
	    {
	      clp = lback (clp);

	      if (clp == curbp->b_linep)
		{
		  mlwrite ("Not found");
		  return (FALSE);
		}
	      cbo = llength (clp) + 1;
	    }
	  /* fake the <NL> at the end of a line */
	  if (--cbo == llength (clp))
	    c = '\n';
	  else
	    c = lgetc (clp, cbo);

	  /* check for a match against the end of the pattern */
	  if (eq (c, *epp) != FALSE)
	    {
	      tlp = clp;
	      tbo = cbo;
	      pp = epp;
	      /* scanning backwards through the rest of the pattern
	       * looking for a match */
	      while (pp != &pat[0])
		{
		  /* wrap across a line break */
		  if (tbo == 0)
		    {
		      tlp = lback (tlp);
		      if (tlp == curbp->b_linep)
			goto fail;

		      tbo = llength (tlp) + 1;
		    }
		  /* fake the <NL> */
		  if (--tbo == llength (tlp))
		    c = '\n';
		  else
		    c = lgetc (tlp, tbo);

		  if (eq (c, *--pp) == FALSE)
		    goto fail;
		}

	      /* A Match!  reset the current cursor */
	      curwp->w_dotp = tlp;
	      curwp->w_doto = tbo;
	      curwp->w_flag |= WFMOVE;
	      goto next;
	    }
	fail:;
	}
    next:;
    }
  return (TRUE);
}

// Assembly:
movq $-0x1, %rcx
leaq 0x6d56(%rip), %rax      # 0xd890
cmpb $0x0, 0x2(%rax,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x6b3a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x1, %ebx
testl %esi, %esi
jle 0x6c7b
leaq 0x6cf4(%rip), %rdx      # 0xd858
movq (%rdx), %rdx
movl 0x20(%rdx), %r9d
movq 0x18(%rdx), %rdi
leaq 0x6cd2(%rip), %r8       # 0xd848
movq (%r8), %r8
leal -0x1(%rsi), %r10d
testl %r9d, %r9d
jne 0x6b97
movq 0x8(%rdi), %rdi
cmpq 0x28(%r8), %rdi
je 0x6c6b
movl 0x14(%rdi), %r9d
incl %r9d
movslq %r9d, %r9
decq %r9
movl $0xa, %r11d
cmpl 0x14(%rdi), %r9d
je 0x6baf
movzbl 0x18(%rdi,%r9), %r11d
movsbl (%rax,%rcx), %r14d
leal -0x61(%r11), %ebp
leal -0x20(%r11), %r15d
cmpl $0x1a, %ebp
cmovael %r11d, %r15d
leal -0x61(%r14), %r11d
leal -0x20(%r14), %ebp
cmpl $0x1a, %r11d
cmovael %r14d, %ebp
cmpl %ebp, %r15d
jne 0x6b7d
movq %rcx, %r14
movq %rdi, %r11
movl %r9d, %r15d
testq %r14, %r14
je 0x6c49
testl %r15d, %r15d
jne 0x6bfc
movq 0x8(%r11), %r11
cmpq 0x28(%r8), %r11
je 0x6b7d
movl 0x14(%r11), %r15d
incl %r15d
movslq %r15d, %r15
decq %r15
movl $0xa, %r12d
cmpl 0x14(%r11), %r15d
je 0x6c14
movzbl 0x18(%r11,%r15), %r12d
leal -0x61(%r12), %ebp
leal -0x20(%r12), %r13d
cmpl $0x1a, %ebp
cmovael %r12d, %r13d
movsbl -0x1(%rax,%r14), %r12d
leal -0x61(%r12), %ebp
leal -0x20(%r12), %ebx
cmpl $0x1a, %ebp
cmovael %r12d, %ebx
decq %r14
cmpl %ebx, %r13d
je 0x6be1
jmp 0x6b7d
movq %r11, 0x18(%rdx)
movslq %r15d, %r11
movq %r11, 0x20(%rdx)
orb $0x2, 0x3b(%rdx)
cmpl $0x1, %esi
movl %r10d, %esi
jg 0x6b79
movl $0x1, %ebx
jmp 0x6c7b
leaq 0x2818(%rip), %rdi      # 0x948a
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x446e
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq