// File: 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
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpl $0x10, 0x48(%rax)
jl 0x5ab8
movq -0x40(%rbp), %rdi
movss 0x14572(%rip), %xmm0    # 0x1a018
mulss 0x190(%rdi), %xmm0
callq 0x18840
cmpl $0x0, %eax
jne 0x5abd
jmp 0x5e87
movq -0x40(%rbp), %rax
movl 0x48(%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x5ada
jmp 0x5e87
cmpl $0x1, -0xc(%rbp)
jne 0x5b19
movq -0x40(%rbp), %rax
movss 0x1dc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x14748(%rip), %xmm1    # 0x1a240
mulsd %xmm1, %xmm0
movq 0x38(%rax), %rax
movss 0x4(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5b14
jmp 0x5e87
jmp 0x5b9d
movq -0x40(%rbp), %rax
movss 0x1dc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x146ff(%rip), %xmm1    # 0x1a230
mulsd %xmm1, %xmm0
movq 0x38(%rax), %rax
movss 0xc(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5b4d
jmp 0x5e87
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rcx
movss (%rcx), %xmm0
movq 0x38(%rax), %rcx
addss 0x4(%rcx), %xmm0
movq 0x38(%rax), %rcx
addss 0x8(%rcx), %xmm0
movq 0x38(%rax), %rcx
addss 0xc(%rcx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x146b8(%rip), %xmm1    # 0x1a238
mulsd %xmm1, %xmm0
movss 0x1dc(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5b9b
jmp 0x5e87
jmp 0x5b9d
movq -0x40(%rbp), %rax
movss 0x14473(%rip), %xmm0    # 0x1a01c
mulss 0x184(%rax), %xmm0
ucomiss 0x190(%rax), %xmm0
jbe 0x5bbf
jmp 0x5e87
movq -0x40(%rbp), %rax
movl 0x48(%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0x10(%rbp)
movslq -0x10(%rbp), %rax
cmpq $0x80, %rax
jbe 0x5be2
jmp 0x5e87
movq -0x40(%rbp), %rdi
callq 0x16180
movq -0x40(%rbp), %rax
movq 0x38(%rax), %rax
movl -0xc(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movss (%rax), %xmm0
movq -0x18(%rbp), %rax
addss 0x4(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x18(%rbp), %rax
addss 0xc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movss 0x10(%rax), %xmm0
movq -0x18(%rbp), %rax
addss 0x14(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x20(%rbp), %xmm0
ucomisd -0x28(%rbp), %xmm0
jbe 0x5c81
movsd 0x145de(%rip), %xmm1    # 0x1a248
mulsd -0x28(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x5c7f
jmp 0x5e87
jmp 0x5cf9
movsd 0x145bf(%rip), %xmm1    # 0x1a248
mulsd -0x20(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x5c9e
jmp 0x5e87
movsd -0x28(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
movsd 0x14588(%rip), %xmm2    # 0x1a238
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x5cc8
jmp 0x5e87
movq -0x40(%rbp), %rax
movl 0xc0(%rax), %ecx
andl $0x7, %ecx
movl $0x80, %esi
sarl %cl, %esi
movl 0xc0(%rax), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl 0xa0(%rax,%rcx), %edx
orl %esi, %edx
movb %dl, 0xa0(%rax,%rcx)
movq -0x40(%rbp), %rax
movl 0xc0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc0(%rax)
movq -0x18(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x18(%rbp)
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
cmpq 0x40(%rcx), %rax
jb 0x5c06
movq -0x40(%rbp), %rax
movl -0x10(%rbp), %edx
movq 0x160(%rax), %rcx
movl %edx, (%rcx)
movl -0xc(%rbp), %edx
subl $0x1, %edx
movq 0x168(%rax), %rcx
movl %edx, (%rcx)
movzbl 0xa0(%rax), %edx
movq 0x170(%rax), %rcx
movl %edx, (%rcx)
movq 0x160(%rax), %rax
cmpl $0x8, (%rax)
jge 0x5dd3
movq -0x40(%rbp), %rax
movl $0x1, 0x5c(%rax)
movl 0x48(%rax), %ecx
movl %ecx, 0x58(%rax)
movq 0x170(%rax), %rcx
movl (%rcx), %edx
sarl %edx
movq 0x178(%rax), %rcx
movl %edx, (%rcx)
movq 0x160(%rax), %rdx
movl $0x8, %ecx
subl (%rdx), %ecx
movq 0x170(%rax), %rdx
movq %rdx, -0x48(%rbp)
movl (%rdx), %edx
sarl %cl, %edx
movq -0x48(%rbp), %rcx
movl %edx, (%rcx)
movq 0x168(%rax), %rax
cmpl $0x0, (%rax)
je 0x5dce
movq -0x40(%rbp), %rax
movq 0x178(%rax), %rax
movl (%rax), %ecx
addl $0x80, %ecx
movl %ecx, (%rax)
jmp 0x5e70
movq -0x40(%rbp), %rax
movq 0x160(%rax), %rax
cmpl $0x8, (%rax)
jle 0x5e6e
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0xa0, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movq 0x150(%rax), %rdi
movq -0x38(%rbp), %rax
movzbl (%rax), %edx
leaq 0x1527d(%rip), %rsi     # 0x1b08f
movb $0x0, %al
callq 0x2060
movl -0x10(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x10(%rbp)
cmpl $0x8, %eax
jle 0x5e6c
movq -0x40(%rbp), %rax
movq 0x150(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x150(%rax), %rdi
callq 0x20a0
movq -0x50(%rbp), %rdi
addq %rax, %rdi
movq -0x38(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rbp)
movzbl 0x1(%rax), %edx
leaq 0x14f88(%rip), %rsi     # 0x1adeb
movb $0x0, %al
callq 0x2060
jmp 0x5e19
jmp 0x5e6e
jmp 0x5e70
movq -0x40(%rbp), %rax
movq 0x148(%rax), %rdi
leaq 0x15212(%rip), %rsi     # 0x1b094
callq 0x2120
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)