// File: /workspace/github_cpp_makefile_star2_O2/probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::phaseBit2()
int Signal::phaseBit2()
{
	// On entry pBit points to the mid bit boundary of the prior bit
	// nState is the value of the prior bit:
    //   -1 =  LongHi/Lo
	//    0 = ShortHi/Lo
	//    1 =      Lo/Hi
	// Find the next mid bit boundary (current bit) and emit the decode of that bit.
	// If *pBit is short
	//    then *pBit represents just the second half of the prior bit
	//         and (*++pBit must be short) represents the first half
	//             of the current bit.
	// If *pBit is long
	//    then *pBit represents both the second half of the prior bit and the first
	//         half of the current bit.
	// In other cases return failure.
    // Returns
    //    1 = success
    //    0 = failure
    //   -1 = posible rc5x gap
	
	if ( nBit >= sizeof(cBits)*8 )
	{
		return 0;
	}
	if ( nState>0 )   // *pBit is pulse
	{
		double x = *pBit;
		if ( x < m_minShortPulse || x > m_maxLongPulse )
		{
			return 0;
		}
		if ( x > m_maxShortPulse )
		{
			m_extra = x - m_nominalLongPulse;
			nState = -1;
			++pBit;
			nBit++;
			return 1;
		}
		x += *++pBit - m_nominalShortPulse;
		if ( x < m_minShortGap )
		{
			return 0;
		}
		if ( x > m_maxShortGap )
		{
			if ( pBit == pFrameEnd )
			{
				return 1;	// Last bit was Lo/Hi and the frame ended on a bit boundary, so caller
							// went too far.  So return success, but don't emit a decoded bit.
			}
			return -1;
		}

        x -= m_nominalShortGap;
        if ( x > m_posDelta ) m_posDelta = x;
        if ( x < m_negDelta ) m_negDelta = x;

		cBits[nBit>>3] |= 1 << (nBit&7);
		++pBit;
		nBit++;
		return 1;
	}
	else            // *pBit is a gap
	{
		double x = *pBit + m_extra;
		if ( x < m_minShortGap )
		{
			return 0;
		}
		if ( x > m_maxLongGap )
		{
			return -1;
		}
		if ( x >= m_minLongGap )
		{
            x -= m_nominalLongGap;
            x *= (nState==0) ? (2./3.) : .5;
            if ( x > m_posDelta ) m_posDelta = x;
            if ( x < m_negDelta ) m_negDelta = x;

			nState = 1;
			cBits[nBit>>3] |= 1 << (nBit&7);
			++pBit;
			nBit++;
			return 1;
		}
		if ( x > m_maxShortGap )
		{
			return 0;
		}

        x -= m_nominalShortGap;
        if ( nState )
        {
            x *= (2./3.);
            nState = 0;
        }
        if ( x > m_posDelta ) m_posDelta = x;
        if ( x < m_negDelta ) m_negDelta = x;

		x = *++pBit;
		if ( x < m_minShortPulse || x > m_maxShortPulse )
		{
			return 0;
		}
		m_extra = x - m_nominalShortPulse;

		++pBit;
		nBit++;
		return 1;
	}
}

// Assembly:
movl 0xc0(%rdi), %edx
xorl %eax, %eax
cmpq $0x7f, %rdx
ja 0xf4f2
pushq %rbp
movq %rsp, %rbp
movl 0xc4(%rdi), %esi
movq 0xc8(%rdi), %rcx
movss (%rcx), %xmm1
testl %esi, %esi
jle 0xf2f0
movss 0xfc(%rdi), %xmm0
ucomiss %xmm1, %xmm0
ja 0xf4f1
ucomiss 0x10c(%rdi), %xmm1
ja 0xf4f1
ucomiss 0x104(%rdi), %xmm1
jbe 0xf31c
subss 0x108(%rdi), %xmm1
movss %xmm1, 0x130(%rdi)
orl $-0x1, 0xc4(%rdi)
addq $0x4, %rcx
movq %rcx, 0xc8(%rdi)
incl %edx
movl %edx, 0xc0(%rdi)
movl $0x1, %eax
jmp 0xf4f1
addss 0x130(%rdi), %xmm1
movss 0x110(%rdi), %xmm0
ucomiss %xmm1, %xmm0
ja 0xf4f1
ucomiss 0x11c(%rdi), %xmm1
jbe 0xf379
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xf4f1
cvtss2sd %xmm1, %xmm1
leaq 0x4(%rcx), %rsi
movq %rsi, 0xc8(%rdi)
movss 0x4(%rcx), %xmm0
subss 0x100(%rdi), %xmm0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtss2sd 0x110(%rdi), %xmm1
ucomisd %xmm0, %xmm1
ja 0xf4f1
cvtss2sd 0x114(%rdi), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xf48e
xorl %eax, %eax
cmpq 0x40(%rdi), %rsi
sete %al
leal -0x1(,%rax,2), %eax
jmp 0xf4f1
cvtss2sd %xmm1, %xmm0
ucomiss 0x118(%rdi), %xmm1
jae 0xf42d
ucomiss 0x114(%rdi), %xmm1
ja 0xf4f1
cvtss2sd 0x120(%rdi), %xmm1
subsd %xmm1, %xmm0
testl %esi, %esi
je 0xf3b6
mulsd 0x2131(%rip), %xmm0     # 0x114e0
andl $0x0, 0xc4(%rdi)
cvtss2sd 0x12c(%rdi), %xmm1
ucomisd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm1
jbe 0xf3d0
movss %xmm1, 0x12c(%rdi)
cvtss2sd 0x128(%rdi), %xmm2
ucomisd %xmm0, %xmm2
jbe 0xf3e6
movss %xmm1, 0x128(%rdi)
leaq 0x4(%rcx), %rsi
movq %rsi, 0xc8(%rdi)
movss 0x4(%rcx), %xmm0
movss 0xfc(%rdi), %xmm1
ucomiss %xmm0, %xmm1
ja 0xf4f1
ucomiss 0x104(%rdi), %xmm0
ja 0xf4f1
subss 0x100(%rdi), %xmm0
movss %xmm0, 0x130(%rdi)
addq $0x8, %rcx
jmp 0xf2d7
cvtss2sd 0x124(%rdi), %xmm1
subsd %xmm1, %xmm0
xorl %eax, %eax
testl %esi, %esi
sete %al
leaq 0x1c69(%rip), %rcx      # 0x110b0
mulsd (%rcx,%rax,8), %xmm0
cvtss2sd 0x12c(%rdi), %xmm1
ucomisd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm1
jbe 0xf466
movss %xmm1, 0x12c(%rdi)
cvtss2sd 0x128(%rdi), %xmm2
ucomisd %xmm0, %xmm2
jbe 0xf47c
movss %xmm1, 0x128(%rdi)
movl $0x1, %eax
movl %eax, 0xc4(%rdi)
movl %edx, %ecx
andb $0x7, %cl
jmp 0xf4d4
cvtss2sd 0x120(%rdi), %xmm1
subsd %xmm1, %xmm0
cvtss2sd 0x12c(%rdi), %xmm1
ucomisd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm1
jbe 0xf4b4
movss %xmm1, 0x12c(%rdi)
cvtss2sd 0x128(%rdi), %xmm2
ucomisd %xmm0, %xmm2
jbe 0xf4ca
movss %xmm1, 0x128(%rdi)
movl %edx, %ecx
andb $0x7, %cl
movl $0x1, %eax
movl %eax, %esi
shll %cl, %esi
shrl $0x3, %edx
orb %sil, 0xa0(%rdi,%rdx)
addq $0x4, 0xc8(%rdi)
incl 0xc0(%rdi)
popq %rbp
retq
nop