// File: /workspace/github_c_makefile_star2_O0/mincebert[P]maketzx/maketzx.c
// Function: BeepSearch
word BeepSearch(word minlen)
{
  byte tolerance,noise,nobeep;
  word count,pulsecount;
  dword pulse=0,
	maxlim=samprate/(2*425),
	minlim=samprate/(2*3500);
  double beepfreq,wavelen;
  mspause=0;
  PushFilePointers();
  do {
       noise=0; nobeep=0; wavelen=0; beeplength=0; pulsecount=0;
       do {
	    tolerance=(pulse=FindEdge1())/2;
	    if (!blocktype) return 0;
//new code begins
	    if (!tonesearch && tolerance>4) tolerance=4;
//new code ends
	  }
       while ((pulse-lastpulse)>tolerance || pulse<minlim || pulse>maxlim);
       wavelen=(beeplength=pulse)*2; pulsecount=1;
//new code begins
       if (tonesearch)
	  { tolerance=wavelen-samprate/((samprate/wavelen)+400); }
//new code ends
       for (count=0; count<minlen; count++)
	   {
	     pulse=FindEdge2();
	     if (fabs(pulse-wavelen)>tolerance)
	     { noise=1; break; }
	     else { beeplength+=pulse; pulsecount+=2; }
	   }
     }
  while (noise || nobeep);
  if (!raw)
     do {
	  pulse=FindEdge1();
	  if (!blocktype) return 0;
	  beeplength+=pulse; pulsecount++;
	}
     while (fabs(pulse-wavelen/2)<=tolerance || ((pulse-5)<3 && tonesearch));
  beeplength-=pulse;
  wavelen=(float)2*beeplength/pulsecount;
  beepfreq=(samprate/wavelen);
  if (CheckingSpeed)
     {
       PopFilePointers();
       return beepfreq;
     }
  msbeep=(beeplength*1000)/samprate;
  if (msbeep<30 || msbeep>100)
     {
       if (!tonesearch)
	  {
	    PopFilePointers();
	    lseek(inpfile.handle,filepos,SEEK_SET);
	    inpfile.bufpoint=0;
	    mspause+=(FindPause()/samprate)*1000;
	    WriteTZXPause(mspause);
	    endbeep=1;
	  }
       else RemoveFilePointers();
     }
  else {
	 byte count;
	 word beeptstates;
	 if (beepfreq) beeptstates=(word)((float)(3500000/(2*beepfreq))+.5);
	 if (!tonesearch)
	    {
	      WriteTZXTone(beeptstates,beeplength/(wavelen/2));
	      pulses[1]=6;
	      for (count=0; count<6; count++)
		  { pulseseq[count]=bump[count]; }
	      WriteTZXPulseSequence(sizeof(bump));
	    }
	 RemoveFilePointers();
       }
  mspause+=(pulse/samprate)*1000;
  return beepfreq;
}

// Assembly:
subq $0x78, %rsp
movl %edi, 0x70(%rsp)
movq $0x0, 0x58(%rsp)
movss 0xeb37(%rip), %xmm0     # 0x131d0
movss 0xb4ab(%rip), %xmm1     # 0xfb4c
divss %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttss2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movss 0xb494(%rip), %xmm1     # 0xfb50
subss %xmm1, %xmm0
cvttss2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x50(%rsp)
movss 0xeaf8(%rip), %xmm0     # 0x131d0
movss 0xb474(%rip), %xmm2     # 0xfb54
divss %xmm2, %xmm0
movaps %xmm0, %xmm2
cvttss2si %xmm2, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subss %xmm1, %xmm0
cvttss2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, 0x48(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xeaee(%rip)     # 0x13200
callq 0x18e0
movb $0x0, 0x6e(%rsp)
movb $0x0, 0x6d(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movq $0x0, 0x1b7db(%rip) # 0x1ff10
movl $0x0, 0x64(%rsp)
callq 0x2e80
movq %rax, 0x58(%rsp)
shrq %rax
movb %al, 0x6f(%rsp)
cmpb $0x0, 0x1af4c(%rip)     # 0x1f6a1
jne 0x4764
movl $0x0, 0x74(%rsp)
jmp 0x4d5c
cmpb $0x0, 0xea75(%rip)      # 0x131e0
jne 0x477c
movzbl 0x6f(%rsp), %eax
cmpl $0x4, %eax
jle 0x477c
movb $0x4, 0x6f(%rsp)
jmp 0x477e
movq 0x58(%rsp), %rcx
subq 0x1af26(%rip), %rcx     # 0x1f6b0
movzbl 0x6f(%rsp), %eax
movl %eax, %edx
movb $0x1, %al
cmpq %rdx, %rcx
movb %al, 0x2f(%rsp)
ja 0x47bf
movq 0x58(%rsp), %rcx
movb $0x1, %al
cmpq 0x48(%rsp), %rcx
movb %al, 0x2f(%rsp)
jb 0x47bf
movq 0x58(%rsp), %rax
cmpq 0x50(%rsp), %rax
seta %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x473d
movq 0x58(%rsp), %rax
movq %rax, 0x1b739(%rip)     # 0x1ff10
addq %rax, %rax
movq %rax, %xmm0
movaps 0xb38a(%rip), %xmm1     # 0xfb70
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xb38e(%rip), %xmm1     # 0xfb80
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x1, 0x64(%rsp)
cmpb $0x0, 0xe9ca(%rip)      # 0x131e0
je 0x484d
movsd 0x38(%rsp), %xmm0
movss 0xe9aa(%rip), %xmm1     # 0x131d0
cvtss2sd %xmm1, %xmm1
movaps %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd 0xb217(%rip), %xmm3     # 0xfa50
addsd %xmm3, %xmm2
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movb %al, 0x6f(%rsp)
movl $0x0, 0x68(%rsp)
movl 0x68(%rsp), %eax
cmpl 0x70(%rsp), %eax
jae 0x48ec
callq 0x3150
movq %rax, 0x58(%rsp)
movaps 0xb2fc(%rip), %xmm1     # 0xfb70
movq 0x58(%rsp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xb2fa(%rip), %xmm1     # 0xfb80
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
subsd 0x38(%rsp), %xmm0
movaps 0xb2be(%rip), %xmm1     # 0xfb60
pand %xmm1, %xmm0
movzbl 0x6f(%rsp), %eax
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x48bc
movb $0x1, 0x6e(%rsp)
jmp 0x48ec
movq 0x58(%rsp), %rax
addq 0x1b648(%rip), %rax     # 0x1ff10
movq %rax, 0x1b641(%rip)     # 0x1ff10
movl 0x64(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x64(%rsp)
jmp 0x48dc
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0x4855
jmp 0x48ee
movzbl 0x6e(%rsp), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, 0x2e(%rsp)
jne 0x490d
movzbl 0x6d(%rsp), %eax
cmpl $0x0, %eax
setne %al
movb %al, 0x2e(%rsp)
movb 0x2e(%rsp), %al
testb $0x1, %al
jne 0x4717
cmpb $0x0, 0xe876(%rip)      # 0x13196
jne 0x4a00
jmp 0x4928
callq 0x2e80
movq %rax, 0x58(%rsp)
cmpb $0x0, 0x1ad68(%rip)     # 0x1f6a1
jne 0x4948
movl $0x0, 0x74(%rsp)
jmp 0x4d5c
movq 0x58(%rsp), %rax
addq 0x1b5bc(%rip), %rax     # 0x1ff10
movq %rax, 0x1b5b5(%rip)     # 0x1ff10
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
movaps 0xb203(%rip), %xmm0     # 0xfb70
movq 0x58(%rsp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0xb201(%rip), %xmm0     # 0xfb80
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
movsd 0xb06c(%rip), %xmm2     # 0xfa08
divsd %xmm2, %xmm0
subsd %xmm0, %xmm1
movaps 0xb1b5(%rip), %xmm0     # 0xfb60
pand %xmm0, %xmm1
movzbl 0x6f(%rsp), %eax
cvtsi2sd %eax, %xmm0
movb $0x1, %al
ucomisd %xmm1, %xmm0
movb %al, 0x2d(%rsp)
jae 0x49f2
movq 0x58(%rsp), %rcx
subq $0x5, %rcx
xorl %eax, %eax
cmpq $0x3, %rcx
movb %al, 0x2c(%rsp)
jae 0x49ea
movzbl 0xe800(%rip), %eax      # 0x131e0
cmpl $0x0, %eax
setne %al
movb %al, 0x2c(%rsp)
movb 0x2c(%rsp), %al
movb %al, 0x2d(%rsp)
movb 0x2d(%rsp), %al
testb $0x1, %al
jne 0x4928
jmp 0x4a00
movq 0x58(%rsp), %rcx
movq 0x1b504(%rip), %rax     # 0x1ff10
subq %rcx, %rax
movq %rax, 0x1b4fa(%rip)     # 0x1ff10
movq 0x1b4f3(%rip), %rax     # 0x1ff10
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x24(%rsp)
testq %rax, %rax
movss %xmm0, 0x28(%rsp)
js 0x4a56
movss 0x24(%rsp), %xmm0
movss %xmm0, 0x28(%rsp)
movss 0x28(%rsp), %xmm0
addss %xmm0, %xmm0
movl 0x64(%rsp), %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movss 0xe751(%rip), %xmm0     # 0x131d0
cvtss2sd %xmm0, %xmm0
divsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
cmpb $0x0, 0xe706(%rip)      # 0x1319c
je 0x4aad
callq 0x1a10
cvttsd2si 0x40(%rsp), %rax
movl %eax, 0x74(%rsp)
jmp 0x4d5c
movq 0x1b45c(%rip), %rax     # 0x1ff10
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
cvtsi2ss %rax, %xmm0
movss %xmm0, 0x1c(%rsp)
movq %rax, %rcx
shrq %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
testq %rax, %rax
movss %xmm0, 0x20(%rsp)
js 0x4aec
movss 0x1c(%rsp), %xmm0
movss %xmm0, 0x20(%rsp)
movss 0x20(%rsp), %xmm0
movss 0xe6d6(%rip), %xmm1     # 0x131d0
divss %xmm1, %xmm0
cvttss2si %xmm0, %rax
movl %eax, 0x1b40f(%rip)     # 0x1ff18
cmpl $0x1e, 0x1b408(%rip)    # 0x1ff18
jb 0x4b1f
cmpl $0x64, 0x1b3ff(%rip)    # 0x1ff18
jbe 0x4be7
cmpb $0x0, 0xe6ba(%rip)      # 0x131e0
jne 0x4bdd
callq 0x1a10
movzbl 0xe728(%rip), %edi      # 0x13260
movq 0xe689(%rip), %rsi      # 0x131c8
xorl %edx, %edx
callq 0x10b0
movl $0x0, 0xe810(%rip)      # 0x13360
callq 0x5d40
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x14(%rsp)
testq %rax, %rax
movss %xmm0, 0x18(%rsp)
js 0x4b8e
movss 0x14(%rsp), %xmm0
movss %xmm0, 0x18(%rsp)
movss 0x18(%rsp), %xmm0
movss 0xe634(%rip), %xmm1     # 0x131d0
divss %xmm1, %xmm0
movss 0xaf9c(%rip), %xmm1     # 0xfb44
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0xe648(%rip), %xmm0     # 0x13200
addsd %xmm1, %xmm0
movsd %xmm0, 0xe63c(%rip)     # 0x13200
cvttsd2si 0xe633(%rip), %rax # 0x13200
movl %eax, %edi
callq 0x7510
movb $0x1, 0x1b341(%rip)     # 0x1ff1c
jmp 0x4be2
callq 0x1b30
jmp 0x4cdd
movsd 0x40(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4bfa
jp 0x4bfa
jmp 0x4c2d
movsd 0x40(%rsp), %xmm1
addsd %xmm1, %xmm1
movsd 0xadb4(%rip), %xmm0     # 0xf9c0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xae10(%rip), %xmm1     # 0xfa30
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, 0x30(%rsp)
cmpb $0x0, 0xe5ac(%rip)      # 0x131e0
jne 0x4cd8
movl 0x30(%rsp), %edi
movaps 0xaf2b(%rip), %xmm1     # 0xfb70
movq 0x1b2c3(%rip), %xmm0    # 0x1ff10
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xaf27(%rip), %xmm1     # 0xfb80
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x38(%rsp), %xmm1
movsd 0xadba(%rip), %xmm2     # 0xfa30
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, %esi
callq 0x4480
movb $0x6, 0xe4c8(%rip)      # 0x13159
movb $0x0, 0x37(%rsp)
movzbl 0x37(%rsp), %eax
cmpl $0x6, %eax
jge 0x4cce
movzbl 0x37(%rsp), %eax
movl %eax, %ecx
leaq 0xe462(%rip), %rax      # 0x13110
movl (%rax,%rcx,4), %edx
movzbl 0x37(%rsp), %eax
movl %eax, %ecx
leaq 0x1aae1(%rip), %rax     # 0x1f7a0
movl %edx, (%rax,%rcx,4)
movb 0x37(%rsp), %al
addb $0x1, %al
movb %al, 0x37(%rsp)
jmp 0x4c96
movl $0x18, %edi
callq 0x4520
callq 0x1b30
movq 0x58(%rsp), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0xc(%rsp)
testq %rax, %rax
movss %xmm0, 0x10(%rsp)
js 0x4d1b
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x10(%rsp), %xmm0
movss 0xe4a7(%rip), %xmm1     # 0x131d0
divss %xmm1, %xmm0
movss 0xae0f(%rip), %xmm1     # 0xfb44
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0xe4bb(%rip), %xmm0     # 0x13200
addsd %xmm1, %xmm0
movsd %xmm0, 0xe4af(%rip)     # 0x13200
cvttsd2si 0x40(%rsp), %rax
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)