// File: /workspace/github_cpp_makefile_star2_O2/probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::tryRC5()
void Signal::tryRC5()
//
// RC5         {36k,msb,889}<1,-1|-1,1>(1:1,~F:1:6,T:1,D:5,F:6,^114m)+
// StreamZap  OLD {36k,msb,889}<1,-1|-1,1>(1:1,~F:1:6,T:1,D:6,F:6 // OLD changed to RC5-7F DAR Dec 2010 
// RC5-7F      {36k,msb,889}<1,-1|-1,1>(1:1, D:1:5,T:1,D:5,F:7,^114m)+   NEW DAR Dec 2010
// RC5x        {36k,msb,889}<1,-1|-1,1>(1:1,~S:1:6,T:1,D:5,-4,S:6,F:6,^114m)+
//
{
	if ( nFrameL < 6 )
		return;
	const float HB = 889; 
	if ( nTotDur < 10.*HB )
		return;
	if ( sortOn.min1 < HB * .3 )
		return;
	if ( sortOn.max1 > HB * 2.4 )
		return;
	if (   !framed(20*HB)  //framed(nGap) is: return nGap <= frame, which pFramedEnd
		|| nMaxDur > HB*6.5     // -4 in RC5x with -1 half bit on either side
        || sortBurst.max2 > HB*4.5  // nominal 2,-2
		|| *pFrame < HB*.5 )
	{
		return;
	}

    // Log of tweaks:
    //  8/14/05 reduced m_maxShortPulse 1.35 -> 1.3 to avoid misdecoding pid_0003 as rc5-1-16
    //
	m_minShortPulse = HB * .3 ;
	m_nominalShortPulse = HB * 1 ;
	m_nominalShortGap = HB * 1 ;
	m_maxShortPulse = HB * 1.3 ;
	m_nominalLongPulse = HB * 2 ;
	m_nominalLongGap = HB * 2 ;
	m_maxLongPulse = HB * 2.4 ;

	m_minShortGap = HB * .5 ;
	m_maxShortGap = HB * 1.4 ;
	m_minLongGap = HB * 1.55 ;
	m_maxLongGap = HB * 2.4 ;

    m_negDelta = 99999.;
    m_posDelta = -99999.;
	/** DAR this also works for RC5
	cleanup();
	if (processManchesterAtoms(0, 13, HB, 2*HB, pFrame) ) {
		*pDevice = getMsb(2,5);
		sprintf(pMisc, "T=%d", getMsb(1,1));
		*pOBC = 64*(getMsb(0,1)^1) + getMsb(7,6);
		strcpy(pProtocol, "RC5");
		return;
	}
	**/
	cleanup();
	nBit = 1;
	nState = 1;

	int bRC5x = 0;
	do
	{
		if (nBit >= sizeof(cBits)*8)
			return;
		int sw = phaseBit2();
		if ( sw <= 0 )
		{
			if ( sw == 0 || nBit != 8 )  
			{
				return;
			}
			double x = *pBit + m_extra;
			if ( nState )
			{
				x = pBit[-1] + pBit[0];
			}
			if ( x < HB * 4.5 || x > HB * 6.5 )
				return;
			++pBit;
			if ( x > HB * 5.5 )
			{
				nState = 1;
				cBits[8>>3] |= 1 << (8&7);
			}
			else
			{
				m_extra = *pBit - HB;
				if ( m_extra < -(HB*.7) || m_extra > (HB*.3) )
					return;
				nState = 0;
				++pBit;
			}
			++nBit;
			bRC5x = 1;
		}
        if ( m_posDelta - m_negDelta > 300. )
            return;
	} while (pBit < pFrameEnd);

	if (nBit < 8)
		return;

	makeMsb();

	*pDevice = cBits[0] & 31;
	// sprintf(pMisc, "T=%d U=%d:%d", (cBits[0]>>5)&1, (int)(m_negDelta+2*HB), (int)(m_posDelta+2*HB));
	sprintf(pMisc, "T=%d", (cBits[0]>>5)&1);	// GD Removed confusing U-values

	*pOBC = (64^cBits[0]&64) + getMsb(nBit-6,6);
	if (bRC5x)
	{
		strcpy(pProtocol, "RC5x");
		if (nBit == 20)
		{
			*pOBC &= 63;
			*pSubDevice = (64^cBits[0]&64) + (cBits[1]>>2);
			return;
		}
	}
	else if ( preemptValue >= prRCx )		// GD 2009  Avoids spurious decode of OrtekMCE
	{
		return;
	}
	else
	{
		strcpy(pProtocol, "RC5");
		if (nBit == 14)
		{
			int nHex = (255-cBits[1])&0xFC;
			pHex[0] = nHex;
			pHex[1] = nHex+1;
			pHex[2] = nHex+2;
			return;
		}
		else if (nBit == 15)
		{
			strcpy(pProtocol, "RC5-7F");
			if ((nFreq > 55000) && (nFreq < 59000)) 
			{
				strcat(pProtocol,"-57");
			}
			*pDevice += 64^cBits[0]&64;
			*pOBC = getMsb(8,7);
			pHex[0] = (255-*pOBC);
			return;
		}
	}

	if (nBit)
	{
		sprintf(pProtocol+strlen(pProtocol), "-%d-%d?", (cBits[0]>>6), nBit);
		if (nBit > 8)
		{
			if (nBit <= 16)
			{
				*pOBC = getMsb(8,nBit-8);
				return;
			}
			*pOBC = getMsb(nBit-8,8);
			*pSubDevice = getMsb(8, nBit-16);
		}
	}
}

// Assembly:
cmpl $0x6, 0x48(%rdi)
jl 0xab3d
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movss 0x6b14(%rip), %xmm0     # 0x11618
ucomiss 0x98(%rdi), %xmm0
ja 0xab35
cvtss2sd 0x180(%rbx), %xmm0
movsd 0x691b(%rip), %xmm1     # 0x11438
ucomisd %xmm0, %xmm1
ja 0xab35
cvtss2sd 0x184(%rbx), %xmm0
ucomisd 0x690d(%rip), %xmm0     # 0x11440
jbe 0xab3e
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movss 0x140(%rbx), %xmm0
ucomiss 0x6acf(%rip), %xmm0     # 0x1161c
jb 0xab35
movss 0x9c(%rbx), %xmm0
ucomiss 0x6ac2(%rip), %xmm0     # 0x11620
ja 0xab35
movss 0x1e0(%rbx), %xmm0
ucomiss 0x6ab5(%rip), %xmm0     # 0x11624
ja 0xab35
movq 0x38(%rbx), %rax
movss 0x6aab(%rip), %xmm0     # 0x11628
ucomiss (%rax), %xmm0
ja 0xab35
movabsq $0x445e40004385599a, %rcx # imm = 0x445E40004385599A
movq %rcx, 0xfc(%rbx)
movabsq $0x44de400044907666, %rcx # imm = 0x44DE400044907666
movq %rcx, 0x104(%rbx)
movl $0x44de4000, 0x124(%rbx) # imm = 0x44DE4000
movaps 0x649b(%rip), %xmm0     # 0x11050
movups %xmm0, 0x10c(%rbx)
movabsq $0x445e40004505599a, %rcx # imm = 0x445E40004505599A
movq %rcx, 0x11c(%rbx)
movabsq $-0x383cb07fb83cb080, %rcx # imm = 0xC7C34F8047C34F80
movq %rcx, 0x128(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0xa0(%rbx)
movq %rax, 0xc8(%rbx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0xc0(%rbx)
leaq 0x130(%rbx), %r14
xorl %r12d, %r12d
pushq $0x1
popq %r15
movl %r15d, %eax
cmpl $0x7f, %eax
ja 0xab35
movq %rbx, %rdi
callq 0xf26a
movsd 0x680e(%rip), %xmm1     # 0x11438
testl %eax, %eax
jg 0xacf8
je 0xab35
cmpl $0x8, 0xc0(%rbx)
jne 0xab35
movq 0xc8(%rbx), %rax
movss (%rax), %xmm0
leaq -0x4(%rax), %rcx
cmpl $0x0, 0xc4(%rbx)
cmoveq %r14, %rcx
addss (%rcx), %xmm0
movss 0x69b9(%rip), %xmm2     # 0x11624
ucomiss %xmm0, %xmm2
ja 0xab35
ucomiss 0x69a5(%rip), %xmm0     # 0x11620
ja 0xab35
leaq 0x4(%rax), %rcx
movq %rcx, 0xc8(%rbx)
ucomiss 0x6999(%rip), %xmm0     # 0x1162c
jbe 0xaca8
movl $0x1, 0xc4(%rbx)
orb $0x1, 0xa1(%rbx)
jmp 0xaceb
movss (%rcx), %xmm0
addss 0x697c(%rip), %xmm0     # 0x11630
movss %xmm0, (%r14)
cvtss2sd %xmm0, %xmm0
movsd 0x6783(%rip), %xmm2     # 0x11448
ucomisd %xmm0, %xmm2
ja 0xab35
ucomisd %xmm1, %xmm0
ja 0xab35
andl $0x0, 0xc4(%rbx)
addq $0x8, %rax
movq %rax, 0xc8(%rbx)
movl $0x9, 0xc0(%rbx)
movl %r15d, %r12d
movss 0x12c(%rbx), %xmm0
subss 0x128(%rbx), %xmm0
ucomiss 0x67ed(%rip), %xmm0     # 0x114fc
ja 0xab35
movq 0xc8(%rbx), %rcx
movl 0xc0(%rbx), %eax
cmpq 0x40(%rbx), %rcx
jb 0xac11
cmpl $0x8, %eax
jl 0xab35
movq %rbx, %rdi
callq 0xec52
movzbl 0xa0(%rbx), %eax
andl $0x1f, %eax
movq 0x160(%rbx), %rcx
movl %eax, (%rcx)
movq 0x150(%rbx), %rdi
movl 0xa0(%rbx), %edx
shrl $0x5, %edx
andl $0x1, %edx
leaq 0x7127(%rip), %rsi      # 0x11e91
xorl %eax, %eax
callq 0x2060
movl 0xa0(%rbx), %r14d
movl 0xc0(%rbx), %esi
notl %r14d
andl $0x40, %r14d
addl $-0x6, %esi
pushq $0x6
popq %rdx
movq %rbx, %rdi
callq 0xeb6a
addl %r14d, %eax
movq 0x170(%rbx), %rcx
movl %eax, (%rcx)
testl %r12d, %r12d
je 0xadf7
movq 0x148(%rbx), %rax
movb $0x0, 0x4(%rax)
movl $0x78354352, (%rax)     # imm = 0x78354352
movl 0xc0(%rbx), %r14d
cmpl $0x14, %r14d
jne 0xae4d
movq 0x170(%rbx), %rax
andl $0x3f, (%rax)
movzbl 0xa0(%rbx), %eax
andl $0x40, %eax
movzbl 0xa1(%rbx), %ecx
shrl $0x2, %ecx
orl %eax, %ecx
xorl $0x40, %ecx
movq 0x168(%rbx), %rax
movl %ecx, (%rax)
jmp 0xab35
cmpl $0x2, 0x54(%rbx)
jg 0xab35
movq 0x148(%rbx), %rax
movl $0x354352, (%rax)       # imm = 0x354352
movl 0xc0(%rbx), %r14d
cmpl $0xf, %r14d
je 0xaebb
cmpl $0xe, %r14d
jne 0xae4d
movzbl 0xa1(%rbx), %eax
notl %eax
andl $0xfc, %eax
movq 0x178(%rbx), %rcx
movl %eax, (%rcx)
leal 0x1(%rax), %edx
movl %edx, 0x4(%rcx)
orl $0x2, %eax
movl %eax, 0x8(%rcx)
jmp 0xab35
testl %r14d, %r14d
je 0xab35
movq 0x148(%rbx), %r15
movq %r15, %rdi
callq 0x20a0
addq %rax, %r15
movzbl 0xa0(%rbx), %edx
shrl $0x6, %edx
leaq 0x6e7f(%rip), %rsi      # 0x11cf8
movq %r15, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2060
movl 0xc0(%rbx), %eax
cmpl $0x9, %eax
jl 0xab35
leal -0x8(%rax), %edx
movq 0x170(%rbx), %r15
cmpl $0x10, %eax
ja 0xaf29
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0xeb6a
movl %eax, (%r15)
jmp 0xab35
movq 0x148(%rbx), %rax
movl $0x46372d, 0x3(%rax)    # imm = 0x46372D
movl $0x2d354352, (%rax)     # imm = 0x2D354352
movl $0xffff2927, %eax       # imm = 0xFFFF2927
addl 0x2c(%rbx), %eax
cmpl $0xf9e, %eax            # imm = 0xF9E
ja 0xaef5
movq 0x148(%rbx), %r14
movq %r14, %rdi
callq 0x20a0
movl $0x37352d, (%r14,%rax)  # imm = 0x37352D
movl 0xa0(%rbx), %eax
notl %eax
andl $0x40, %eax
movq 0x160(%rbx), %rcx
addl %eax, (%rcx)
movzbl 0xa1(%rbx), %eax
shrl %eax
movq 0x170(%rbx), %rcx
movl %eax, (%rcx)
xorl $0xff, %eax
movq 0x178(%rbx), %rcx
jmp 0xaf58
pushq $0x8
popq %r14
movq %rbx, %rdi
movl %edx, %esi
movl %r14d, %edx
callq 0xeb6a
movl %eax, (%r15)
movl 0xc0(%rbx), %edx
addl $-0x10, %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0xeb6a
movq 0x168(%rbx), %rcx
movl %eax, (%rcx)
jmp 0xab35
nop