// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r12
movq %rdi, %rbx
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rdx
movups 0x28(%rbp), %xmm0
movq 0x40(%rbp), %rdi
movq 0x38(%rbp), %r11
movq 0x10(%rbp), %r10
movq %rsi, (%rbx)
xorl %r15d, %r15d
movq %r15, 0x8(%rbx)
movl %r8d, 0x20(%rbx)
movl %r9d, 0x24(%rbx)
movl %ecx, 0x30(%rbx)
movq %r10, 0x148(%rbx)
movq %r11, 0x150(%rbx)
movq %rdi, 0x158(%rbx)
movq %rdx, 0x160(%rbx)
movq %rax, 0x168(%rbx)
movups %xmm0, 0x170(%rbx)
movaps 0xfbcf(%rip), %xmm0     # 0x12010
movups %xmm0, 0x180(%rbx)
movl %r15d, 0x190(%rbx)
leaq 0x1a0(%rbx), %rcx
movl %r15d, 0x1a0(%rbx)
movq %r15, 0x1a8(%rbx)
movq %rcx, 0x1b0(%rbx)
movq %rcx, 0x1b8(%rbx)
movq %r15, 0x1c0(%rbx)
movabsq $0x4e6e6b284e6e6b28, %rcx # imm = 0x4E6E6B284E6E6B28
movq %rcx, 0x1c8(%rbx)
movl $0x4e6e6b28, 0x1d0(%rbx) # imm = 0x4E6E6B28
movq %r15, 0x1dc(%rbx)
movl %r15d, 0x1e4(%rbx)
movl %r15d, 0x60(%rbx)
movq %r15, 0x68(%rbx)
movq $-0x1, 0x88(%rbx)
movl %r15d, 0x7c(%rbx)
movq %r15, 0xb8(%rbx)
movl %r15d, 0x70(%rbx)
testl %r9d, %r9d
jle 0x24e2
movl $0x1, 0x64(%rbx)
movl (%rdx), %ecx
movl %ecx, %edx
negl %edx
xorl %r15d, %r15d
cmpl $-0x1, %ecx
cmovll %edx, %r15d
jmp 0x24ed
xorl %ecx, %ecx
cmpl $-0x1, (%rdx)
setl %cl
movl %ecx, 0x64(%rbx)
movl %r15d, 0x28(%rbx)
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmpl $-0x1, %eax
movl $0x2, %eax
cmovll %ecx, %eax
movl %eax, 0x74(%rbx)
cmpl $0x8, %eax
jl 0x2510
movq 0x18(%rsi), %rax
jmp 0x2512
xorl %eax, %eax
movq %rax, 0x90(%rbx)
movq %r8, -0x40(%rbp)
leal (%r9,%r8), %eax
movq %rax, -0x30(%rbp)
leal (%r15,%rax), %r14d
movq %r9, -0x38(%rbp)
leal (%r14,%r9), %eax
addl %eax, %eax
cltq
leaq 0x10(,%rax,4), %rcx
cmpl $-0x4, %eax
movq $-0x1, %rdi
cmovgeq %rcx, %rdi
callq 0x2030
movq %rax, %r13
movq %r15, -0x48(%rbp)
movq -0x30(%rbp), %rax
leal (%rax,%rax), %edx
addl %r14d, %r14d
movq %r14, -0x50(%rbp)
movq %r13, 0x8(%rbx)
testl %eax, %eax
jle 0x2592
cmpl $0x2, %edx
movl $0x1, %eax
cmovgel %edx, %eax
xorl %ecx, %ecx
xorps %xmm0, %xmm0
cvtsi2ssl (%r12,%rcx,4), %xmm0
movss %xmm0, (%r13,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x257a
movslq %edx, %r14
leaq (,%r14,4), %rdi
addq %r13, %rdi
movq -0x40(%rbp), %rax
addl %eax, %eax
cltq
leaq (,%rax,4), %rsi
addq %r13, %rsi
movq -0x38(%rbp), %rax
addl %eax, %eax
movq %rax, -0x38(%rbp)
movslq %eax, %r15
movl %edx, -0x30(%rbp)
leaq (,%r15,4), %rdx
callq 0x20e0
movq -0x50(%rbp), %rdx
cmpl %edx, -0x30(%rbp)
jge 0x25fe
movslq %edx, %rax
leaq (,%r15,4), %rcx
addq %r13, %rcx
xorps %xmm0, %xmm0
cvtsi2ssl (%r12,%r14,4), %xmm0
movss %xmm0, (%rcx,%r14,4)
incq %r14
cmpq %r14, %rax
jne 0x25e7
movslq %edx, %rax
leaq (,%rax,4), %rax
addq %r13, %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax,%r15,4)
movq -0x48(%rbp), %rcx
testl %ecx, %ecx
jle 0x2633
movq -0x38(%rbp), %rax
addl -0x40(%rbp), %eax
movl %eax, 0x6c(%rbx)
addl %ecx, %eax
movl %eax, 0x20(%rbx)
movq $0x0, 0x24(%rbx)
cmpl $0x0, 0x24(%rbx)
jne 0x2646
movslq 0x20(%rbx), %rax
movl $0x497423f0, -0x4(%r13,%rax,8) # imm = 0x497423F0
movl $0x10, %edi
callq 0x2030
movq %rax, 0xb0(%rbx)
movb $0x0, (%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
addq $0x198, %rbx            # imm = 0x198
movq %rbx, %rdi
callq 0x116c4
movq %r14, %rdi
callq 0x2210
nop