// File: 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
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq 0x40(%rax), %rax
movss 0x6c78(%rip), %xmm0     # 0x1a138
ucomiss (%rax), %xmm0
jbe 0x134ca
jmp 0x13869
movq -0x38(%rbp), %rax
movss 0x6caa(%rip), %xmm0     # 0x1a180
ucomiss 0x98(%rax), %xmm0
ja 0x134f8
movq -0x38(%rbp), %rax
movss 0x98(%rax), %xmm0
movss 0x6c91(%rip), %xmm1     # 0x1a184
ucomiss %xmm1, %xmm0
jbe 0x134fd
jmp 0x13869
movq -0x38(%rbp), %rax
cmpl $0xa, 0x48(%rax)
jl 0x13511
movq -0x38(%rbp), %rax
cmpl $0x12, 0x48(%rax)
jle 0x13516
jmp 0x13869
movq -0x38(%rbp), %rdi
movq 0x38(%rdi), %rax
addq $0xc, %rax
movq %rax, -0x10(%rbp)
movss 0x6bc6(%rip), %xmm0     # 0x1a0f4
movss %xmm0, -0x14(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x18(%rbp)
callq 0x16180
movq -0x38(%rbp), %rax
movl $0x0, 0xc0(%rax)
movq -0x38(%rbp), %rax
cmpl $0x10, 0xc0(%rax)
jge 0x1377c
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movss (%rcx), %xmm0
movss 0x4(%rcx), %xmm1
addss %xmm1, %xmm0
movss %xmm0, -0x1c(%rbp)
movl 0xc0(%rax), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
leaq 0xa0(%rax,%rcx), %rcx
movq %rcx, -0x28(%rbp)
movl 0xc0(%rax), %eax
andl $0x6, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
movss 0x6bdb(%rip), %xmm1     # 0x1a188
addss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x7163(%rip), %xmm1     # 0x1a720
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x6, %eax
ja 0x136eb
movq -0x40(%rbp), %rax
leaq 0x7292(%rip), %rcx      # 0x1a874
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x2c(%rbp), %ecx
movl $0xc0, %edx
sarl %cl, %edx
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
movq -0x10(%rbp), %rax
addss 0x4(%rax), %xmm0
addss -0x1c(%rbp), %xmm0
movss %xmm0, -0x1c(%rbp)
jmp 0x136f0
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
movl -0x2c(%rbp), %ecx
movl $0x3f3f, %edx           # imm = 0x3F3F
sarl %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movl -0x2c(%rbp), %ecx
movl $0x80, %edx
sarl %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
movq -0x10(%rbp), %rax
addss 0x4(%rax), %xmm0
addss -0x1c(%rbp), %xmm0
movss %xmm0, -0x1c(%rbp)
jmp 0x136f0
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
movl -0x2c(%rbp), %ecx
movl $0x3f3f, %edx           # imm = 0x3F3F
sarl %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
movl -0x2c(%rbp), %ecx
movl $0x40, %edx
sarl %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movss (%rax), %xmm0
movq -0x10(%rbp), %rax
addss 0x4(%rax), %xmm0
addss -0x1c(%rbp), %xmm0
movss %xmm0, -0x1c(%rbp)
jmp 0x136f0
movl -0x2c(%rbp), %ecx
movl $0x3f3f, %edx           # imm = 0x3F3F
sarl %cl, %edx
movq -0x28(%rbp), %rax
movzbl (%rax), %ecx
andl %edx, %ecx
movb %cl, (%rax)
jmp 0x136f0
jmp 0x13869
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq 0x40(%rcx), %rax
jbe 0x1370f
jmp 0x13869
movss 0x6a75(%rip), %xmm0     # 0x1a18c
ucomiss -0x1c(%rbp), %xmm0
ja 0x1372f
movss -0x1c(%rbp), %xmm0
movss 0x6a66(%rip), %xmm1     # 0x1a190
ucomiss %xmm1, %xmm0
jbe 0x13734
jmp 0x13869
movss -0x14(%rbp), %xmm0
ucomiss -0x1c(%rbp), %xmm0
jbe 0x13749
movss -0x1c(%rbp), %xmm0
movss %xmm0, -0x14(%rbp)
movss -0x18(%rbp), %xmm1
movss -0x1c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x13762
movss -0x1c(%rbp), %xmm0
movss %xmm0, -0x18(%rbp)
jmp 0x13764
movq -0x38(%rbp), %rax
movl 0xc0(%rax), %ecx
addl $0x2, %ecx
movl %ecx, 0xc0(%rax)
jmp 0x1354e
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
cmpq 0x40(%rcx), %rax
je 0x1378f
jmp 0x13869
movq -0x38(%rbp), %rax
movq 0x148(%rax), %rdi
leaq 0x7850(%rip), %rsi      # 0x1aff1
callq 0x2120
movq -0x38(%rbp), %rax
cmpl $0x80e8, 0x2c(%rax)     # imm = 0x80E8
jge 0x137ca
movq -0x38(%rbp), %rax
movq 0x148(%rax), %rdi
leaq 0x7836(%rip), %rsi      # 0x1affb
callq 0x2230
movq -0x38(%rbp), %rdi
movl $0x9, %esi
movl $0x7, %edx
callq 0x15f50
movq -0x38(%rbp), %rdi
movl %eax, %ecx
movq 0x160(%rdi), %rax
movl %ecx, (%rax)
movl $0x1, %esi
movl $0x8, %edx
callq 0x15f50
movq -0x38(%rbp), %rdi
movl %eax, %ecx
movq 0x170(%rdi), %rax
movl %ecx, (%rax)
movl $0x2, %esi
movl $0x8, %edx
callq 0x15f50
movq -0x38(%rbp), %rdi
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %ecx
andl $0x55, %ecx
shll %ecx
movl -0x30(%rbp), %eax
sarl %eax
xorl -0x30(%rbp), %eax
andl $0x55, %eax
addl %eax, %ecx
movq 0x178(%rdi), %rax
movl %ecx, (%rax)
movq 0x150(%rdi), %rax
movq %rax, -0x48(%rbp)
xorl %esi, %esi
movl $0x1, %edx
callq 0x15f50
movq -0x48(%rbp), %rdi
movl %eax, %edx
leaq 0x774a(%rip), %rsi      # 0x1afac
movb $0x0, %al
callq 0x2060
addq $0x50, %rsp
popq %rbp
retq
nop