// File: /workspace/github_c_makefile_star2_O0/mincebert[P]maketzx/maketzx.c
// Function: SyncSearch
dword SyncSearch(void)
{
  byte minsmp=(byte)(samprate/((pilot.freq+30)*4)),
       middle=(byte)((float)(samprate/((pilot.freq+50)*2)+.5)),
       maxsmp=(byte)(samprate/(pilot.freq-230)),
       pulseget=0;
  word hwaves=0;
  long pulse;
  float tolerance=(middle-syncx.samples)*.75;
  if (spdchk) syncx.samples*=ecf;
  SyncLoadOK=0;
     {
       do {
	    do {
		 if (!pulseget) pulse=FindEdge1();
		 else { pulse-=lastpulse; pulseget=0; }
		 if (!pulse || pulse<(minsmp-tolerance)/2 || pulse>maxsmp/2)
		    { mspause+=(pulse/samprate)*1000; return hwaves; }
		 if ((pulse-lastpulse)>diff*5 && (pulse-lastpulse) && abs(diff)>tolerance) pulse+=(diff*(abs(diff)<5));
		 if (pulse<0)
		 pulse-=diff;
		 hwaves++;
		 pilotlength+=pulse;
	       }
	    while (pulse>(byte)((double)(middle+tolerance)/2+.5) || (pulse/2+lastpulse/2<middle/2 && diff>minsmp/2));
	    if ((pulse-lastpulse)>middle/2 && (lastpulse-middle)>tolerance && pulse)
	       {
		 double sum=pulse+lastpulse;
//               if (!pulse) sum-=diff;
		 pulse=sum*.3; lastpulse=sum-pulse;
	       }
	    if (pulse+lastpulse>middle || ((lastpulse-(byte)pilot.samples/2)<=tolerance && pulse>=syncx.samples/2) || syncx.samples<2)// || abs(lastpulse-(byte)syncx.samples)>1) //lastpulse>syncx.samples)
	       {
		 pilotlength-=pulse;
		 if (!pulseget) { pulse+=FindEdge1(); pulseget=1; }
		 else { pulseget=0; pulse+=lastpulse; }
	       }
	    else { pulse+=lastpulse; pulseget=0; }
//          if (ClickSearch && !(hwaves%2) && abs(pulse-middle)<tolerance) pulse=middle;
	  }
       while (pulse<minsmp || pulse>middle);
       SyncLoadOK=1;
       return hwaves;
     }
}

// Assembly:
subq $0x58, %rsp
movss 0xf304(%rip), %xmm0     # 0x131d0
cvtss2sd %xmm0, %xmm0
movsd 0x1b840(%rip), %xmm1    # 0x1f718
movsd 0xbb38(%rip), %xmm2     # 0xfa18
addsd %xmm2, %xmm1
movsd 0xbb34(%rip), %xmm2     # 0xfa20
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x4f(%rsp)
movss 0xf2cc(%rip), %xmm0     # 0x131d0
cvtss2sd %xmm0, %xmm0
movsd 0x1b808(%rip), %xmm1    # 0x1f718
movsd 0xbb10(%rip), %xmm2     # 0xfa28
addsd %xmm2, %xmm1
addsd %xmm1, %xmm1
divsd %xmm1, %xmm0
movsd 0xbb04(%rip), %xmm1     # 0xfa30
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvttss2si %xmm0, %eax
movb %al, 0x4e(%rsp)
movss 0xf28c(%rip), %xmm0     # 0x131d0
cvtss2sd %xmm0, %xmm0
movsd 0x1b7c8(%rip), %xmm1    # 0x1f718
movsd 0xbae0(%rip), %xmm2     # 0xfa38
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x4d(%rsp)
movb $0x0, 0x4c(%rsp)
movl $0x0, 0x48(%rsp)
movzbl 0x4e(%rsp), %eax
cvtsi2sd %eax, %xmm0
subsd 0x1b7c2(%rip), %xmm0    # 0x1f748
movsd 0xba82(%rip), %xmm1     # 0xfa10
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x3c(%rsp)
cmpb $0x0, 0xf1f6(%rip)      # 0x13199
je 0x3fbd
movsd 0xf12b(%rip), %xmm0     # 0x130d8
mulsd 0x1b793(%rip), %xmm0    # 0x1f748
movsd %xmm0, 0x1b78b(%rip)    # 0x1f748
movb $0x0, 0x1b7d6(%rip)     # 0x1f79a
jmp 0x3fc6
cmpb $0x0, 0x4c(%rsp)
jne 0x3fd9
callq 0x2e80
movq %rax, 0x40(%rsp)
jmp 0x3ff2
movq 0x1b6d0(%rip), %rcx     # 0x1f6b0
movq 0x40(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x40(%rsp)
movb $0x0, 0x4c(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0x4047
cvtsi2ssq 0x40(%rsp), %xmm1
movzbl 0x4f(%rsp), %eax
cvtsi2ss %eax, %xmm0
subss 0x3c(%rsp), %xmm0
movss 0xbb30(%rip), %xmm2     # 0xfb48
divss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
ja 0x4047
movq 0x40(%rsp), %rax
movq %rax, 0x28(%rsp)
movzbl 0x4d(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x28(%rsp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
jle 0x4084
cvtsi2ssq 0x40(%rsp), %xmm0
divss 0xf17a(%rip), %xmm0     # 0x131d0
movss 0xbae6(%rip), %xmm1     # 0xfb44
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0xf192(%rip), %xmm0     # 0x13200
movsd %xmm0, 0xf18a(%rip)     # 0x13200
movl 0x48(%rsp), %eax
movq %rax, 0x50(%rsp)
jmp 0x4469
movq 0x40(%rsp), %rax
subq 0x1b620(%rip), %rax     # 0x1f6b0
imull $0x5, 0xf13d(%rip), %ecx # 0x131d4
movslq %ecx, %rcx
cmpq %rcx, %rax
jbe 0x40f7
movq 0x40(%rsp), %rax
subq 0x1b605(%rip), %rax     # 0x1f6b0
cmpq $0x0, %rax
je 0x40f7
movl 0xf11d(%rip), %eax      # 0x131d4
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cvtsi2ss %eax, %xmm0
ucomiss 0x3c(%rsp), %xmm0
jbe 0x40f7
movl 0xf105(%rip), %eax      # 0x131d4
movl 0xf0ff(%rip), %ecx      # 0x131d4
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
cmpl $0x5, %ecx
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
imull %ecx, %eax
cltq
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
jge 0x4113
movslq 0xf0ce(%rip), %rcx      # 0x131d4
movq 0x40(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x40(%rsp)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
movq 0x40(%rsp), %rax
addq 0x1ba96(%rip), %rax     # 0x1fbc0
movq %rax, 0x1ba8f(%rip)     # 0x1fbc0
movq 0x40(%rsp), %rcx
movzbl 0x4e(%rsp), %eax
cvtsi2ss %eax, %xmm0
movss 0x3c(%rsp), %xmm1
addss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xb8db(%rip), %xmm1     # 0xfa30
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movzbl %al, %eax
movl %eax, %edx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, 0x27(%rsp)
jg 0x41d9
movq 0x40(%rsp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq 0x1b526(%rip), %rax     # 0x1f6b0
shrq %rax
addq %rax, %rcx
movzbl 0x4e(%rsp), %eax
movl $0x2, %esi
cltd
idivl %esi
movslq %eax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x26(%rsp)
jae 0x41d1
movl 0xf023(%rip), %eax      # 0x131d4
movl %eax, 0x20(%rsp)
movzbl 0x4f(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x20(%rsp), %eax
cmpl %ecx, %eax
setg %al
movb %al, 0x26(%rsp)
movb 0x26(%rsp), %al
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x3fc6
movq 0x40(%rsp), %rax
subq 0x1b4bf(%rip), %rax     # 0x1f6b0
movq %rax, 0x18(%rsp)
movzbl 0x4e(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x18(%rsp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
jbe 0x4311
movq 0x1b493(%rip), %rax     # 0x1f6b0
movzbl 0x4e(%rsp), %ecx
subq %rcx, %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x10(%rsp)
testq %rax, %rax
movss %xmm0, 0x14(%rsp)
js 0x425e
movss 0x10(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movss 0x14(%rsp), %xmm0
ucomiss 0x3c(%rsp), %xmm0
jbe 0x4311
cmpq $0x0, 0x40(%rsp)
je 0x4311
movq 0x40(%rsp), %rax
movq 0x1b429(%rip), %rcx     # 0x1f6b0
addq %rcx, %rax
movq %rax, %xmm0
movaps 0xb8da(%rip), %xmm1     # 0xfb70
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xb8de(%rip), %xmm1     # 0xfb80
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
movsd 0xb77b(%rip), %xmm1     # 0xfa40
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, 0x40(%rsp)
movsd 0x30(%rsp), %xmm0
cvtsi2sdq 0x40(%rsp), %xmm1
subsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0xb74d(%rip), %xmm1     # 0xfa48
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x1b39f(%rip)     # 0x1f6b0
movq 0x40(%rsp), %rax
addq 0x1b393(%rip), %rax     # 0x1f6b0
movzbl 0x4e(%rsp), %ecx
cmpq %rcx, %rax
ja 0x43bf
movq 0x1b37e(%rip), %rax     # 0x1f6b0
cvttsd2si 0x1b3ee(%rip), %ecx # 0x1f728
movzbl %cl, %ecx
shrl %ecx
subq %rcx, %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x8(%rsp)
testq %rax, %rax
movss %xmm0, 0xc(%rsp)
js 0x437b
movss 0x8(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0xc(%rsp), %xmm1
movss 0x3c(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x43ad
cvtsi2sdq 0x40(%rsp), %xmm0
movsd 0x1b3ad(%rip), %xmm1    # 0x1f748
movsd 0xb665(%rip), %xmm2     # 0xfa08
divsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jae 0x43bf
movsd 0xb653(%rip), %xmm0     # 0xfa08
ucomisd 0x1b38b(%rip), %xmm0    # 0x1f748
jbe 0x440a
movq 0x40(%rsp), %rcx
movq 0x1b7f5(%rip), %rax     # 0x1fbc0
subq %rcx, %rax
movq %rax, 0x1b7eb(%rip)     # 0x1fbc0
cmpb $0x0, 0x4c(%rsp)
jne 0x43f2
callq 0x2e80
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
movb $0x1, 0x4c(%rsp)
jmp 0x4408
movb $0x0, 0x4c(%rsp)
movq 0x1b2b2(%rip), %rax     # 0x1f6b0
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x4420
movq 0x1b29f(%rip), %rax     # 0x1f6b0
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
movb $0x0, 0x4c(%rsp)
jmp 0x4422
movq 0x40(%rsp), %rcx
movzbl 0x4f(%rsp), %eax
movl %eax, %edx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, 0x7(%rsp)
jl 0x444d
movq 0x40(%rsp), %rax
movzbl 0x4e(%rsp), %ecx
cmpq %rcx, %rax
setg %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x3fc4
movb $0x1, 0x1b33a(%rip)     # 0x1f79a
movl 0x48(%rsp), %eax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)