// File: /workspace/github_cpp_makefile_star2_O3/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
jbe 0x10403
xorl %eax, %eax
retq
pushq %rbp
movq %rsp, %rbp
movl 0xc4(%rdi), %esi
movq 0xc8(%rdi), %rcx
movss (%rcx), %xmm1
testl %esi, %esi
jle 0x1047e
movss 0xfc(%rdi), %xmm0
ucomiss %xmm1, %xmm0
ja 0x106ca
ucomiss 0x10c(%rdi), %xmm1
ja 0x106ca
ucomiss 0x104(%rdi), %xmm1
jbe 0x10570
subss 0x108(%rdi), %xmm1
movss %xmm1, 0x130(%rdi)
movl $0xffffffff, 0xc4(%rdi) # imm = 0xFFFFFFFF
addq $0x4, %rcx
movq %rcx, 0xc8(%rdi)
incl %edx
movl %edx, 0xc0(%rdi)
movl $0x1, %eax
jmp 0x106ca
addss 0x130(%rdi), %xmm1
movss 0x110(%rdi), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x1049a
xorl %eax, %eax
jmp 0x106ca
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
ucomiss 0x11c(%rdi), %xmm1
ja 0x106ca
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
ucomiss 0x118(%rdi), %xmm1
jae 0x105d5
ucomiss 0x114(%rdi), %xmm1
ja 0x10493
xorps %xmm1, %xmm1
cvtss2sd 0x120(%rdi), %xmm1
subsd %xmm1, %xmm0
testl %esi, %esi
je 0x104ee
mulsd 0x1ffc(%rip), %xmm0     # 0x124e0
movl $0x0, 0xc4(%rdi)
xorps %xmm1, %xmm1
cvtss2sd 0x12c(%rdi), %xmm1
ucomisd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
jbe 0x1050e
movss %xmm1, 0x12c(%rdi)
cvtss2sd 0x128(%rdi), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x10524
movss %xmm1, 0x128(%rdi)
leaq 0x4(%rcx), %rax
movq %rax, 0xc8(%rdi)
movss 0x4(%rcx), %xmm0
movss 0xfc(%rdi), %xmm1
ucomiss %xmm0, %xmm1
ja 0x10493
ucomiss 0x104(%rdi), %xmm0
movl $0x0, %eax
ja 0x106ca
subss 0x100(%rdi), %xmm0
movss %xmm0, 0x130(%rdi)
addq $0x8, %rcx
jmp 0x10465
leaq 0x4(%rcx), %rsi
movq %rsi, 0xc8(%rdi)
movss 0x4(%rcx), %xmm0
subss 0x100(%rdi), %xmm0
cvtss2sd %xmm1, %xmm1
cvtss2sd %xmm0, %xmm0
cvtss2sd 0x110(%rdi), %xmm2
addsd %xmm1, %xmm0
ucomisd %xmm0, %xmm2
movl $0x0, %eax
ja 0x106ca
xorps %xmm1, %xmm1
cvtss2sd 0x114(%rdi), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x10659
xorl %eax, %eax
cmpq 0x40(%rdi), %rsi
sete %al
leal -0x1(,%rax,2), %eax
jmp 0x106ca
xorps %xmm1, %xmm1
cvtss2sd 0x124(%rdi), %xmm1
subsd %xmm1, %xmm0
xorl %eax, %eax
testl %esi, %esi
sete %al
leaq 0x1abe(%rip), %rcx      # 0x120b0
mulsd (%rcx,%rax,8), %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x12c(%rdi), %xmm1
ucomisd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
jbe 0x10617
movss %xmm1, 0x12c(%rdi)
cvtss2sd 0x128(%rdi), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x1062d
movss %xmm1, 0x128(%rdi)
movl $0x1, %eax
movl %eax, 0xc4(%rdi)
movl %edx, %ecx
andb $0x7, %cl
movl $0x1, %esi
shll %cl, %esi
shrl $0x3, %edx
orb %sil, 0xa0(%rdi,%rdx)
addq $0x4, 0xc8(%rdi)
jmp 0x106c4
xorps %xmm1, %xmm1
cvtss2sd 0x120(%rdi), %xmm1
subsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x12c(%rdi), %xmm1
ucomisd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
jbe 0x10688
movss %xmm1, 0x12c(%rdi)
xorps %xmm2, %xmm2
cvtss2sd 0x128(%rdi), %xmm2
ucomisd %xmm0, %xmm2
jbe 0x106a1
movss %xmm1, 0x128(%rdi)
movl %edx, %ecx
andb $0x7, %cl
movl $0x1, %eax
shll %cl, %eax
shrl $0x3, %edx
orb %al, 0xa0(%rdi,%rdx)
addq $0x4, 0xc8(%rdi)
movl $0x1, %eax
incl 0xc0(%rdi)
popq %rbp
retq