// File: /workspace/github_cpp_makefile_star2_O3/probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::tryX10()
void Signal::tryX10()
{
	// <2,-13|7,-7>(8,-8, F:5, ~F:5, 23,-8)+

	// GD 2009: That IRP is only the second part of the protocol that is decoded here.
	// A more complete description is
	// <2,-13|7,-7>(8,-8,F:5,N:-4,23,-8,(8,-8, F:5, ~F:5, 23,-8)+)
	// where N is a 4-bit counter (incremented at each keypress, though that doesn't
	// show in the decode).  However, according to the UEI executor for
	// the X10 protocol, PID 003F, the start frame should not have the (8,-8) 
	// leadin, so that frame is not picked up.  In addition, the UEI timing
	// is slightly different, which may be for convenience but it means that
	// the repeat frame of the UEI executor is also often not picked up.  UEI uses
	//
	// {40.8k,565}<2,-12|7,-7>(F:5,N:-4,21,-7,(7,-7,F:5,~F:5,21,-7)+).
	//
	// This has all bursts of equal length while the IRP above has the lead-in burst
	// being the longest.  The decode tests whether the lead-in is the longest
	// burst and random variations in the UEI execution mean that is often is not, so
	// the frame is missed.  I have removed this test, corrected the start frame and
	// added a test on burst lengths that allows that the (8,-8) lead-in may be correct.

//	if ( nFrameL > 12 || nFrameL < 11 )
	if ( nFrameL != 12 && nFrameL != 10 )		// GD 2009
		return;
	if ( sortOn.max1 <= sortBurst.max1 )	// leadOutOn should exceed sortBurst.max1
		return;
	/*  GD 2009 Allow for all bursts to have same nominal length, so next condition
		removed and following one modified
	if ( pFrame[0]+pFrame[1] <= sortBurst.max2 )
		return;
	*/
	if ( sortBurst.min1*5 <= /* sortBurst.max2*4 */ sortBurst.max1*4 )
		return;
	// GD 2009 Test burst lengths
	if ( sortBurst.min1 < 0.8*14*565 || sortBurst.max1 > 1.2*16*565 )
		return;
	if ( !framedLeft(sortOn.max1) )
		if ( pFrame[-2] < sortBurst.max1 )
			if (   pFrame != pDuration+2*nSingle
				|| pDuration[2*(nSingle+nRepeat)-2] < sortBurst.max1 )
					return;
	cleanup();
	nMaxShort = sortBurst.min1/3;
	decodeX(11);
	int obc = /* getLsb(1,5); */ getLsb(0,6);	// GD 2009 Covers both frame situations
	if ( nFrameL == 12 )
	{
		if ( (obc & 1) != 1 )					// GD 2009 Test lead-in bit 
			return;
		pHex[0] = msb(obc);					// GD 2009 Lead-in 1-bit is included in hex
		obc >>= 1;							// GD 2009 Remove lead-in bit
		if ( getLsb(6,5) + obc != 31 )
			return;
		strcpy(pProtocol,"X10");
		*pOBC = obc;
		bInitLeadIn = false;				// GD 2009
		return;
	}
	sprintf(pProtocol,"X10:%d", msb( getLsb(/* 6 */ 5,4), 4) );
	obc &= 0x1F;							// GD 2009 Remove spurious 6th bit
	*pOBC = obc;	
	pHex[0] = msb(obc<<1 | 1);				// GD 2009 Lead-in 1-bit must be included in hex
	nNote_out = 0;
	nAuxNote_out = 5;
	strcpy(pMisc, "invalid signal");
	bInitLeadIn = true;						// GD 2009
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x48(%rdi), %eax
cmpl $0xc, %eax
je 0x49ea
cmpl $0xa, %eax
jne 0x4c4d
movss 0x184(%rbx), %xmm2
movss 0x1dc(%rbx), %xmm1
ucomiss %xmm2, %xmm1
jae 0x4c4d
ucomiss 0xdb02(%rip), %xmm1     # 0x1250c
ja 0x4c4d
movss 0x1d0(%rbx), %xmm0
movss 0xdae8(%rip), %xmm3     # 0x12508
mulss %xmm0, %xmm3
movss 0xdad4(%rip), %xmm4     # 0x12500
mulss %xmm1, %xmm4
ucomiss %xmm3, %xmm4
jae 0x4c4d
xorps %xmm3, %xmm3
cvtss2sd %xmm0, %xmm3
movsd 0xd700(%rip), %xmm4     # 0x12148
ucomisd %xmm3, %xmm4
ja 0x4c4d
movss 0x13c(%rbx), %xmm3
ucomiss %xmm2, %xmm3
movq 0x38(%rbx), %rax
jae 0x4a90
ucomiss -0x8(%rax), %xmm1
jbe 0x4a90
movq 0x8(%rbx), %rcx
movslq 0x20(%rbx), %rdx
leaq (%rcx,%rdx,8), %rsi
cmpq %rsi, %rax
jne 0x4c4d
movslq 0x24(%rbx), %rsi
addq %rdx, %rsi
ucomiss -0x8(%rcx,%rsi,8), %xmm1
ja 0x4c4d
xorps %xmm1, %xmm1
movups %xmm1, 0xa0(%rbx)
movq %rax, 0xc8(%rbx)
movq $0x0, 0xc0(%rbx)
divss 0xda40(%rip), %xmm0     # 0x124f4
movss %xmm0, 0xe8(%rbx)
movq %rbx, %rdi
movl $0xb, %esi
callq 0xfe52
movzbl 0xa0(%rbx), %r14d
cmpl $0xc, 0x48(%rbx)
jne 0x4b6d
testb $0x1, %r14b
je 0x4c4d
andl $0x3f, %r14d
movl %r14d, %eax
bswapl %eax
movl %eax, %ecx
andl $0xc000000, %ecx        # imm = 0xC000000
movl %eax, %edx
shll $0x4, %edx
shrl $0x4, %eax
andl $0x3000000, %eax        # imm = 0x3000000
orl %edx, %eax
shll $0x2, %eax
leal (%rax,%rcx,4), %eax
movl %eax, %ecx
andl $0x54000000, %ecx       # imm = 0x54000000
shrl %eax
andl $0x55555540, %eax       # imm = 0x55555540
leal (%rax,%rcx,2), %eax
shrl $0x18, %eax
movq 0x178(%rbx), %rcx
movl %eax, (%rcx)
shrl %r14d
movzbl 0xa0(%rbx), %eax
shrl $0x6, %eax
movzbl 0xa1(%rbx), %ecx
andl $0x7, %ecx
leal (%rax,%rcx,4), %eax
addl %r14d, %eax
cmpl $0x1f, %eax
jne 0x4c4d
movq 0x148(%rbx), %rax
movl $0x303158, (%rax)       # imm = 0x303158
movq 0x170(%rbx), %rax
movl %r14d, (%rax)
xorl %eax, %eax
jmp 0x4c4a
movq 0x148(%rbx), %rdi
movl %r14d, %eax
shrl $0x5, %eax
movzbl 0xa1(%rbx), %ecx
andl $0x1f, %ecx
leal (%rax,%rcx,8), %eax
bswapl %eax
movl $0xc000000, %r15d       # imm = 0xC000000
movl %eax, %ecx
andl %r15d, %ecx
shll $0x6, %eax
leal (%rax,%rcx,4), %eax
movl %eax, %ecx
andl $0x50000000, %ecx       # imm = 0x50000000
shrl %eax
andl $0x55554040, %eax       # imm = 0x55554040
leal (%rax,%rcx,2), %edx
shrl $0x1c, %edx
leaq 0xe2f6(%rip), %rsi      # 0x12eac
xorl %eax, %eax
callq 0x2060
andl $0x1f, %r14d
movq 0x170(%rbx), %rax
movl %r14d, (%rax)
leal 0x1(,%r14,2), %eax
bswapl %eax
movl %eax, %ecx
shll $0x4, %ecx
movl %eax, %edx
shrl $0x4, %edx
andl $0x3000000, %edx        # imm = 0x3000000
orl %ecx, %edx
andl $0x33303030, %edx       # imm = 0x33303030
shll $0x2, %edx
andl %r15d, %eax
leal (%rdx,%rax,4), %eax
movl $0x54404040, %ecx       # imm = 0x54404040
movl %eax, %edx
andl %ecx, %edx
shrl %eax
andl %ecx, %eax
leal (%rax,%rdx,2), %eax
shrl $0x18, %eax
movq 0x178(%rbx), %rcx
movl %eax, (%rcx)
movabsq $0x500000000, %rax      # imm = 0x500000000
movq %rax, 0x88(%rbx)
movq 0x150(%rbx), %rax
movabsq $0x2064696c61766e69, %rcx # imm = 0x2064696C61766E69
movq %rcx, (%rax)
movabsq $0x6c616e67697320, %rcx # imm = 0x6C616E67697320
movq %rcx, 0x7(%rax)
movl $0x1, %eax
movl %eax, 0x70(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq