// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rdi, %rbx
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rdx
movups 0x28(%rbp), %xmm0
movq 0x40(%rbp), %rdi
movq 0x38(%rbp), %r14
movq 0x10(%rbp), %r10
movq %rsi, (%rbx)
xorl %r11d, %r11d
movq %r11, 0x8(%rbx)
movl %r8d, 0x20(%rbx)
movl %r9d, 0x24(%rbx)
movl %ecx, 0x30(%rbx)
movq %r10, 0x148(%rbx)
movq %r14, 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 %r11d, 0x190(%rbx)
leaq 0x1a0(%rbx), %rcx
movl %r11d, 0x1a0(%rbx)
movq %r11, 0x1a8(%rbx)
movq %rcx, 0x1b0(%rbx)
movq %rcx, 0x1b8(%rbx)
movq %r11, 0x1c0(%rbx)
movabsq $0x4e6e6b284e6e6b28, %rcx # imm = 0x4E6E6B284E6E6B28
movq %rcx, 0x1c8(%rbx)
movl $0x4e6e6b28, 0x1d0(%rbx) # imm = 0x4E6E6B28
movq %r11, 0x1dc(%rbx)
movl %r11d, 0x1e4(%rbx)
movl %r11d, 0x60(%rbx)
movq %r11, 0x68(%rbx)
movq $-0x1, 0x88(%rbx)
movl %r11d, 0x7c(%rbx)
movq %r11, 0xb8(%rbx)
movl %r11d, 0x70(%rbx)
testl %r9d, %r9d
jle 0x24e2
movl $0x1, 0x64(%rbx)
movl (%rdx), %ecx
movl %ecx, %edx
negl %edx
xorl %r11d, %r11d
cmpl $-0x1, %ecx
cmovll %edx, %r11d
jmp 0x24ed
xorl %ecx, %ecx
cmpl $-0x1, (%rdx)
setl %cl
movl %ecx, 0x64(%rbx)
movl %r11d, 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), %r14d
movq %r11, -0x60(%rbp)
leal (%r11,%r14), %r15d
movq %r9, -0x38(%rbp)
leal (%r15,%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
leal (%r14,%r14), %edx
addl %r15d, %r15d
movq %r15, -0x58(%rbp)
movq %rax, 0x8(%rbx)
testl %r14d, %r14d
jle 0x258c
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 0x2574
movslq %edx, %r14
leaq (,%r14,4), %rdi
addq %r13, %rdi
movq -0x40(%rbp), %rax
leal (%rax,%rax), %eax
cltq
movq %rax, -0x48(%rbp)
leaq (%r13,%rax,4), %rsi
movq -0x38(%rbp), %rax
leal (%rax,%rax), %r15d
movslq %r15d, %rax
movq %rax, -0x50(%rbp)
movl %edx, -0x2c(%rbp)
leaq (,%rax,4), %rdx
callq 0x20e0
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
cmpl %edx, -0x2c(%rbp)
jge 0x25fd
movslq %edx, %rax
leaq (,%rsi,4), %rcx
addq %r13, %rcx
xorps %xmm0, %xmm0
cvtsi2ssl (%r12,%r14,4), %xmm0
movss %xmm0, (%rcx,%r14,4)
incq %r14
cmpq %r14, %rax
jne 0x25e6
movslq %edx, %rax
leaq (,%rax,4), %rax
addq %r13, %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax,%rsi,4)
movq -0x60(%rbp), %rax
testl %eax, %eax
jle 0x2642
addl -0x40(%rbp), %r15d
movl %r15d, 0x6c(%rbx)
addl %eax, %r15d
movl %r15d, 0x20(%rbx)
movq $0x0, 0x24(%rbx)
addl %r15d, %r15d
movslq %r15d, %rax
movl $0x497423f0, -0x4(%r13,%rax,4) # imm = 0x497423F0
jmp 0x264c
cmpl $0x0, -0x38(%rbp)
movq -0x48(%rbp), %rax
je 0x2637
movl $0x10, %edi
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, %r14
addq $0x198, %rbx            # imm = 0x198
movq %rbx, %rdi
callq 0x11524
movq %r14, %rdi
callq 0x2210
nop