// File: /workspace/github_cpp_makefile_star2_O2/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
movb $0x0, (%rax)
movq 0x160(%rdi), %rax
orl $-0x1, (%rax)
movq 0x168(%rdi), %rax
orl $-0x1, (%rax)
movq 0x170(%rdi), %rax
orl $-0x1, (%rax)
movq 0x178(%rdi), %rax
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0x2713
orl $-0x1, (%rax,%rcx,4)
incq %rcx
jmp 0x2704
movq 0x150(%rbx), %rax
xorl %ecx, %ecx
movb %cl, (%rax)
movq 0x158(%rbx), %rax
movb %cl, (%rax)
movq (%rbx), %rdx
movl (%rdx), %r8d
movl %r8d, %eax
shrl $0x14, %eax
movl %eax, 0x50(%rbx)
movzwl 0x6(%rdx), %ecx
leal 0x2(%rcx), %esi
movl %esi, 0x48(%rbx)
movzbl 0x4(%rdx), %esi
movl %esi, 0x4c(%rbx)
movzbl 0x5(%rdx), %edx
movl %edx, 0x54(%rbx)
andq $0x0, 0x58(%rbx)
movslq 0x20(%rbx), %rdx
movslq 0x24(%rbx), %rsi
addq %rsi, %rdx
movq %rdx, %rdi
shlq $0x3, %rdi
addq 0x8(%rbx), %rdi
leal (%rdx,%rsi), %r9d
movl %r9d, -0x34(%rbp)
cmpq $0x2, %rsi
movq %rdi, 0x10(%rbx)
leaq (%rdi,%rsi,8), %rdi
movq %rdi, 0x18(%rbx)
leal -0x1(%rdx,%rsi), %esi
cmovgel %edx, %esi
leaq 0x180(%rbx), %r15
leaq 0x18c(%rbx), %r12
leaq 0x198(%rbx), %r13
andl $0xfffff, %r8d          # imm = 0xFFFFF
movslq %esi, %rdi
leal 0x4(,%rcx,2), %ecx
pushq $0x4
popq %r9
movsd 0xe916(%rip), %xmm3     # 0x110d0
movss 0xed2e(%rip), %xmm4     # 0x114f0
cmpq %rdi, %r8
jge 0x2ab3
movq 0x8(%rbx), %rdx
leaq (%rdx,%r8,8), %r14
movq %r14, 0x38(%rbx)
movl $0x4e6e6b28, 0x13c(%rbx) # imm = 0x4E6E6B28
movq %r8, -0x30(%rbp)
testq %r8, %r8
je 0x287a
movss -0x4(%r14), %xmm0
movss %xmm0, 0x13c(%rbx)
movl 0x20(%rbx), %esi
cmpq %rsi, -0x30(%rbp)
jne 0x2824
movslq %esi, %rax
movslq 0x24(%rbx), %rsi
addq %rax, %rsi
movss -0x4(%rdx,%rsi,8), %xmm1
ucomiss %xmm0, %xmm1
jb 0x287a
movss %xmm1, 0x13c(%rbx)
jmp 0x287a
cvtss2sd -0x8(%r14), %xmm1
movss (%r14), %xmm2
mulsd %xmm3, %xmm1
ucomiss %xmm4, %xmm2
ja 0x287a
addss 0x4(%r14), %xmm2
cvtss2sd %xmm2, %xmm2
cvtss2sd %xmm0, %xmm0
addsd %xmm0, %xmm1
ucomisd %xmm2, %xmm1
ja 0x287a
movl $0x2, 0x48(%rbx)
leal -0x1(%rax), %ecx
movl %ecx, 0x50(%rbx)
cmpl $0x1, %eax
jg 0x2869
andq $0x0, 0x50(%rbx)
xorl %ecx, %ecx
movq -0x30(%rbp), %r8
incq %r8
movl %ecx, %eax
movq %r9, %rcx
jmp 0x27c2
movq %rdi, -0x40(%rbp)
leaq (%r14,%rcx,4), %rax
addq $-0xc, %rax
movq %rax, 0x40(%rbx)
andl $0x0, 0x98(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0xffe6
leaq 0x4(%r14), %rsi
movq %r12, %rdi
callq 0x10020
movq %r13, %rdi
movq %r14, %rsi
callq 0x10042
movss (%r14), %xmm0
addss 0x4(%r14), %xmm0
addss 0x98(%rbx), %xmm0
movss %xmm0, 0x98(%rbx)
addq $0x8, %r14
cmpq 0x40(%rbx), %r14
jb 0x2891
movq %r13, %rdi
callq 0x100e4
movl -0x34(%rbp), %r14d
subl -0x30(%rbp), %r14d
cmpl $0x64, %r14d
pushq $0x64
popq %rax
cmovgel %eax, %r14d
movq 0x40(%rbx), %rsi
addq $0x4, %rsi
movq %rsi, 0x40(%rbx)
movq %r15, %rdi
callq 0xffe6
movss 0x184(%rbx), %xmm0
movss 0x190(%rbx), %xmm1
movss %xmm1, 0x9c(%rbx)
ucomiss %xmm1, %xmm0
jbe 0x292c
movss %xmm0, 0x9c(%rbx)
movq 0x40(%rbx), %rax
leaq 0x4(%rax), %rcx
movq %rcx, 0x40(%rbx)
movss (%rax), %xmm0
addss 0x98(%rbx), %xmm0
movss %xmm0, 0x98(%rbx)
movss 0x4(%rax), %xmm1
movss %xmm1, 0x140(%rbx)
movss 0x13c(%rbx), %xmm0
ucomiss %xmm0, %xmm1
jb 0x296e
movss %xmm0, 0x140(%rbx)
cmpl $0x5, 0x74(%rbx)
jl 0x2991
cmpq $0x0, 0x90(%rbx)
je 0x2991
movl 0x48(%rbx), %edx
movq -0x30(%rbp), %rsi
addl %esi, %edx
movq %rbx, %rdi
callq 0xddb8
jmp 0x2994
movl 0x30(%rbx), %eax
movl %eax, 0x2c(%rbx)
movl 0x4c(%rbx), %eax
cmpl $0x1f, %eax
ja 0x29d7
movl %eax, %eax
shlq $0x4, %rax
leaq 0x12204(%rip), %rcx     # 0x14bb0
movq (%rax,%rcx), %rax
testb $0x1, %al
je 0x29bc
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 0x299a
jmp 0x2a56
andl $0x0, 0x4c(%rbx)
cmpl %r14d, 0x48(%rbx)
jge 0x2a19
movq 0x40(%rbx), %rsi
movss (%rsi), %xmm0
addss 0x98(%rbx), %xmm0
movss %xmm0, 0x98(%rbx)
addq $-0x4, %rsi
movq %r13, %rdi
callq 0x1014a
movq 0x40(%rbx), %rsi
movq %r12, %rdi
callq 0x10020
incl 0x48(%rbx)
jmp 0x28f3
movaps 0xe5f0(%rip), %xmm0     # 0x11010
movups %xmm0, 0x180(%rbx)
andl $0x0, 0x190(%rbx)
movq %r13, %rdi
callq 0x1026a
movl 0x50(%rbx), %eax
movq -0x40(%rbp), %rdi
pushq $0x4
popq %r9
movsd 0xe687(%rip), %xmm3     # 0x110d0
movss 0xea9f(%rip), %xmm4     # 0x114f0
jmp 0x2850
movl 0x5c(%rbx), %eax
cmpl 0x54(%rbx), %eax
jle 0x2a67
movl 0x58(%rbx), %edx
movq -0x30(%rbp), %rsi
jmp 0x2a84
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 0x2a8c
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