// File: /workspace/github_c_makefile_star2_O0/mincebert[P]maketzx/maketzx.c
// Function: ClickingPilotSearch
dword ClickingPilotSearch(void)
{
  byte pulsenum[255],pulsecount,tpointer=0;
  word minplen=samprate/(pilot.freq+150);
  dword hpulses;
  ClickSearch=1;
  ClickingPilotOK=0;
  printf("Loading clicking pilot... \x0d");
  do {
       hpulses=80;
       PilotSearch(hpulses/2);
       hpulses+=(SyncSearch()+1);
       if (SyncLoadOK)
	  {
	    if (hpulses>254) return hpulses;
	    if (hpulses&1)
	       if (lastpulse*2<minplen) hpulses--;
	    pulsenum[tpointer]=hpulses;
	    tpointer++;
	    if (tzxhead[9]<0x0a)
	       {
		 WriteTZXTone(pilot.tstates,hpulses);
		 pulseseq[0]=pulseseq[1]=syncx.tstates;
		 WriteTZXPulseSequence(2);
	       }
	  }
       else {

	      word p250num=0;
	      word syncp;
	      int diff=hpulses-(pulsenum[tpointer-(tpointer+1)/8]);
	      hpulses-=diff;
	      if (!diff) FindEdge1();
	      if (!blocktype) return 0;
	      pulsenum[tpointer]=hpulses;
	      pulsecount=++tpointer;
	      if (tzxhead[9]>=0x0a)
		 {
		   byte count;
		   WriteTZXLoopStart(7);
		   for (count=tpointer-(tpointer+1)/8; count<tpointer; count++)
		       {
			 WriteTZXTone(pilot.tstates,pulsenum[count]);
			 pulseseq[0]=pulseseq[1]=syncx.tstates;
			 WriteTZXPulseSequence(2);
		       }
		   WriteTZXLoopEnd();
		   for (count=tpointer-(tpointer+1)/8; count<tpointer-1; count++)
		       {
			 WriteTZXTone(pilot.tstates,pulsenum[count]);
			 pulseseq[0]=pulseseq[1]=syncx.tstates;
			 WriteTZXPulseSequence(2);
		       }

		 }
	      WriteTZXTone(pilot.tstates,hpulses);
	      pulseseq[0]=pulseseq[1]=3500000/(2*555);
	      WriteTZXPulseSequence(2);
	      ClickingPilotOK=1;
	      for (tpointer=0; tpointer<pulsecount; tpointer++)
		  { if (pulsenum[tpointer]==250) p250num++; }
	      if (p250num>(pulsecount/8)-1) slockflagbits=6;
	    }

     }
  while (SyncLoadOK);
  ClickSearch=0;
  return hpulses;
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movb $0x0, 0x3e(%rsp)
movss 0xfb7c(%rip), %xmm0     # 0x131d0
cvtss2sd %xmm0, %xmm0
movsd 0x1c0b8(%rip), %xmm1    # 0x1f718
movsd 0xc368(%rip), %xmm2     # 0xf9d0
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x38(%rsp)
movb $0x1, 0xfb1b(%rip)      # 0x1319b
movb $0x0, 0x1c112(%rip)     # 0x1f799
leaq 0xcb22(%rip), %rdi      # 0x101b0
movb $0x0, %al
callq 0x1090
movq $0x50, 0x30(%rsp)
movq 0x30(%rsp), %rax
shrq %rax
movl %eax, %edi
callq 0x39e0
callq 0x3ec0
addq $0x1, %rax
addq 0x30(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpb $0x0, 0x1c0d3(%rip)     # 0x1f79a
je 0x3775
cmpq $0xfe, 0x30(%rsp)
jbe 0x36ea
movq 0x30(%rsp), %rax
movq %rax, 0x140(%rsp)
jmp 0x39d0
movq 0x30(%rsp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x371c
movq 0x1bfb0(%rip), %rax     # 0x1f6b0
shlq %rax
movl 0x38(%rsp), %ecx
cmpq %rcx, %rax
jae 0x371a
movq 0x30(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x30(%rsp)
jmp 0x371c
movq 0x30(%rsp), %rax
movb %al, %cl
movzbl 0x3e(%rsp), %eax
movb %cl, 0x40(%rsp,%rax)
movb 0x3e(%rsp), %al
addb $0x1, %al
movb %al, 0x3e(%rsp)
movzbl 0xf9fa(%rip), %eax      # 0x13137
cmpl $0xa, %eax
jge 0x3770
movl 0x1bfe8(%rip), %edi     # 0x1f730
movq 0x30(%rsp), %rax
movl %eax, %esi
callq 0x4480
movl 0x1bff6(%rip), %eax     # 0x1f750
movl %eax, 0x1c044(%rip)     # 0x1f7a4
movl %eax, 0x1c03a(%rip)     # 0x1f7a0
movl $0x2, %edi
callq 0x4520
jmp 0x39ad
movl $0x0, 0x2c(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
movzbl 0x3e(%rsp), %ecx
movzbl 0x3e(%rsp), %eax
addl $0x1, %eax
movl $0x8, %esi
cltd
idivl %esi
movl %eax, %edx
movq 0x18(%rsp), %rax
subl %edx, %ecx
movslq %ecx, %rcx
movzbl 0x40(%rsp,%rcx), %ecx
subq %rcx, %rax
movl %eax, 0x24(%rsp)
movslq 0x24(%rsp), %rcx
movq 0x30(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x24(%rsp)
jne 0x37d2
callq 0x2e80
cmpb $0x0, 0x1bec8(%rip)     # 0x1f6a1
jne 0x37ec
movq $0x0, 0x140(%rsp)
jmp 0x39d0
movq 0x30(%rsp), %rax
movb %al, %cl
movzbl 0x3e(%rsp), %eax
movb %cl, 0x40(%rsp,%rax)
movb 0x3e(%rsp), %al
addb $0x1, %al
movb %al, 0x3e(%rsp)
movb %al, 0x3f(%rsp)
movzbl 0xf926(%rip), %eax      # 0x13137
cmpl $0xa, %eax
jl 0x390e
movl $0x7, %edi
callq 0x45f0
movzbl 0x3e(%rsp), %eax
movl %eax, 0x14(%rsp)
movzbl 0x3e(%rsp), %eax
addl $0x1, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x14(%rsp), %eax
subl %ecx, %eax
movb %al, 0x23(%rsp)
movzbl 0x23(%rsp), %eax
movzbl 0x3e(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3894
movl 0x1bed3(%rip), %edi     # 0x1f730
movzbl 0x23(%rsp), %eax
movzbl 0x40(%rsp,%rax), %esi
callq 0x4480
movl 0x1bede(%rip), %eax     # 0x1f750
movl %eax, 0x1bf2c(%rip)     # 0x1f7a4
movl %eax, 0x1bf22(%rip)     # 0x1f7a0
movl $0x2, %edi
callq 0x4520
movb 0x23(%rsp), %al
addb $0x1, %al
movb %al, 0x23(%rsp)
jmp 0x3849
callq 0x4660
movzbl 0x3e(%rsp), %eax
movl %eax, 0x10(%rsp)
movzbl 0x3e(%rsp), %eax
addl $0x1, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x10(%rsp), %eax
subl %ecx, %eax
movb %al, 0x23(%rsp)
movzbl 0x23(%rsp), %eax
movzbl 0x3e(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x390c
movl 0x1be5b(%rip), %edi     # 0x1f730
movzbl 0x23(%rsp), %eax
movzbl 0x40(%rsp,%rax), %esi
callq 0x4480
movl 0x1be66(%rip), %eax     # 0x1f750
movl %eax, 0x1beb4(%rip)     # 0x1f7a4
movl %eax, 0x1beaa(%rip)     # 0x1f7a0
movl $0x2, %edi
callq 0x4520
movb 0x23(%rsp), %al
addb $0x1, %al
movb %al, 0x23(%rsp)
jmp 0x38be
jmp 0x390e
movl 0x1be1c(%rip), %edi     # 0x1f730
movq 0x30(%rsp), %rax
movl %eax, %esi
callq 0x4480
movl $0xc51, 0x1be7a(%rip)   # imm = 0xC51
movl $0xc51, 0x1be6c(%rip)   # imm = 0xC51
movl $0x2, %edi
callq 0x4520
movb $0x1, 0x1be54(%rip)     # 0x1f799
movb $0x0, 0x3e(%rsp)
movzbl 0x3e(%rsp), %eax
movzbl 0x3f(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3982
movzbl 0x3e(%rsp), %eax
movzbl 0x40(%rsp,%rax), %eax
cmpl $0xfa, %eax
jne 0x3974
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x3976
movb 0x3e(%rsp), %al
addb $0x1, %al
movb %al, 0x3e(%rsp)
jmp 0x394a
movl 0x2c(%rsp), %eax
movl %eax, 0xc(%rsp)
movzbl 0x3f(%rsp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0xc(%rsp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jbe 0x39ab
movb $0x6, 0xf761(%rip)      # 0x1310c
jmp 0x39ad
jmp 0x39af
cmpb $0x0, 0x1bde4(%rip)     # 0x1f79a
jne 0x3695
movb $0x0, 0xf7d8(%rip)      # 0x1319b
movq 0x30(%rsp), %rax
movq %rax, 0x140(%rsp)
movq 0x140(%rsp), %rax
addq $0x148, %rsp            # imm = 0x148
retq