// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
leaq 0x7beb(%rip), %rax      # 0x118b0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x9ce6
jmp 0x9cd8
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x9cc9
leaq 0x7b8b(%rip), %rax      # 0x11878
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
leaq 0x7b79(%rip), %rax      # 0x11878
movq (%rax), %rax
movq 0x20(%rax), %rax
movl %eax, -0x34(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0xc(%rbp)
cmpl $0x0, %eax
jle 0x9eb0
jmp 0x9d1f
cmpl $0x0, -0x34(%rbp)
jne 0x9d6c
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
leaq 0x7b2c(%rip), %rcx      # 0x11868
movq (%rcx), %rcx
cmpq 0x28(%rcx), %rax
jne 0x9d5f
leaq 0x382a(%rip), %rdi      # 0xd576
movb $0x0, %al
callq 0x5970
movl $0x0, -0x4(%rbp)
jmp 0x9eb7
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x9d87
movl $0xa, -0x3c(%rbp)
jmp 0x9d9c
movq -0x18(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl 0x18(%rax,%rcx), %eax
andl $0xff, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %edi
movq -0x28(%rbp), %rax
movsbl (%rax), %esi
callq 0x9ec0
cmpl $0x0, %eax
je 0x9ea4
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq 0x7adf(%rip), %rax      # 0x118b0
cmpq %rax, -0x30(%rbp)
je 0x9e6a
cmpl $0x0, -0x38(%rbp)
jne 0x9e13
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
leaq 0x7a70(%rip), %rcx      # 0x11868
movq (%rcx), %rcx
cmpq 0x28(%rcx), %rax
jne 0x9e06
jmp 0x9ea6
movq -0x20(%rbp), %rax
movl 0x14(%rax), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x9e2e
movl $0xa, -0x3c(%rbp)
jmp 0x9e43
movq -0x20(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsbl 0x18(%rax,%rcx), %eax
andl $0xff, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %edi
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x30(%rbp)
movsbl -0x1(%rax), %esi
callq 0x9ec0
cmpl $0x0, %eax
jne 0x9e65
jmp 0x9ea6
jmp 0x9dca
movq -0x20(%rbp), %rcx
leaq 0x7a03(%rip), %rax      # 0x11878
movq (%rax), %rax
movq %rcx, 0x18(%rax)
movslq -0x38(%rbp), %rcx
leaq 0x79f1(%rip), %rax      # 0x11878
movq (%rax), %rax
movq %rcx, 0x20(%rax)
leaq 0x79e3(%rip), %rax      # 0x11878
movq (%rax), %rax
movsbl 0x3b(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x3b(%rax)
jmp 0x9eab
jmp 0x9ea6
jmp 0x9d1f
jmp 0x9d09
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq