// File: probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::decodeRaw(int)
int Signal::decodeRaw( int bitsRequested )
{
	_ASSERT(nBit+bitsRequested < sizeof(cBits)*8);
	while ( bitsRequested > 0 )
	{
		if (pBit>pFrameEnd)
		{
			return 0;
		}
		double x =   *pBit * m_rawUnit
				   + ( ((pBit-pFrame)&1) ? m_rawGapAdjust : m_rawPulseAdjust );
		double y = floor(x);
		// GD Added test pBit<pFrameEnd as this return should not occur on a lead-out
		if ( pBit < pFrameEnd && x-y > m_rawErrorLimit || y==0. )
		{
			return 0;
		}
		int bits = (int)y;
		if ( (bitsRequested -= bits) < 0 )
		{
			bits += bitsRequested;
		}
		if ( (pBit-pFrame) & 1 )
		{
			nBit += bits;
		}
		else
		{
			do
			{
				cBits[nBit>>3] |= 1 << (nBit & 7);
				nBit++;
			} while (--bits);
		}
		pBit++;
	}
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movl 0xc0(%rax), %eax
addl -0x14(%rbp), %eax
cltq
cmpq $0x80, %rax
jae 0x1656c
jmp 0x1658b
leaq 0x450b(%rip), %rdi      # 0x1aa7e
leaq 0x446c(%rip), %rsi      # 0x1a9e6
movl $0x325, %edx            # imm = 0x325
leaq 0x451d(%rip), %rcx      # 0x1aaa3
callq 0x20e0
jmp 0x1658d
cmpl $0x0, -0x14(%rbp)
jle 0x16754
movq -0x38(%rbp), %rcx
movq 0xc8(%rcx), %rax
cmpq 0x40(%rcx), %rax
jbe 0x165b4
movl $0x0, -0x4(%rbp)
jmp 0x1675b
movq -0x38(%rbp), %rcx
movq 0xc8(%rcx), %rax
movss (%rax), %xmm0
movss %xmm0, -0x40(%rbp)
movss 0xfc(%rcx), %xmm0
movss %xmm0, -0x3c(%rbp)
movq 0xc8(%rcx), %rax
movq 0x38(%rcx), %rcx
subq %rcx, %rax
sarq $0x2, %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x16604
movq -0x38(%rbp), %rax
movss 0x104(%rax), %xmm0
movss %xmm0, -0x44(%rbp)
jmp 0x16615
movq -0x38(%rbp), %rax
movss 0x100(%rax), %xmm0
movss %xmm0, -0x44(%rbp)
movss -0x3c(%rbp), %xmm2
movss -0x40(%rbp), %xmm0
movss -0x44(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x2200
movq -0x38(%rbp), %rcx
movsd %xmm0, -0x28(%rbp)
movq 0xc8(%rcx), %rax
cmpq 0x40(%rcx), %rax
jae 0x16675
movq -0x38(%rbp), %rax
movsd -0x20(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movss 0x108(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
ja 0x16685
movsd -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16691
jp 0x16691
movl $0x0, -0x4(%rbp)
jmp 0x1675b
cvttsd2si -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movl -0x14(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jge 0x166b2
movl -0x14(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movq 0xc8(%rcx), %rax
movq 0x38(%rcx), %rcx
subq %rcx, %rax
sarq $0x2, %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x166e7
movq -0x38(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl 0xc0(%rax), %ecx
movl %ecx, 0xc0(%rax)
jmp 0x16739
jmp 0x166e9
movq -0x38(%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)
movl 0xc0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc0(%rax)
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
jne 0x166e9
jmp 0x16739
movq -0x38(%rbp), %rax
movq 0xc8(%rax), %rcx
addq $0x4, %rcx
movq %rcx, 0xc8(%rax)
jmp 0x1658d
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)