// File: probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::processHumaxAtoms(int, float*, int)
bool Signal::processHumaxAtoms(int bitStart, float* pFr, int maxBursts)   
{
	int atomIdx,i;
	float one = 105.0;
	float four = 4* one;
	float delta = one * 0.5;
	float edge, used = 0.0;
	float first[4];
	first[0] = 2*one; first[1] = 3*one; first[2] = one; first[3] = 2*one;
	int burstIdx = 0;
	int bitIdx=bitStart;
	int (*_abs)( int ) = & std::abs;
	do {	
		atomIdx=2 * (1 - burstIdx&1); //odd burstIdx is "off" signal, which can only be the beginning of bits value 0 or 1
		for (i=0; i<2; i++) { //<-2,2|-3,1|1,-3|2,-2>
			edge = first[atomIdx + i ]; 
			if (_abs(pFr[burstIdx]- used - edge) < delta) {
				cBits[bitIdx >> 2] |= (atomIdx + i) << (6- 2*(bitIdx&3));
				burstIdx++;
				if (_abs(pFr[burstIdx] - (four - edge)) < delta) {
					used = 0.0;
					burstIdx++;
				}
				else
					used = four - edge;
				break;
			}
		}
		if (i > 1) 
			return false;  //arrive here if no match found
		bitIdx++;
		if (bitIdx >= sizeof(cBits)*4) 
			return false;  //not enough room in cBits
		if (bitIdx % 12 == 0) {
			used = 0.0;
			burstIdx++;
		}
	} while (burstIdx < maxBursts );
	if (bitIdx % 12 != 0)
		return false;  // wrong frame length
	int cIdx = (bitIdx - 1) >> 2;
	if ((cBits[cIdx] & 2) == (cBits[cIdx] & 1)) 
		return false;  // failed check bit
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movss 0x2d22(%rip), %xmm0     # 0x1a1b8
movss %xmm0, -0x30(%rbp)
movss 0x2b75(%rip), %xmm0     # 0x1a018
mulss -0x30(%rbp), %xmm0
movss %xmm0, -0x34(%rbp)
movss -0x30(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x2d02(%rip), %xmm1     # 0x1a1c0
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
movss 0x2b39(%rip), %xmm0     # 0x1a014
mulss -0x30(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movss 0x2b37(%rip), %xmm0     # 0x1a024
mulss -0x30(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x30(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
movss 0x2b0b(%rip), %xmm0     # 0x1a014
mulss -0x30(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x58(%rbp)
movq 0x7a89(%rip), %rax      # 0x1efb0
movq %rax, -0x60(%rbp)
movl $0x1, %eax
subl -0x54(%rbp), %eax
andl $0x1, %eax
shll %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x2, -0x2c(%rbp)
jge 0x17637
movl -0x28(%rbp), %eax
addl -0x2c(%rbp), %eax
cltq
movss -0x50(%rbp,%rax,4), %xmm0
movss %xmm0, -0x3c(%rbp)
movq -0x60(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x54(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm0
subss -0x40(%rbp), %xmm0
subss -0x3c(%rbp), %xmm0
cvttss2si %xmm0, %edi
callq *%rax
cvtsi2ss %eax, %xmm1
movss -0x38(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x17627
movq -0x70(%rbp), %rax
movl -0x28(%rbp), %esi
addl -0x2c(%rbp), %esi
movl -0x58(%rbp), %edx
andl $0x3, %edx
shll %edx
movl $0x6, %ecx
subl %edx, %ecx
shll %cl, %esi
movl -0x58(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rcx
movzbl 0xa0(%rax,%rcx), %edx
orl %esi, %edx
movb %dl, 0xa0(%rax,%rcx)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x60(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x54(%rbp), %rdx
movss (%rcx,%rdx,4), %xmm0
movss -0x34(%rbp), %xmm1
subss -0x3c(%rbp), %xmm1
subss %xmm1, %xmm0
cvttss2si %xmm0, %edi
callq *%rax
cvtsi2ss %eax, %xmm1
movss -0x38(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x17616
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x17625
movss -0x34(%rbp), %xmm0
subss -0x3c(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
jmp 0x17637
jmp 0x17629
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x17542
cmpl $0x1, -0x2c(%rbp)
jle 0x17646
movb $0x0, -0x1(%rbp)
jmp 0x176e3
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movslq -0x58(%rbp), %rax
cmpq $0x40, %rax
jb 0x17662
movb $0x0, -0x1(%rbp)
jmp 0x176e3
movl -0x58(%rbp), %eax
movl $0xc, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x17683
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x17685
movl -0x54(%rbp), %eax
cmpl -0x24(%rbp), %eax
jl 0x1752b
movl -0x58(%rbp), %eax
movl $0xc, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x176a7
movb $0x0, -0x1(%rbp)
jmp 0x176e3
movq -0x70(%rbp), %rcx
movl -0x58(%rbp), %eax
subl $0x1, %eax
sarl $0x2, %eax
movl %eax, -0x64(%rbp)
movslq -0x64(%rbp), %rax
movzbl 0xa0(%rcx,%rax), %eax
andl $0x2, %eax
movslq -0x64(%rbp), %rdx
movzbl 0xa0(%rcx,%rdx), %ecx
andl $0x1, %ecx
cmpl %ecx, %eax
jne 0x176df
movb $0x0, -0x1(%rbp)
jmp 0x176e3
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
nop