// File: 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:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movslq 0xc0(%rax), %rax
cmpq $0x80, %rax
jb 0x16acb
movl $0x0, -0x4(%rbp)
jmp 0x17046
movq -0x28(%rbp), %rax
cmpl $0x0, 0xc4(%rax)
jle 0x16d1c
movq -0x28(%rbp), %rax
movq 0xc8(%rax), %rcx
movss (%rcx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm1
movss 0xfc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
ja 0x16b26
movq -0x28(%rbp), %rax
movsd -0x18(%rbp), %xmm0
movss 0x10c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16b32
movl $0x0, -0x4(%rbp)
jmp 0x17046
movq -0x28(%rbp), %rax
movsd -0x18(%rbp), %xmm0
movss 0x104(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16ba9
movq -0x28(%rbp), %rax
movsd -0x18(%rbp), %xmm0
movss 0x108(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x130(%rax)
movl $0xffffffff, 0xc4(%rax) # imm = 0xFFFFFFFF
movq 0xc8(%rax), %rcx
addq $0x4, %rcx
movq %rcx, 0xc8(%rax)
movl 0xc0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc0(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x17046
movq -0x28(%rbp), %rax
movq 0xc8(%rax), %rcx
movq %rcx, %rdx
addq $0x4, %rdx
movq %rdx, 0xc8(%rax)
movss 0x4(%rcx), %xmm0
subss 0x100(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm1
movss 0x110(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16c00
movl $0x0, -0x4(%rbp)
jmp 0x17046
movq -0x28(%rbp), %rax
movsd -0x18(%rbp), %xmm0
movss 0x114(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16c44
movq -0x28(%rbp), %rcx
movq 0xc8(%rcx), %rax
cmpq 0x40(%rcx), %rax
jne 0x16c38
movl $0x1, -0x4(%rbp)
jmp 0x17046
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x17046
movq -0x28(%rbp), %rax
movss 0x120(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd -0x18(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
movss 0x12c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16c8e
movq -0x28(%rbp), %rax
movsd -0x18(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x12c(%rax)
movq -0x28(%rbp), %rax
movsd -0x18(%rbp), %xmm1
movss 0x128(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16cbe
movq -0x28(%rbp), %rax
movsd -0x18(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x128(%rax)
movq -0x28(%rbp), %rax
movl 0xc0(%rax), %ecx
andl $0x7, %ecx
movl $0x1, %esi
shll %cl, %esi
movl 0xc0(%rax), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl 0xa0(%rax,%rcx), %edx
orl %esi, %edx
movb %dl, 0xa0(%rax,%rcx)
movq 0xc8(%rax), %rcx
addq $0x4, %rcx
movq %rcx, 0xc8(%rax)
movl 0xc0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc0(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x17046
movq -0x28(%rbp), %rax
movq 0xc8(%rax), %rcx
movss (%rcx), %xmm0
addss 0x130(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm1
movss 0x110(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16d5f
movl $0x0, -0x4(%rbp)
jmp 0x17046
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
movss 0x11c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16d86
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x17046
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
movss 0x118(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x16ec9
movq -0x28(%rbp), %rax
movss 0x124(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd -0x20(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movl 0xc4(%rax), %eax
movsd 0x398f(%rip), %xmm0     # 0x1a760
movsd 0x33e7(%rip), %xmm1     # 0x1a1c0
movsd %xmm1, -0x38(%rbp)
cmpl $0x0, %eax
movsd %xmm0, -0x30(%rbp)
je 0x16df2
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x28(%rbp), %rax
movsd -0x30(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movss 0x12c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16e31
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x12c(%rax)
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm1
movss 0x128(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16e61
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x128(%rax)
movq -0x28(%rbp), %rax
movl $0x1, 0xc4(%rax)
movl 0xc0(%rax), %ecx
andl $0x7, %ecx
movl $0x1, %esi
shll %cl, %esi
movl 0xc0(%rax), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl 0xa0(%rax,%rcx), %edx
orl %esi, %edx
movb %dl, 0xa0(%rax,%rcx)
movq 0xc8(%rax), %rcx
addq $0x4, %rcx
movq %rcx, 0xc8(%rax)
movl 0xc0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc0(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x17046
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
movss 0x114(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16ef0
movl $0x0, -0x4(%rbp)
jmp 0x17046
movq -0x28(%rbp), %rax
movss 0x120(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd -0x20(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
cmpl $0x0, 0xc4(%rax)
je 0x16f37
movq -0x28(%rbp), %rax
movsd 0x383d(%rip), %xmm0     # 0x1a760
mulsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movl $0x0, 0xc4(%rax)
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
movss 0x12c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16f67
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x12c(%rax)
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm1
movss 0x128(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x16f97
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x128(%rax)
movq -0x28(%rbp), %rax
movq 0xc8(%rax), %rcx
movq %rcx, %rdx
addq $0x4, %rdx
movq %rdx, 0xc8(%rax)
movss 0x4(%rcx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm1
movss 0xfc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
ja 0x16ff0
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
movss 0x104(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16ff9
movl $0x0, -0x4(%rbp)
jmp 0x17046
movq -0x28(%rbp), %rax
movsd -0x20(%rbp), %xmm0
movss 0x100(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x130(%rax)
movq 0xc8(%rax), %rcx
addq $0x4, %rcx
movq %rcx, 0xc8(%rax)
movl 0xc0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc0(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)