// File: /workspace/github_cpp_makefile_star2_O2/probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::tryZenith()
void Signal::tryZenith()
// Half bits are either 1,-10 or 1,-1,1,-8
// There is an initial independent half bit, followed by full bits, where each
// full bit is a half bit and its complement.
// Each full bit is this 3 bursts long.  So the whole is either 3N+1 or 3N+2
// bursts, depending on the first half bit.  N is at least 5.
{
	// {40K,520}<1,-1,1,-8|1,-10>( S:1,<1:2|2:2>( F:D ),-90m )+ //OLD
	// {40K,520,msb}<1,-10|1,-1,1,-8>( S:1,<1:2|2:2>( F:D ),-90m )+ //DAR July 2011  This appears to be the correct IRP


	// MaxDur should be 10*520.  Use 10.5*520 for cut off.
	// Lead Out should be greater than 90000.  90000/(10.5*520)=16.5
	// But the CML files I checked had a lot of short LeadOuts, so I cut the ratio
	if (   nFrameL < 16
		|| ! framed(sortOff.max1*4) )
	{
		return;
	}

	int nStyle = nFrameL % 3;	// 1 if Start is 1,-10.  2 if start is 1,-1,1,-8
	if (nStyle == 0)
		return;
	if (nStyle == 1)
	{
        // First burst and largest burst must both be 1,-10 
        
		if ( sortBurst.max1 * (.9*10./11.) > pFrame[1] )
			return;
	}
	else // nStyle == 2
	{
        // First burst is 1,-1
        // Second burst is 1,-8
        // Largest burst is 1,-10

		if ( sortBurst.max1 * (.9*8./11.) > pFrame[3] ) // -8 too small
			return;
        if ( (pFrame[0]+pFrame[1]+pFrame[2]+pFrame[3])*.9 > sortBurst.max1 )
            return;
	}

    if ( sortOn.max1*6 > sortOff.max1 )
		return;			// One of the ON values is too big
	int nBits = nFrameL / 3;
	if (nBits > sizeof(cBits)*8)
		return;

    cleanup();
    burst pnt = pFrame + nStyle * 2;
    do
    {
        double x = pnt[0] + pnt[1];
        double y = pnt[2] + pnt[3];
        double z = pnt[4] + pnt[5];
        if ( x > y )
        {
            // x nominal 11 // y nominal 2 // z nominal 9 or last
            require( y*4. < z )
        }
        else
        {
            // x nominal 2 // y nominal 9 // z nominal 11 or last
            require( x*4 < y )
            require( y*.9 + x < z )
			cBits[nBit>>3] |= 0x80 >> (nBit & 7);
        }
        ++nBit;
        pnt += 6;
    } while ( pnt < pFrameEnd );

	*pDevice = nBits;
	*pSubDevice = nStyle-1;
    *pOBC = cBits[0];
	if (*pDevice < 8)
	{
		newPreemptValue = prByZenith; 	// Avoid Gap decode of same frame
		newPreemptLength = nFrameL;
        *pHex = *pOBC >> 1;
		*pOBC >>= 8 - *pDevice;
		if (*pSubDevice)
			*pHex += 0x80;
	}
	else if (*pDevice > 8)
	{
        unsigned char* cb=cBits+1;
		sprintf(pMisc, "E=%X", *cb);
		while ( (nBits -= 8) > 8)
			sprintf(pMisc+strlen(pMisc), ".%X", *++cb);
	}
	strcpy(pProtocol, "Zenith");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x48(%rdi), %ecx
cmpl $0x10, %ecx
jl 0x45a0
movq %rdi, %rbx
movss 0x140(%rdi), %xmm1
movss 0x190(%rdi), %xmm0
movss 0xd15d(%rip), %xmm2     # 0x11500
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jb 0x45a0
pushq $0x3
popq %rsi
movl %ecx, %eax
xorl %edx, %edx
divl %esi
testl %edx, %edx
je 0x45a0
movl %eax, %r14d
cmpl $0x1, %edx
jne 0x43ed
cvtss2sd 0x1dc(%rbx), %xmm1
mulsd 0xcd4f(%rip), %xmm1     # 0x11128
movq 0x38(%rbx), %rax
cvtss2sd 0x4(%rax), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x4440
jmp 0x45a0
cvtss2sd 0x1dc(%rbx), %xmm1
movsd 0xcd33(%rip), %xmm3     # 0x11130
mulsd %xmm1, %xmm3
movq 0x38(%rbx), %rax
movss 0xc(%rax), %xmm2
cvtss2sd %xmm2, %xmm4
ucomisd %xmm4, %xmm3
ja 0x45a0
movss (%rax), %xmm3
addss 0x4(%rax), %xmm3
addss 0x8(%rax), %xmm3
addss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
mulsd 0xcd02(%rip), %xmm2     # 0x11138
ucomisd %xmm1, %xmm2
ja 0x45a0
movss 0x184(%rbx), %xmm1
mulss 0xd0b4(%rip), %xmm1     # 0x11504
ucomiss %xmm0, %xmm1
seta %sil
cmpl $0x183, %ecx            # imm = 0x183
setae %cl
orb %sil, %cl
jne 0x45a0
xorps %xmm0, %xmm0
movups %xmm0, 0xa0(%rbx)
movq %rax, 0xc8(%rbx)
andq $0x0, 0xc0(%rbx)
leal (%rdx,%rdx), %ecx
leaq (%rax,%rcx,4), %rax
xorl %esi, %esi
movsd 0xccad(%rip), %xmm0     # 0x11140
movsd 0xcc9d(%rip), %xmm1     # 0x11138
movss (%rax), %xmm4
movss 0x8(%rax), %xmm5
addss 0x4(%rax), %xmm4
addss 0xc(%rax), %xmm5
movss 0x10(%rax), %xmm3
addss 0x14(%rax), %xmm3
cvtss2sd %xmm5, %xmm2
cvtss2sd %xmm3, %xmm3
ucomiss %xmm5, %xmm4
jbe 0x44d4
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
ja 0x451b
jmp 0x45a0
cvtss2sd %xmm4, %xmm4
movaps %xmm4, %xmm5
mulsd %xmm0, %xmm5
ucomisd %xmm5, %xmm2
mulsd %xmm1, %xmm2
jbe 0x45a0
addsd %xmm4, %xmm2
ucomisd %xmm2, %xmm3
jbe 0x45a0
movl %esi, %ecx
andb $0x7, %cl
movl $0x80, %edi
shrl %cl, %edi
sarl $0x3, %esi
movslq %esi, %rcx
orb %dil, 0xa0(%rbx,%rcx)
movl 0xc0(%rbx), %esi
incl %esi
movl %esi, 0xc0(%rbx)
addq $0x18, %rax
cmpq 0x40(%rbx), %rax
jb 0x449b
movq 0x160(%rbx), %rax
movl %r14d, (%rax)
decl %edx
movq 0x168(%rbx), %rsi
movl %edx, (%rsi)
movzbl 0xa0(%rbx), %ecx
movq 0x170(%rbx), %rdx
movl %ecx, (%rdx)
movl (%rax), %ecx
cmpl $0x7, %ecx
jg 0x4587
movl $0x1, 0x5c(%rbx)
movl 0x48(%rbx), %ecx
movl %ecx, 0x58(%rbx)
movl (%rdx), %ecx
sarl %ecx
movq 0x178(%rbx), %rdi
movl %ecx, (%rdi)
movb $0x8, %cl
subb (%rax), %cl
sarl %cl, (%rdx)
cmpl $0x0, (%rsi)
je 0x458c
subl $-0x80, (%rdi)
jmp 0x458c
cmpl $0x8, %ecx
jne 0x45af
movq 0x148(%rbx), %rax
movl $0x687469, 0x3(%rax)    # imm = 0x687469
movl $0x696e655a, (%rax)     # imm = 0x696E655A
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x150(%rbx), %rdi
movzbl 0xa1(%rbx), %edx
leaq 0xd99c(%rip), %rsi      # 0x11f60
xorl %eax, %eax
callq 0x2060
leaq 0xa2(%rbx), %r13
leaq 0xd70b(%rip), %r15      # 0x11ce4
cmpl $0x11, %r14d
jl 0x458c
addl $-0x8, %r14d
movq 0x150(%rbx), %r12
movq %r12, %rdi
callq 0x20a0
addq %rax, %r12
movzbl (%r13), %edx
movq %r12, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2060
incq %r13
jmp 0x45d9