// File: /workspace/github_c_makefile_star2_O1/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 $0x128, %rsp            # imm = 0x128
cvtss2sd 0xc8bf(%rip), %xmm0     # 0xf1f0
movsd 0x18dff(%rip), %xmm1    # 0x1b738
addsd 0x894f(%rip), %xmm1     # 0xb290
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rbx
movb $0x1, 0xc86a(%rip)      # 0xf1bb
movb $0x0, 0x18e61(%rip)     # 0x1b7b9
leaq 0x8cd9(%rip), %rdi      # 0xb638
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x10b0
movl %ebx, %eax
movq %rax, 0x18(%rsp)
movl $0x28, %edi
callq 0x2bfc
callq 0x2f5c
leaq 0x51(%rax), %r14
cmpb $0x0, 0x18e31(%rip)     # 0x1b7ba
je 0x29fd
cmpq $0xfe, %r14
ja 0x2be7
testb $0x1, %r14b
je 0x29b5
movq 0x18d2b(%rip), %rcx     # 0x1b6d0
addq %rcx, %rcx
addq $0x50, %rax
cmpq 0x18(%rsp), %rcx
cmovbq %rax, %r14
movzbl %bpl, %ebp
movb %r14b, 0x20(%rsp,%rbp)
incb %bpl
cmpb $0x9, 0xc78f(%rip)      # 0xf157
ja 0x2bce
movl 0x18d7c(%rip), %edi     # 0x1b750
movl %r14d, %esi
callq 0x3321
movl 0x18d8e(%rip), %eax     # 0x1b770
movl %eax, 0x18ddc(%rip)     # 0x1b7c4
movl %eax, 0x18dd2(%rip)     # 0x1b7c0
movl $0x2, %edi
callq 0x3374
jmp 0x2bce
movzbl %bpl, %ebx
leal 0x1(%rbx), %eax
shrl $0x3, %eax
movl %ebx, %ecx
subl %eax, %ecx
movslq %ecx, %rax
movzbl 0x20(%rsp,%rax), %eax
movq %r14, %r15
subq %rax, %r15
testl %r15d, %r15d
jne 0x2a23
callq 0x24b6
movslq %r15d, %rax
subq %rax, %r14
movb 0x18c92(%rip), %al      # 0x1b6c1
testb %al, %al
je 0x2bca
movb %al, 0xb(%rsp)
movb %r14b, 0x20(%rsp,%rbx)
leal 0x1(%rbp), %eax
cmpb $0xa, 0xc70d(%rip)      # 0xf157
movl %eax, 0xc(%rsp)
movzbl %al, %r13d
jb 0x2b58
movw $0x7, 0xc72b(%rip)      # 0xf18c
xorl %ebx, %ebx
leaq 0xc721(%rip), %r15      # 0xf18b
leaq 0x10927(%rip), %r12     # 0x13398
movzbl (%rbx,%r15), %esi
movq %r12, %rdi
movl $0x1, %edx
callq 0x1e21
incq %rbx
cmpq $0x3, %rbx
jne 0x2a71
leal 0x1(%r13), %r12d
shrl $0x3, %r12d
movl %r13d, %eax
subb %r12b, %al
movzbl %al, %ecx
movq %rcx, 0x10(%rsp)
cmpb %r13b, %al
jae 0x2aeb
movq 0x10(%rsp), %rax
leaq (%rsp,%rax), %rbx
addq $0x20, %rbx
xorl %r15d, %r15d
movl 0x18c93(%rip), %edi     # 0x1b750
movzbl (%rbx,%r15), %esi
callq 0x3321
movl 0x18ca3(%rip), %eax     # 0x1b770
movl %eax, 0x18cf1(%rip)     # 0x1b7c4
movl %eax, 0x18ce7(%rip)     # 0x1b7c0
movl $0x2, %edi
callq 0x3374
incq %r15
cmpb %r15b, %r12b
jne 0x2ab7
movzbl 0xc69c(%rip), %esi      # 0xf18e
leaq 0x1089f(%rip), %rdi     # 0x13398
movl $0x1, %edx
callq 0x1e21
leal -0x1(%r13), %ebx
movq 0x10(%rsp), %rax
cmpl %eax, %ebx
jle 0x2b58
leaq (%rsp,%rax), %r15
addq $0x20, %r15
subb %r12b, %bpl
addb $0x2, %bpl
movl 0x18c2b(%rip), %edi     # 0x1b750
movzbl (%r15), %esi
callq 0x3321
movl 0x18c3c(%rip), %eax     # 0x1b770
movl %eax, 0x18c8a(%rip)     # 0x1b7c4
movl %eax, 0x18c80(%rip)     # 0x1b7c0
movl $0x2, %edi
callq 0x3374
movzbl %bpl, %eax
incq %r15
leal 0x1(%rax), %ebp
cmpl %eax, %ebx
jg 0x2b1f
movl 0x18bf2(%rip), %edi     # 0x1b750
movl %r14d, %esi
callq 0x3321
movabsq $0xc5100000c51, %rax    # imm = 0xC5100000C51
movq %rax, 0x18c49(%rip)     # 0x1b7c0
movl $0x2, %edi
callq 0x3374
movb $0x1, 0x18c31(%rip)     # 0x1b7b9
movl 0xc(%rsp), %esi
testb %sil, %sil
je 0x2bad
xorl %ecx, %ecx
xorl %eax, %eax
xorl %edx, %edx
cmpb $-0x6, 0x20(%rsp,%rcx)
sete %dl
addl %edx, %eax
incq %rcx
cmpq %rcx, %r13
jne 0x2b95
movl %esi, %ebp
jmp 0x2bb1
xorl %eax, %eax
xorl %ebp, %ebp
shrb $0x3, %sil
movzbl %sil, %ecx
decl %ecx
cmpl %ecx, %eax
jbe 0x2bc6
movb $0x6, 0xc566(%rip)      # 0xf12c
movb 0xb(%rsp), %al
testb %al, %al
je 0x2be4
cmpb $0x0, 0x18be5(%rip)     # 0x1b7ba
jne 0x296f
movb $0x0, 0xc5d9(%rip)      # 0xf1bb
jmp 0x2be7
xorl %r14d, %r14d
movq %r14, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq