// File: probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::Signal(unsigned int*, int*, int, int, int, char*, int*, int*, int*, int*, char*, char*)
Signal::Signal(
		unsigned int* p_Context,
		int* p_Bursts,
		int n_Freq,
		int n_Single,
		int n_Repeat,
		char* p_Protocol,
		int* p_Device,
		int* p_SubDevice,
		int* p_OBC,
		int* p_Hex,
		char* p_Misc,
		char* p_Error) :
	pContext(p_Context),
	nFreq_in(n_Freq),
	nSingle(n_Single),
	nRepeat(n_Repeat),
	pProtocol(p_Protocol),
	pDevice(p_Device),
	pSubDevice(p_SubDevice),
	pOBC(p_OBC),
	pHex(p_Hex),
	pMisc(p_Misc),
	pError(p_Error),
	pDuration(NULL)
{
	// GD 2009 Start
	nFrameCount = 0;
	nDittos = 0;
	nNote_out = -1;		// unset
	nAuxNote_out = -1;	// unset
	nNonSpurious = 0;	// Only valid when >0
	bXMPHalfValid = false;
	AminoToggleDetected = false; 
	ZaptorToggleDetected = false;
	bInitLeadIn = false;
	// Don't output frame count if repeat or extra frames present.  If neither are present
	// then *pDevice = -2 can still be used to suppress frame count, as *pDevice is only
	// taken as carrying nExtra if nRepeat is nonzero.
	bSuppressCount = nRepeat > 0 || *pDevice < -1;
	// Older versions of IR.exe add extra count to single count when no repeat frames.
	// This is retained for compatibility, so a value of *pDevice , -1 is ignored unless
	// nRepeat > 0.
	nExtra = nRepeat > 0 && *pDevice < -1 ? - *pDevice : 0;
	// Additional info can be provided or returned in Context[] if its length is carried in 
	// pSubDevice and is > 2.  The maximum supported length is 18, due to the form of the
	// returned handshake.  See decode2() for details of the use of the additional fields.
	nContextLength = *pSubDevice < -1 ? - *pSubDevice : 2;
	// The only additional incoming data in an enhanced context is a pointer, potentially 64-bit,
	// to an array of carrier cycle counts corresponding to the timings in p_Bursts[].  This is
	// only used by IRScope, which uses nRepeat=nExtra=0, so it does not need extending in the
	// way that pDuration[] is extended from p_Bursts.
	pCounts = nContextLength > 7 ? reinterpret_cast<short int*>(*(int64_t *)(&pContext[6])) : NULL;
	// GD 2009 End

	int nSR = (nRepeat+nSingle)*2;
//	pDuration = new float[nRepeat*2 + nSR + 4];
	int nSRE = nSR + nExtra*2;	// GD 2009
	pDuration = new float[nRepeat*2 + nSRE + 4];		// GD 2009
	for (int ndx=0; ndx<nSR; ++ndx)
	{
		pDuration[ndx] = p_Bursts[ndx];
	}
	memcpy(pDuration+nSR, pDuration+2*nSingle, nRepeat*2*sizeof(float));
	// GD 2009 Start
	for (int ndx=nSR; ndx<nSRE; ++ndx)
	{
		pDuration[ndx+2*nRepeat] = p_Bursts[ndx];
	}
	// GD 2009 End
	// memset(pDuration+nSR+2*nRepeat, 0, 4*sizeof(float));
	memset(pDuration+nSRE+2*nRepeat, 0, 4*sizeof(float));	// GD 2009

	// GD 2009  Start.  If nExtra > 0 treat all bursts as single
	if ( nExtra > 0 )
	{
		nNonSpurious = nSingle + 2*nRepeat;	// Extra bursts can be spurious
		nSingle += 2*nRepeat + nExtra;
		nRepeat = 0;
		nExtra = 0;
	}
	// GD 2009 End

	if ( nRepeat==0 )
		pDuration[nSingle*2-1] = 999999.; 
	pSuffix = new char[16];
	strcpy(pSuffix, "" );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq %rax, (%rdi)
movq $0x0, 0x8(%rdi)
movl -0x20(%rbp), %eax
movl %eax, 0x20(%rdi)
movl -0x24(%rbp), %eax
movl %eax, 0x24(%rdi)
movl -0x1c(%rbp), %eax
movl %eax, 0x30(%rdi)
movq 0x10(%rbp), %rax
movq %rax, 0x148(%rdi)
movq 0x38(%rbp), %rax
movq %rax, 0x150(%rdi)
movq 0x40(%rbp), %rax
movq %rax, 0x158(%rdi)
movq 0x18(%rbp), %rax
movq %rax, 0x160(%rdi)
movq 0x20(%rbp), %rax
movq %rax, 0x168(%rdi)
movq 0x28(%rbp), %rax
movq %rax, 0x170(%rdi)
movq 0x30(%rbp), %rax
movq %rax, 0x178(%rdi)
addq $0x180, %rdi            # imm = 0x180
callq 0x18110
movq -0x50(%rbp), %rdi
addq $0x18c, %rdi            # imm = 0x18C
callq 0x18130
movq -0x50(%rbp), %rdi
addq $0x198, %rdi            # imm = 0x198
movq %rdi, -0x58(%rbp)
callq 0x18150
movq -0x50(%rbp), %rcx
movl $0x0, 0x60(%rcx)
movl $0x0, 0x68(%rcx)
movl $0xffffffff, 0x88(%rcx) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x8c(%rcx) # imm = 0xFFFFFFFF
movl $0x0, 0x6c(%rcx)
movl $0x0, 0x7c(%rcx)
movl $0x0, 0xb8(%rcx)
movl $0x0, 0xbc(%rcx)
movl $0x0, 0x70(%rcx)
movb $0x1, %al
cmpl $0x0, 0x24(%rcx)
movb %al, -0x45(%rbp)
jg 0x24f2
movq -0x50(%rbp), %rax
movq 0x160(%rax), %rax
cmpl $-0x1, (%rax)
setl %al
movb %al, -0x45(%rbp)
movq -0x50(%rbp), %rax
movb -0x45(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
movl %ecx, 0x64(%rax)
cmpl $0x0, 0x24(%rax)
jle 0x252c
movq -0x50(%rbp), %rax
movq 0x160(%rax), %rax
cmpl $-0x1, (%rax)
jge 0x252c
movq -0x50(%rbp), %rax
movq 0x160(%rax), %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x5c(%rbp)
jmp 0x2533
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0x2533
movq -0x50(%rbp), %rax
movl -0x5c(%rbp), %ecx
movl %ecx, 0x28(%rax)
movq 0x168(%rax), %rax
cmpl $-0x1, (%rax)
jge 0x255d
movq -0x50(%rbp), %rax
movq 0x168(%rax), %rcx
xorl %eax, %eax
subl (%rcx), %eax
movl %eax, -0x60(%rbp)
jmp 0x2567
movl $0x2, %eax
movl %eax, -0x60(%rbp)
jmp 0x2567
movq -0x50(%rbp), %rax
movl -0x60(%rbp), %ecx
movl %ecx, 0x74(%rax)
cmpl $0x7, 0x74(%rax)
jle 0x2588
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x2590
xorl %eax, %eax
movq %rax, -0x68(%rbp)
jmp 0x2590
movq -0x50(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, 0x90(%rax)
movl 0x20(%rax), %edx
movl 0x24(%rax), %ecx
addl %edx, %ecx
addl %ecx, %ecx
movl %ecx, -0x28(%rbp)
movl -0x28(%rbp), %esi
movl 0x28(%rax), %ecx
movl %ecx, %edx
movl %esi, %ecx
leal (%rcx,%rdx,2), %ecx
movl %ecx, -0x2c(%rbp)
movl 0x24(%rax), %eax
movl -0x2c(%rbp), %edx
movl %eax, %ecx
movl %edx, %eax
leal 0x4(%rax,%rcx,2), %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x2030
movq %rax, -0x70(%rbp)
jmp 0x25ed
movq -0x50(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x264b
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x40(%rbp), %rdx
cvtsi2ssl (%rcx,%rdx,4), %xmm0
movq 0x8(%rax), %rax
movslq -0x40(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x2600
movq -0x58(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x181a0
jmp 0x278b
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0x28(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movq 0x8(%rax), %rsi
movl 0x20(%rax), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rsi
movl 0x24(%rax), %eax
shll %eax
movslq %eax, %rdx
shlq $0x2, %rdx
callq 0x2100
movl -0x28(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x26c2
movq -0x50(%rbp), %rdx
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
cvtsi2ssl (%rax,%rcx,4), %xmm0
movq 0x8(%rdx), %rax
movl -0x44(%rbp), %ecx
movl 0x24(%rdx), %edx
shll %edx
addl %edx, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2688
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0x2c(%rbp), %rcx
shlq $0x2, %rcx
addq %rcx, %rdi
movl 0x24(%rax), %eax
shll %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x20c0
movq -0x50(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jle 0x2726
movq -0x50(%rbp), %rax
movl 0x20(%rax), %ecx
movl 0x24(%rax), %edx
shll %edx
addl %edx, %ecx
movl %ecx, 0x6c(%rax)
movl 0x24(%rax), %ecx
shll %ecx
addl 0x28(%rax), %ecx
addl 0x20(%rax), %ecx
movl %ecx, 0x20(%rax)
movl $0x0, 0x24(%rax)
movl $0x0, 0x28(%rax)
movq -0x50(%rbp), %rax
cmpl $0x0, 0x24(%rax)
jne 0x2750
movq -0x50(%rbp), %rcx
movq 0x8(%rcx), %rax
movl 0x20(%rcx), %ecx
shll %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movss 0x178b9(%rip), %xmm0    # 0x1a004
movss %xmm0, (%rax,%rcx,4)
movl $0x10, %edi
callq 0x2030
movq %rax, -0x78(%rbp)
jmp 0x2760
movq -0x50(%rbp), %rax
movq -0x78(%rbp), %rcx
movq %rcx, 0xb0(%rax)
movq 0xb0(%rax), %rdi
leaq 0x18ab6(%rip), %rsi     # 0x1b233
callq 0x2120
addq $0x80, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x2220
nopw %cs:(%rax,%rax)