// File: /workspace/github_c_makefile_star2_O1/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 0xc27e(%rip), %xmm0     # 0xf1f0
movsd 0x187be(%rip), %xmm1    # 0x1b738
movsd 0x8356(%rip), %xmm2     # 0xb2d8
addsd %xmm1, %xmm2
mulsd 0x8352(%rip), %xmm2     # 0xb2e0
movaps %xmm0, %xmm3
divsd %xmm2, %xmm3
cvttsd2si %xmm3, %eax
movsd 0x8347(%rip), %xmm2     # 0xb2e8
addsd %xmm1, %xmm2
addsd %xmm2, %xmm2
movaps %xmm0, %xmm3
divsd %xmm2, %xmm3
addsd 0x8318(%rip), %xmm3     # 0xb2d0
xorps %xmm2, %xmm2
cvtsd2ss %xmm3, %xmm2
cvttss2si %xmm2, %edx
addsd 0x8325(%rip), %xmm1     # 0xb2f0
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movzbl %dl, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd 0x18783(%rip), %xmm0    # 0x1b768
subsd %xmm0, %xmm1
mulsd 0x8307(%rip), %xmm1     # 0xb2f8
cvtsd2ss %xmm1, %xmm1
movss %xmm1, (%rsp)
cmpb $0x0, 0xc1b8(%rip)      # 0xf1b9
je 0x3013
mulsd 0xc0ed(%rip), %xmm0     # 0xf0f8
movsd %xmm0, 0x18755(%rip)    # 0x1b768
movb $0x0, 0x187a0(%rip)     # 0x1b7ba
movzbl %al, %esi
xorps %xmm2, %xmm2
cvtsi2ss %esi, %xmm2
movss (%rsp), %xmm1
subss %xmm1, %xmm2
mulss 0x83b3(%rip), %xmm2     # 0xb3e8
shrb %cl
movzbl %cl, %r12d
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
addss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x827e(%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 %ecx, %ecx
xorl %edx, %edx
movss %xmm2, 0x4(%rsp)
testb %dl, %dl
sete %dl
movl %ecx, %r14d
movq %rax, %rbx
testb $0x1, %dl
je 0x30a5
callq 0x24b6
movss 0x4(%rsp), %xmm2
movq %rax, %rbx
jmp 0x30ac
subq 0x18624(%rip), %rbx     # 0x1b6d0
xorps %xmm0, %xmm0
cvtsi2ss %rbx, %xmm0
testq %rbx, %rbx
je 0x32eb
ucomiss %xmm0, %xmm2
ja 0x32eb
cmpq %r12, %rbx
jg 0x32eb
movq 0x185fa(%rip), %rax     # 0x1b6d0
movq %rbx, %rcx
subq %rax, %rcx
movslq 0xc111(%rip), %rdx      # 0xf1f4
leaq (%rdx,%rdx,4), %rsi
cmpq %rsi, %rcx
jbe 0x310f
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
ucomiss (%rsp), %xmm0
jbe 0x310f
movl %edx, %esi
cmpl $0x5, %ecx
jb 0x3109
xorl %esi, %esi
movslq %esi, %rcx
addq %rcx, %rbx
movq %rbx, %rcx
sarq $0x3f, %rcx
andq %rdx, %rcx
subq %rcx, %rbx
movq 0x18abd(%rip), %rcx     # 0x1bbe0
addq %rbx, %rcx
movq %rcx, 0x18ab3(%rip)     # 0x1bbe0
cmpq %r13, %rbx
jg 0x3152
movq %rbx, %rsi
shrq $0x3f, %rsi
addq %rbx, %rsi
sarq %rsi
movq %rax, %rdi
shrq %rdi
addq %rsi, %rdi
cmpq %rbp, %rdi
jae 0x315c
cmpl %r15d, %edx
jle 0x315c
incl %r14d
movb $0x1, %dl
jmp 0x3090
movq %rbx, %rdx
subq %rax, %rdx
cmpq %rbp, %rdx
jbe 0x3209
movq %rax, %rdx
subq 0x8(%rsp), %rdx
js 0x317f
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
jmp 0x3197
movq %rdx, %rsi
shrq %rsi
andl $0x1, %edx
orq %rsi, %rdx
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
addss %xmm0, %xmm0
ucomiss (%rsp), %xmm0
jbe 0x3209
testq %rbx, %rbx
je 0x3209
addq %rax, %rbx
movq %rbx, %xmm0
punpckldq 0x825e(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x8266(%rip), %xmm0     # 0xb420
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
mulsd 0x812e(%rip), %xmm0     # 0xb300
cvttsd2si %xmm0, %rbx
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
subsd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
subsd 0x8115(%rip), %xmm1     # 0xb308
cvttsd2si %xmm1, %rsi
sarq $0x3f, %rdx
andq %rdx, %rsi
orq %rax, %rsi
movq %rsi, 0x184c7(%rip)     # 0x1b6d0
movq 0x184c0(%rip), %rax     # 0x1b6d0
leaq (%rax,%rbx), %rdx
cmpq 0x8(%rsp), %rdx
jbe 0x3237
subq %rbx, %rcx
movq %rcx, 0x189bb(%rip)     # 0x1bbe0
callq 0x24b6
movb $0x1, %dl
movss 0x4(%rsp), %xmm2
jmp 0x32c2
cvttsd2si 0x18509(%rip), %edx # 0x1b748
shrb %dl
movzbl %dl, %esi
movq %rax, %rdx
subq %rsi, %rdx
js 0x3256
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
jmp 0x326e
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 0x328c
movsd 0x8090(%rip), %xmm0     # 0xb310
ucomisd 0x184e0(%rip), %xmm0    # 0x1b768
ja 0x321b
jmp 0x32c0
movsd 0x184d4(%rip), %xmm0    # 0x1b768
movsd 0x8074(%rip), %xmm1     # 0xb310
ucomisd %xmm0, %xmm1
mulsd 0x8028(%rip), %xmm0     # 0xb2d0
ja 0x321b
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
ucomisd %xmm0, %xmm1
jae 0x321b
xorl %edx, %edx
leal 0x1(%r14), %ecx
addq %rbx, %rax
cmpq 0x10(%rsp), %rax
jl 0x3085
cmpq 0x8(%rsp), %rax
jg 0x3085
movb $0x1, 0x184d4(%rip)     # 0x1b7ba
incl %r14d
jmp 0x330f
divss 0xbefd(%rip), %xmm0     # 0xf1f0
mulss 0x80e9(%rip), %xmm0     # 0xb3e4
cvtss2sd %xmm0, %xmm0
addsd 0xbf19(%rip), %xmm0     # 0xf220
movsd %xmm0, 0xbf11(%rip)     # 0xf220
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq