// File: /workspace/github_cpp_makefile_star2_O3/probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::decode()
void Signal::decode()
{
	typedef void (Signal::* SignalFnc)();
	static const SignalFnc Funcs[] = {
		&Signal::tryXMP,
		&Signal::tryZenith,
		&Signal::tryX10,
		&Signal::tryXX,
		&Signal::tryTDC,		// GD 2009. Needs to be above Q2
		&Signal::trySejin,		// GD 2009
		&Signal::tryQ1,
		&Signal::tryQ2,
		&Signal::tryDirecTV,
		&Signal::trySomfy,
		&Signal::tryGap,		// if this moves, change nGapProtocol value	
		&Signal::tryRC5,
		&Signal::tryRC6,
		&Signal::tryCanalSat,	// GD 2009
		&Signal::tryNokia,
		&Signal::tryPCTV,
		&Signal::tryF12,
		&Signal::trySony,
		&Signal::trySingleBurstSize,
		&Signal::tryGXB,
		&Signal::tryAsync,
		&Signal::tryAirboard,
		&Signal::tryAirAsync,
		&Signal::tryAK,
		&Signal::trySunfire,
		&Signal::tryGrundig16,
		&Signal::tryPid13,
		&Signal::tryLutron,		// GD 2010
		&Signal::tryElan,		// DAR 2012
		&Signal::tryBryston,	// DAR 2012
		&Signal::tryHumax,		// DAR 2012
		&Signal::tryAdNotam		// DAR 2012
	};

	nGapProtocol = 10;

	*pProtocol = 0;
	// GD 2009 Start - Initialize output variables as IRScope does not appear
	// to do so on repeat calls
	/* if ( *pDevice >= 0 ) */ *pDevice = -1;	// Initialize Device only if not carrying ExtraBurstCount
	*pSubDevice = -1;
	*pOBC = -1;
	for (int n = 0; n < 4; n++) pHex[n] = -1;
	*pMisc = 0;
	*pError = 0;
	// GD 2009 End
	int nStart = pContext[0] & 0xFFFFF;
	preemptLength = pContext[0] >> 20;
	nFrameL = (pContext[1] >> 16) + MinFrame;
	nProtocol = (pContext[1] & 0xFF);
	preemptValue = (pContext[1] >> 8) & 0xFF;
	newPreemptValue = 0;
	newPreemptLength = 0;

	int nStartLimit = nSingle + nRepeat;
	int nTot = nStartLimit + nRepeat;
	pMainLimit = pDuration + 2 * nStartLimit;
	pFullLimit = pMainLimit + 2 * nRepeat;
	if (nRepeat < MinFrame)
		nStartLimit = nTot - (MinFrame-1);

 // /* Cover bug in CCF2EFC */ if (nStartLimit>200) nStartLimit=200;

	for (; nStart<nStartLimit; nStart++)
	{
		pFrame = pDuration + nStart*2;
        frameLeft = 1e9;
        if ( nStart )
        {
            frameLeft = pFrame[-1];
            if ( nStart == nSingle )
            {
                float wrap = pDuration[ 2*(nSingle+nRepeat) -1 ];
                if ( wrap >= frameLeft )
                    frameLeft = wrap;
            }
        }
		if ( nStart == 0 || nStart == nSingle || pFrame[0]+pFrame[1] < pFrame[-2]*.5+pFrame[-1]
			|| pFrame[0] > 14000 )  // This last one deals with Lutron, which uses a long lead-in rather than framing
		{
			pFrameEnd = pFrame + nFrameL*2-3;	// Point to Off half of second to last burst (advanced later to be final Off)
			nTotDur = 0;
			for (float* pDur = pFrame; ; )
			{
				sortOn.insert(pDur);
				sortOff.insert(pDur+1);
				sortBurst.insert1(pDur);
				nTotDur += pDur[0] + pDur[1];
				pDur+=2;
				if (pDur >= pFrameEnd)
					break;
			}
            sortBurst.findMid();

			int nMaxL = nTot - nStart;  // Maximum frame length that could start at nStart
			if (nMaxL > MaxFrame)
				nMaxL = MaxFrame;
			for (; ; nFrameL++)  //  Loop over posible frame lengths
			{
				pFrameEnd++;    // Point at last burst (lead out)
				sortOn.insert(pFrameEnd);

				nMaxDur = sortOff.max1;   // Excludes final Off
                if (nMaxDur < sortOn.max1)
					nMaxDur = sortOn.max1;

				nTotDur += *pFrameEnd++;    // On
                
                frame = *pFrameEnd;
                if ( frameLeft <= frame )
                    frame = frameLeft;

				// GD Start


				int xxStart = nStart;
				int xxFrameL = nFrameL;
				// Calc freq for this frame
				nFreq = (nContextLength > 4 && pCounts != NULL) ? getFreq(nStart, nStart+nFrameL) : nFreq_in;
				// GD End

				for ( ;nProtocol < sizeof(Funcs)/sizeof(*Funcs); )
				{
					(this->*(Funcs[nProtocol]))();
					++nProtocol;
					if (*pProtocol)
					{
						if (   newPreemptValue > preemptValue
							||    newPreemptValue == preemptValue
							   && newPreemptLength > preemptLength )
						{
							preemptValue = newPreemptValue;
							preemptLength = newPreemptLength;
						}
						pContext[0] = nStart + (preemptLength<<20);
						pContext[1] = ((nFrameL - MinFrame)<<16) + (preemptValue<<8) + nProtocol;
						return;
					}
				}
				nProtocol = 0;

                if ( nFrameL >= nMaxL )
                    break;

				nTotDur += *pFrameEnd;    // Off
				sortBurst.insert(pFrameEnd-1);
				sortOff.insert(pFrameEnd);
			}	// for (; ; nFrameL++)
			sortOn.clear();
			sortOff.clear();
			sortBurst.clear();
		}	// if ( nStart == 0 || ...
		nFrameL=MinFrame;
		if (--preemptLength <= 0)
		{
			preemptLength = preemptValue = 0;
		}
	}  // for (; nStart<nStartLimit; nStart++)
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl $0xa, 0x78(%rdi)
movq 0x148(%rdi), %rax
xorl %edx, %edx
movb %dl, (%rax)
movq 0x160(%rdi), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, (%rax)
movq 0x168(%rdi), %rax
movl %ecx, (%rax)
movq 0x170(%rdi), %rax
movl %ecx, (%rax)
movq 0x178(%rdi), %rax
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%rax)
movq 0x150(%rdi), %rax
movb %dl, (%rax)
movq 0x158(%rdi), %rax
movb %dl, (%rax)
movq (%rdi), %rsi
movl (%rsi), %r9d
movl %r9d, %edx
andl $0xfffff, %edx          # imm = 0xFFFFF
movl %r9d, %ecx
shrl $0x14, %ecx
movl %ecx, 0x50(%rdi)
movzwl 0x6(%rsi), %eax
addq $0x2, %rax
movl %eax, 0x48(%rdi)
movzbl 0x4(%rsi), %edi
movl %edi, 0x4c(%rbx)
movzbl 0x5(%rsi), %esi
movl %esi, 0x54(%rbx)
movq $0x0, 0x58(%rbx)
movslq 0x20(%rbx), %rsi
movslq 0x24(%rbx), %rdi
addq %rdi, %rsi
movq %rsi, %r8
shlq $0x3, %r8
addq 0x8(%rbx), %r8
cmpq $0x2, %rdi
movq %r8, 0x10(%rbx)
leaq (%r8,%rdi,8), %r8
movq %r8, 0x18(%rbx)
leal -0x1(%rsi,%rdi), %r8d
cmovgel %esi, %r8d
cmpl %r8d, %edx
jge 0x2c19
leal (%rsi,%rdi), %edx
movl %edx, -0x34(%rbp)
leaq 0x188(%rbx), %r13
leaq 0x198(%rbx), %r15
leaq 0x184(%rbx), %r14
andl $0xfffff, %r9d          # imm = 0xFFFFF
movl %r8d, %edi
addl %eax, %eax
movsd 0xf895(%rip), %xmm3     # 0x120d0
movss 0xfcad(%rip), %xmm4     # 0x124f0
movq %rdi, -0x40(%rbp)
movq 0x8(%rbx), %rdx
leaq (%rdx,%r9,8), %r12
movq %r12, 0x38(%rbx)
movl $0x4e6e6b28, 0x13c(%rbx) # imm = 0x4E6E6B28
movq %r9, -0x30(%rbp)
testq %r9, %r9
je 0x290b
movss -0x4(%r12), %xmm0
movss %xmm0, 0x13c(%rbx)
movl 0x20(%rbx), %esi
cmpq %rsi, -0x30(%rbp)
jne 0x28a1
movslq %esi, %rcx
movslq 0x24(%rbx), %rsi
addq %rcx, %rsi
movss -0x4(%rdx,%rsi,8), %xmm1
ucomiss %xmm0, %xmm1
jb 0x290b
movss %xmm1, 0x13c(%rbx)
jmp 0x290b
xorps %xmm1, %xmm1
cvtss2sd -0x8(%r12), %xmm1
movss (%r12), %xmm2
mulsd %xmm3, %xmm1
ucomiss %xmm4, %xmm2
ja 0x290b
addss 0x4(%r12), %xmm2
cvtss2sd %xmm2, %xmm2
cvtss2sd %xmm0, %xmm0
addsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
ja 0x290b
movl $0x2, 0x48(%rbx)
leal -0x1(%rcx), %edx
movl %edx, 0x50(%rbx)
cmpl $0x1, %ecx
jg 0x28ef
movq $0x0, 0x50(%rbx)
xorl %edx, %edx
movq -0x30(%rbp), %r9
incq %r9
movl $0x4, %eax
movl %edx, %ecx
cmpq %rdi, %r9
jne 0x2847
jmp 0x2c19
leaq (%r12,%rax,4), %rax
addq $-0xc, %rax
movq %rax, 0x40(%rbx)
movl $0x0, 0x98(%rbx)
movss (%r12), %xmm0
movss 0x180(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x293c
movss %xmm0, 0x180(%rbx)
ucomiss (%r13), %xmm0
jbe 0x295d
movss (%r14), %xmm1
ucomiss %xmm1, %xmm0
movq %r13, %rax
jbe 0x2959
movss %xmm1, (%r13)
movq %r14, %rax
movss %xmm0, (%rax)
movss 0x4(%r12), %xmm0
movss 0x18c(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x2979
movss %xmm0, 0x18c(%rbx)
ucomiss 0x190(%rbx), %xmm0
jbe 0x298a
movss %xmm0, 0x190(%rbx)
movq %r15, %rdi
movq %r12, %rsi
callq 0x11234
movss (%r12), %xmm0
addss 0x4(%r12), %xmm0
addss 0x98(%rbx), %xmm0
movss %xmm0, 0x98(%rbx)
addq $0x8, %r12
cmpq 0x40(%rbx), %r12
jb 0x2921
movq %r15, %rdi
callq 0x112d6
movl -0x34(%rbp), %r12d
subl -0x30(%rbp), %r12d
cmpl $0x64, %r12d
movl $0x64, %eax
cmovgel %eax, %r12d
movq 0x40(%rbx), %rax
movss 0x4(%rax), %xmm0
movss 0x180(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x29fb
movss %xmm0, 0x180(%rbx)
ucomiss (%r13), %xmm0
jbe 0x2a1c
movss (%r14), %xmm1
ucomiss %xmm1, %xmm0
movq %r13, %rcx
jbe 0x2a18
movss %xmm1, (%r13)
movq %r14, %rcx
movss %xmm0, (%rcx)
movss 0x184(%rbx), %xmm0
movss 0x190(%rbx), %xmm1
movss %xmm1, 0x9c(%rbx)
ucomiss %xmm1, %xmm0
jbe 0x2a41
movss %xmm0, 0x9c(%rbx)
leaq 0x8(%rax), %rcx
movq %rcx, 0x40(%rbx)
movss 0x4(%rax), %xmm0
addss 0x98(%rbx), %xmm0
movss %xmm0, 0x98(%rbx)
movss 0x8(%rax), %xmm1
movss %xmm1, 0x140(%rbx)
movss 0x13c(%rbx), %xmm0
ucomiss %xmm0, %xmm1
jb 0x2a80
movss %xmm0, 0x140(%rbx)
cmpl $0x5, 0x74(%rbx)
jl 0x2aa3
cmpq $0x0, 0x90(%rbx)
je 0x2aa3
movl 0x48(%rbx), %edx
movq -0x30(%rbp), %rsi
addl %esi, %edx
movq %rbx, %rdi
callq 0xee28
jmp 0x2aa6
movl 0x30(%rbx), %eax
movl %eax, 0x2c(%rbx)
movl 0x4c(%rbx), %eax
cmpl $0x1f, %eax
ja 0x2aec
movl %eax, %eax
shlq $0x4, %rax
leaq 0x130f2(%rip), %rcx     # 0x15bb0
movq (%rax,%rcx), %rax
testb $0x1, %al
je 0x2ace
movq (%rbx), %rcx
movq -0x1(%rcx,%rax), %rax
movq %rbx, %rdi
callq *%rax
movl 0x4c(%rbx), %eax
incl %eax
movl %eax, 0x4c(%rbx)
movq 0x148(%rbx), %rcx
cmpb $0x0, (%rcx)
je 0x2aac
jmp 0x2bbc
movl $0x0, 0x4c(%rbx)
cmpl %r12d, 0x48(%rbx)
jge 0x2b53
movq 0x40(%rbx), %rsi
movss (%rsi), %xmm0
addss 0x98(%rbx), %xmm0
movss %xmm0, 0x98(%rbx)
addq $-0x4, %rsi
movq %r15, %rdi
callq 0x11358
movq 0x40(%rbx), %rax
movss (%rax), %xmm0
movss 0x18c(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x2b3a
movss %xmm0, 0x18c(%rbx)
ucomiss 0x190(%rbx), %xmm0
jbe 0x2b4b
movss %xmm0, 0x190(%rbx)
incl 0x48(%rbx)
jmp 0x29e1
movaps 0xf4b6(%rip), %xmm0     # 0x12010
movups %xmm0, 0x180(%rbx)
xorl %r12d, %r12d
movl %r12d, 0x190(%rbx)
movq %r15, %rdi
callq 0x116a8
movabsq $0x4e6e6b284e6e6b28, %rax # imm = 0x4E6E6B284E6E6B28
movq %rax, 0x1c8(%rbx)
movl $0x4e6e6b28, 0x1d0(%rbx) # imm = 0x4E6E6B28
movq $0x0, 0x1dc(%rbx)
movl %r12d, 0x1e4(%rbx)
movl 0x50(%rbx), %ecx
movq -0x40(%rbp), %rdi
movsd 0xf521(%rip), %xmm3     # 0x120d0
movss 0xf939(%rip), %xmm4     # 0x124f0
jmp 0x28d3
movl 0x5c(%rbx), %eax
cmpl 0x54(%rbx), %eax
jle 0x2bcd
movl 0x58(%rbx), %edx
movq -0x30(%rbp), %rsi
jmp 0x2bea
sete %sil
movl 0x50(%rbx), %ecx
movl 0x58(%rbx), %edx
cmpl %ecx, %edx
setg %dil
andb %sil, %dil
cmpb $0x1, %dil
movq -0x30(%rbp), %rsi
jne 0x2bf2
movl %eax, 0x54(%rbx)
movl %edx, 0x50(%rbx)
movl %edx, %ecx
shll $0x14, %ecx
addl %esi, %ecx
movq (%rbx), %rax
movl %ecx, (%rax)
movl 0x48(%rbx), %ecx
movl 0x4c(%rbx), %edx
shll $0x10, %ecx
movl 0x54(%rbx), %esi
shll $0x8, %esi
addl %ecx, %esi
leal (%rdx,%rsi), %ecx
addl $0xfffe0000, %ecx       # imm = 0xFFFE0000
movl %ecx, 0x4(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq