// File: probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::phaseBit()
int Signal::phaseBit()
{
	// On entry pBit points to a mid bit boundary (prior bit)
	// Find the next mid bit boundary (current bit) and emit the decode of that bit.
	// If nMinShort <= *pBit <= nMaxShort
	//    then *pBit represents just the second half of the prior bit
	//         and ( nMinShort2 <= *++pBit <= nMaxShort2 ) represents the first half
	//             of the current bit.
	// If nMinLong <= *pBit <= nMaxLong
	//    then *pBit represents both the second half of the prior bit and the first
	//         half of the current bit.
	// In other cases return failure.

    float dur = *pBit;
	if (dur < nMinShort || dur > nMaxLong || nBit >= sizeof(cBits)*8)
    {
		return 0;
    }
	if (dur >= nMinLong)
	{
		nState = 1-nState;
	}
	else if (dur > nMaxShort )
	{
		return 0;
	}
    else
	{
        float dur2 = *++pBit;
		if (dur2 < nMinShort2 )
		{
            if (dur2 <= minGlitch)
            {
                if ( ++pBit < pFrameEnd )
                {
                    dur += dur2 + *pBit;
                    if ( dur >= nMinLong && dur <= nMaxLong )
                    {
                		nState = 1-nState;
                        goto ok;
                    }
                }
            }
			return 0;
		}
		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.
						// (When last bit is Hi/Lo the frame ends on a mid bit boundary,
						//  so the caller would know when to quit and we wouldn't get here).
		if ( dur2 > nMaxShort2 )
			return 0;
	}
ok:
	++pBit;
	cBits[nBit>>3] |= nState << (nBit&7);
	nBit++;
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq 0xc8(%rax), %rcx
movss (%rcx), %xmm0
movss %xmm0, -0x14(%rbp)
movss -0x14(%rbp), %xmm1
movss 0xe4(%rax), %xmm0
ucomiss %xmm1, %xmm0
ja 0x170a7
movq -0x20(%rbp), %rax
movss -0x14(%rbp), %xmm0
ucomiss 0xf0(%rax), %xmm0
ja 0x170a7
movq -0x20(%rbp), %rax
movslq 0xc0(%rax), %rax
cmpq $0x80, %rax
jb 0x170b3
movl $0x0, -0x4(%rbp)
jmp 0x17266
movq -0x20(%rbp), %rax
movss -0x14(%rbp), %xmm0
ucomiss 0xec(%rax), %xmm0
jb 0x170df
movq -0x20(%rbp), %rax
movl $0x1, %ecx
subl 0xc4(%rax), %ecx
movl %ecx, 0xc4(%rax)
jmp 0x1720a
movq -0x20(%rbp), %rax
movss -0x14(%rbp), %xmm0
ucomiss 0xe8(%rax), %xmm0
jbe 0x170fd
movl $0x0, -0x4(%rbp)
jmp 0x17266
movq -0x20(%rbp), %rax
movq 0xc8(%rax), %rcx
movq %rcx, %rdx
addq $0x4, %rdx
movq %rdx, 0xc8(%rax)
movss 0x4(%rcx), %xmm0
movss %xmm0, -0x18(%rbp)
movss -0x18(%rbp), %xmm1
movss 0xf4(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x171d1
movq -0x20(%rbp), %rax
movss -0x18(%rbp), %xmm1
movss 0xe0(%rax), %xmm0
ucomiss %xmm1, %xmm0
jb 0x171c5
movq -0x20(%rbp), %rcx
movq 0xc8(%rcx), %rax
addq $0x4, %rax
movq %rax, 0xc8(%rcx)
cmpq 0x40(%rcx), %rax
jae 0x171c3
movq -0x20(%rbp), %rax
movss -0x18(%rbp), %xmm0
movq 0xc8(%rax), %rcx
addss (%rcx), %xmm0
addss -0x14(%rbp), %xmm0
movss %xmm0, -0x14(%rbp)
movss -0x14(%rbp), %xmm0
ucomiss 0xec(%rax), %xmm0
jb 0x171c1
movq -0x20(%rbp), %rax
movss -0x14(%rbp), %xmm1
movss 0xf0(%rax), %xmm0
ucomiss %xmm1, %xmm0
jb 0x171c1
movq -0x20(%rbp), %rax
movl $0x1, %ecx
subl 0xc4(%rax), %ecx
movl %ecx, 0xc4(%rax)
jmp 0x1720c
jmp 0x171c3
jmp 0x171c5
movl $0x0, -0x4(%rbp)
jmp 0x17266
movq -0x20(%rbp), %rcx
movq 0xc8(%rcx), %rax
cmpq 0x40(%rcx), %rax
jne 0x171eb
movl $0x1, -0x4(%rbp)
jmp 0x17266
movq -0x20(%rbp), %rax
movss -0x18(%rbp), %xmm0
ucomiss 0xf8(%rax), %xmm0
jbe 0x17206
movl $0x0, -0x4(%rbp)
jmp 0x17266
jmp 0x17208
jmp 0x1720a
jmp 0x1720c
movq -0x20(%rbp), %rax
movq 0xc8(%rax), %rcx
addq $0x4, %rcx
movq %rcx, 0xc8(%rax)
movl 0xc4(%rax), %esi
movl 0xc0(%rax), %ecx
andl $0x7, %ecx
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)
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)