// File: /workspace/github_cpp_makefile_star2_O2/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), %r8
movss 0x44eb(%rip), %xmm0     # 0x115ec
ucomiss (%r8), %xmm0
jbe 0xd10c
popq %rbx
popq %r14
popq %rbp
retq
movq %rdi, %rbx
movss 0x98(%rdi), %xmm0
movss 0x457d(%rip), %xmm1     # 0x1169c
ucomiss %xmm0, %xmm1
ja 0xd107
ucomiss 0x4575(%rip), %xmm0     # 0x116a0
ja 0xd107
movl 0x48(%rbx), %eax
addl $-0x13, %eax
cmpl $-0x9, %eax
jb 0xd107
movq 0x38(%rbx), %rdx
leaq 0xa0(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0xa0(%rbx)
movq %rdx, 0xc8(%rbx)
andl $0x0, 0xc4(%rbx)
addq $0xc, %rdx
xorl %ecx, %ecx
movss 0x453b(%rip), %xmm0     # 0x116a4
movsd 0x4337(%rip), %xmm1     # 0x114a8
leaq 0x4638(%rip), %rsi      # 0x117b0
movss 0x43c4(%rip), %xmm2     # 0x11544
movss 0x4520(%rip), %xmm3     # 0x116a8
pushq $0x40
popq %rdi
movl %ecx, 0xc0(%rbx)
cmpl $0xf, %ecx
jg 0xd274
movss (%rdx), %xmm4
movaps %xmm4, %xmm5
addss %xmm0, %xmm5
cvtss2sd %xmm5, %xmm5
mulsd %xmm1, %xmm5
cvttsd2si %xmm5, %r9d
addl $-0x2, %r9d
cmpl $0x6, %r9d
ja 0xd107
addss 0x4(%rdx), %xmm4
movl %ecx, %r8d
sarl $0x3, %r8d
movslq %r8d, %r8
andl $0x6, %ecx
movslq (%rsi,%r9,4), %r9
addq %rsi, %r9
jmpq *%r9
movl $0xc0, %r9d
shrl %cl, %r9d
orb %r9b, (%rax,%r8)
jmp 0xd231
movl $0x3f3f, %r9d           # imm = 0x3F3F
shrl %cl, %r9d
movzbl (%rax,%r8), %r10d
andl %r10d, %r9d
movl $0x80, %r10d
jmp 0xd227
movl $0x3f3f, %r9d           # imm = 0x3F3F
shrl %cl, %r9d
andb %r9b, (%rax,%r8)
jmp 0xd243
movl $0x3f3f, %r9d           # imm = 0x3F3F
shrl %cl, %r9d
movzbl (%rax,%r8), %r10d
andl %r10d, %r9d
movl %edi, %r10d
shrl %cl, %r10d
addl %r9d, %r10d
movb %r10b, (%rax,%r8)
movss 0x8(%rdx), %xmm5
addss 0xc(%rdx), %xmm5
addq $0x8, %rdx
addss %xmm5, %xmm4
addq $0x8, %rdx
movq 0x40(%rbx), %r8
cmpq %r8, %rdx
ja 0xd107
ucomiss %xmm4, %xmm2
ja 0xd107
ucomiss %xmm3, %xmm4
ja 0xd107
movl 0xc0(%rbx), %ecx
addl $0x2, %ecx
jmp 0xd18b
cmpq %r8, %rdx
jne 0xd107
movq 0x148(%rbx), %rax
movabsq $0x316769646e757247, %rcx # imm = 0x316769646E757247
movq %rcx, (%rax)
movw $0x36, 0x8(%rax)
cmpl $0x80e7, 0x2c(%rbx)     # imm = 0x80E7
jg 0xd2b7
movq 0x148(%rbx), %r14
movq %r14, %rdi
callq 0x20a0
movl $0x30332d, (%r14,%rax)  # imm = 0x30332D
movzbl 0xa1(%rbx), %eax
andl $0x7f, %eax
movq 0x160(%rbx), %rcx
movl %eax, (%rcx)
pushq $0x1
popq %rsi
pushq $0x8
popq %r14
movq %rbx, %rdi
movl %r14d, %edx
callq 0xeb6a
movq 0x170(%rbx), %rcx
movl %eax, (%rcx)
pushq $0x2
popq %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0xeb6a
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 0x4b6e(%rip), %rsi      # 0x11e91
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
jmp 0x2060