// File: /workspace/github_cpp_makefile_star2_O1/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), %r14d
cmpl $0x10, %r14d
jl 0x48b4
movq %rdi, %rbx
movss 0x140(%rdi), %xmm1
movss 0x190(%rdi), %xmm0
movss 0xdecb(%rip), %xmm2     # 0x12500
mulss %xmm0, %xmm2
ucomiss %xmm2, %xmm1
jb 0x48b4
movl %r14d, %eax
movl $0xaaaaaaab, %r12d      # imm = 0xAAAAAAAB
imulq %rax, %r12
shrq $0x21, %r12
leal (%r12,%r12,2), %ecx
movl %r14d, %eax
subl %ecx, %eax
je 0x48b4
cmpl $0x1, %eax
jne 0x4691
xorps %xmm1, %xmm1
cvtss2sd 0x1dc(%rbx), %xmm1
mulsd 0xdaae(%rip), %xmm1     # 0x12128
movq 0x38(%rbx), %rcx
xorps %xmm2, %xmm2
cvtss2sd 0x4(%rcx), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x46e7
jmp 0x48b4
xorps %xmm1, %xmm1
cvtss2sd 0x1dc(%rbx), %xmm1
movsd 0xda8c(%rip), %xmm3     # 0x12130
mulsd %xmm1, %xmm3
movq 0x38(%rbx), %rcx
movss 0xc(%rcx), %xmm2
cvtss2sd %xmm2, %xmm4
ucomisd %xmm4, %xmm3
ja 0x48b4
movss (%rcx), %xmm3
addss 0x4(%rcx), %xmm3
addss 0x8(%rcx), %xmm3
addss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
mulsd 0xda5b(%rip), %xmm2     # 0x12138
ucomisd %xmm1, %xmm2
ja 0x48b4
movss 0x184(%rbx), %xmm1
mulss 0xde0d(%rip), %xmm1     # 0x12504
ucomiss %xmm0, %xmm1
seta %cl
cmpl $0x183, %r14d           # imm = 0x183
setae %dl
orb %cl, %dl
jne 0x48b4
xorps %xmm0, %xmm0
movups %xmm0, 0xa0(%rbx)
movq 0x38(%rbx), %rcx
movq %rcx, 0xc8(%rbx)
movq $0x0, 0xc0(%rbx)
leal (%rax,%rax), %edx
leaq (%rcx,%rdx,4), %rdx
movsd 0xda02(%rip), %xmm0     # 0x12140
movsd 0xd9f2(%rip), %xmm1     # 0x12138
movss (%rdx), %xmm4
movss 0x8(%rdx), %xmm5
addss 0x4(%rdx), %xmm4
addss 0xc(%rdx), %xmm5
movss 0x10(%rdx), %xmm3
addss 0x14(%rdx), %xmm3
xorps %xmm2, %xmm2
cvtss2sd %xmm5, %xmm2
cvtss2sd %xmm3, %xmm3
ucomiss %xmm5, %xmm4
jbe 0x4781
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm3
ja 0x47c2
xorl %ecx, %ecx
jmp 0x47ce
cvtss2sd %xmm4, %xmm4
movaps %xmm4, %xmm5
mulsd %xmm0, %xmm5
xorl %ecx, %ecx
ucomisd %xmm5, %xmm2
mulsd %xmm1, %xmm2
jbe 0x47ce
addsd %xmm4, %xmm2
ucomisd %xmm2, %xmm3
jbe 0x47ce
movl 0xc0(%rbx), %esi
movl %esi, %ecx
andb $0x7, %cl
movl $0x80, %edi
shrl %cl, %edi
sarl $0x3, %esi
movslq %esi, %rcx
orb %dil, 0xa0(%rbx,%rcx)
incl 0xc0(%rbx)
addq $0x18, %rdx
movb $0x1, %cl
testb %cl, %cl
je 0x48b4
cmpq 0x40(%rbx), %rdx
jb 0x4746
movq 0x160(%rbx), %rdx
movl %r12d, (%rdx)
decl %eax
movq 0x168(%rbx), %rsi
movl %eax, (%rsi)
movzbl 0xa0(%rbx), %ecx
movq 0x170(%rbx), %rax
movl %ecx, (%rax)
movl (%rdx), %ecx
cmpl $0x7, %ecx
jg 0x4836
movl $0x1, 0x5c(%rbx)
movl 0x48(%rbx), %ecx
movl %ecx, 0x58(%rbx)
movl (%rax), %ecx
sarl %ecx
movq 0x178(%rbx), %rdi
movl %ecx, (%rdi)
movb $0x8, %cl
subb (%rdx), %cl
sarl %cl, (%rax)
cmpl $0x0, (%rsi)
je 0x48a0
subl $-0x80, (%rdi)
jmp 0x48a0
cmpl $0x8, %ecx
je 0x48a0
movq 0x150(%rbx), %rdi
movzbl 0xa1(%rbx), %edx
leaq 0xe719(%rip), %rsi      # 0x12f69
xorl %eax, %eax
callq 0x2060
cmpl $0x33, %r14d
jb 0x48a0
leaq 0xa2(%rbx), %r13
addl $0x8, %r12d
leaq 0xe47e(%rip), %r14      # 0x12ced
movq 0x150(%rbx), %r15
movq %r15, %rdi
callq 0x2090
addq %rax, %r15
movzbl (%r13), %edx
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x2060
incq %r13
addl $-0x8, %r12d
cmpl $0x18, %r12d
jg 0x486f
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
nop