// File: /workspace/github_c_makefile_star2_O1/mincebert[P]maketzx/maketzx.c
// Function: PilotSearch
dword PilotSearch(word pulses)
{
  byte tolerance=pilot.samples-samprate/(pilot.freq+200-(pilot.freq/100*correction));
  word count;
  dword skipped1=0,skipped2=0,hpulse,pulse;
  wmaxcount=wmincount=wmax=wmin=0;
  PilotLinkingOK=0;
  if (spdchk && pilot.freq==808)
     do {
	  word pfreq;
	  CheckingSpeed=1;
	  PushFilePointers();
	  pfreq=BeepSearch(16);
	  if (!pfreq && !blocktype)
	     {
	       PopFilePointers();
	       lseek(inpfile.handle,filepos,SEEK_SET);
	       inpfile.bufpoint=0;
	       ecf=1; break;
	     }
	  PopFilePointers();
	  lseek(inpfile.handle,filepos,SEEK_SET);
	  inpfile.bufpoint=0;
	  ecf=(double)808/pfreq;
	  if (fabs(ecf)<.10) ecf=1;
	  CheckingSpeed=0;
	}
     while (fabs(ecf-1)>.20);
  if (!FindingPause && !ClickSearch) printf("Searching pilot...     \x0d");
  if (spdchk) pilot.samples*=ecf;
  do {
       do {
	    hpulse=FindEdge1();
	    if (!blocktype) return skipped1+skipped2+hpulse;
	    skipped1+=hpulse;
	  }
       while (hpulse<(pilot.samples/2)-tolerance || hpulse>(pilot.samples/2)+tolerance);
       skipped2=0;
       PushFilePointers();
       for (count=0; count<pulses; count++)
	   {
	     skipped2+=(pulse=FindEdge2());
	     if ((pulse<pilot.samples-(2*tolerance) || pulse>pilot.samples+(2*tolerance)) && !tonesearch)
		{ RemoveFilePointers(); break; }
/*           if (tapespeedcheck)
		{
		  if (pulse==wmax-(wmax-wmin)/2 && wmax!=0) wmaxcount++;
		  else if (pulse==wmin+(wmax-wmin)/2 && wmin!=0) wmincount++;
		  if (pulse<wmin) wmincount=1;
		  else if (pulse>wmax) wmaxcount=1;
		  if (wmax==0) wmax=pulse;
		  else wmax=(pulse*(pulse>wmax))+(wmax*(pulse<=wmax));
		  if (wmin==0) wmin=pulse;
		  else wmin=(pulse*(pulse<wmin))+(wmin*(pulse>=wmin));
		} */
	   }
       if (count==pulses) PilotLinkingOK=1;
       else { skipped1+=skipped2; skipped2=0; }
     }
  while (count!=pulses);
  if (!FindingPause) pilotlength+=skipped2+hpulse;
  if (!FindingPause && !ClickSearch) printf("Loading pilot...       \x0d");
  if (FindingPause)
     {
       PopFilePointers();
       lseek(inpfile.handle,filepos,SEEK_SET);
       inpfile.bufpoint=0;
       RemoveFilePointers();
       PushFilePointers();
     }
  else RemoveFilePointers();
  return skipped1-hpulse;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
cvtss2sd 0xc5dc(%rip), %xmm1     # 0xf1f0
movsd 0x18b2c(%rip), %xmm4    # 0x1b748
movsd 0x18b14(%rip), %xmm0    # 0x1b738
movsd 0x866c(%rip), %xmm2     # 0xb298
movapd %xmm0, %xmm3
divsd 0x8668(%rip), %xmm3     # 0xb2a0
mulsd 0xc5b8(%rip), %xmm3     # 0xf1f8
addsd %xmm0, %xmm2
addsd %xmm2, %xmm3
divsd %xmm3, %xmm1
subsd %xmm1, %xmm4
movsd %xmm4, 0x8(%rsp)
xorl %eax, %eax
movq %rax, 0x18f61(%rip)     # 0x1bbc0
movq %rax, 0x18f62(%rip)     # 0x1bbc8
movl %eax, 0x18f64(%rip)     # 0x1bbd0
movl %eax, 0x18f62(%rip)     # 0x1bbd4
movb $0x0, 0x18f5f(%rip)     # 0x1bbd8
cmpb $0x0, 0xc539(%rip)      # 0xf1b9
je 0x2d76
ucomisd 0x861a(%rip), %xmm0     # 0xb2a8
jne 0x2d76
jp 0x2d76
movabsq $0x3ff0000000000000, %r14 # imm = 0x3FF0000000000000
movb $0x1, 0xc511(%rip)      # 0xf1bc
callq 0x165a
movl $0x10, %edi
callq 0x345d
movl %eax, %ebp
testl %eax, %eax
setne %al
cmpb $0x0, 0x189f9(%rip)     # 0x1b6c1
setne %r15b
orb %al, %r15b
callq 0x16fb
movzbl 0xc5a5(%rip), %edi      # 0xf280
movq 0xc506(%rip), %rsi      # 0xf1e8
xorl %edx, %edx
callq 0x10d0
movl $0x0, 0xc68d(%rip)      # 0xf380
testb %r15b, %r15b
je 0x2d44
movl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x859e(%rip), %xmm1     # 0xb2a8
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
cmpltsd 0x8595(%rip), %xmm0     # 0xb2b0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
movsd 0x858d(%rip), %xmm1     # 0xb2b8
andpd %xmm1, %xmm0
orpd %xmm2, %xmm0
movlpd %xmm0, 0xc3bd(%rip)     # 0xf0f8
movb $0x0, 0xc47a(%rip)      # 0xf1bc
jmp 0x2d4b
movq %r14, 0xc3ad(%rip)      # 0xf0f8
testb %r15b, %r15b
je 0x2d76
movsd 0xc3a0(%rip), %xmm0     # 0xf0f8
addsd 0x8560(%rip), %xmm0     # 0xb2c0
andpd 0x8698(%rip), %xmm0     # 0xb400
ucomisd 0x8558(%rip), %xmm0     # 0xb2c8
ja 0x2ca4
cvttsd2si 0x8(%rsp), %ebp
movb 0xc439(%rip), %al       # 0xf1bb
orb 0xc432(%rip), %al       # 0xf1ba
jne 0x2d98
leaq 0x88c3(%rip), %rdi      # 0xb654
xorl %eax, %eax
callq 0x10b0
cmpb $0x0, 0xc41a(%rip)      # 0xf1b9
je 0x2db9
movsd 0xc34f(%rip), %xmm0     # 0xf0f8
mulsd 0x18997(%rip), %xmm0    # 0x1b748
movsd %xmm0, 0x1898f(%rip)    # 0x1b748
movzbl %bpl, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
xorl %r12d, %r12d
xorl %r14d, %r14d
movsd %xmm0, 0x10(%rsp)
callq 0x24b6
addq %rax, %r14
cmpb $0x0, 0x188d3(%rip)     # 0x1b6c1
je 0x2f3d
movq %rax, %r15
movq %rax, %xmm1
punpckldq 0x860c(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x8614(%rip), %xmm1     # 0xb420
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x18928(%rip), %xmm1    # 0x1b748
mulsd 0x84a8(%rip), %xmm1     # 0xb2d0
movapd %xmm1, %xmm2
subsd 0x8(%rsp), %xmm2
ucomisd %xmm0, %xmm2
ja 0x2ddf
addsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2ddf
callq 0x165a
xorl %r13d, %r13d
xorl %r12d, %r12d
testl %ebx, %ebx
je 0x2ebd
callq 0x2648
addq %rax, %r12
movq %rax, %xmm1
punpckldq 0x85a8(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x85b0(%rip), %xmm1     # 0xb420
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x188c4(%rip), %xmm1    # 0x1b748
movapd %xmm1, %xmm2
movsd 0x10(%rsp), %xmm3
subsd %xmm3, %xmm2
ucomisd %xmm0, %xmm2
ja 0x2ea2
addsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2eab
cmpb $0x0, 0xc357(%rip)      # 0xf200
je 0x2eb8
incl %r13d
cmpl %r13d, %ebx
jne 0x2e53
movl %ebx, %r13d
jmp 0x2ebd
callq 0x178c
cmpl %ebx, %r13d
jne 0x2ecb
movb $0x1, 0x18d0f(%rip)     # 0x1bbd8
jmp 0x2ed1
addq %r12, %r14
xorl %r12d, %r12d
cmpl %ebx, %r13d
jne 0x2ddf
movb 0xc2da(%rip), %al       # 0xf1ba
testb %al, %al
jne 0x2eee
addq %r15, %r12
addq %r12, 0x18cf2(%rip)     # 0x1bbe0
orb 0xc2c7(%rip), %al       # 0xf1bb
jne 0x2f04
leaq 0x8770(%rip), %rdi      # 0xb66d
xorl %eax, %eax
callq 0x10b0
cmpb $0x0, 0xc2af(%rip)      # 0xf1ba
je 0x2f52
callq 0x16fb
movzbl 0xc367(%rip), %edi      # 0xf280
movq 0xc2c8(%rip), %rsi      # 0xf1e8
xorl %edx, %edx
callq 0x10d0
movl $0x0, 0xc44f(%rip)      # 0xf380
callq 0x178c
callq 0x165a
jmp 0x2f57
addq %r12, %r14
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x178c
subq %r15, %r14
jmp 0x2f40