// File: /workspace/github_c_makefile_star2_O3/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 0x6e6b(%rip), %rax      # 0xd890
cmpb $0x0, 0x2(%rax,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x6a25
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x1, %ebx
testl %esi, %esi
jle 0x6b7d
leaq 0x6e09(%rip), %rdx      # 0xd858
movq (%rdx), %rdx
movl 0x20(%rdx), %r9d
movq 0x18(%rdx), %rdi
leaq 0x6de7(%rip), %r8       # 0xd848
movq (%r8), %r8
leal -0x1(%rsi), %r10d
movl %r10d, 0x4(%rsp)
testl %r9d, %r9d
je 0x6a8f
movl 0x14(%rdi), %r11d
movslq %r9d, %r9
decq %r9
movl $0xa, %r14d
cmpl %r11d, %r9d
je 0x6aaa
movzbl 0x18(%rdi,%r9), %r14d
jmp 0x6aaa
movq 0x8(%rdi), %rdi
cmpq 0x28(%r8), %rdi
je 0x6b6d
movl 0x14(%rdi), %r9d
movl $0xa, %r14d
movl %r9d, %r11d
movsbl (%rax,%rcx), %r15d
leal -0x61(%r14), %ebp
leal -0x20(%r14), %r12d
cmpl $0x1a, %ebp
cmovael %r14d, %r12d
leal -0x61(%r15), %ebp
leal -0x20(%r15), %r14d
cmpl $0x1a, %ebp
cmovael %r15d, %r14d
cmpl %r14d, %r12d
jne 0x6a6d
movq %rcx, %r14
movq %rdi, %r15
movl %r9d, %r12d
testq %r14, %r14
je 0x6b4a
testl %r12d, %r12d
je 0x6afe
movslq %r12d, %r12
decq %r12
movl $0xa, %r13d
cmpl %r11d, %r12d
je 0x6b19
movzbl 0x18(%r15,%r12), %r13d
jmp 0x6b19
movq 0x8(%r15), %r15
cmpq 0x28(%r8), %r15
je 0x6a6d
movl 0x14(%r15), %r12d
movl $0xa, %r13d
movl %r12d, %r11d
leal -0x61(%r13), %ebp
leal -0x20(%r13), %ebx
cmpl $0x1a, %ebp
cmovael %r13d, %ebx
movsbl -0x1(%rax,%r14), %r13d
leal -0x61(%r13), %ebp
leal -0x20(%r13), %r10d
cmpl $0x1a, %ebp
cmovael %r13d, %r10d
decq %r14
cmpl %r10d, %ebx
je 0x6adb
jmp 0x6a6d
movq %r15, 0x18(%rdx)
movslq %r12d, %r10
movq %r10, 0x20(%rdx)
orb $0x2, 0x3b(%rdx)
cmpl $0x1, %esi
movl 0x4(%rsp), %esi
jg 0x6a64
movl $0x1, %ebx
jmp 0x6b7d
leaq 0x2916(%rip), %rdi      # 0x948a
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4352
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq