// File: /workspace/github_c_makefile_star2_O3/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 0xc635(%rip), %xmm1     # 0xf1f0
movsd 0x18b85(%rip), %xmm4    # 0x1b748
movsd 0x18b6d(%rip), %xmm0    # 0x1b738
movsd 0x86c5(%rip), %xmm2     # 0xb298
movapd %xmm0, %xmm3
divsd 0x86c1(%rip), %xmm3     # 0xb2a0
mulsd 0xc611(%rip), %xmm3     # 0xf1f8
addsd %xmm0, %xmm2
addsd %xmm2, %xmm3
divsd %xmm3, %xmm1
subsd %xmm1, %xmm4
movsd %xmm4, 0x8(%rsp)
xorl %eax, %eax
movq %rax, 0x18fba(%rip)     # 0x1bbc0
movq %rax, 0x18fbb(%rip)     # 0x1bbc8
movl %eax, 0x18fbd(%rip)     # 0x1bbd0
movl %eax, 0x18fbb(%rip)     # 0x1bbd4
movb $0x0, 0x18fb8(%rip)     # 0x1bbd8
cmpb $0x0, 0xc592(%rip)      # 0xf1b9
je 0x2d08
ucomisd 0x8673(%rip), %xmm0     # 0xb2a8
jne 0x2d08
jp 0x2d08
movb $0x1, 0xc574(%rip)      # 0xf1bc
callq 0x1659
movl $0x10, %edi
callq 0x33d9
movl %eax, %ebp
movb 0x18a61(%rip), %r14b    # 0x1b6c1
callq 0x16fa
movzbl 0xc614(%rip), %edi      # 0xf280
movq 0xc575(%rip), %rsi      # 0xf1e8
xorl %edx, %edx
callq 0x10d0
movl $0x0, 0xc6fc(%rip)      # 0xf380
testl %ebp, %ebp
jne 0x2c8d
testb %r14b, %r14b
je 0x2cf7
movl %ebp, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x8609(%rip), %xmm1     # 0xb2a8
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
cmpltsd 0x8600(%rip), %xmm0     # 0xb2b0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
movsd 0x85f8(%rip), %xmm1     # 0xb2b8
andpd %xmm1, %xmm0
orpd %xmm2, %xmm0
movlpd %xmm0, 0xc428(%rip)     # 0xf0f8
movb $0x0, 0xc4e5(%rip)      # 0xf1bc
addsd 0x85e1(%rip), %xmm0     # 0xb2c0
andpd 0x8719(%rip), %xmm0     # 0xb400
ucomisd 0x85d9(%rip), %xmm0     # 0xb2c8
ja 0x2c41
jmp 0x2d08
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0xc3f0(%rip)      # 0xf0f8
cvttsd2si 0x8(%rsp), %ebp
movb 0xc4a7(%rip), %al       # 0xf1bb
orb 0xc4a0(%rip), %al       # 0xf1ba
jne 0x2d2a
leaq 0x8931(%rip), %rdi      # 0xb654
xorl %eax, %eax
callq 0x10b0
cmpb $0x0, 0xc488(%rip)      # 0xf1b9
je 0x2d4b
movsd 0xc3bd(%rip), %xmm0     # 0xf0f8
mulsd 0x18a05(%rip), %xmm0    # 0x1b748
movsd %xmm0, 0x189fd(%rip)    # 0x1b748
movzbl %bpl, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x10(%rsp)
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r12d, %r12d
movq %r12, %r14
callq 0x249f
addq %rax, %r12
cmpb $0x0, 0x18941(%rip)     # 0x1b6c1
je 0x2eaf
movq %rax, %r15
movq %rax, %xmm1
punpckldq 0x867a(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x8682(%rip), %xmm1     # 0xb420
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x18996(%rip), %xmm1    # 0x1b748
mulsd 0x8516(%rip), %xmm1     # 0xb2d0
movapd %xmm1, %xmm2
subsd 0x10(%rsp), %xmm2
ucomisd %xmm0, %xmm2
ja 0x2d6e
addsd 0x10(%rsp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2d6e
callq 0x1659
xorl %ebp, %ebp
xorl %r13d, %r13d
testl %ebx, %ebx
je 0x2e49
callq 0x260f
addq %rax, %r13
movq %rax, %xmm1
punpckldq 0x8617(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x861f(%rip), %xmm1     # 0xb420
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd 0x18933(%rip), %xmm1    # 0x1b748
movapd %xmm1, %xmm2
movsd 0x8(%rsp), %xmm3
subsd %xmm3, %xmm2
ucomisd %xmm0, %xmm2
ja 0x2e33
addsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2e3c
cmpb $0x0, 0xc3c6(%rip)      # 0xf200
je 0x2e44
incl %ebp
cmpl %ebp, %ebx
jne 0x2de4
jmp 0x2e55
callq 0x178b
cmpl %ebx, %ebp
je 0x2e55
addq %r13, %r12
jmp 0x2d6e
movb $0x1, 0x18d7c(%rip)     # 0x1bbd8
cmpb $0x0, 0xc357(%rip)      # 0xf1ba
je 0x2e95
callq 0x16fa
movzbl 0xc40f(%rip), %edi      # 0xf280
movq 0xc370(%rip), %rsi      # 0xf1e8
xorl %edx, %edx
callq 0x10d0
movl $0x0, 0xc4f7(%rip)      # 0xf380
callq 0x178b
callq 0x1659
jmp 0x2eb2
addq %r15, %r13
addq %r13, 0x18d41(%rip)     # 0x1bbe0
cmpb $0x0, 0xc315(%rip)      # 0xf1bb
je 0x2ec4
callq 0x178b
jmp 0x2eb2
movq %r12, %r14
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x87a2(%rip), %rdi      # 0xb66d
xorl %eax, %eax
callq 0x10b0
cmpb $0x0, 0xc2e1(%rip)      # 0xf1ba
jne 0x2e65
jmp 0x2ea8