// File: /workspace/github_cpp_makefile_star2_O1/probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::tryGrundig16()
void Signal::tryGrundig16()
{
    if ( pFrameEnd[0] < 5000 )
        return;
	if (nTotDur < 29800 || nTotDur > 35800)
		return;
	if (nFrameL < 10 || nFrameL > 18)
		return;
	float* pB = pFrame+3;
	float nMin=99999;
	float nMax=0;
	cleanup();		// GD 2009   added for safety
	for (nBit=0; nBit<16; nBit+=2)
	{
		float tot = pB[0] + pB[1];
		unsigned char& cB = cBits[nBit>>3];
		unsigned int cN = (nBit & 6);
		switch ( (int)((*pB+144)*(1./289.)) )
		{
		case 2:
			cB |= (0xC0 >> cN);
			pB += 2;
			tot += pB[0] + pB[1];
			break;
		case 4:
			cB = (cB & (0x3F3F >> cN)) + (0x80 >> cN);
			pB += 2;
			tot += pB[0] + pB[1];
			break;
		case 6:
			cB = (cB & (0x3F3F >> cN)) + (0x40 >> cN);
			pB += 2;
			tot += pB[0] + pB[1];
			break;
		case 8:
			cB &= (0x3F3F >> cN);
			break;
		default:
			return;
		}
		pB+=2;
		if (pB > pFrameEnd)
			return;
		if (tot < 3000 || tot > 4161)
			return;
		if (nMin > tot)
			nMin = tot;
		if (nMax < tot)
			nMax = tot;
	}
	if (pB != pFrameEnd)
		return;
	strcpy(pProtocol, "Grundig16");
	if (nFreq < 33000) strcat(pProtocol, "-30");
	
	*pDevice = getMsb(9,7);
	*pOBC = getMsb(1,8);
	int hx = getMsb(2,8);
	*pHex = ((hx & 0x55)<<1) + (((hx>>1)^hx) & 0x55);
//	sprintf(pMisc, "T=%d tot=%.0f U=%.0f_%.0f", getMsb(0,1), nTotDur, nMin, nMax);
	sprintf(pMisc, "T=%d", getMsb(0,1));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq 0x40(%rdi), %rax
movss 0x45df(%rip), %xmm0     # 0x125f0
ucomiss (%rax), %xmm0
jbe 0xe01b
popq %rbx
popq %r14
popq %rbp
retq
movq %rdi, %rbx
movss 0x98(%rdi), %xmm0
movss 0x466e(%rip), %xmm1     # 0x1269c
ucomiss %xmm0, %xmm1
ja 0xe016
ucomiss 0x4666(%rip), %xmm0     # 0x126a0
ja 0xe016
movl 0x48(%rbx), %eax
addl $-0x13, %eax
cmpl $-0x9, %eax
jb 0xe016
movq 0x38(%rbx), %rdx
leaq 0xa0(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0xa0(%rbx)
movq %rdx, 0xc8(%rbx)
addq $0xc, %rdx
movq $0x0, 0xc0(%rbx)
xorl %ecx, %ecx
movss 0x4628(%rip), %xmm0     # 0x126a4
movsd 0x4424(%rip), %xmm1     # 0x124a8
leaq 0x4725(%rip), %rsi      # 0x127b0
movss 0x4615(%rip), %xmm2     # 0x126a8
movss 0x44a9(%rip), %xmm3     # 0x12544
movss (%rdx), %xmm4
movaps %xmm4, %xmm5
addss %xmm0, %xmm5
cvtss2sd %xmm5, %xmm5
mulsd %xmm1, %xmm5
cvttsd2si %xmm5, %r9d
xorl %r8d, %r8d
addl $-0x2, %r9d
cmpl $0x6, %r9d
ja 0xe16a
addss 0x4(%rdx), %xmm4
movl %ecx, %edi
sarl $0x3, %edi
movslq %edi, %rdi
andl $0x6, %ecx
movslq (%rsi,%r9,4), %r9
addq %rsi, %r9
jmpq *%r9
movl $0xc0, %r8d
shrl %cl, %r8d
orb %r8b, (%rax,%rdi)
jmp 0xe127
movl $0x3f3f, %r8d           # imm = 0x3F3F
shrl %cl, %r8d
movzbl (%rax,%rdi), %r9d
andl %r9d, %r8d
movl $0x40, %r9d
jmp 0xe11d
movl $0x3f3f, %r8d           # imm = 0x3F3F
shrl %cl, %r8d
movzbl (%rax,%rdi), %r9d
andl %r9d, %r8d
movl $0x80, %r9d
shrl %cl, %r9d
addl %r8d, %r9d
movb %r9b, (%rax,%rdi)
movss 0x8(%rdx), %xmm5
addss 0xc(%rdx), %xmm5
addq $0x8, %rdx
addss %xmm5, %xmm4
jmp 0xe148
movl $0x3f3f, %r8d           # imm = 0x3F3F
shrl %cl, %r8d
andb %r8b, (%rax,%rdi)
addq $0x8, %rdx
cmpq 0x40(%rbx), %rdx
jbe 0xe157
xorl %r8d, %r8d
jmp 0xe16a
movaps %xmm2, %xmm5
cmpnltps %xmm4, %xmm5
cmpnltps %xmm3, %xmm4
andps %xmm5, %xmm4
movd %xmm4, %r8d
testb $0x1, %r8b
je 0xe016
movl 0xc0(%rbx), %edi
leal 0x2(%rdi), %ecx
movl %ecx, 0xc0(%rbx)
cmpl $0xe, %edi
jl 0xe09b
cmpq 0x40(%rbx), %rdx
jne 0xe016
movq 0x148(%rbx), %rax
movabsq $0x316769646e757247, %rcx # imm = 0x316769646E757247
movq %rcx, (%rax)
movw $0x36, 0x8(%rax)
cmpl $0x80e7, 0x2c(%rbx)     # imm = 0x80E7
jg 0xe1d0
movq 0x148(%rbx), %r14
movq %r14, %rdi
callq 0x2090
movl $0x30332d, (%r14,%rax)  # imm = 0x30332D
movzbl 0xa1(%rbx), %eax
andl $0x7f, %eax
movq 0x160(%rbx), %rcx
movl %eax, (%rcx)
movb 0xa0(%rbx), %al
movb 0xa1(%rbx), %cl
shrb $0x7, %cl
addb %al, %al
orb %cl, %al
movzbl %al, %eax
movq 0x170(%rbx), %rcx
movl %eax, (%rcx)
movb 0xa0(%rbx), %al
movb 0xa1(%rbx), %cl
shrb $0x6, %cl
shlb $0x2, %al
orb %cl, %al
movzbl %al, %eax
movl %eax, %ecx
shrl %ecx
xorl %eax, %ecx
andl $0x55, %eax
andl $0x55, %ecx
leal (%rcx,%rax,2), %eax
movq 0x178(%rbx), %rcx
movl %eax, (%rcx)
movq 0x150(%rbx), %rdi
movzbl 0xa0(%rbx), %edx
shrl $0x7, %edx
leaq 0x4c51(%rip), %rsi      # 0x12e9a
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
jmp 0x2060