// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cvtss2sd 0xc2fd(%rip), %xmm0     # 0xf1f0
movsd 0x1883d(%rip), %xmm1    # 0x1b738
movsd 0x83d5(%rip), %xmm2     # 0xb2d8
addsd %xmm1, %xmm2
mulsd 0x83d1(%rip), %xmm2     # 0xb2e0
movaps %xmm0, %xmm3
divsd %xmm2, %xmm3
cvttsd2si %xmm3, %eax
movsd 0x83c6(%rip), %xmm2     # 0xb2e8
addsd %xmm1, %xmm2
addsd %xmm2, %xmm2
movaps %xmm0, %xmm3
divsd %xmm2, %xmm3
addsd 0x8397(%rip), %xmm3     # 0xb2d0
xorps %xmm2, %xmm2
cvtsd2ss %xmm3, %xmm2
cvttss2si %xmm2, %edx
addsd 0x83a4(%rip), %xmm1     # 0xb2f0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movzbl %dl, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd 0x18802(%rip), %xmm0    # 0x1b768
subsd %xmm0, %xmm1
mulsd 0x8386(%rip), %xmm1     # 0xb2f8
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%rsp)
cmpb $0x0, 0xc237(%rip)      # 0xf1b9
je 0x2f94
mulsd 0xc16c(%rip), %xmm0     # 0xf0f8
movsd %xmm0, 0x187d4(%rip)    # 0x1b768
movb $0x0, 0x1881f(%rip)     # 0x1b7ba
movzbl %al, %esi
xorps %xmm2, %xmm2
cvtsi2ss %esi, %xmm2
movss (%rsp), %xmm1
subss %xmm1, %xmm2
mulss 0x8432(%rip), %xmm2     # 0xb3e8
shrb %cl
movzbl %cl, %r12d
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
addss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x82fd(%rip), %xmm1     # 0xb2d0
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movzbl %al, %r13d
movq %rdx, 0x8(%rsp)
movl %edx, %eax
shrb %al
movzbl %al, %ebp
movq %rsi, 0x10(%rsp)
movl %esi, %eax
shrb %al
movzbl %al, %r15d
xorl %edx, %edx
xorl %ecx, %ecx
movss %xmm2, 0x4(%rsp)
testb %cl, %cl
sete %cl
movl %edx, %r14d
movq %rax, %rbx
testb $0x1, %cl
je 0x3026
callq 0x249f
movss 0x4(%rsp), %xmm2
movq %rax, %rbx
jmp 0x302d
subq 0x186a3(%rip), %rbx     # 0x1b6d0
xorps %xmm0, %xmm0
cvtsi2ss %rbx, %xmm0
testq %rbx, %rbx
je 0x3264
ucomiss %xmm0, %xmm2
ja 0x3264
cmpq %r12, %rbx
jg 0x3264
movq 0x18679(%rip), %rdx     # 0x1b6d0
movq %rbx, %rcx
subq %rdx, %rcx
movslq 0xc190(%rip), %rax      # 0xf1f4
leaq (%rax,%rax,4), %rsi
cmpq %rsi, %rcx
jbe 0x3090
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
ucomiss (%rsp), %xmm0
jbe 0x3090
movl %eax, %esi
cmpl $0x5, %ecx
jb 0x308a
xorl %esi, %esi
movslq %esi, %rcx
addq %rcx, %rbx
movq %rbx, %rcx
sarq $0x3f, %rcx
andq %rax, %rcx
subq %rcx, %rbx
movq 0x18b3c(%rip), %rcx     # 0x1bbe0
addq %rbx, %rcx
movq %rcx, 0x18b32(%rip)     # 0x1bbe0
cmpq %r13, %rbx
jg 0x30d3
movq %rbx, %rsi
shrq $0x3f, %rsi
addq %rbx, %rsi
sarq %rsi
movq %rdx, %rdi
shrq %rdi
addq %rsi, %rdi
cmpq %rbp, %rdi
jae 0x30dd
cmpl %r15d, %eax
jle 0x30dd
incl %r14d
movb $0x1, %cl
jmp 0x3011
movq %rbx, %rax
subq %rdx, %rax
cmpq %rbp, %rax
jbe 0x318a
movq %rdx, %rax
subq 0x8(%rsp), %rax
js 0x3100
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x3118
movq %rax, %rsi
shrq %rsi
andl $0x1, %eax
orq %rsi, %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
addss %xmm0, %xmm0
ucomiss (%rsp), %xmm0
jbe 0x318a
testq %rbx, %rbx
je 0x318a
addq %rdx, %rbx
movq %rbx, %xmm0
punpckldq 0x82dd(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x82e5(%rip), %xmm0     # 0xb420
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
mulsd 0x81ad(%rip), %xmm0     # 0xb300
cvttsd2si %xmm0, %rbx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
subsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rsi
subsd 0x8194(%rip), %xmm1     # 0xb308
cvttsd2si %xmm1, %rdx
sarq $0x3f, %rsi
andq %rsi, %rdx
orq %rax, %rdx
movq %rdx, 0x18546(%rip)     # 0x1b6d0
leaq (%rdx,%rbx), %rax
cmpq 0x8(%rsp), %rax
jbe 0x31b4
subq %rbx, %rcx
movq %rcx, 0x18a41(%rip)     # 0x1bbe0
callq 0x249f
movss 0x4(%rsp), %xmm2
addq %rbx, %rax
movb $0x1, %cl
jmp 0x323e
cvttsd2si 0x1858c(%rip), %esi # 0x1b748
shrb %sil
movzbl %sil, %esi
subq %rsi, %rdx
js 0x31d2
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
jmp 0x31ea
movq %rdx, %rsi
shrq %rsi
andl $0x1, %edx
orq %rsi, %rdx
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
addss %xmm0, %xmm0
movss (%rsp), %xmm1
ucomiss %xmm0, %xmm1
jae 0x3208
movsd 0x8114(%rip), %xmm0     # 0xb310
ucomisd 0x18564(%rip), %xmm0    # 0x1b768
ja 0x3195
jmp 0x323c
movsd 0x18558(%rip), %xmm0    # 0x1b768
movsd 0x80f8(%rip), %xmm1     # 0xb310
ucomisd %xmm0, %xmm1
mulsd 0x80ac(%rip), %xmm0     # 0xb2d0
ja 0x3195
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
ucomisd %xmm0, %xmm1
jae 0x3195
xorl %ecx, %ecx
leal 0x1(%r14), %edx
cmpq 0x10(%rsp), %rax
jl 0x3006
cmpq 0x8(%rsp), %rax
jg 0x3006
movb $0x1, 0x1855b(%rip)     # 0x1b7ba
incl %r14d
jmp 0x3288
divss 0xbf84(%rip), %xmm0     # 0xf1f0
mulss 0x8170(%rip), %xmm0     # 0xb3e4
cvtss2sd %xmm0, %xmm0
addsd 0xbfa0(%rip), %xmm0     # 0xf220
movsd %xmm0, 0xbf98(%rip)     # 0xf220
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq