// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
cvtss2sd 0xc9a3(%rip), %xmm0     # 0xf1e0
movsd 0x18ee3(%rip), %xmm1    # 0x1b728
addsd 0x7a43(%rip), %xmm1     # 0xa290
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rbx
movb $0x1, 0xc94e(%rip)      # 0xf1ab
movb $0x0, 0x18f45(%rip)     # 0x1b7a9
leaq 0x7d6d(%rip), %rdi      # 0xa5d8
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x10b0
movl %ebx, %ebp
pushq $0x28
popq %rbx
pushq $0x2
popq %r14
movq %rbp, 0x8(%rsp)
movl %ebx, %edi
callq 0x2a7c
callq 0x2dad
leaq 0x51(%rax), %r15
cmpb $0x0, 0x18f10(%rip)     # 0x1b7aa
movzbl %r12b, %r12d
je 0x290a
cmpq $0xfe, %r15
ja 0x2a67
testb $0x1, %r15b
je 0x28c8
movq 0x18e06(%rip), %rcx     # 0x1b6c0
addq %rcx, %rcx
addq $0x50, %rax
cmpq %rbp, %rcx
cmovbq %rax, %r15
movb %r15b, 0x10(%rsp,%r12)
incb %r12b
cmpb $0x9, 0xc870(%rip)      # 0xf147
ja 0x2a4e
movl 0x18e5d(%rip), %edi     # 0x1b740
movl %r15d, %esi
callq 0x3141
movl 0x18e6f(%rip), %eax     # 0x1b760
movl %eax, 0x18ebd(%rip)     # 0x1b7b4
movl %eax, 0x18eb3(%rip)     # 0x1b7b0
movl %r14d, %edi
callq 0x319d
jmp 0x2a4e
leal 0x1(%r12), %eax
shrl $0x3, %eax
movl %r12d, %ecx
subl %eax, %ecx
movslq %ecx, %rax
movzbl 0x10(%rsp,%rax), %eax
movq %r15, %rbx
subq %rax, %rbx
testl %ebx, %ebx
jne 0x292e
callq 0x2429
cmpb $0x0, 0x18d7c(%rip)     # 0x1b6b1
je 0x2a64
movslq %ebx, %rax
subq %rax, %r15
movb %r15b, 0x10(%rsp,%r12)
incb %r12b
cmpb $0x9, 0xc7f7(%rip)      # 0xf147
movzbl %r12b, %r13d
jbe 0x29ed
pushq $0x7
popq %rdi
callq 0x322a
leal 0x1(%r13), %eax
shrl $0x3, %eax
movl %r13d, %ebp
subb %al, %bpl
movzbl %bpl, %ebx
cmpq %r13, %rbx
jae 0x29a7
movl 0x18dc2(%rip), %edi     # 0x1b740
movzbl 0x10(%rsp,%rbx), %esi
callq 0x3141
movl 0x18dd2(%rip), %eax     # 0x1b760
movl %eax, 0x18e20(%rip)     # 0x1b7b4
movl %eax, 0x18e16(%rip)     # 0x1b7b0
movl %r14d, %edi
callq 0x319d
incq %rbx
jmp 0x2973
callq 0x3271
movl %r13d, %ebx
decl %ebx
movzbl %bpl, %ebp
cmpl %ebp, %ebx
jle 0x29e8
movl 0x18d81(%rip), %edi     # 0x1b740
movzbl 0x10(%rsp,%rbp), %esi
callq 0x3141
movl 0x18d91(%rip), %eax     # 0x1b760
movl %eax, 0x18ddf(%rip)     # 0x1b7b4
movl %eax, 0x18dd5(%rip)     # 0x1b7b0
movl %r14d, %edi
callq 0x319d
incb %bpl
jmp 0x29b1
movq 0x8(%rsp), %rbp
movl 0x18d4d(%rip), %edi     # 0x1b740
movl %r15d, %esi
callq 0x3141
movabsq $0xc5100000c51, %rax    # imm = 0xC5100000C51
movq %rax, 0x18da4(%rip)     # 0x1b7b0
movl %r14d, %edi
callq 0x319d
movb $0x1, 0x18d8e(%rip)     # 0x1b7a9
xorl %ecx, %ecx
xorl %eax, %eax
cmpq %rcx, %r13
je 0x2a35
xorl %edx, %edx
cmpb $-0x6, 0x10(%rsp,%rcx)
sete %dl
addl %edx, %eax
incq %rcx
jmp 0x2a1f
movl %r12d, %ecx
shrb $0x3, %cl
movzbl %cl, %ecx
decl %ecx
cmpl %ecx, %eax
jbe 0x2a4b
movb $0x6, 0xc6d1(%rip)      # 0xf11c
pushq $0x28
popq %rbx
cmpb $0x0, 0x18d55(%rip)     # 0x1b7aa
jne 0x2883
movb $0x0, 0xc749(%rip)      # 0xf1ab
jmp 0x2a67
xorl %r15d, %r15d
movq %r15, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq