// File: /workspace/github_cpp_makefile_star2_O3/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::WriteTDCData(unsigned long long, unsigned int*, unsigned short*)
void LMF_IO::WriteTDCData(unsigned __int64 timestamp, unsigned __int32 cnt[], unsigned __int16 * us16TDC)
/////////////////////////////////////////////////////////////////
{
	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;

	if (DAQ_ID_output == DAQ_ID_HM1_ABM) {
		for (i=0;i<number_of_channels_output;++i) {
			if (data_format_in_userheader_output == 2)  *output_lmf << us16TDC[i*num_ions];
			if (data_format_in_userheader_output == 5)  {dummy_double = double(us16TDC[i*num_ions]); *output_lmf << dummy_double;}
			if (data_format_in_userheader_output == 10) {dummy_int32 = __int32(us16TDC[i*num_ions]); *output_lmf << dummy_int32;}
		}
	}
	if (DAQ_ID_output != DAQ_ID_SIMPLE && DAQ_ID_output != DAQ_ID_HM1_ABM) {
		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) *output_lmf << us16TDC[i*num_ions+j];
				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) {dummy_double = double(us16TDC[i*num_ions+j]); *output_lmf << dummy_double;}
				dummy_double = 0.;
				for (j=hits;j<max_number_of_hits_output;++j) *output_lmf << dummy_double;
			}
			if (data_format_in_userheader_output == 10) {
				*output_lmf <<__int32(hits);
				for (j=0;j<hits;++j) {dummy_int32 = __int32(us16TDC[i*num_ions+j]); *output_lmf << dummy_int32;}
				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) {
					dummy_int32 = __int32(us16TDC[i*num_ions+j]);
					if (DAQ_ID_output != DAQ_ID_HM1 && DAQ_ID_output != DAQ_ID_TDC8 && DAQ_ID_output != DAQ_ID_2TDC8) *output_lmf << dummy_int32;
						else *output_lmf << (unsigned __int16)(dummy_int32);
				}
			}
		}
				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) *output_lmf << us16TDC[i*num_ions+j];
				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) {dummy_double = double(us16TDC[i*num_ions+j]); *output_lmf << dummy_double;}
				dummy_double = 0.;
				for (j=hits;j<max_number_of_hits2_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) {dummy_int32 = __int32(us16TDC[i*num_ions+j]); *output_lmf << dummy_int32;}
				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 = 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) *output_lmf << us16TDC[channel*num_ions+i];
				}
			}
		}
		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(us16TDC[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 0xfaa7
cmpb $0x0, 0x2b29(%r15)
je 0xfaa7
movq %rcx, %rbp
movq %rdx, %r13
incq 0x2b10(%r15)
movq %r15, %rdi
callq 0xe24a
movl 0x28c(%r15), %eax
cmpl $0x6, %eax
movq %rbp, 0x8(%rsp)
movq %r13, 0x28(%rsp)
jne 0xf511
cmpl $0x0, 0x2c4(%r15)
jle 0xf854
xorl %ebp, %ebp
movl 0x294(%r15), %eax
movslq %ebp, %r14
cmpl $0x2, %eax
jne 0xf49e
movq 0x2b20(%r15), %rdi
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
movq 0x8(%rsp), %rcx
movzwl (%rcx,%rax,2), %esi
callq 0x13404
movl 0x294(%r15), %eax
cmpl $0x5, %eax
jne 0xf4d1
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
movq 0x8(%rsp), %rcx
movzwl (%rcx,%rax,2), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13618
movl 0x294(%r15), %eax
cmpl $0xa, %eax
jne 0xf4f6
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
movq 0x8(%rsp), %rcx
movzwl (%rcx,%rax,2), %esi
movq 0x2b20(%r15), %rdi
callq 0x1365e
incl %ebp
cmpl 0x2c4(%r15), %ebp
jl 0xf468
movl 0x28c(%r15), %eax
movq 0x8(%rsp), %rbp
cmpl $0x6, %eax
je 0xf854
cmpl $0x65, %eax
je 0xf854
cmpl $0x0, 0x2c4(%r15)
jle 0xf7ad
xorl %ecx, %ecx
movslq (%r13,%rcx,4), %rdx
movslq 0x2cc(%r15), %rax
cmpl %eax, %edx
movq %rax, 0x20(%rsp)
movl %eax, %r14d
movq %rdx, 0x10(%rsp)
cmovll %edx, %r14d
movl 0x294(%r15), %eax
movq %rcx, 0x30(%rsp)
movslq %ecx, %r12
cmpl $0x2, %eax
movl %r14d, 0x18(%rsp)
jne 0xf5ef
movq 0x2b20(%r15), %rdi
movzwl %r14w, %esi
callq 0x13404
testl %r14d, %r14d
jle 0xf5be
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %rax
cmpq %r14, %rax
cmovlq %rax, %r14
xorl %ebx, %ebx
movq 0x2b20(%r15), %rdi
movslq 0x2b74(%r15), %rax
imulq %r12, %rax
addq %rbx, %rax
movzwl (%rbp,%rax,2), %esi
callq 0x13404
incq %rbx
cmpl %ebx, %r14d
jne 0xf597
movl 0x18(%rsp), %r14d
movl %r14d, %ebx
cmpl 0x2cc(%r15), %r14d
jge 0xf5e8
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x13404
incl %ebx
cmpl 0x2cc(%r15), %ebx
jl 0xf5cf
movl 0x294(%r15), %eax
cmpl $0x5, %eax
jne 0xf685
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13618
testl %r14d, %r14d
movq %rbp, %r13
jle 0xf656
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %rax
cmpq %r14, %rax
cmovlq %rax, %r14
xorl %ebp, %ebp
movslq 0x2b74(%r15), %rax
imulq %r12, %rax
addq %rbp, %rax
movzwl (%r13,%rax,2), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13618
incq %rbp
cmpl %ebp, %r14d
jne 0xf627
movl 0x18(%rsp), %r14d
movl %r14d, %ebx
cmpl 0x2cc(%r15), %r14d
movq %r13, %rbp
jge 0xf685
movq 0x2b20(%r15), %rdi
xorpd %xmm0, %xmm0
callq 0x13618
incl %ebx
cmpl 0x2cc(%r15), %ebx
jl 0xf66a
movl 0x294(%r15), %eax
cmpl $0xa, %eax
jne 0xf710
movq 0x2b20(%r15), %rdi
movl %r14d, %esi
callq 0x1365e
testl %r14d, %r14d
jle 0xf6df
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %rax
cmpq %r14, %rax
cmovlq %rax, %r14
xorl %ebx, %ebx
movslq 0x2b74(%r15), %rax
imulq %r12, %rax
addq %rbx, %rax
movzwl (%rbp,%rax,2), %esi
movq 0x2b20(%r15), %rdi
callq 0x1365e
incq %rbx
cmpl %ebx, %r14d
jne 0xf6b8
movl 0x18(%rsp), %r14d
movl %r14d, %ebx
cmpl 0x2cc(%r15), %r14d
jge 0xf709
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x1365e
incl %ebx
cmpl 0x2cc(%r15), %ebx
jl 0xf6f0
movl 0x294(%r15), %eax
cmpl $-0x1, %eax
movl $0x26, %ebx
jne 0xf789
movq 0x2b20(%r15), %rdi
movzwl %r14w, %esi
callq 0x13404
testl %r14d, %r14d
jle 0xf789
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %rax
cmpq %r13, %rax
cmovlq %rax, %r13
xorl %r14d, %r14d
movslq 0x2b74(%r15), %rax
imulq %r12, %rax
addq %r14, %rax
movzwl (%rbp,%rax,2), %esi
movl 0x28c(%r15), %eax
cmpl $0x5, %eax
ja 0xf775
btl %eax, %ebx
jae 0xf775
movq 0x2b20(%r15), %rdi
callq 0x13404
jmp 0xf781
movq 0x2b20(%r15), %rdi
callq 0x1365e
incq %r14
cmpl %r14d, %r13d
jne 0xf743
movq 0x30(%rsp), %rcx
incq %rcx
movslq 0x2c4(%r15), %rax
cmpq %rax, %rcx
movq 0x28(%rsp), %r13
jl 0xf533
movl 0x28c(%r15), %eax
cmpl $0x8, %eax
sete %dl
movl 0x12a8(%r15), %ecx
cmpl $0x9, %ecx
setge %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xf7eb
movq 0x2b20(%r15), %rdi
movq 0x2d8(%r15), %rsi
callq 0x13448
movl 0x28c(%r15), %eax
movl 0x12a8(%r15), %ecx
cmpl $0x8, %eax
jne 0xf85b
cmpl $0xa, %ecx
jl 0xf85b
movq 0x2b20(%r15), %rdi
movl 0x1280(%r15), %esi
callq 0x1365e
cmpl $0x0, 0x1280(%r15)
jle 0xf854
xorl %r14d, %r14d
movq 0x2b20(%r15), %rbx
movsbl 0x2e0(%r15,%r14), %edi
movq (%rbx), %rsi
callq 0x2190
movq 0x10(%rbx), %rcx
movq 0x20(%rbx), %rax
incq %rax
movq %rax, 0x20(%rbx)
cmpq %rax, %rcx
jae 0xf845
movq %rax, 0x10(%rbx)
incq %r14
movslq 0x1280(%r15), %rax
cmpq %rax, %r14
jl 0xf815
movl 0x28c(%r15), %eax
cmpl $0x5, %eax
jne 0xfa7b
cmpl $0x0, 0x2c8(%r15)
jle 0xfab2
movslq 0x2c4(%r15), %rsi
movl 0x2d0(%r15), %ebp
movl %ebp, %eax
movslq (%r13,%rsi,4), %rcx
cmpl %ebp, %ecx
movl %ebp, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
cmovll %ecx, %ebp
movl 0x294(%r15), %ecx
movq %rsi, 0x20(%rsp)
movslq %esi, %r14
cmpl $0x2, %ecx
jne 0xf934
movq 0x2b20(%r15), %rdi
movzwl %bp, %esi
callq 0x13404
testl %ebp, %ebp
movq 0x8(%rsp), %r13
jle 0xf900
movslq 0x10(%rsp), %r12
movq 0x18(%rsp), %rax
cmpq %rax, %r12
cmovgeq %rax, %r12
xorl %ebx, %ebx
movq 0x2b20(%r15), %rdi
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
addq %rbx, %rax
movzwl (%r13,%rax,2), %esi
callq 0x13404
incq %rbx
cmpl %ebx, %r12d
jne 0xf8d8
movl 0x2d0(%r15), %eax
movl %ebp, %ebx
cmpl %eax, %ebp
jge 0xf928
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x13404
incl %ebx
movl 0x2d0(%r15), %eax
cmpl %eax, %ebx
jl 0xf90d
movl 0x294(%r15), %ecx
movq 0x28(%rsp), %r13
cmpl $0x5, %ecx
jne 0xf9ca
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13618
testl %ebp, %ebp
movq 0x8(%rsp), %r13
jle 0xf99b
movslq 0x10(%rsp), %r12
movq 0x18(%rsp), %rax
cmpq %rax, %r12
cmovgeq %rax, %r12
xorl %ebx, %ebx
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
addq %rbx, %rax
movzwl (%r13,%rax,2), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13618
incq %rbx
cmpl %ebx, %r12d
jne 0xf96c
movl 0x2d0(%r15), %eax
movl %ebp, %ebx
cmpl %eax, %ebp
movq 0x28(%rsp), %r13
jge 0xf9ca
movq 0x2b20(%r15), %rdi
xorpd %xmm0, %xmm0
callq 0x13618
incl %ebx
movl 0x2d0(%r15), %eax
cmpl %eax, %ebx
jl 0xf9ad
cmpl $0xa, 0x294(%r15)
jne 0xfa50
movq 0x2b20(%r15), %rdi
movl %ebp, %esi
callq 0x1365e
testl %ebp, %ebp
movq 0x8(%rsp), %r12
movq 0x18(%rsp), %r13
jle 0xfa25
movslq 0x10(%rsp), %rax
cmpq %r13, %rax
cmovlq %rax, %r13
xorl %ebx, %ebx
movslq 0x2b74(%r15), %rax
imulq %r14, %rax
addq %rbx, %rax
movzwl (%r12,%rax,2), %esi
movq 0x2b20(%r15), %rdi
callq 0x1365e
incq %rbx
cmpl %ebx, %r13d
jne 0xf9fe
movl 0x2d0(%r15), %eax
cmpl %eax, %ebp
movq 0x28(%rsp), %r13
jge 0xfa50
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x1365e
incl %ebp
movl 0x2d0(%r15), %eax
cmpl %eax, %ebp
jl 0xfa35
movq 0x20(%rsp), %rsi
incq %rsi
movslq 0x2c4(%r15), %rcx
movslq 0x2c8(%r15), %rdx
addq %rcx, %rdx
movl %eax, %ebp
cmpq %rdx, %rsi
jl 0xf882
movl 0x28c(%r15), %eax
cmpl $0x65, %eax
jne 0xfab2
movl 0x2c4(%r15), %eax
testq %rax, %rax
je 0xfac1
xorl %ecx, %ecx
xorl %ebp, %ebp
movl (%r13,%rcx,4), %edx
addl %edx, %ebp
cmpl $0x1, %edx
sbbl $-0x1, %ebp
incq %rcx
cmpq %rcx, %rax
jne 0xfa90
jmp 0xfac3
movl $0xa, 0x12e0(%r15)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
movl 0x294(%r15), %eax
cmpl $0x2, %eax
jne 0xfae5
movq 0x2b20(%r15), %rdi
movzwl %bp, %esi
callq 0x13404
movl 0x294(%r15), %eax
cmpl $0xa, %eax
jne 0xfaff
movq 0x2b20(%r15), %rdi
movl %ebp, %esi
callq 0x13378
movl 0x294(%r15), %eax
movl 0x2c4(%r15), %ecx
cmpl $0x2, %eax
jne 0xfb80
testl %ecx, %ecx
movq 0x8(%rsp), %r12
je 0xfab2
xorl %r14d, %r14d
movl (%r13,%r14,4), %eax
testl %eax, %eax
je 0xfb68
movl %r14d, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x13404
cmpl $0x0, (%r13,%r14,4)
je 0xfb68
xorl %ebx, %ebx
movq 0x2b20(%r15), %rdi
movl 0x2b74(%r15), %eax
imull %r14d, %eax
addl %ebx, %eax
movzwl (%r12,%rax,2), %esi
callq 0x13404
incl %ebx
cmpl (%r13,%r14,4), %ebx
jb 0xfb41
incq %r14
movl 0x2c4(%r15), %ecx
cmpq %rcx, %r14
jb 0xfb17
movl 0x294(%r15), %eax
jmp 0xfb85
movq 0x8(%rsp), %r12
cmpl $0xa, %eax
sete %al
testl %ecx, %ecx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xfab2
xorl %r14d, %r14d
movl (%r13,%r14,4), %esi
testl %esi, %esi
je 0xfbec
movl %r14d, %eax
shll $0x18, %eax
addl %eax, %esi
movq 0x2b20(%r15), %rdi
callq 0x1365e
cmpl $0x0, (%r13,%r14,4)
je 0xfbec
xorl %ebx, %ebx
movl 0x2b74(%r15), %eax
imull %r14d, %eax
addl %ebx, %eax
movzwl (%r12,%rax,2), %esi
movq 0x2b20(%r15), %rdi
callq 0x1365e
incl %ebx
cmpl (%r13,%r14,4), %ebx
jb 0xfbc5
incq %r14
movl 0x2c4(%r15), %eax
cmpq %rax, %r14
jb 0xfb9e
jmp 0xfab2