// File: /workspace/github_c_makefile_star2_O3/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 %rbx
subq $0x50, %rsp
xorl %eax, %eax
movl %eax, 0x1411e(%rip)     # 0x1bbd4
movl %eax, 0x14114(%rip)     # 0x1bbd0
callq 0x260f
movq %rax, %xmm0
punpckldq 0x3942(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x394a(%rip), %xmm0     # 0xb420
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movapd %xmm3, %xmm0
addsd %xmm3, %xmm0
subsd 0x13c56(%rip), %xmm0    # 0x1b748
addsd 0x37d6(%rip), %xmm0     # 0xb2d0
movsd 0x38ae(%rip), %xmm4     # 0xb3b0
ucomisd %xmm4, %xmm0
movsd 0x38aa(%rip), %xmm1     # 0xb3b8
mulsd %xmm3, %xmm1
movsd 0x379e(%rip), %xmm2     # 0xb2b8
addsd %xmm3, %xmm2
cmpltsd %xmm0, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm2, %xmm4
orpd %xmm1, %xmm4
movapd %xmm4, 0x20(%rsp)
ja 0x7b41
mulsd 0x3881(%rip), %xmm3     # 0xb3c0
jmp 0x7b49
addsd 0x3777(%rip), %xmm3     # 0xb2c0
incl 0x14081(%rip)           # 0x1bbd0
incl 0x1407f(%rip)           # 0x1bbd4
movl $0x15, %ebx
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 0x260f
testb %al, %al
je 0x7bdf
movzbl %al, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movapd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm5
subsd %xmm5, %xmm1
movapd 0x3851(%rip), %xmm2     # 0xb400
andpd %xmm2, %xmm1
movsd 0x3755(%rip), %xmm4     # 0xb310
ucomisd %xmm1, %xmm4
movsd 0x18(%rsp), %xmm3
jbe 0x7bf0
incl 0x14007(%rip)           # 0x1bbd4
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x7c18
movsd 0x18(%rsp), %xmm4
movapd 0x30(%rsp), %xmm5
jmp 0x7cd6
movapd %xmm0, %xmm1
subsd %xmm3, %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm1, %xmm4
jbe 0x7c18
incl 0x13fc8(%rip)           # 0x1bbd0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
xorl %edx, %edx
ucomisd %xmm5, %xmm0
movl $0x0, %esi
jbe 0x7c52
movapd %xmm3, %xmm1
mulsd 0x3797(%rip), %xmm1     # 0xb3c8
movl $0x1, %esi
ucomisd %xmm0, %xmm1
jae 0x7c52
movapd %xmm5, %xmm1
mulsd 0x3788(%rip), %xmm1     # 0xb3d0
xorl %esi, %esi
ucomisd %xmm0, %xmm1
setae %sil
imull %ecx, %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
movapd %xmm0, %xmm2
cmplesd %xmm5, %xmm2
movsd 0x364b(%rip), %xmm4     # 0xb2b8
andpd %xmm4, %xmm2
mulsd %xmm2, %xmm5
addsd %xmm1, %xmm5
ucomisd %xmm0, %xmm3
jbe 0x7cab
movapd %xmm5, %xmm1
divsd 0x35fd(%rip), %xmm1     # 0xb288
movl $0x1, %edx
ucomisd %xmm1, %xmm0
jae 0x7cab
movapd %xmm3, %xmm1
mulsd 0x362e(%rip), %xmm1     # 0xb2d0
xorl %edx, %edx
ucomisd %xmm1, %xmm0
setae %dl
imull %ecx, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movapd %xmm3, %xmm2
cmplesd %xmm0, %xmm2
movsd 0x35f2(%rip), %xmm0     # 0xb2b8
andpd %xmm0, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movapd %xmm2, %xmm4
decq %rbx
je 0x7d0f
movzbl %al, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movapd %xmm5, %xmm0
mulsd 0x36df(%rip), %xmm0     # 0xb3d0
ucomisd %xmm1, %xmm0
movapd %xmm4, %xmm0
mulsd 0x35cf(%rip), %xmm0     # 0xb2d0
jbe 0x7d1b
ucomisd %xmm0, %xmm1
ja 0x7b7a
jmp 0x7d1b
movsd 0x35b9(%rip), %xmm0     # 0xb2d0
mulsd %xmm4, %xmm0
movl 0x13eaf(%rip), %eax     # 0x1bbd0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movsd 0x10(%rsp), %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rsp)
movl 0x13e95(%rip), %ecx     # 0x1bbd4
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
movsd 0x8(%rsp), %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x8(%rsp)
movapd %xmm4, %xmm1
addsd %xmm4, %xmm1
subsd %xmm5, %xmm1
andpd 0x3695(%rip), %xmm1     # 0xb400
ucomisd %xmm0, %xmm1
jbe 0x7d79
movsd 0x10(%rsp), %xmm0
jmp 0x7ddf
cmpl $0x1, %eax
sete %dl
cmpl $0x2, %ecx
setae %sil
testb %sil, %dl
jne 0x7daf
movapd %xmm4, %xmm0
subsd 0x20(%rsp), %xmm0
andpd 0x3663(%rip), %xmm0     # 0xb400
movsd 0x3633(%rip), %xmm1     # 0xb3d8
ucomisd %xmm0, %xmm1
jbe 0x7e34
movsd 0x8(%rsp), %xmm0
mulsd 0x3513(%rip), %xmm0     # 0xb2d0
movapd %xmm0, %xmm4
addsd %xmm5, %xmm4
divsd 0x34bb(%rip), %xmm4     # 0xb288
movapd %xmm4, %xmm0
addsd %xmm4, %xmm0
movsd %xmm0, 0x8(%rsp)
movapd %xmm4, %xmm0
xorpd %xmm1, %xmm1
movapd %xmm0, %xmm2
ucomisd %xmm1, %xmm0
xorps %xmm0, %xmm0
cvtss2sd 0x73fa(%rip), %xmm0     # 0xf1f0
jne 0x7dfa
jnp 0x7e17
movsd 0x8(%rsp), %xmm3
ucomisd %xmm1, %xmm3
jne 0x7e08
jnp 0x7e17
movaps %xmm0, %xmm1
divsd %xmm2, %xmm1
movsd %xmm1, 0x13961(%rip)    # 0x1b778
divsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x13973(%rip)    # 0x1b798
callq 0x240d
addq $0x50, %rsp
popq %rbx
jmp 0x161e
cmpl $0x1, %ecx
sete %cl
cmpl $0x2, %eax
setae %al
testb %al, %cl
jne 0x7e68
movapd %xmm5, %xmm0
subsd 0x40(%rsp), %xmm0
andpd 0x35aa(%rip), %xmm0     # 0xb400
movsd 0x3452(%rip), %xmm1     # 0xb2b0
ucomisd %xmm0, %xmm1
jbe 0x7dc1
movsd 0x10(%rsp), %xmm0
addsd %xmm0, %xmm0
movapd %xmm0, %xmm5
jmp 0x7dc1