// File: /workspace/github_c_makefile_star2_O2/mincebert[P]maketzx/maketzx.c
// Function: SearchDataFrequencies
void SearchDataFrequencies(void)
{
  dword dwpulse,count,pulsecount=0;
//  double tolerance=2; //((125-(samprate/282.22))/samprate)*1000;
  double pmax=0,pmin=0,totmin=0,totmax=0,startmax,startmin,min,max;
  byte pulse;
  wmincount=wmaxcount=0;
/*  do {
       dwpulse=FindEdge2();
       if (!blocktype) break;
       if (dwpulse<samprate/808 && dwpulse)
	  {
	    pulse=dwpulse;
	    PutData(&tempfile,pulse,1);
	    pulsecount++;
	  }
     }
  while (dwpulse<pilot.samples && dwpulse);
  ResetTempFile();
  for (count=0; count<2; count++) GetData(&tempfile); */
//  FindEdge2();
//  FindEdge2();
//  for (count=0; count<2; count++)
//      {
	pmax=pmin=FindEdge2(); //GetData(&tempfile);
	if (pmax*2-pilot.samples+.5>-3)
	   {
	     startmin=totmin=pmin=pmax*.7;
	     pmax--;
	     startmax=totmax=pmax;
	     wmincount++;
	     wmaxcount++;
	   }
	else {
	       startmax=totmax=pmax=pmin*1.8;
	       pmin++;
	       startmin=totmin=pmin;
	       wmaxcount++;
	       wmincount++;
	     }
/*  wmaxcount=wmincount=0;
  if (pulsecount<10) { bit0.freq=bit1.freq=0; return; }
  for (count=0; count<pulsecount-5; count++) */
	do {
	     pulse=FindEdge2(); //GetData(&tempfile);
	     pulsecount++;
	     if (pulse)
		{
		  if (fabs(pulse-pmax)<2) { wmaxcount++; totmax+=pulse; }
		  else if (fabs(pulse-pmin)<2) { wmincount++; totmin+=pulse; }
		  //if (pulse==pmax || (pulse>pmax && pulse<=pmax*1.5 && abs(pmin*2-pulse)<2)) { wmaxcount++; totmax+=pulse; }// && pulse<=pmax*1.5) wmaxcount++;
		  //else if (pulse>pmax && pulse<=pmax*1.5) wmaxcount=1;
		       //else if (pulse==pmin || (pulse<pmin && pulse>=pmin*.5 && abs(pmax/2-pulse)<2)) { wmincount++; totmin+=pulse; }//&& pulse>=pmin*.5) wmincount++;
			    //else if (pulse<pmin && pulse>=pmin*.5) wmincount=1;
		  pmax=(pulse*(pulse>pmax && (pulse<=pmin*2.5 || pulse<=pmax*1.5)))+(pmax*(pulse<=pmax));
		  pmin=(pulse*(pulse<pmin && (pulse>=pmax/3 || pulse>=pmin*.5)))+(pmin*(pulse>=pmin));
//                diff=abs(pmax-2*pmin);
		}
	   }
	while (pulsecount<21 && pulse<pmax*1.5 && pulse>pmin*.5);
//      totmin+=pmin;
//      totmax+=pmax;
//      }
//  if (wmaxcount>wmincount && wmincount<wmaxcount/2 || wmincount<15) pmin+=.25;
//  if (wmaxcount<wmincount && wmaxcount<wmincount/2 || wmaxcount<15) pmax-=.75;
//  pmax+=((pmin*2+pmax)/3-middle/pulsecount);
//  pmin=(3*pmin+6*pmax)/15; pmax=2*pmin;  // pmax++; pmin++;
//  pmax+=1.2-abs(diff); pmin+=.4-abs(diff/2);
//  ratio=(double)max(wmaxcount,wmincount)/min(wmaxcount,wmincount);
/*  if (pmax-start*2>pmin/2) { totmax+=start; totmin-=start; wmincount--; }
  else { totmax-=start; wmaxcount--; } */
  min=totmin/wmincount; max=totmax/wmaxcount;
  if (fabs(pmin*2-pmax)>pmin/2) { pmin=min; pmax=max; }
  else {
	 if ((wmincount==1 && wmaxcount>1) || fabs(pmin-startmin)<.01) pmin=max/2;
	    else if ((wmaxcount==1 && wmincount>1) || fabs(pmax-startmax)<0.1) pmax=min*2;
	 pmin=(pmin+pmax)/3; pmax=2*pmin;
       }
//  pmax+=(pmax*(2*ratio/3)/100);
//  pmin-=(pmin*(ratio/3)/100);
/*  pmin=(pmin+pmax)/3; pmax=pmin*2; //pmin=diff/4; pmax-=diff/2;*/
  if (pmin && pmax) bit0.freq=(samprate/pmin); bit1.freq=(samprate/pmax); SetTimings();
  ResetTempFile();
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x58, %rsp
andl $0x0, 0x1487f(%rip)     # 0x1bbc4
andl $0x0, 0x14874(%rip)     # 0x1bbc0
callq 0x258c
movq %rax, %xmm0
punpckldq 0x30b2(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x30ba(%rip), %xmm0     # 0xa420
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movapd %xmm3, %xmm0
addsd %xmm3, %xmm0
subsd 0x143b6(%rip), %xmm0    # 0x1b738
addsd 0x2f46(%rip), %xmm0     # 0xa2d0
movsd 0x301e(%rip), %xmm4     # 0xa3b0
ucomisd %xmm4, %xmm0
movsd 0x301a(%rip), %xmm1     # 0xa3b8
mulsd %xmm3, %xmm1
movsd 0x2f0e(%rip), %xmm2     # 0xa2b8
addsd %xmm3, %xmm2
cmpltsd %xmm0, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm2, %xmm4
orpd %xmm1, %xmm4
movapd %xmm4, 0x20(%rsp)
ja 0x73d1
mulsd 0x2ff1(%rip), %xmm3     # 0xa3c0
jmp 0x73d9
addsd 0x2ee7(%rip), %xmm3     # 0xa2c0
incl 0x147e1(%rip)           # 0x1bbc0
incl 0x147df(%rip)           # 0x1bbc4
pushq $0x15
popq %rbx
pushq $0x1
popq %rbp
movapd 0x20(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm3, 0x8(%rsp)
movapd %xmm0, %xmm4
movapd %xmm3, 0x40(%rsp)
movapd %xmm3, %xmm5
movapd %xmm5, 0x30(%rsp)
movsd %xmm4, 0x18(%rsp)
callq 0x258c
testb %al, %al
je 0x746d
movzbl %al, %ecx
cvtsi2sd %ecx, %xmm0
movapd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm5
subsd %xmm5, %xmm1
movapd 0x2fc3(%rip), %xmm2     # 0xa400
andpd %xmm2, %xmm1
movsd 0x2ec7(%rip), %xmm4     # 0xa310
ucomisd %xmm1, %xmm4
movsd 0x18(%rsp), %xmm3
jbe 0x747e
incl 0x14769(%rip)           # 0x1bbc4
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x74a6
movsd 0x18(%rsp), %xmm4
movapd 0x30(%rsp), %xmm5
jmp 0x7558
movapd %xmm0, %xmm1
subsd %xmm3, %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm1, %xmm4
jbe 0x74a6
incl 0x1472a(%rip)           # 0x1bbc0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
xorl %edx, %edx
ucomisd %xmm5, %xmm0
movl $0x0, %esi
jbe 0x74dd
movapd %xmm3, %xmm1
mulsd 0x2f09(%rip), %xmm1     # 0xa3c8
ucomisd %xmm0, %xmm1
movl %ebp, %esi
jae 0x74dd
movapd %xmm5, %xmm1
mulsd 0x2efd(%rip), %xmm1     # 0xa3d0
xorl %esi, %esi
ucomisd %xmm0, %xmm1
setae %sil
imull %ecx, %esi
cvtsi2sd %esi, %xmm1
movapd %xmm0, %xmm2
cmplesd %xmm5, %xmm2
movsd 0x2dc3(%rip), %xmm4     # 0xa2b8
andpd %xmm4, %xmm2
mulsd %xmm2, %xmm5
addsd %xmm1, %xmm5
ucomisd %xmm0, %xmm3
jbe 0x7530
movapd %xmm5, %xmm1
divsd 0x2d75(%rip), %xmm1     # 0xa288
ucomisd %xmm1, %xmm0
movl %ebp, %edx
jae 0x7530
movapd %xmm3, %xmm1
mulsd 0x2da9(%rip), %xmm1     # 0xa2d0
xorl %edx, %edx
ucomisd %xmm1, %xmm0
setae %dl
imull %ecx, %edx
cvtsi2sd %edx, %xmm1
movapd %xmm3, %xmm2
cmplesd %xmm0, %xmm2
movsd 0x2d70(%rip), %xmm0     # 0xa2b8
andpd %xmm0, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movapd %xmm2, %xmm4
decq %rbx
je 0x758e
movzbl %al, %eax
cvtsi2sd %eax, %xmm1
movapd %xmm5, %xmm0
mulsd 0x2e60(%rip), %xmm0     # 0xa3d0
ucomisd %xmm1, %xmm0
movapd %xmm4, %xmm0
mulsd 0x2d50(%rip), %xmm0     # 0xa2d0
jbe 0x759a
ucomisd %xmm0, %xmm1
ja 0x740b
jmp 0x759a
movsd 0x2d3a(%rip), %xmm0     # 0xa2d0
mulsd %xmm4, %xmm0
movl 0x14620(%rip), %eax     # 0x1bbc0
cvtsi2sd %rax, %xmm1
movsd 0x10(%rsp), %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rsp)
movl 0x14609(%rip), %ecx     # 0x1bbc4
cvtsi2sd %rcx, %xmm1
movsd 0x8(%rsp), %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x8(%rsp)
movapd %xmm4, %xmm1
addsd %xmm4, %xmm1
subsd %xmm5, %xmm1
andpd 0x2e1c(%rip), %xmm1     # 0xa400
ucomisd %xmm0, %xmm1
jbe 0x75f2
movsd 0x10(%rsp), %xmm0
jmp 0x7658
cmpl $0x1, %eax
sete %dl
cmpl $0x2, %ecx
setae %sil
testb %sil, %dl
jne 0x7628
movapd %xmm4, %xmm0
subsd 0x20(%rsp), %xmm0
andpd 0x2dea(%rip), %xmm0     # 0xa400
movsd 0x2dba(%rip), %xmm1     # 0xa3d8
ucomisd %xmm0, %xmm1
jbe 0x76ab
movsd 0x8(%rsp), %xmm0
mulsd 0x2c9a(%rip), %xmm0     # 0xa2d0
movapd %xmm0, %xmm4
addsd %xmm5, %xmm4
divsd 0x2c42(%rip), %xmm4     # 0xa288
movapd %xmm4, %xmm0
addsd %xmm4, %xmm0
movsd %xmm0, 0x8(%rsp)
movapd %xmm4, %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, %xmm2
ucomisd %xmm1, %xmm0
cvtss2sd 0x7b74(%rip), %xmm0     # 0xf1e0
jne 0x7670
jnp 0x768d
movsd 0x8(%rsp), %xmm3
ucomisd %xmm1, %xmm3
jne 0x767e
jnp 0x768d
movaps %xmm0, %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, 0x140db(%rip)    # 0x1b768
divsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x140ed(%rip)    # 0x1b788
callq 0x2397
addq $0x58, %rsp
popq %rbx
popq %rbp
jmp 0x15e9
cmpl $0x1, %ecx
sete %cl
cmpl $0x2, %eax
setae %al
testb %al, %cl
jne 0x76df
movapd %xmm5, %xmm0
subsd 0x40(%rsp), %xmm0
andpd 0x2d33(%rip), %xmm0     # 0xa400
movsd 0x2bdb(%rip), %xmm1     # 0xa2b0
ucomisd %xmm0, %xmm1
jbe 0x763a
movsd 0x10(%rsp), %xmm0
addsd %xmm0, %xmm0
movapd %xmm0, %xmm5
jmp 0x763a