// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %rdx, %r15
movq %rdi, %rbx
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rdx
movq 0x20(%rbp), %rdi
movq 0x18(%rbp), %r10
movq 0x40(%rbp), %r11
movq 0x38(%rbp), %r14
movq 0x10(%rbp), %r12
movq %rsi, (%rbx)
andq $0x0, 0x8(%rbx)
movl %r8d, 0x20(%rbx)
movl %r9d, 0x24(%rbx)
movl %ecx, 0x30(%rbx)
movq %r12, 0x148(%rbx)
movq %r14, 0x150(%rbx)
movq %r11, 0x158(%rbx)
movq %r10, 0x160(%rbx)
movq %rdi, 0x168(%rbx)
movq %rdx, 0x170(%rbx)
movq %rax, 0x178(%rbx)
movaps 0xebe6(%rip), %xmm0     # 0x11010
movups %xmm0, 0x180(%rbx)
andl $0x0, 0x190(%rbx)
leaq 0x198(%rbx), %rdi
movq %rdi, -0x40(%rbp)
callq 0xffa8
andl $0x0, 0x60(%rbx)
andl $0x0, 0x68(%rbx)
orq $-0x1, 0x88(%rbx)
andq $0x0, 0x6c(%rbx)
andl $0x0, 0x7c(%rbx)
andq $0x0, 0xb8(%rbx)
movl 0x24(%rbx), %esi
testl %esi, %esi
jle 0x248e
movl $0x1, 0x64(%rbx)
movq 0x160(%rbx), %rax
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
xorl %edx, %edx
cmpl $-0x1, %eax
cmovll %ecx, %edx
jmp 0x24a2
movq 0x160(%rbx), %rax
xorl %ecx, %ecx
cmpl $-0x1, (%rax)
setl %cl
movl %ecx, 0x64(%rbx)
xorl %edx, %edx
movl %edx, 0x28(%rbx)
movq 0x168(%rbx), %rax
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmpl $-0x1, %eax
pushq $0x2
popq %rax
cmovll %ecx, %eax
movl %eax, 0x74(%rbx)
cmpl $0x8, %eax
jl 0x24cc
movq (%rbx), %rax
movq 0x18(%rax), %rax
jmp 0x24ce
xorl %eax, %eax
movq %rax, 0x90(%rbx)
movslq 0x20(%rbx), %rax
movq %rax, -0x38(%rbp)
leal (%rax,%rsi), %r13d
movq %rdx, -0x60(%rbp)
leal (%rdx,%r13), %r14d
movq %rsi, -0x30(%rbp)
leal (%r14,%rsi), %eax
addl %eax, %eax
cltq
leaq 0x10(,%rax,4), %rcx
cmpl $-0x4, %eax
pushq $-0x1
popq %rdi
cmovgeq %rcx, %rdi
callq 0x2030
movq %rax, %r12
addl %r13d, %r13d
addl %r14d, %r14d
movq %rax, 0x8(%rbx)
xorl %eax, %eax
testl %r13d, %r13d
movl $0x0, %ecx
cmovgl %r13d, %ecx
movq %r14, %rdx
cmpq %rax, %rcx
je 0x2540
cvtsi2ssl (%r15,%rax,4), %xmm0
movss %xmm0, (%r12,%rax,4)
incq %rax
jmp 0x252a
movslq %r13d, %r13
leaq (%r12,%r13,4), %rdi
movq -0x38(%rbp), %rax
leaq (%rax,%rax), %rcx
movq %rcx, -0x48(%rbp)
leaq (%r12,%rax,8), %rsi
movq -0x30(%rbp), %rax
addl %eax, %eax
movq %rax, -0x50(%rbp)
movslq %eax, %r14
movq %rdx, -0x58(%rbp)
leaq (,%r14,4), %rdx
callq 0x2100
movslq -0x58(%rbp), %rax
leaq (%r12,%r14,4), %rcx
movq -0x60(%rbp), %rdx
cmpq %rax, %r13
jge 0x2597
cvtsi2ssl (%r15,%r13,4), %xmm0
movss %xmm0, (%rcx,%r13,4)
incq %r13
jmp 0x2581
leaq (%r12,%rax,4), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax,%r14,4)
testl %edx, %edx
jle 0x25d1
movq -0x38(%rbp), %rcx
movq -0x50(%rbp), %rsi
leal (%rcx,%rsi), %eax
movl %eax, 0x6c(%rbx)
addl %esi, %edx
addl %ecx, %edx
movl %edx, 0x20(%rbx)
andq $0x0, 0x24(%rbx)
addl %edx, %edx
movslq %edx, %rax
movl $0x497423f0, -0x4(%r12,%rax,4) # imm = 0x497423F0
jmp 0x25db
cmpl $0x0, -0x30(%rbp)
movq -0x48(%rbp), %rax
je 0x25c6
pushq $0x10
popq %rdi
callq 0x2030
movq %rax, 0xb0(%rbx)
movb $0x0, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x40(%rbp), %rdi
callq 0x10368
movq %rbx, %rdi
callq 0x2230