// File: /workspace/github_cpp_makefile_star2_O3/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 %ebx, %ebx
cmpl %edx, %eax
jle 0x1033b
movapd %xmm1, %xmm4
movapd %xmm0, %xmm5
movl %edx, %r10d
movl %edx, %eax
cltd
idivl %r8d
movq %rsi, %r12
subq 0x38(%rdi), %r12
xorps %xmm0, %xmm0
cvtss2sd (%rsi), %xmm0
testb $0x4, %r12b
movl $0x9, %r13d
cmovnel %r8d, %r13d
movaps %xmm0, %xmm1
divsd %xmm5, %xmm1
addsd 0x22c9(%rip), %xmm1     # 0x124c8
cvttsd2si %xmm1, %r14d
subl %edx, %r13d
cmpq %rsi, 0x40(%rdi)
je 0x1034e
divsd %xmm4, %xmm0
addsd 0x22b3(%rip), %xmm0     # 0x124d0
cvttsd2si %xmm0, %r15d
cmpl $0x1, %r15d
adcl $0x0, %r15d
cmpl %r14d, %r13d
cmovll %r13d, %r14d
cmpl %r14d, %r15d
jg 0x1033b
movl %eax, -0x3c(%rbp)
leaq 0x4(%rsi), %rax
movq %rax, -0x78(%rbp)
incl %r14d
movsd 0x1f08(%rip), %xmm6     # 0x12158
movsd 0x2280(%rip), %xmm7     # 0x124d8
movq %rdi, -0x58(%rbp)
movsd %xmm4, -0x38(%rbp)
movsd %xmm5, -0x30(%rbp)
movl %r8d, -0x44(%rbp)
movq %r10, -0x70(%rbp)
movq %rcx, -0x68(%rbp)
movl %r9d, -0x40(%rbp)
movq %rsi, -0x60(%rbp)
movq %rdx, -0x50(%rbp)
testb $0x4, %r12b
je 0x10296
leal (%rdx,%r15), %eax
cmpl $0x9, %eax
jl 0x10296
cmpl %r13d, %r15d
jl 0x1032f
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
ucomisd %xmm0, %xmm1
jb 0x1032f
leal (%r10,%r15), %edx
btsl %r15d, %ecx
movq -0x78(%rbp), %rsi
callq 0x101a2
movl %eax, %ebx
testl %eax, %eax
je 0x102f5
movl %r12d, %eax
andl $0x4, %eax
je 0x103c8
testl %ebx, %ebx
movq -0x58(%rbp), %rdi
movsd -0x38(%rbp), %xmm4
movsd -0x30(%rbp), %xmm5
movl -0x44(%rbp), %r8d
movq -0x70(%rbp), %r10
movq -0x68(%rbp), %rcx
movl -0x40(%rbp), %r9d
movq -0x60(%rbp), %rsi
movq -0x50(%rbp), %rdx
movsd 0x1e33(%rip), %xmm6     # 0x12158
movsd 0x21ab(%rip), %xmm7     # 0x124d8
jne 0x1033d
incl %r15d
cmpl %r15d, %r14d
jne 0x1027e
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %r9d, %r10d
jl 0x1033d
cmpl %r14d, %r13d
jge 0x1033d
leal -0x1(%rcx), %eax
andl %ecx, %eax
leal -0x1(%rax), %ecx
movl $0x0, %ebx
testl %ecx, %eax
je 0x1033d
movl %r10d, %eax
cltd
idivl %r8d
movl %eax, %ebx
incl %ebx
movq %rdi, %r14
addq $0xa0, %rdi
movslq %ebx, %rdx
movl $0xff, %esi
movsd %xmm4, -0x38(%rbp)
movsd %xmm5, -0x30(%rbp)
callq 0x20b0
movsd -0x30(%rbp), %xmm0
callq 0x21f0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe4(%r14)
movsd -0x38(%rbp), %xmm0
callq 0x2050
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe8(%r14)
jmp 0x1033d
movl $0xff, %eax
movl %r15d, %ecx
shll %cl, %eax
incl %eax
movq -0x50(%rbp), %rcx
shll %cl, %eax
decl %eax
shrl %eax
movslq -0x3c(%rbp), %rcx
movq -0x58(%rbp), %rdx
andb %al, 0xa0(%rdx,%rcx)
jmp 0x1033d