// File: /workspace/github_cpp_makefile_star2_O3/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 0x45b9(%rip), %xmm0     # 0x125ec
ucomiss (%rax), %xmm0
jbe 0xe03d
popq %rbx
popq %r14
popq %rbp
retq
movq %rdi, %rbx
movss 0x98(%rdi), %xmm0
movss 0x464c(%rip), %xmm1     # 0x1269c
ucomiss %xmm0, %xmm1
ja 0xe038
ucomiss 0x4644(%rip), %xmm0     # 0x126a0
ja 0xe038
movl 0x48(%rbx), %eax
addl $-0x13, %eax
cmpl $-0x9, %eax
jb 0xe038
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 0x4606(%rip), %xmm0     # 0x126a4
movsd 0x4402(%rip), %xmm1     # 0x124a8
leaq 0x4703(%rip), %rsi      # 0x127b0
movss 0x448f(%rip), %xmm2     # 0x12544
movss 0x45eb(%rip), %xmm3     # 0x126a8
movss (%rdx), %xmm4
movaps %xmm4, %xmm5
addss %xmm0, %xmm5
cvtss2sd %xmm5, %xmm5
mulsd %xmm1, %xmm5
cvttsd2si %xmm5, %r8d
addl $-0x2, %r8d
cmpl $0x6, %r8d
ja 0xe038
addss 0x4(%rdx), %xmm4
movl %ecx, %edi
sarl $0x3, %edi
movslq %edi, %rdi
andl $0x6, %ecx
movslq (%rsi,%r8,4), %r8
addq %rsi, %r8
jmpq *%r8
movl $0xc0, %r8d
shrl %cl, %r8d
orb %r8b, (%rax,%rdi)
jmp 0xe155
movl $0x3f3f, %r8d           # imm = 0x3F3F
shrl %cl, %r8d
movzbl (%rax,%rdi), %r9d
andl %r9d, %r8d
movl $0x80, %r9d
jmp 0xe14b
movl $0x3f3f, %r8d           # imm = 0x3F3F
shrl %cl, %r8d
andb %r8b, (%rax,%rdi)
jmp 0xe167
movl $0x3f3f, %r8d           # imm = 0x3F3F
shrl %cl, %r8d
movzbl (%rax,%rdi), %r9d
andl %r9d, %r8d
movl $0x40, %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
addq $0x8, %rdx
movq 0x40(%rbx), %rdi
cmpq %rdi, %rdx
ja 0xe038
ucomiss %xmm4, %xmm2
ja 0xe038
ucomiss %xmm3, %xmm4
ja 0xe038
movl 0xc0(%rbx), %r8d
leal 0x2(%r8), %ecx
movl %ecx, 0xc0(%rbx)
cmpl $0xe, %r8d
jl 0xe0bd
cmpq %rdi, %rdx
jne 0xe038
movq 0x148(%rbx), %rax
movabsq $0x316769646e757247, %rcx # imm = 0x316769646E757247
movq %rcx, (%rax)
movw $0x36, 0x8(%rax)
cmpl $0x80e7, 0x2c(%rbx)     # imm = 0x80E7
jg 0xe1e8
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 0x4c30(%rip), %rsi      # 0x12e91
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
jmp 0x2060