// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
pushq $-0x1
popq %r15
leaq 0x6594(%rip), %rbp      # 0xc880
cmpb $0x0, 0x2(%rbp,%r15)
leaq 0x1(%r15), %r15
jne 0x62ec
leaq 0x6549(%rip), %rax      # 0xc848
movq (%rax), %rax
movq 0x18(%rax), %r13
movq %rax, 0x20(%rsp)
movl 0x20(%rax), %r12d
leaq 0x6522(%rip), %rax      # 0xc838
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq %r15, (%rsp)
testl %esi, %esi
jle 0x640d
decl %esi
movl %esi, 0x14(%rsp)
testl %r12d, %r12d
je 0x634c
movl 0x14(%r13), %ebx
movslq %r12d, %r12
decq %r12
cmpl %ebx, %r12d
je 0x6366
movzbl 0x18(%r13,%r12), %edi
jmp 0x6369
movq 0x8(%r13), %r13
movq 0x18(%rsp), %rax
cmpq 0x28(%rax), %r13
je 0x63fb
movl 0x14(%r13), %r12d
movl %r12d, %ebx
pushq $0xa
popq %rdi
movsbl (%rbp,%r15), %esi
callq 0x6421
testl %eax, %eax
je 0x6330
movq %r13, 0x8(%rsp)
movl %r12d, %ecx
movslq %ecx, %r14
testq %r15, %r15
je 0x63d8
testl %ecx, %ecx
je 0x639c
decq %r14
cmpl %ebx, %r14d
je 0x63b2
movzbl 0x18(%r13,%r14), %edi
jmp 0x63b5
movq 0x8(%r13), %r13
movq 0x18(%rsp), %rax
cmpq 0x28(%rax), %r13
je 0x63ca
movl 0x14(%r13), %r14d
movl %r14d, %ebx
pushq $0xa
popq %rdi
movsbl -0x1(%rbp,%r15), %esi
callq 0x6421
decq %r15
movl %r14d, %ecx
testl %eax, %eax
jne 0x6380
movq (%rsp), %r15
movq 0x8(%rsp), %r13
jmp 0x6330
movq 0x20(%rsp), %rax
movq %r13, 0x18(%rax)
movq %r14, 0x20(%rax)
orb $0x2, 0x3b(%rax)
movl 0x14(%rsp), %esi
movq (%rsp), %r15
movq 0x8(%rsp), %r13
jmp 0x6322
leaq 0x2088(%rip), %rdi      # 0x848a
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x3e83
jmp 0x6410
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq