// File: /workspace/github_c_makefile_star2_O3/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 0xc90f(%rip), %xmm0     # 0xf1f0
movsd 0x18e4f(%rip), %xmm1    # 0x1b738
addsd 0x899f(%rip), %xmm1     # 0xb290
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rbx
movb $0x1, 0xc8ba(%rip)      # 0xf1bb
movb $0x0, 0x18eb1(%rip)     # 0x1b7b9
leaq 0x8d29(%rip), %rdi      # 0xb638
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x10b0
movl %ebx, %eax
movq %rax, 0x10(%rsp)
movl $0x28, %edi
callq 0x2ba3
callq 0x2edd
leaq 0x51(%rax), %r12
cmpb $0x0, 0x18e81(%rip)     # 0x1b7ba
je 0x29ad
cmpq $0xfe, %r12
ja 0x2b8e
testb $0x1, %r12b
je 0x2965
movq 0x18d7b(%rip), %rcx     # 0x1b6d0
addq %rcx, %rcx
addq $0x50, %rax
cmpq 0x10(%rsp), %rcx
cmovbq %rax, %r12
movzbl %bpl, %r13d
movb %r12b, 0x20(%rsp,%r13)
incb %r13b
cmpb $0x9, 0xc7df(%rip)      # 0xf157
ja 0x2b72
movl 0x18dcc(%rip), %edi     # 0x1b750
movl %r12d, %esi
callq 0x329a
movl 0x18dde(%rip), %eax     # 0x1b770
movl %eax, 0x18e2c(%rip)     # 0x1b7c4
movl %eax, 0x18e22(%rip)     # 0x1b7c0
movl $0x2, %edi
callq 0x32ed
jmp 0x2b72
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 %r12, %r14
subq %rax, %r14
testl %r14d, %r14d
jne 0x29d3
callq 0x249f
cmpb $0x0, 0x18ce7(%rip)     # 0x1b6c1
je 0x2b8b
movslq %r14d, %rax
subq %rax, %r12
movq %r12, 0x18(%rsp)
movb %r12b, 0x20(%rsp,%rbx)
leal 0x1(%rbp), %r13d
cmpb $0xa, 0xc75c(%rip)      # 0xf157
movzbl %r13b, %r15d
jb 0x2b05
movw $0x7, 0xc77e(%rip)      # 0xf18c
xorl %ebx, %ebx
leaq 0xc774(%rip), %r14      # 0xf18b
leaq 0x1097a(%rip), %r12     # 0x13398
movzbl (%rbx,%r14), %esi
movq %r12, %rdi
movl $0x1, %edx
callq 0x1e01
incq %rbx
cmpq $0x3, %rbx
jne 0x2a1e
leal 0x1(%r15), %r12d
shrl $0x3, %r12d
movl %r15d, %eax
subb %r12b, %al
movzbl %al, %ecx
movq %rcx, 0x8(%rsp)
cmpb %r15b, %al
jae 0x2a98
movq 0x8(%rsp), %rax
leaq (%rsp,%rax), %rbx
addq $0x20, %rbx
xorl %r14d, %r14d
movl 0x18ce6(%rip), %edi     # 0x1b750
movzbl (%rbx,%r14), %esi
callq 0x329a
movl 0x18cf6(%rip), %eax     # 0x1b770
movl %eax, 0x18d44(%rip)     # 0x1b7c4
movl %eax, 0x18d3a(%rip)     # 0x1b7c0
movl $0x2, %edi
callq 0x32ed
incq %r14
cmpb %r14b, %r12b
jne 0x2a64
movzbl 0xc6ef(%rip), %esi      # 0xf18e
leaq 0x108f2(%rip), %rdi     # 0x13398
movl $0x1, %edx
callq 0x1e01
leal -0x1(%r15), %ebx
movq 0x8(%rsp), %rax
cmpl %eax, %ebx
jle 0x2b05
leaq (%rsp,%rax), %r14
addq $0x20, %r14
subb %r12b, %bpl
addb $0x2, %bpl
movl 0x18c7e(%rip), %edi     # 0x1b750
movzbl (%r14), %esi
callq 0x329a
movl 0x18c8f(%rip), %eax     # 0x1b770
movl %eax, 0x18cdd(%rip)     # 0x1b7c4
movl %eax, 0x18cd3(%rip)     # 0x1b7c0
movl $0x2, %edi
callq 0x32ed
movzbl %bpl, %eax
incq %r14
leal 0x1(%rax), %ebp
cmpl %eax, %ebx
ja 0x2acc
movl 0x18c45(%rip), %edi     # 0x1b750
movq 0x18(%rsp), %r12
movl %r12d, %esi
callq 0x329a
movabsq $0xc5100000c51, %rax    # imm = 0xC5100000C51
movq %rax, 0x18c97(%rip)     # 0x1b7c0
movl $0x2, %edi
callq 0x32ed
movb $0x1, 0x18c7f(%rip)     # 0x1b7b9
xorl %eax, %eax
testb %r13b, %r13b
je 0x2b6f
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $-0x6, 0x20(%rsp,%rcx)
sete %dl
addl %edx, %eax
incq %rcx
cmpq %rcx, %r15
jne 0x2b43
movl %r13d, %ecx
shrb $0x3, %cl
movzbl %cl, %ecx
decl %ecx
cmpl %ecx, %eax
jbe 0x2b72
movb $0x6, 0xc5bf(%rip)      # 0xf12c
jmp 0x2b72
xorl %r13d, %r13d
cmpb $0x0, 0x18c41(%rip)     # 0x1b7ba
movl %r13d, %ebp
jne 0x291f
movb $0x0, 0xc632(%rip)      # 0xf1bb
jmp 0x2b8e
xorl %r12d, %r12d
movq %r12, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq