// File: /workspace/github_cpp_makefile_star2_O3/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::WriteTDCData(unsigned long long, unsigned int*, double*)
void LMF_IO::WriteTDCData(unsigned __int64 timestamp, unsigned __int32 cnt[], double * d64TDC)
/////////////////////////////////////////////////////////////////
{
	unsigned __int16 dummy_uint16;
	double dummy_double;
	__int32 dummy_int32;

	if (!output_lmf || !OutputFileIsOpen) {
		errorflag = 10;
		return;
	}
	
	++uint64_number_of_written_events;

	WriteEventHeader(timestamp,cnt);

	__int32 i,j;
	__int32 ii = 0;
	if (DAQ_ID_output != DAQ_ID_SIMPLE) {
		for (i=0;i<number_of_channels_output;++i) {
			__int32 hits = cnt[i];
			if (hits > max_number_of_hits_output) hits = max_number_of_hits_output;
			if (data_format_in_userheader_output == 2) {
				dummy_uint16 = (unsigned __int16)(hits);
				*output_lmf << dummy_uint16;
				for (j=0;j<hits;++j) {
					dummy_uint16 = (unsigned __int16)(d64TDC[i*num_ions+j]+1.e-6);
					*output_lmf << dummy_uint16;
				}
				dummy_uint16 = 0;
				for (j=hits;j<max_number_of_hits_output;++j) *output_lmf << dummy_uint16;
			}
			if (data_format_in_userheader_output == 5) {
				dummy_double = double(hits);
				*output_lmf << dummy_double;
				for (j=0;j<hits;++j) 	*output_lmf << d64TDC[i*num_ions+j];
				dummy_double = 0.;
				for (j=hits;j<max_number_of_hits_output;++j) *output_lmf << dummy_double;
			}
			if (data_format_in_userheader_output == 10) {
				dummy_int32 = __int32(hits);
				*output_lmf << dummy_int32;
				for (j=0;j<hits;++j) {
					if (d64TDC[i*num_ions+j] >= 0.) ii =__int32(d64TDC[i*num_ions+j]+1.e-6);
					if (d64TDC[i*num_ions+j] <  0.) ii =__int32(d64TDC[i*num_ions+j]-1.e-6);
					*output_lmf << ii;
				}
				dummy_int32 = 0;
				for (j=hits;j<max_number_of_hits_output;++j) *output_lmf << dummy_int32;
			}
			if (data_format_in_userheader_output == LM_USERDEF) {
				dummy_uint16 = (unsigned __int16)(hits);
				*output_lmf << dummy_uint16;
				for (j=0;j<hits;++j) {
					if (d64TDC[i*num_ions+j] >= 0.) ii =__int32(d64TDC[i*num_ions+j]+1.e-6);
					if (d64TDC[i*num_ions+j] <  0.) ii =__int32(d64TDC[i*num_ions+j]-1.e-6);
					if (DAQ_ID_output != DAQ_ID_HM1 && DAQ_ID_output != DAQ_ID_TDC8 && DAQ_ID_output != DAQ_ID_2TDC8) *output_lmf << ii;
						else *output_lmf << (unsigned __int16)(ii);
				}
			}
		}
				if (DAQ_ID_output == DAQ_ID_TDC8HP && this->LMF_Version_output >= 9) {
					*output_lmf << ui64LevelInfo;
				}
				if (DAQ_ID_output == DAQ_ID_TDC8HP && this->LMF_Version_output >= 10) {
					*output_lmf << number_of_bytes_in_PostEventData;
					for (__int32 i=0;i<number_of_bytes_in_PostEventData;i++) *output_lmf << ui8_PostEventData[i];
		}
	}
	if (DAQ_ID_output == DAQ_ID_2TDC8 && number_of_channels2_output > 0) {
		for (i=number_of_channels_output;i<number_of_channels_output+number_of_channels2_output;++i) {
			__int32 hits = cnt[i];
			if (hits > max_number_of_hits2_output) hits = max_number_of_hits2_output;
			if (data_format_in_userheader_output == 2) {
				dummy_uint16 = (unsigned __int16)(hits);
				*output_lmf << dummy_uint16;
				for (j=0;j<hits;++j) {
					dummy_uint16 = (unsigned __int16)(d64TDC[i*num_ions+j]+1.e-6);
					*output_lmf << dummy_uint16;
				}
				dummy_uint16 = 0;
				for (j=hits;j<max_number_of_hits2_output;++j) *output_lmf << dummy_uint16;
			}
			if (data_format_in_userheader_output == 5) {
				dummy_double = double(hits);
				*output_lmf << dummy_double;
				for (j=0;j<hits;++j) *output_lmf << d64TDC[i*num_ions+j];
				dummy_double = 0.;
				for (j=hits;j<max_number_of_hits2_output;++j) *output_lmf << dummy_double;
			}
			if (data_format_in_userheader_output == 10) {
				*output_lmf <<__int32(hits);
				for (j=0;j<hits;++j) {
					if (d64TDC[i*num_ions+j] >= 0.) ii =__int32(d64TDC[i*num_ions+j]+1.e-6);
					if (d64TDC[i*num_ions+j] <  0.) ii =__int32(d64TDC[i*num_ions+j]-1.e-6);
					*output_lmf << ii;
				}
				dummy_int32 = 0;
				for (j=hits;j<max_number_of_hits2_output;++j) *output_lmf << dummy_int32;
			}
		}
	}

	if (DAQ_ID_output == DAQ_ID_SIMPLE) {
		unsigned __int32 channel;
		unsigned __int32 i;
		i = 0;
		for (channel=0;channel < (unsigned __int32)number_of_channels_output;++channel) i = i + cnt[channel] + (cnt[channel]>0 ? 1 : 0);
		if (data_format_in_userheader_output == 2)  {
			dummy_uint16 = (unsigned __int16)i;
			*output_lmf << dummy_uint16;
		}
		if (data_format_in_userheader_output == 10) *output_lmf << i;
		if (data_format_in_userheader_output == 2) {
			for (channel=0;channel < (unsigned __int32)number_of_channels_output;++channel) {
				if (cnt[channel]>0) {
					dummy_uint16 = (unsigned __int16)((channel << 8) + cnt[channel]);
					*output_lmf << dummy_uint16;
					for (i=0;i < cnt[channel]; ++i) {
						dummy_uint16 = (unsigned __int16)(d64TDC[channel*num_ions+i]);
						*output_lmf << dummy_uint16;
					}
				}
			}
		}
		if (data_format_in_userheader_output == 10) {
			for (channel=0;channel < (unsigned __int32)number_of_channels_output;++channel) {
				if (cnt[channel]>0) {
					dummy_int32 = __int32((channel << 24) + cnt[channel]);
					*output_lmf << dummy_int32;
					for (i=0;i<cnt[channel];++i) {
						dummy_int32 = __int32(d64TDC[channel*num_ions+i]);
						*output_lmf << dummy_int32;
					}
				}
			}
		}
	} // end if (DAQ_ID_output == DAQ_ID_SIMPLE)

	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r15
cmpq $0x0, 0x2b20(%rdi)
je 0xeee6
cmpb $0x0, 0x2b29(%r15)
je 0xeee6
movq %rcx, %rbx
movq %rdx, %r12
incq 0x2b10(%r15)
movq %r15, %rdi
callq 0xe24a
movl 0x28c(%r15), %eax
cmpl $0x65, %eax
je 0xf24a
cmpl $0x0, 0x2c4(%r15)
movq %r12, 0x30(%rsp)
jle 0xef00
xorl %ecx, %ecx
xorl %ebp, %ebp
movslq (%r12,%rcx,4), %rdx
movslq 0x2cc(%r15), %rax
cmpl %eax, %edx
movq %rax, 0x18(%rsp)
movl %eax, %r13d
movq %rdx, 0x10(%rsp)
cmovll %edx, %r13d
movl 0x294(%r15), %eax
movq %rcx, 0x20(%rsp)
movslq %ecx, %r14
cmpl $0x2, %eax
movl %r13d, 0x8(%rsp)
jne 0xeca1
movq 0x2b20(%r15), %rdi
movzwl %r13w, %esi
callq 0x13404
testl %r13d, %r13d
movsd 0x54b1(%rip), %xmm1     # 0x140d0
jle 0xec6f
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rax
cmpq %r12, %rax
cmovlq %rax, %r12
xorl %r13d, %r13d
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
addq %r13, %rax
movsd (%rbx,%rax,8), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x13404
movsd 0x5469(%rip), %xmm1     # 0x140d0
incq %r13
cmpl %r13d, %r12d
jne 0xec35
movl 0x8(%rsp), %r13d
movl %r13d, %r12d
cmpl 0x2cc(%r15), %r13d
jge 0xec9a
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x13404
incl %r12d
cmpl 0x2cc(%r15), %r12d
jl 0xec80
movl 0x294(%r15), %eax
cmpl $0x5, %eax
jne 0xed2b
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13618
testl %r13d, %r13d
jle 0xecfe
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rax
cmpq %r12, %rax
cmovlq %rax, %r12
xorl %r13d, %r13d
movq 0x2b20(%r15), %rdi
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
addq %r13, %rax
movsd (%rbx,%rax,8), %xmm0
callq 0x13618
incq %r13
cmpl %r13d, %r12d
jne 0xecd7
movl 0x8(%rsp), %r13d
movl %r13d, %r12d
cmpl 0x2cc(%r15), %r13d
jge 0xed2b
movq 0x2b20(%r15), %rdi
xorpd %xmm0, %xmm0
callq 0x13618
incl %r12d
cmpl 0x2cc(%r15), %r12d
jl 0xed0f
movl 0x294(%r15), %eax
cmpl $0xa, %eax
jne 0xedec
movq 0x2b20(%r15), %rdi
movl %r13d, %esi
callq 0x1365e
testl %r13d, %r13d
jle 0xedba
movq 0x18(%rsp), %r13
movq 0x10(%rsp), %rax
cmpq %r13, %rax
cmovlq %rax, %r13
xorl %r12d, %r12d
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
addq %r12, %rax
movsd (%rbx,%rax,8), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm0, %xmm1
addsd 0x5346(%rip), %xmm1     # 0x140d0
cvttsd2si %xmm1, %eax
cmovbl %ebp, %eax
ucomisd %xmm0, %xmm2
addsd 0x533b(%rip), %xmm0     # 0x140d8
cvttsd2si %xmm0, %ebp
cmovbel %eax, %ebp
movq 0x2b20(%r15), %rdi
movl %ebp, %esi
callq 0x1365e
incq %r12
cmpl %r12d, %r13d
jne 0xed63
movl 0x8(%rsp), %r13d
movl %r13d, %r12d
cmpl 0x2cc(%r15), %r13d
jge 0xede5
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x1365e
incl %r12d
cmpl 0x2cc(%r15), %r12d
jl 0xedcb
movl 0x294(%r15), %eax
cmpl $-0x1, %eax
jne 0xeec0
movq 0x2b20(%r15), %rdi
movzwl %r13w, %esi
callq 0x13404
testl %r13d, %r13d
jle 0xeec0
movq 0x18(%rsp), %r13
movq 0x10(%rsp), %rax
cmpq %r13, %rax
cmovlq %rax, %r13
xorl %r12d, %r12d
movsd 0x52a6(%rip), %xmm2     # 0x140d0
xorpd %xmm3, %xmm3
movsd 0x52a2(%rip), %xmm4     # 0x140d8
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
addq %r12, %rax
movsd (%rbx,%rax,8), %xmm0
ucomisd %xmm3, %xmm0
movapd %xmm0, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
cmovbl %ebp, %eax
ucomisd %xmm0, %xmm3
addsd %xmm4, %xmm0
cvttsd2si %xmm0, %ebp
cmovbel %eax, %ebp
movl 0x28c(%r15), %eax
cmpl $0x5, %eax
ja 0xee92
movl $0x26, %ecx
btl %eax, %ecx
jae 0xee92
movq 0x2b20(%r15), %rdi
movzwl %bp, %esi
callq 0x13404
jmp 0xeea0
movq 0x2b20(%r15), %rdi
movl %ebp, %esi
callq 0x1365e
incq %r12
cmpl %r12d, %r13d
movsd 0x5222(%rip), %xmm2     # 0x140d0
xorpd %xmm3, %xmm3
movsd 0x521e(%rip), %xmm4     # 0x140d8
jne 0xee36
movq 0x20(%rsp), %rcx
incq %rcx
movslq 0x2c4(%r15), %rax
cmpq %rax, %rcx
movq 0x30(%rsp), %r12
jl 0xebc9
movl 0x28c(%r15), %eax
jmp 0xef02
movl $0xa, 0x12e0(%r15)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
cmpl $0x8, %eax
sete %dl
movl 0x12a8(%r15), %ecx
cmpl $0x9, %ecx
setge %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xef40
movq 0x2b20(%r15), %rdi
movq 0x2d8(%r15), %rsi
callq 0x13448
movl 0x28c(%r15), %eax
movl 0x12a8(%r15), %ecx
cmpl $0x8, %eax
jne 0xefba
cmpl $0xa, %ecx
jl 0xefba
movq 0x2b20(%r15), %rdi
movl 0x1280(%r15), %esi
callq 0x1365e
cmpl $0x0, 0x1280(%r15)
jle 0xefae
xorl %r14d, %r14d
movq 0x2b20(%r15), %r12
movsbl 0x2e0(%r15,%r14), %edi
movq (%r12), %rsi
callq 0x2190
movq 0x10(%r12), %rcx
movq 0x20(%r12), %rax
incq %rax
movq %rax, 0x20(%r12)
cmpq %rax, %rcx
jae 0xef9f
movq %rax, 0x10(%r12)
incq %r14
movslq 0x1280(%r15), %rax
cmpq %rax, %r14
jl 0xef6a
movl 0x28c(%r15), %eax
movq 0x30(%rsp), %r12
cmpl $0x5, %eax
jne 0xf241
cmpl $0x0, 0x2c8(%r15)
jle 0xeef1
movslq 0x2c4(%r15), %rsi
movl 0x2d0(%r15), %edi
movl %edi, %eax
movq %rbx, 0x28(%rsp)
movslq (%r12,%rsi,4), %rcx
cmpl %edi, %ecx
movl %edi, 0x20(%rsp)
movl %edi, %r12d
movq %rcx, 0x10(%rsp)
cmovll %ecx, %r12d
movl 0x294(%r15), %ecx
movq %rsi, 0x18(%rsp)
movslq %esi, %r13
cmpl $0x2, %ecx
jne 0xf0be
movq 0x2b20(%r15), %rdi
movzwl %r12w, %esi
callq 0x13404
testl %r12d, %r12d
movsd 0x50a1(%rip), %xmm1     # 0x140d0
jle 0xf086
movslq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rax
cmpq %rax, %rsi
cmovgeq %rax, %rsi
movq %rsi, 0x8(%rsp)
xorl %r14d, %r14d
movslq 0x2b74(%r15), %rax
imulq %r13, %rax
addq %r14, %rax
movsd (%rbx,%rax,8), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x13404
movsd 0x5054(%rip), %xmm1     # 0x140d0
incq %r14
cmpl %r14d, 0x8(%rsp)
jne 0xf04a
movl 0x2d0(%r15), %eax
movl %r12d, %r14d
cmpl %eax, %r12d
jge 0xf0b2
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x13404
incl %r14d
movl 0x2d0(%r15), %eax
cmpl %eax, %r14d
jl 0xf095
movl 0x294(%r15), %ecx
movq 0x28(%rsp), %rbx
cmpl $0x5, %ecx
jne 0xf150
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13618
testl %r12d, %r12d
jle 0xf122
movslq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rax
cmpq %rax, %rsi
cmovgeq %rax, %rsi
movq %rsi, 0x8(%rsp)
xorl %r14d, %r14d
movq 0x2b20(%r15), %rdi
movslq 0x2b74(%r15), %rax
imulq %r13, %rax
addq %r14, %rax
movsd (%rbx,%rax,8), %xmm0
callq 0x13618
incq %r14
cmpl %r14d, 0x8(%rsp)
jne 0xf0f9
movl 0x2d0(%r15), %eax
movl %r12d, %r14d
cmpl %eax, %r12d
jge 0xf150
movq 0x2b20(%r15), %rdi
xorpd %xmm0, %xmm0
callq 0x13618
incl %r14d
movl 0x2d0(%r15), %eax
cmpl %eax, %r14d
jl 0xf131
cmpl $0xa, 0x294(%r15)
jne 0xf211
movq 0x2b20(%r15), %rdi
movl %r12d, %esi
callq 0x1365e
testl %r12d, %r12d
jle 0xf200
movslq 0x20(%rsp), %rax
movq 0x10(%rsp), %r14
cmpq %r14, %rax
cmovlq %rax, %r14
movq %r13, 0x8(%rsp)
xorl %r13d, %r13d
movq 0x28(%rsp), %rbx
movslq 0x2b74(%r15), %rax
imulq 0x8(%rsp), %rax
addq %r13, %rax
movsd (%rbx,%rax,8), %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
movapd %xmm0, %xmm1
addsd 0x4f13(%rip), %xmm1     # 0x140d0
cvttsd2si %xmm1, %eax
cmovbl %ebp, %eax
ucomisd %xmm0, %xmm2
addsd 0x4f08(%rip), %xmm0     # 0x140d8
cvttsd2si %xmm0, %ebp
cmovbel %eax, %ebp
movq 0x2b20(%r15), %rdi
movl %ebp, %esi
callq 0x1365e
incq %r13
cmpl %r13d, %r14d
jne 0xf194
jmp 0xf200
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x1365e
incl %r12d
movl 0x2d0(%r15), %eax
cmpl %eax, %r12d
jl 0xf1ef
movq 0x28(%rsp), %rbx
movq 0x18(%rsp), %rsi
incq %rsi
movslq 0x2c4(%r15), %rcx
movslq 0x2c8(%r15), %rdx
addq %rcx, %rdx
movl %eax, %edi
cmpq %rdx, %rsi
movq 0x30(%rsp), %r12
jl 0xefe6
movl 0x28c(%r15), %eax
cmpl $0x65, %eax
jne 0xeef1
movl 0x2c4(%r15), %eax
testq %rax, %rax
je 0xf270
xorl %ecx, %ecx
xorl %ebp, %ebp
movl (%r12,%rcx,4), %edx
addl %edx, %ebp
cmpl $0x1, %edx
sbbl $-0x1, %ebp
incq %rcx
cmpq %rcx, %rax
jne 0xf25a
jmp 0xf272
xorl %ebp, %ebp
movl 0x294(%r15), %eax
cmpl $0x2, %eax
jne 0xf294
movq 0x2b20(%r15), %rdi
movzwl %bp, %esi
callq 0x13404
movl 0x294(%r15), %eax
cmpl $0xa, %eax
jne 0xf2ae
movq 0x2b20(%r15), %rdi
movl %ebp, %esi
callq 0x13378
movl 0x294(%r15), %eax
movl 0x2c4(%r15), %ecx
cmpl $0x2, %eax
jne 0xf32c
testl %ecx, %ecx
je 0xeef1
xorl %r14d, %r14d
movl (%r12,%r14,4), %eax
testl %eax, %eax
je 0xf316
movl %r14d, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x13404
cmpl $0x0, (%r12,%r14,4)
je 0xf316
xorl %ebp, %ebp
movl 0x2b74(%r15), %eax
imull %r14d, %eax
addl %ebp, %eax
cvttsd2si (%rbx,%rax,8), %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x13404
incl %ebp
cmpl (%r12,%r14,4), %ebp
jb 0xf2ed
incq %r14
movl 0x2c4(%r15), %ecx
cmpq %rcx, %r14
jb 0xf2c5
movl 0x294(%r15), %eax
cmpl $0xa, %eax
sete %al
testl %ecx, %ecx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xeef1
xorl %r14d, %r14d
movl (%r12,%r14,4), %esi
testl %esi, %esi
je 0xf390
movl %r14d, %eax
shll $0x18, %eax
addl %eax, %esi
movq 0x2b20(%r15), %rdi
callq 0x1365e
cmpl $0x0, (%r12,%r14,4)
je 0xf390
xorl %ebp, %ebp
movl 0x2b74(%r15), %eax
imull %r14d, %eax
addl %ebp, %eax
cvttsd2si (%rbx,%rax,8), %esi
movq 0x2b20(%r15), %rdi
callq 0x1365e
incl %ebp
cmpl (%r12,%r14,4), %ebp
jb 0xf36a
incq %r14
movl 0x2c4(%r15), %eax
cmpq %rax, %r14
jb 0xf345
jmp 0xeef1