// File: /workspace/github_c_makefile_star2_O1/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 $0x40, %rsp
xorl %eax, %eax
movl %eax, 0x14034(%rip)     # 0x1bbd4
movl %eax, 0x1402a(%rip)     # 0x1bbd0
callq 0x2648
movq %rax, %xmm0
punpckldq 0x3858(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3860(%rip), %xmm0     # 0xb420
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
addsd %xmm1, %xmm0
subsd 0x13b6c(%rip), %xmm0    # 0x1b748
addsd 0x36ec(%rip), %xmm0     # 0xb2d0
ucomisd 0x37c4(%rip), %xmm0     # 0xb3b0
jbe 0x7c12
movsd 0x37ca(%rip), %xmm2     # 0xb3c0
mulsd %xmm1, %xmm2
addsd 0x36be(%rip), %xmm1     # 0xb2c0
leaq 0x13fcb(%rip), %rax     # 0x1bbd4
leaq 0x13fc0(%rip), %rcx     # 0x1bbd0
jmp 0x7c3c
movsd 0x379e(%rip), %xmm0     # 0xb3b8
mulsd %xmm1, %xmm0
addsd 0x3692(%rip), %xmm1     # 0xb2b8
leaq 0x13fa3(%rip), %rax     # 0x1bbd0
leaq 0x13fa0(%rip), %rcx     # 0x1bbd4
movapd %xmm1, %xmm2
movapd %xmm0, %xmm1
incl (%rcx)
incl (%rax)
movl $0x15, %ebx
movsd %xmm2, 0x8(%rsp)
movsd %xmm1, (%rsp)
movsd %xmm2, 0x18(%rsp)
movapd %xmm1, 0x30(%rsp)
movapd %xmm1, %xmm4
movapd %xmm4, 0x20(%rsp)
movsd %xmm2, 0x10(%rsp)
callq 0x2648
testb %al, %al
je 0x7cc3
movzbl %al, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movapd %xmm0, %xmm1
movapd 0x20(%rsp), %xmm4
subsd %xmm4, %xmm1
movapd 0x376b(%rip), %xmm2     # 0xb400
andpd %xmm2, %xmm1
movsd 0x366f(%rip), %xmm5     # 0xb310
ucomisd %xmm1, %xmm5
movsd 0x10(%rsp), %xmm3
jbe 0x7cd4
incl 0x13f21(%rip)           # 0x1bbd4
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
jmp 0x7cfc
movsd 0x10(%rsp), %xmm2
movapd 0x20(%rsp), %xmm4
jmp 0x7db6
movapd %xmm0, %xmm1
subsd %xmm3, %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm1, %xmm5
jbe 0x7cfc
incl 0x13ee4(%rip)           # 0x1bbd0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
xorl %edx, %edx
ucomisd %xmm4, %xmm0
movl $0x0, %esi
jbe 0x7d36
movapd %xmm3, %xmm1
mulsd 0x36b3(%rip), %xmm1     # 0xb3c8
movl $0x1, %esi
ucomisd %xmm0, %xmm1
jae 0x7d36
movapd %xmm4, %xmm1
mulsd 0x36a4(%rip), %xmm1     # 0xb3d0
xorl %esi, %esi
ucomisd %xmm0, %xmm1
setae %sil
imull %ecx, %esi
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
movapd %xmm0, %xmm2
cmplesd %xmm4, %xmm2
movsd 0x3567(%rip), %xmm5     # 0xb2b8
andpd %xmm5, %xmm2
mulsd %xmm2, %xmm4
addsd %xmm1, %xmm4
ucomisd %xmm0, %xmm3
jbe 0x7d8f
movapd %xmm4, %xmm1
divsd 0x3519(%rip), %xmm1     # 0xb288
movl $0x1, %edx
ucomisd %xmm1, %xmm0
jae 0x7d8f
movapd %xmm3, %xmm1
mulsd 0x354a(%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 0x350e(%rip), %xmm0     # 0xb2b8
andpd %xmm0, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
decq %rbx
je 0x7ded
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movapd %xmm4, %xmm1
mulsd 0x35ff(%rip), %xmm1     # 0xb3d0
ucomisd %xmm0, %xmm1
movapd %xmm2, %xmm1
mulsd 0x34ef(%rip), %xmm1     # 0xb2d0
jbe 0x7ded
ucomisd %xmm1, %xmm0
ja 0x7c60
movl 0x13ddd(%rip), %eax     # 0x1bbd0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movl 0x13dc3(%rip), %ecx     # 0x1bbd4
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movapd %xmm2, %xmm0
addsd %xmm2, %xmm0
subsd %xmm4, %xmm0
andpd 0x35c5(%rip), %xmm0     # 0xb400
movsd 0x348d(%rip), %xmm1     # 0xb2d0
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x7e55
movsd 0x8(%rsp), %xmm1
jmp 0x7eb9
cmpl $0x1, %eax
sete %dl
cmpl $0x2, %ecx
setae %sil
testb %sil, %dl
jne 0x7e8b
movapd %xmm2, %xmm0
subsd 0x18(%rsp), %xmm0
andpd 0x3587(%rip), %xmm0     # 0xb400
movsd 0x3557(%rip), %xmm1     # 0xb3d8
ucomisd %xmm0, %xmm1
jbe 0x7f10
movsd (%rsp), %xmm0
mulsd 0x3438(%rip), %xmm0     # 0xb2d0
movapd %xmm0, %xmm2
addsd %xmm4, %xmm2
divsd 0x33e0(%rip), %xmm2     # 0xb288
movapd %xmm2, %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%rsp)
movapd %xmm2, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x7ec5
jnp 0x7ee9
movsd (%rsp), %xmm2
ucomisd %xmm0, %xmm2
jne 0x7ed2
jnp 0x7ee9
xorps %xmm0, %xmm0
cvtss2sd 0x7313(%rip), %xmm0     # 0xf1f0
divsd %xmm1, %xmm0
movsd %xmm0, 0x1388f(%rip)    # 0x1b778
xorps %xmm0, %xmm0
cvtss2sd 0x72fc(%rip), %xmm0     # 0xf1f0
divsd (%rsp), %xmm0
movsd %xmm0, 0x13897(%rip)    # 0x1b798
callq 0x2424
addq $0x40, %rsp
popq %rbx
jmp 0x161f
cmpl $0x1, %ecx
sete %cl
cmpl $0x2, %eax
setae %al
testb %al, %cl
jne 0x7f44
movapd %xmm4, %xmm0
subsd 0x30(%rsp), %xmm0
andpd 0x34ce(%rip), %xmm0     # 0xb400
movsd 0x3376(%rip), %xmm1     # 0xb2b0
ucomisd %xmm0, %xmm1
jbe 0x7e9c
movsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm0
movapd %xmm0, %xmm4
jmp 0x7e9c