// File: /workspace/github_cpp_makefile_star2_O1/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 %r8d, %eax
shll $0x4, %eax
xorl %r12d, %r12d
cmpl %edx, %eax
jle 0x104d6
movapd %xmm1, %xmm4
movapd %xmm0, %xmm5
movl %edx, %r10d
movl %edx, %eax
cltd
idivl %r8d
movq %rsi, %r13
subq 0x38(%rdi), %r13
xorps %xmm0, %xmm0
cvtss2sd (%rsi), %xmm0
testb $0x4, %r13b
movl $0x9, %r14d
cmovnel %r8d, %r14d
movaps %xmm0, %xmm1
divsd %xmm5, %xmm1
addsd 0x218a(%rip), %xmm1     # 0x124c8
cvttsd2si %xmm1, %ebx
subl %edx, %r14d
cmpq %rsi, 0x40(%rdi)
je 0x104eb
divsd %xmm4, %xmm0
addsd 0x2175(%rip), %xmm0     # 0x124d0
cvttsd2si %xmm0, %r15d
cmpl $0x1, %r15d
adcl $0x0, %r15d
cmpl %ebx, %r14d
cmovll %r14d, %ebx
cmpl %ebx, %r15d
jg 0x104d6
leaq 0x4(%rsi), %r11
movq %r11, -0x78(%rbp)
incl %ebx
movsd 0x1dce(%rip), %xmm6     # 0x12158
movsd 0x2146(%rip), %xmm7     # 0x124d8
cltq
movq %rax, -0x70(%rbp)
movq %rdi, -0x60(%rbp)
movsd %xmm4, -0x40(%rbp)
movsd %xmm5, -0x38(%rbp)
movl %r8d, -0x30(%rbp)
movq %r10, -0x58(%rbp)
movq %rcx, -0x50(%rbp)
movl %r9d, -0x2c(%rbp)
movq %rsi, -0x48(%rbp)
movq %rdx, -0x68(%rbp)
testb $0x4, %r13b
je 0x103d6
leal (%rdx,%r15), %eax
cmpl $0x9, %eax
jl 0x103d6
cmpl %r14d, %r15d
jl 0x104ca
xorps %xmm2, %xmm2
cvtss2sd (%rsi), %xmm2
xorps %xmm1, %xmm1
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
movb $0x1, %r11b
ucomisd %xmm0, %xmm1
jb 0x104c5
leal (%r10,%r15), %edx
btsl %r15d, %ecx
movq -0x78(%rbp), %rsi
callq 0x102e0
testl %eax, %eax
sete %r11b
cmovnel %eax, %r12d
je 0x1048f
movl %r13d, %ecx
andl $0x4, %ecx
movq -0x68(%rbp), %rdx
jne 0x1046b
movl $0xff, %esi
movl %r15d, %ecx
shll %cl, %esi
incl %esi
movl %edx, %ecx
shll %cl, %esi
decl %esi
shrl %esi
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %rcx
andb %sil, 0xa0(%rdi,%rcx)
movl %eax, %r12d
jmp 0x1046f
movq -0x60(%rbp), %rdi
movsd -0x40(%rbp), %xmm4
movsd -0x38(%rbp), %xmm5
movl -0x30(%rbp), %r8d
movq -0x58(%rbp), %r10
movq -0x50(%rbp), %rcx
movl -0x2c(%rbp), %r9d
movq -0x48(%rbp), %rsi
jmp 0x104b5
movq -0x60(%rbp), %rdi
movsd -0x40(%rbp), %xmm4
movsd -0x38(%rbp), %xmm5
movl -0x30(%rbp), %r8d
movq -0x58(%rbp), %r10
movq -0x50(%rbp), %rcx
movl -0x2c(%rbp), %r9d
movq -0x48(%rbp), %rsi
movq -0x68(%rbp), %rdx
movsd 0x1c9b(%rip), %xmm6     # 0x12158
movsd 0x2013(%rip), %xmm7     # 0x124d8
testb %r11b, %r11b
je 0x104d9
incl %r15d
cmpl %r15d, %ebx
jne 0x103be
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r9d, %r10d
jl 0x104d9
cmpl %ebx, %r14d
jge 0x104d9
leal -0x1(%rcx), %eax
andl %ecx, %eax
leal -0x1(%rax), %ecx
movl $0x0, %r12d
testl %ecx, %eax
je 0x104d9
movl %r10d, %eax
cltd
idivl %r8d
movl %eax, %r12d
incl %r12d
movq %rdi, %rbx
addq $0xa0, %rdi
movslq %r12d, %rdx
movl $0xff, %esi
movsd %xmm4, -0x40(%rbp)
movsd %xmm5, -0x38(%rbp)
callq 0x20b0
movsd -0x38(%rbp), %xmm0
callq 0x21f0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe4(%rbx)
movsd -0x40(%rbp), %xmm0
callq 0x2050
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe8(%rbx)
jmp 0x104d9