// File: /workspace/github_c_makefile_star2_O0/mincebert[P]maketzx/maketzx.c
// Function: FindEdge1
dword FindEdge1(void)
{
  dword samples=revsamples;
  byte curr,last,wavdir=direction,loopbreak=0;
  revsamples=0;
  curr=last=lastsample;
  diff=(currpulse-lastpulse);
  lastpulse=currpulse;
/****************************************************************************/
  do {
       byte delta,maxrev;
       last=curr;
       curr=ReadVOCData();
       if (!blocktype) return samples;
       if (abs(curr-last)>=128) { samples++; loopbreak=1; }
       else if (!(curr-last)) { samples++; loopbreak=0; }
	    else {

		   wavdir=(curr-last>0);
		   if (wavdir && !direction) lastpeak=last;
		   delta=(abs(128-lastpeak)/6); if (delta>4) delta=4;
		   maxrev=2-(abs(lastpeak-128)<7);
		   if (maxrev>2) maxrev=2; if (!maxrev) maxrev=1;
		   if (wavdir!=direction)
		      {
			revsamples++;
			if (revsamples>maxrev) { wavdir^=1; loopbreak=1; }
		      }
		   else {
			  samples+=(revsamples+1);
			  if (revsamples) revsamples=0;
			  if (abs(curr-last)<128-delta*4 && (wavdir==direction) || (abs(curr-last)<=delta && wavdir==direction) || curr==last) loopbreak=0;
			  else loopbreak=1;
			}
		 }
     }
 while (!loopbreak);
  direction^=1;
  lastsample=curr;
  currpulse=samples;
  return samples;

/****************************************************************************/
/*  if (lastsample>128) while (curr>128)
			    {
			      last=curr;
			      samples++;
			      curr=ReadVOCData();
			      if (!blocktype) return samples;
			      if (abs(last-curr)>=128 || !(last-curr)) curr=240*(curr>128)+15*(curr<=128);
			      else if (curr>127) curr=240;
				   else curr=16;
			    }
  else while (curr<=128)
	     {                           // Routine 2
	       last=curr;                // For squared and non squared files
	       samples++;
	       curr=ReadVOCData();
	       if (!blocktype) return samples;
	       if (abs(last-curr)>=128 || !(last-curr)) curr=240*(curr>128)+15*(curr<=128);
	       else if (curr>127) curr=240;
		    else curr=16;
	     }
  lastsample=curr;
  currpulse=samples;
  return samples; */
/****************************************************************************/
/*  if (lastsample>128) while (last>128)
			    {
			      samples++;
			      last=ReadVOCData();
			      if (!blocktype) return samples;
			      last=240*(last>128)+15*(last<=128);
			    }
  else while (last<=128)                    // Routine 1
	     {                              // For squared files only
	       samples++;
	       last=ReadVOCData();
	       if (!blocktype) return samples;
	       last=240*(last>128)+15*(last<=128);
	     } */
//  peak=last;
/*  lastsample=last;
  currpulse=samples;
  return samples;*/
}

// Assembly:
subq $0x18, %rsp
movq 0x1035d(%rip), %rax     # 0x131e8
movq %rax, 0x8(%rsp)
movb 0x1023b(%rip), %al      # 0x130d1
movb %al, 0x5(%rsp)
movb $0x0, 0x4(%rsp)
movq $0x0, 0x1033e(%rip) # 0x131e8
movb 0x1c7f0(%rip), %al      # 0x1f6a0
movb %al, 0x6(%rsp)
movb %al, 0x7(%rsp)
movq 0x1c7f9(%rip), %rax     # 0x1f6b8
subq 0x1c7ea(%rip), %rax     # 0x1f6b0
movl %eax, 0x10308(%rip)     # 0x131d4
movq 0x1c7e5(%rip), %rax     # 0x1f6b8
movq %rax, 0x1c7d6(%rip)     # 0x1f6b0
movb 0x7(%rsp), %al
movb %al, 0x6(%rsp)
callq 0x28d0
movb %al, 0x7(%rsp)
cmpb $0x0, 0x1c7af(%rip)     # 0x1f6a1
jne 0x2f03
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
jmp 0x3143
movzbl 0x7(%rsp), %eax
movzbl 0x6(%rsp), %ecx
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x80, %eax
jl 0x2f35
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
movb $0x1, 0x4(%rsp)
jmp 0x30ff
movzbl 0x7(%rsp), %eax
movzbl 0x6(%rsp), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
jne 0x2f5e
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
movb $0x0, 0x4(%rsp)
jmp 0x30fd
movzbl 0x7(%rsp), %eax
movzbl 0x6(%rsp), %ecx
subl %ecx, %eax
cmpl $0x0, %eax
setg %al
andb $0x1, %al
movzbl %al, %eax
movb %al, 0x5(%rsp)
movzbl 0x5(%rsp), %eax
cmpl $0x0, %eax
je 0x2f96
cmpb $0x0, 0x10147(%rip)     # 0x130d1
jne 0x2f96
movb 0x6(%rsp), %al
movb %al, 0x1013c(%rip)      # 0x130d2
movzbl 0x10135(%rip), %ecx     # 0x130d2
movl $0x80, %eax
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl $0x6, %ecx
cltd
idivl %ecx
movb %al, 0x3(%rsp)
movzbl 0x3(%rsp), %eax
cmpl $0x4, %eax
jle 0x2fc6
movb $0x4, 0x3(%rsp)
movzbl 0x10105(%rip), %eax     # 0x130d2
subl $0x80, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
cmpl $0x7, %eax
setl %al
andb $0x1, %al
movzbl %al, %ecx
movl $0x2, %eax
subl %ecx, %eax
movb %al, 0x2(%rsp)
movzbl 0x2(%rsp), %eax
cmpl $0x2, %eax
jle 0x2ffe
movb $0x2, 0x2(%rsp)
cmpb $0x0, 0x2(%rsp)
jne 0x300a
movb $0x1, 0x2(%rsp)
movzbl 0x5(%rsp), %eax
movzbl 0x100bb(%rip), %ecx     # 0x130d1
cmpl %ecx, %eax
je 0x3053
movq 0x101c7(%rip), %rax     # 0x131e8
addq $0x1, %rax
movq %rax, 0x101bc(%rip)     # 0x131e8
movq 0x101b5(%rip), %rax     # 0x131e8
movzbl 0x2(%rsp), %ecx
cmpq %rcx, %rax
jbe 0x304e
movzbl 0x5(%rsp), %eax
xorl $0x1, %eax
movb %al, 0x5(%rsp)
movb $0x1, 0x4(%rsp)
jmp 0x30fb
movq 0x1018e(%rip), %rax     # 0x131e8
addq $0x1, %rax
addq 0x8(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x10178(%rip)     # 0x131e8
je 0x307d
movq $0x0, 0x1016b(%rip) # 0x131e8
movzbl 0x7(%rsp), %eax
movzbl 0x6(%rsp), %ecx
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movzbl 0x3(%rsp), %edx
shll $0x2, %edx
movl $0x80, %ecx
subl %edx, %ecx
cmpl %ecx, %eax
jge 0x30b3
movzbl 0x5(%rsp), %eax
movzbl 0x10022(%rip), %ecx     # 0x130d1
cmpl %ecx, %eax
je 0x30ed
movzbl 0x7(%rsp), %eax
movzbl 0x6(%rsp), %ecx
subl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movzbl 0x3(%rsp), %ecx
cmpl %ecx, %eax
jg 0x30df
movzbl 0x5(%rsp), %eax
movzbl 0xfff6(%rip), %ecx      # 0x130d1
cmpl %ecx, %eax
je 0x30ed
movzbl 0x7(%rsp), %eax
movzbl 0x6(%rsp), %ecx
cmpl %ecx, %eax
jne 0x30f4
movb $0x0, 0x4(%rsp)
jmp 0x30f9
movb $0x1, 0x4(%rsp)
jmp 0x30fb
jmp 0x30fd
jmp 0x30ff
jmp 0x3101
cmpb $0x0, 0x4(%rsp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2eda
movzbl 0xffb7(%rip), %eax      # 0x130d1
xorl $0x1, %eax
movb %al, 0xffae(%rip)       # 0x130d1
movb 0x7(%rsp), %al
movb %al, 0x1c573(%rip)      # 0x1f6a0
movq 0x8(%rsp), %rax
movq %rax, 0x1c57f(%rip)     # 0x1f6b8
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x18, %rsp
retq
nopl (%rax)