// File: /workspace/github_cpp_makefile_star2_O2/probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::decodeAsync(float*, int, int, double, double, int, int)
int Signal::decodeAsync(
                        float *pData,
                        int bits,   // previously decoded bits
                        int sizes,  // Bitmask of integerized durations seen
                        double dBitMin,
                        double dBitMax,
                        int bitsPerByte, // 10 or 11 = start + 8 data + 1 or 2 stop
                        int minTotBits )
{
	if (bits >= (int)sizeof(cBits)*bitsPerByte)
		return 0;
	int phase = bits % bitsPerByte;
	int pole = ( pData - pFrame ) & 1;  // 0==pulse  1==gap
	int minBits = (int)(*pData / dBitMax + .69999);  // fewest bits this value might be
	if ( minBits == 0 )
		minBits = 1;
	int maxB = (pole ? bitsPerByte : 9 ) - phase;    // most bits that would be valid here
	int maxBits = (int)(*pData / dBitMin + .30001);  // most bits this value might be
	if ( pData == pFrameEnd )
	{
		if (bits < minTotBits || maxBits <= maxB)
			return 0;
		sizes &= sizes - 1; // clear one bit
		if ( ( sizes & (sizes-1) ) == 0 )
			return 0;  // Need to see at least three sizes
		int bytes = bits/bitsPerByte + 1;
		memset(cBits,0xFF,bytes);
		nMinShort = floor(dBitMin);
		nMaxShort = ceil(dBitMax);
		return bytes;
	}
	if ( maxBits > maxB )
		maxBits = maxB;
	for (int nGuess = minBits; nGuess <= maxBits; ++nGuess)
	{
		if (pole && nGuess+phase > 8 && nGuess < maxB)
			continue;
		double dNewMin = *pData / (nGuess+.3);
		if (dNewMin < dBitMin)
			dNewMin = dBitMin;
		double dNewMax = *pData / (nGuess-.3);
		if (dNewMax > dBitMax)
			dNewMax = dBitMax;
		if ( dNewMin <= dNewMax )
		{
			int result = decodeAsync(pData+1, bits+nGuess, sizes | (1<<nGuess), dNewMin, dNewMax, bitsPerByte, minTotBits);
			if (result)
			{
				if (!pole)
					cBits[bits/bitsPerByte] &= (unsigned char)( ((((0xFF<<nGuess)+1)<<phase) - 1) >>1 ); 
				return result;
			}
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, -0x2c(%rbp)
movq %rcx, -0x60(%rbp)
movl %r8d, %eax
shll $0x4, %eax
xorl %r10d, %r10d
cmpl %edx, %eax
jle 0xf1a8
movapd %xmm1, %xmm4
movapd %xmm0, %xmm5
movl %edx, %r9d
movl %edx, %eax
cltd
idivl %r8d
movq %rsi, %r12
subq 0x38(%rdi), %r12
cvtss2sd (%rsi), %xmm0
testb $0x4, %r12b
pushq $0x9
popq %r14
cmovnel %r8d, %r14d
movaps %xmm0, %xmm1
divsd %xmm5, %xmm1
addsd 0x2449(%rip), %xmm1     # 0x114c8
cvttsd2si %xmm1, %r13d
subl %edx, %r14d
cmpq %rsi, 0x40(%rdi)
je 0xf1bd
movl %eax, -0x44(%rbp)
divsd %xmm4, %xmm0
addsd 0x2430(%rip), %xmm0     # 0x114d0
cvttsd2si %xmm0, %r15d
cmpl $0x1, %r15d
adcl $0x0, %r15d
cmpl %r13d, %r14d
cmovll %r14d, %r13d
leaq 0x4(%rsi), %rax
movq %rax, -0x78(%rbp)
movsd 0x2094(%rip), %xmm6     # 0x11158
movsd 0x240c(%rip), %xmm7     # 0x114d8
movq %rdi, -0x58(%rbp)
movsd %xmm4, -0x40(%rbp)
movsd %xmm5, -0x38(%rbp)
movq %r9, -0x70(%rbp)
movq %rsi, -0x68(%rbp)
movq %rdx, -0x50(%rbp)
cmpl %r13d, %r15d
jg 0xf1a8
testb $0x4, %r12b
je 0xf107
leal (%rdx,%r15), %eax
cmpl $0x9, %eax
jl 0xf107
cmpl %r14d, %r15d
jl 0xf1a0
cvtss2sd (%rsi), %xmm2
cvtsi2sd %r15d, %xmm1
movapd %xmm1, %xmm0
addsd %xmm6, %xmm0
movaps %xmm2, %xmm3
divsd %xmm0, %xmm3
movapd %xmm5, %xmm0
maxsd %xmm3, %xmm0
addsd %xmm7, %xmm1
divsd %xmm1, %xmm2
movapd %xmm4, %xmm1
minsd %xmm2, %xmm1
ucomisd %xmm0, %xmm1
jb 0xf1a0
leal (%r9,%r15), %edx
movq -0x60(%rbp), %rax
movl %eax, %ecx
btsl %r15d, %ecx
movq -0x78(%rbp), %rsi
movl %r8d, %ebx
movl -0x2c(%rbp), %r9d
callq 0xf01e
movl %eax, %r10d
testl %eax, %eax
je 0xf16e
movl %r12d, %eax
andl $0x4, %eax
je 0xf240
testl %r10d, %r10d
movq -0x58(%rbp), %rdi
movsd -0x40(%rbp), %xmm4
movsd -0x38(%rbp), %xmm5
movl %ebx, %r8d
movq -0x70(%rbp), %r9
movq -0x68(%rbp), %rsi
movq -0x50(%rbp), %rdx
movsd 0x1fc2(%rip), %xmm6     # 0x11158
movsd 0x233a(%rip), %xmm7     # 0x114d8
jne 0xf1ab
incl %r15d
jmp 0xf0e6
xorl %r10d, %r10d
movl %r10d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl -0x2c(%rbp), %r9d
jl 0xf1ab
cmpl %r13d, %r14d
jge 0xf1ab
movq -0x60(%rbp), %rcx
leal -0x1(%rcx), %eax
andl %ecx, %eax
leal -0x1(%rax), %ecx
movl $0x0, %r10d
testl %ecx, %eax
je 0xf1ab
movl %r9d, %eax
cltd
idivl %r8d
movl %eax, %ebx
incl %ebx
movq %rdi, %r14
addq $0xa0, %rdi
movslq %ebx, %rdx
movl $0xff, %esi
movsd %xmm4, -0x40(%rbp)
movsd %xmm5, -0x38(%rbp)
callq 0x20c0
movsd -0x38(%rbp), %xmm0
callq 0x2210
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe4(%r14)
movsd -0x40(%rbp), %xmm0
callq 0x2050
movl %ebx, %r10d
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe8(%r14)
jmp 0xf1ab
movl $0xff, %eax
movl %r15d, %ecx
shll %cl, %eax
incl %eax
movq -0x50(%rbp), %rcx
shll %cl, %eax
decl %eax
shrl %eax
movslq -0x44(%rbp), %rcx
movq -0x58(%rbp), %rdx
andb %al, 0xa0(%rdx,%rcx)
jmp 0xf1ab