// File: /workspace/github_c_makefile_star2_O0/mincebert[P]maketzx/maketzx.c
// Function: MidSyncSearch
byte MidSyncSearch(void)
{
  byte count1,count2,value,tolerance,maxpulse;
//  byte good=1;
  word pulse;
  double middle;
  bit0.freq=2000; bit1.freq=1000;
  SetTimings();
  if (spdchk) { bit0.samples*=ecf; bit1.samples*=ecf; }
  tolerance=(bit1.samples-bit0.samples)/2;
  middle=(double)(bit1.samples+bit0.samples)/2;
  maxpulse=bit1.samples+(pilot.samples-bit1.samples)/2+1;
  if (maxpulse>(byte)bit1.samples+(byte)bit0.samples) maxpulse=bit1.samples+bit0.samples-tolerance;
  for (count1=0; count1<2; count1++)
      {
	value=1;
	for (count2=0; count2<8; count2++)
	    {
	      pulse=0;

/*                   do {
			  pulse+=FindEdge1();
			  if (currpulse<2) good=0;
			  else good=1;
			}
		     while (!good && blocktype);
		     do {
			  pulse+=FindEdge1();
			  if (currpulse<2) good=0;
			  else good=1;
			}
		     while (!good && blocktype); */


	      pulse=FindEdge2();


//            if ((abs(pulse-(int)(middle+.5))<2 /* && abs(pulse-2*currpulse)>2 */) || pulse>maxpulse)
//            pulse=((currpulse+lastpulse)/2+pulse-middle+(lastpulse<currpulse))*2;
	      if ((pulse<middle) && (pulse>=bit0.samples-tolerance)) value<<=1;
	      else if ((pulse<=bit1.samples+tolerance) && (pulse>=middle)) { value<<=1; value|=0x1; }
	    }
	if (value!=midsync[count1])
	   {
	     PopFilePointers();
	     lseek(inpfile.handle,filepos,SEEK_SET);
	     inpfile.bufpoint=0;
	     return 0;
	   }
      }
  value=0;
  for (count2=0; count2<5; count2++)
      {
	pulse=0;

/*                   do {
			  pulse+=FindEdge1();
			  if (currpulse<2) good=0;
			  else good=1;
			}
		     while (!good && blocktype);
		     do {
			  pulse+=FindEdge1();
			  if (currpulse<2) good=0;
			  else good=1;
			}
		     while (!good && blocktype); */


	pulse=FindEdge2();
	if (((pulse-(int)(middle+.5))<2 /* && abs(pulse-2*currpulse)>2 */) || pulse>maxpulse) pulse=((currpulse+lastpulse)/2+pulse-middle+(lastpulse<currpulse))*2;
	if ((pulse<middle) && (pulse>=bit0.samples-tolerance)) value<<=1;
	else if ((pulse<=bit1.samples+tolerance) && (pulse>=middle)) { value<<=1; value|=0x1; }
      }
  if (value!=midsync[2])
     {
       PopFilePointers();
       lseek(inpfile.handle,filepos,SEEK_SET);
       inpfile.bufpoint=0;
       return 0;
     }
  savemidsync=1;
  WriteTZXPureData(5,3);
  savemidsync=0;
  return 1;
}

// Assembly:
subq $0x38, %rsp
movsd 0x7a1c(%rip), %xmm0     # 0xfa98
movsd %xmm0, 0x176d4(%rip)    # 0x1f758
movsd 0x7924(%rip), %xmm0     # 0xf9b0
movsd %xmm0, 0x176e4(%rip)    # 0x1f778
callq 0x2d90
cmpb $0x0, 0xb0f9(%rip)      # 0x13199
je 0x80d2
movsd 0xb02e(%rip), %xmm0     # 0x130d8
mulsd 0x176b6(%rip), %xmm0    # 0x1f768
movsd %xmm0, 0x176ae(%rip)    # 0x1f768
movsd 0xb016(%rip), %xmm0     # 0x130d8
mulsd 0x176be(%rip), %xmm0    # 0x1f788
movsd %xmm0, 0x176b6(%rip)    # 0x1f788
movsd 0x176ae(%rip), %xmm0    # 0x1f788
movsd 0x17686(%rip), %xmm1    # 0x1f768
subsd %xmm1, %xmm0
movsd 0x7942(%rip), %xmm2     # 0xfa30
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x33(%rsp)
movsd 0x17686(%rip), %xmm0    # 0x1f788
movsd 0x1765e(%rip), %xmm1    # 0x1f768
addsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x17668(%rip), %xmm0    # 0x1f788
movsd 0x17600(%rip), %xmm1    # 0x1f728
subsd %xmm0, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd 0x78b4(%rip), %xmm1     # 0xf9f0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x32(%rsp)
movzbl 0x32(%rsp), %eax
cvttsd2si 0x17633(%rip), %ecx # 0x1f788
movzbl %cl, %ecx
cvttsd2si 0x17608(%rip), %edx # 0x1f768
movzbl %dl, %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x8192
movsd 0x17617(%rip), %xmm0    # 0x1f788
movsd 0x175ef(%rip), %xmm1    # 0x1f768
addsd %xmm1, %xmm0
movzbl 0x33(%rsp), %eax
cvtsi2sd %eax, %xmm1
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x32(%rsp)
movb $0x0, 0x36(%rsp)
movzbl 0x36(%rsp), %eax
cmpl $0x2, %eax
jge 0x82cd
movb $0x1, 0x34(%rsp)
movb $0x0, 0x35(%rsp)
movzbl 0x35(%rsp), %eax
cmpl $0x8, %eax
jge 0x8273
movl $0x0, 0x2c(%rsp)
callq 0x3150
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cvtsi2sd %rax, %xmm1
movsd 0x20(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x8214
movl 0x2c(%rsp), %eax
cvtsi2sd %rax, %xmm0
movsd 0x17574(%rip), %xmm1    # 0x1f768
movzbl 0x33(%rsp), %eax
cvtsi2sd %eax, %xmm2
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x8214
movzbl 0x34(%rsp), %eax
shll %eax
movb %al, 0x34(%rsp)
jmp 0x8262
movl 0x2c(%rsp), %eax
cvtsi2sd %rax, %xmm1
movsd 0x17563(%rip), %xmm0    # 0x1f788
movzbl 0x33(%rsp), %eax
cvtsi2sd %eax, %xmm2
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x8260
movl 0x2c(%rsp), %eax
cvtsi2sd %rax, %xmm0
ucomisd 0x20(%rsp), %xmm0
jb 0x8260
movzbl 0x34(%rsp), %eax
shll %eax
movb %al, 0x34(%rsp)
movzbl 0x34(%rsp), %eax
orl $0x1, %eax
movb %al, 0x34(%rsp)
jmp 0x8262
jmp 0x8264
movb 0x35(%rsp), %al
addb $0x1, %al
movb %al, 0x35(%rsp)
jmp 0x81af
movzbl 0x34(%rsp), %eax
movzbl 0x36(%rsp), %ecx
movl %ecx, %edx
leaq 0xae87(%rip), %rcx      # 0x1310d
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x82bc
callq 0x1a10
movzbl 0xafc6(%rip), %edi      # 0x13260
movq 0xaf27(%rip), %rsi      # 0x131c8
xorl %edx, %edx
callq 0x10b0
movl $0x0, 0xb0ae(%rip)      # 0x13360
movb $0x0, 0x37(%rsp)
jmp 0x84c0
jmp 0x82be
movb 0x36(%rsp), %al
addb $0x1, %al
movb %al, 0x36(%rsp)
jmp 0x8197
movb $0x0, 0x34(%rsp)
movb $0x0, 0x35(%rsp)
movzbl 0x35(%rsp), %eax
cmpl $0x5, %eax
jge 0x8463
movl $0x0, 0x2c(%rsp)
callq 0x3150
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movsd 0x772e(%rip), %xmm0     # 0xfa30
addsd 0x20(%rsp), %xmm0
cvttsd2si %xmm0, %ecx
subl %ecx, %eax
cmpl $0x2, %eax
jb 0x8324
movl 0x2c(%rsp), %eax
movzbl 0x32(%rsp), %ecx
cmpl %ecx, %eax
jbe 0x83be
movq 0x1738d(%rip), %rcx     # 0x1f6b8
movq 0x1737e(%rip), %rax     # 0x1f6b0
movq %rcx, %rdx
addq %rax, %rdx
shrq %rdx
movl 0x2c(%rsp), %esi
addq %rsi, %rdx
movq %rdx, %xmm0
movaps 0x7822(%rip), %xmm1     # 0xfb70
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x7826(%rip), %xmm1     # 0xfb80
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x20(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
subq %rcx, %rax
movsd 0x766c(%rip), %xmm0     # 0xf9f0
xorps %xmm1, %xmm1
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
jb 0x83a1
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
addsd %xmm1, %xmm0
addsd %xmm0, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cvtsi2sd %rax, %xmm1
movsd 0x20(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x8404
movl 0x2c(%rsp), %eax
cvtsi2sd %rax, %xmm0
movsd 0x17384(%rip), %xmm1    # 0x1f768
movzbl 0x33(%rsp), %eax
cvtsi2sd %eax, %xmm2
subsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x8404
movzbl 0x34(%rsp), %eax
shll %eax
movb %al, 0x34(%rsp)
jmp 0x8452
movl 0x2c(%rsp), %eax
cvtsi2sd %rax, %xmm1
movsd 0x17373(%rip), %xmm0    # 0x1f788
movzbl 0x33(%rsp), %eax
cvtsi2sd %eax, %xmm2
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x8450
movl 0x2c(%rsp), %eax
cvtsi2sd %rax, %xmm0
ucomisd 0x20(%rsp), %xmm0
jb 0x8450
movzbl 0x34(%rsp), %eax
shll %eax
movb %al, 0x34(%rsp)
movzbl 0x34(%rsp), %eax
orl $0x1, %eax
movb %al, 0x34(%rsp)
jmp 0x8452
jmp 0x8454
movb 0x35(%rsp), %al
addb $0x1, %al
movb %al, 0x35(%rsp)
jmp 0x82d7
movzbl 0x34(%rsp), %eax
movzbl 0xaca0(%rip), %ecx      # 0x1310f
cmpl %ecx, %eax
je 0x849e
callq 0x1a10
movzbl 0xade1(%rip), %edi      # 0x13260
movq 0xad42(%rip), %rsi      # 0x131c8
xorl %edx, %edx
callq 0x10b0
movl $0x0, 0xaec9(%rip)      # 0x13360
movb $0x0, 0x37(%rsp)
jmp 0x84c0
movb $0x1, 0xad89(%rip)      # 0x1322e
movl $0x5, %edi
movl $0x3, %esi
callq 0x84d0
movb $0x0, 0xad73(%rip)      # 0x1322e
movb $0x1, 0x37(%rsp)
movb 0x37(%rsp), %al
addq $0x38, %rsp
retq
nopl (%rax)