// File: /workspace/github_cpp_makefile_star2_O1/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
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), %rcx
movl (%rcx), %r14d
movl %r14d, %eax
andl $0xfffff, %eax          # imm = 0xFFFFF
movl %r14d, %edx
shrl $0x14, %edx
movl %edx, 0x50(%rdi)
movzwl 0x6(%rcx), %edx
addl $0x2, %edx
movl %edx, 0x48(%rdi)
movzbl 0x4(%rcx), %edx
movl %edx, 0x4c(%rdi)
movzbl 0x5(%rcx), %ecx
movl %ecx, 0x54(%rdi)
movq $0x0, 0x58(%rdi)
movslq 0x20(%rdi), %rcx
movslq 0x24(%rdi), %rdx
addq %rdx, %rcx
movq %rcx, %rsi
shlq $0x3, %rsi
addq 0x8(%rdi), %rsi
cmpq $0x2, %rdx
movq %rsi, 0x10(%rdi)
leaq (%rsi,%rdx,8), %rsi
movq %rsi, 0x18(%rdi)
leal -0x1(%rcx,%rdx), %esi
cmovgel %ecx, %esi
cmpl %esi, %eax
jge 0x2c0f
movq %rdi, %rbx
leal (%rcx,%rdx), %eax
movl %eax, -0x2c(%rbp)
leaq 0x198(%rdi), %r15
andl $0xfffff, %r14d         # imm = 0xFFFFF
movl %esi, %eax
movq %rax, -0x38(%rbp)
leaq 0x13384(%rip), %r13     # 0x15bb0
movq 0x8(%rbx), %rax
leaq (%rax,%r14,8), %r12
movq %r12, 0x38(%rbx)
movl $0x4e6e6b28, 0x13c(%rbx) # imm = 0x4E6E6B28
testq %r14, %r14
je 0x28c4
movss -0x4(%r12), %xmm0
movss %xmm0, 0x13c(%rbx)
movl 0x20(%rbx), %ecx
cmpq %rcx, %r14
jne 0x2880
movslq 0x24(%rbx), %rdx
movslq %ecx, %rsi
addq %rdx, %rsi
movss -0x4(%rax,%rsi,8), %xmm1
ucomiss %xmm0, %xmm1
jb 0x287b
movss %xmm1, 0x13c(%rbx)
cmpq %rcx, %r14
je 0x28c4
xorps %xmm0, %xmm0
cvtss2sd -0x8(%r12), %xmm0
movss (%r12), %xmm1
mulsd 0xf838(%rip), %xmm0     # 0x120d0
ucomiss 0xfc51(%rip), %xmm1     # 0x124f0
ja 0x28c4
addss 0x4(%r12), %xmm1
xorps %xmm2, %xmm2
cvtss2sd -0x4(%r12), %xmm2
cvtss2sd %xmm1, %xmm1
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2be5
movslq 0x48(%rbx), %rax
leaq (%r12,%rax,8), %rax
addq $-0xc, %rax
movq %rax, 0x40(%rbx)
movl $0x0, 0x98(%rbx)
movss (%r12), %xmm0
movss 0x180(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x28f9
movss %xmm0, 0x180(%rbx)
ucomiss 0x188(%rbx), %xmm0
jbe 0x2929
movss 0x184(%rbx), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x2921
movss %xmm1, 0x188(%rbx)
movss %xmm0, 0x184(%rbx)
jmp 0x2929
movss %xmm0, 0x188(%rbx)
movss 0x4(%r12), %xmm0
movss 0x18c(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x2945
movss %xmm0, 0x18c(%rbx)
ucomiss 0x190(%rbx), %xmm0
jbe 0x2956
movss %xmm0, 0x190(%rbx)
movq %r15, %rdi
movq %r12, %rsi
callq 0x113d4
movss (%r12), %xmm0
addss 0x4(%r12), %xmm0
addss 0x98(%rbx), %xmm0
movss %xmm0, 0x98(%rbx)
addq $0x8, %r12
cmpq 0x40(%rbx), %r12
jb 0x28de
movq %r15, %rdi
callq 0x11476
movl -0x2c(%rbp), %r12d
subl %r14d, %r12d
cmpl $0x64, %r12d
movl $0x64, %eax
cmovgel %eax, %r12d
movq 0x40(%rbx), %rax
leaq 0x4(%rax), %rcx
movq %rcx, 0x40(%rbx)
movss 0x4(%rax), %xmm0
movss 0x180(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x29ce
movss %xmm0, 0x180(%rbx)
ucomiss 0x188(%rbx), %xmm0
jbe 0x29fe
movss 0x184(%rbx), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x29f6
movss %xmm1, 0x188(%rbx)
movss %xmm0, 0x184(%rbx)
jmp 0x29fe
movss %xmm0, 0x188(%rbx)
movss 0x184(%rbx), %xmm0
movss 0x190(%rbx), %xmm1
movss %xmm1, 0x9c(%rbx)
ucomiss %xmm1, %xmm0
jbe 0x2a23
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 0x2a62
movss %xmm0, 0x140(%rbx)
cmpl $0x5, 0x74(%rbx)
jl 0x2a85
cmpq $0x0, 0x90(%rbx)
je 0x2a85
movl 0x48(%rbx), %edx
addl %r14d, %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0xee1c
jmp 0x2a88
movl 0x30(%rbx), %eax
movl %eax, 0x2c(%rbx)
movl 0x4c(%rbx), %ecx
cmpq $0x1f, %rcx
ja 0x2ad4
shlq $0x4, %rcx
movq (%rcx,%r13), %rax
movq 0x8(%rcx,%r13), %rdi
addq %rbx, %rdi
testb $0x1, %al
je 0x2ab0
movq (%rdi), %rcx
movq -0x1(%rcx,%rax), %rax
callq *%rax
incl 0x4c(%rbx)
movq 0x148(%rbx), %rax
cmpb $0x0, (%rax)
je 0x2a8b
movl 0x5c(%rbx), %eax
cmpl 0x54(%rbx), %eax
jle 0x2b40
movl %eax, 0x54(%rbx)
movl 0x58(%rbx), %eax
movl %eax, 0x50(%rbx)
jmp 0x2b4e
movl $0x0, 0x4c(%rbx)
cmpl %r12d, 0x48(%rbx)
jge 0x2b39
movq 0x40(%rbx), %rsi
movss (%rsi), %xmm0
addss 0x98(%rbx), %xmm0
movss %xmm0, 0x98(%rbx)
addq $-0x4, %rsi
movq %r15, %rdi
callq 0x114f8
movq 0x40(%rbx), %rax
movss (%rax), %xmm0
movss 0x18c(%rbx), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x2b22
movss %xmm0, 0x18c(%rbx)
xorl %ecx, %ecx
movb $0x1, %al
ucomiss 0x190(%rbx), %xmm0
jbe 0x2b7f
movss %xmm0, 0x190(%rbx)
jmp 0x2b7f
movl $0xa, %ecx
jmp 0x2b7d
jne 0x2b4e
movl 0x58(%rbx), %ecx
cmpl 0x50(%rbx), %ecx
jg 0x2ac9
movl 0x50(%rbx), %eax
shll $0x14, %eax
addl %r14d, %eax
movq (%rbx), %rcx
movl %eax, (%rcx)
movl 0x48(%rbx), %eax
movl 0x4c(%rbx), %edx
shll $0x10, %eax
movl 0x54(%rbx), %esi
shll $0x8, %esi
addl %eax, %esi
leal (%rdx,%rsi), %eax
addl $0xfffe0000, %eax       # imm = 0xFFFE0000
movl %eax, 0x4(%rcx)
movl $0x1, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0x2b8b
incl 0x48(%rbx)
jmp 0x29a8
cmpl $0xa, %ecx
jne 0x2be1
movapd 0xf478(%rip), %xmm0     # 0x12010
movupd %xmm0, 0x180(%rbx)
xorl %r12d, %r12d
movl %r12d, 0x190(%rbx)
movq %r15, %rdi
callq 0x1185a
movabsq $0x4e6e6b284e6e6b28, %rax # imm = 0x4E6E6B284E6E6B28
movq %rax, 0x1c8(%rbx)
movl $0x4e6e6b28, 0x1d0(%rbx) # imm = 0x4E6E6B28
movq $0x0, 0x1dc(%rbx)
movl %r12d, 0x1e4(%rbx)
jmp 0x2be5
testb %al, %al
je 0x2c0f
movl $0x2, 0x48(%rbx)
movl 0x50(%rbx), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x50(%rbx)
cmpl $0x1, %eax
jg 0x2c02
movq $0x0, 0x50(%rbx)
incq %r14
cmpq -0x38(%rbp), %r14
jne 0x282c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq