// File: /workspace/github_cpp_makefile_star2_O1/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::WriteTDCData(unsigned long long, unsigned int*, int*)
void LMF_IO::WriteTDCData(unsigned __int64 timestamp, unsigned __int32 cnt[], __int32 * i32TDC)
/////////////////////////////////////////////////////////////////
{
	unsigned __int16 dummy_uint16;
	__int32 dummy_int32;
	double dummy_double;

	if (!output_lmf || !OutputFileIsOpen) {
		errorflag = 10;
		return;
	}
	
	++uint64_number_of_written_events;

	WriteEventHeader(timestamp,cnt);

	__int32 i,j;
	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 + (DAQ_ID == DAQ_ID_HM1 ? 1 : 0));
				*output_lmf << dummy_uint16;
				for (j=0;j<hits;++j) {
					dummy_uint16 = (unsigned __int16)(i32TDC[i*num_ions+j]);
					*output_lmf << dummy_uint16;
				}
				dummy_uint16 = (unsigned __int16)(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 + (DAQ_ID == DAQ_ID_HM1 ? 1 : 0));
				*output_lmf << dummy_double;
				for (j=0;j<hits;++j) {
					dummy_double = double(i32TDC[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 + (DAQ_ID == DAQ_ID_HM1 ? 1 : 0));
				for (j=0;j<hits;++j) *output_lmf << i32TDC[i*num_ions+j];
				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 + (DAQ_ID == DAQ_ID_HM1 ? 1 : 0));
				*output_lmf << dummy_uint16;
				if (DAQ_ID_output == DAQ_ID_2TDC8 || DAQ_ID_output == DAQ_ID_TDC8 || DAQ_ID_output == DAQ_ID_HM1) {
					for (j=0;j<hits;++j) {
						dummy_uint16 = (unsigned __int16)(i32TDC[i*num_ions+j]);
						*output_lmf << dummy_uint16;
					}
				} else {
				for (j=0;j<hits;++j) *output_lmf << i32TDC[i*num_ions+j];
				}
			}
		}
				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) { // here we write only the stuff for the second TDC (because the first TDC was written above)
		for (i=number_of_channels_output;i<number_of_channels2_output+number_of_channels_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 + (DAQ_ID == DAQ_ID_HM1 ? 1 : 0));  *output_lmf << dummy_uint16;
				for (j=0;j<hits;++j) {
					dummy_uint16 = (unsigned __int16)(i32TDC[i*num_ions+j]);
					*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 + (DAQ_ID == DAQ_ID_HM1 ? 1 : 0));		*output_lmf << dummy_double;
				for (j=0;j<hits;++j) {
					dummy_double = double(i32TDC[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 + (DAQ_ID == DAQ_ID_HM1 ? 1 : 0));		*output_lmf << dummy_int32;
				for (j=0;j<hits;++j) *output_lmf << i32TDC[i*num_ions+j];
				dummy_int32 = 0;
				for (j=hits;j<max_number_of_hits2_output;++j) *output_lmf << dummy_int32;
			}
			if (data_format_in_userheader_output == LM_USERDEF) {
				dummy_uint16 = (unsigned __int16)(hits + (DAQ_ID == DAQ_ID_HM1 ? 1 : 0));
				*output_lmf << dummy_uint16;
				for (j=0;j<hits;++j) {
					dummy_uint16 = (unsigned __int16)(i32TDC[i*num_ions+j]);
					*output_lmf << dummy_uint16;
				}
			}
		}
	}

	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)(i32TDC[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) *output_lmf << i32TDC[channel*num_ions+i];
				}
			}
		}
	} // end if (DAQ_ID_output == DAQ_ID_SIMPLE)

	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r15
cmpq $0x0, 0x2b20(%rdi)
je 0xebdb
cmpb $0x0, 0x2b29(%r15)
je 0xebdb
movq %rcx, %rbx
incq 0x2b10(%r15)
movq %r15, %rdi
movq %rdx, 0x18(%rsp)
callq 0xe480
cmpl $0x65, 0x28c(%r15)
je 0xe8fe
cmpl $0x0, 0x2c4(%r15)
jle 0xe864
xorl %ecx, %ecx
movq 0x18(%rsp), %rax
movslq (%rax,%rcx,4), %rax
movslq 0x2cc(%r15), %r14
cmpl %r14d, %eax
movl %r14d, %r13d
movq %rax, 0x10(%rsp)
cmovll %eax, %r13d
cmpl $0x2, 0x294(%r15)
movq %rcx, 0x20(%rsp)
movslq %ecx, %rbp
movl %r13d, 0xc(%rsp)
jne 0xe663
xorl %eax, %eax
cmpl $0x1, 0x288(%r15)
sete %al
addl %r13d, %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x139f4
testl %r13d, %r13d
jle 0xe638
movq 0x10(%rsp), %rax
cmpq %r14, %rax
movq %r14, %r13
cmovlq %rax, %r13
xorl %r12d, %r12d
movslq 0x2b74(%r15), %rax
imulq %rbp, %rax
addq %r12, %rax
movzwl (%rbx,%rax,4), %esi
movq 0x2b20(%r15), %rdi
callq 0x139f4
incq %r12
cmpl %r12d, %r13d
jne 0xe612
movl 0xc(%rsp), %r13d
movl %r13d, %r12d
cmpl 0x2cc(%r15), %r13d
jge 0xe663
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x139f4
incl %r12d
cmpl 0x2cc(%r15), %r12d
jl 0xe649
cmpl $0x5, 0x294(%r15)
jne 0xe702
xorl %eax, %eax
cmpl $0x1, 0x288(%r15)
sete %al
addl %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13c3c
testl %r13d, %r13d
jle 0xe6d5
movq 0x10(%rsp), %rax
cmpq %r14, %rax
movq %r14, %r13
cmovlq %rax, %r13
xorl %r12d, %r12d
movslq 0x2b74(%r15), %rax
imulq %rbp, %rax
addq %r12, %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rbx,%rax,4), %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13c3c
incq %r12
cmpl %r12d, %r13d
jne 0xe6ab
movl 0xc(%rsp), %r13d
movl %r13d, %r12d
cmpl 0x2cc(%r15), %r13d
jge 0xe702
movq 0x2b20(%r15), %rdi
xorpd %xmm0, %xmm0
callq 0x13c3c
incl %r12d
cmpl 0x2cc(%r15), %r12d
jl 0xe6e6
cmpl $0xa, 0x294(%r15)
jne 0xe794
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
cmpl $0x1, 0x288(%r15)
sete %sil
addl %r13d, %esi
callq 0x13c82
testl %r13d, %r13d
jle 0xe769
movq 0x10(%rsp), %rax
cmpq %r14, %rax
movq %r14, %r13
cmovlq %rax, %r13
xorl %r12d, %r12d
movq 0x2b20(%r15), %rdi
movslq 0x2b74(%r15), %rax
imulq %rbp, %rax
addq %r12, %rax
movl (%rbx,%rax,4), %esi
callq 0x13c82
incq %r12
cmpl %r12d, %r13d
jne 0xe744
movl 0xc(%rsp), %r13d
movl %r13d, %r12d
cmpl 0x2cc(%r15), %r13d
jge 0xe794
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x13c82
incl %r12d
cmpl 0x2cc(%r15), %r12d
jl 0xe77a
cmpl $-0x1, 0x294(%r15)
jne 0xe84c
xorl %eax, %eax
cmpl $0x1, 0x288(%r15)
sete %al
addl %r13d, %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x139f4
movl 0x28c(%r15), %eax
cmpl $0x5, %eax
ja 0xe813
movl $0x26, %ecx
btl %eax, %ecx
jae 0xe813
testl %r13d, %r13d
jle 0xe84c
movq 0x10(%rsp), %rax
cmpq %r14, %rax
cmovlq %rax, %r14
xorl %r12d, %r12d
movslq 0x2b74(%r15), %rax
imulq %rbp, %rax
addq %r12, %rax
movzwl (%rbx,%rax,4), %esi
movq 0x2b20(%r15), %rdi
callq 0x139f4
incq %r12
cmpl %r12d, %r14d
jne 0xe7eb
jmp 0xe84c
testl %r13d, %r13d
jle 0xe84c
movq 0x10(%rsp), %rax
cmpq %r14, %rax
cmovlq %rax, %r14
xorl %r12d, %r12d
movq 0x2b20(%r15), %rdi
movslq 0x2b74(%r15), %rax
imulq %rbp, %rax
addq %r12, %rax
movl (%rbx,%rax,4), %esi
callq 0x13c82
incq %r12
cmpl %r12d, %r14d
jne 0xe827
movq 0x20(%rsp), %rcx
incq %rcx
movslq 0x2c4(%r15), %rax
cmpq %rax, %rcx
jl 0xe5a2
cmpl $0x8, 0x28c(%r15)
jne 0xe88b
cmpl $0x9, 0x12a8(%r15)
jl 0xe88b
movq 0x2b20(%r15), %rdi
movq 0x2d8(%r15), %rsi
callq 0x13a38
cmpl $0x8, 0x28c(%r15)
jne 0xe8fe
cmpl $0xa, 0x12a8(%r15)
jl 0xe8fe
movq 0x2b20(%r15), %rdi
movl 0x1280(%r15), %esi
callq 0x13c82
cmpl $0x0, 0x1280(%r15)
jle 0xe8fe
xorl %r12d, %r12d
movq 0x2b20(%r15), %r14
movsbl 0x2e0(%r15,%r12), %edi
movq (%r14), %rsi
callq 0x2190
movq 0x10(%r14), %rcx
movq 0x20(%r14), %rax
incq %rax
movq %rax, 0x20(%r14)
cmpq %rax, %rcx
jae 0xe8ef
movq %rax, 0x10(%r14)
incq %r12
movslq 0x1280(%r15), %rax
cmpq %rax, %r12
jl 0xe8bf
cmpl $0x5, 0x28c(%r15)
jne 0xeba6
cmpl $0x0, 0x2c8(%r15)
jle 0xeba6
cmpl $0x0, 0x2c8(%r15)
jle 0xeba6
movslq 0x2c4(%r15), %rdx
movq 0x18(%rsp), %rax
movslq (%rax,%rdx,4), %rax
movslq 0x2d0(%r15), %r13
cmpl %r13d, %eax
movl %r13d, %r12d
movq %rax, 0x10(%rsp)
cmovll %eax, %r12d
cmpl $0x2, 0x294(%r15)
movq %rdx, 0x20(%rsp)
movslq %edx, %rbp
movl %r12d, 0xc(%rsp)
jne 0xe9f0
xorl %eax, %eax
cmpl $0x1, 0x288(%r15)
sete %al
addl %r12d, %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x139f4
testl %r12d, %r12d
jle 0xe9c5
movq 0x10(%rsp), %rax
cmpq %r13, %rax
movq %r13, %r14
cmovlq %rax, %r14
xorl %r12d, %r12d
movslq 0x2b74(%r15), %rax
imulq %rbp, %rax
addq %r12, %rax
movzwl (%rbx,%rax,4), %esi
movq 0x2b20(%r15), %rdi
callq 0x139f4
incq %r12
cmpl %r12d, %r14d
jne 0xe99f
movl 0xc(%rsp), %r12d
movl %r12d, %r14d
cmpl 0x2d0(%r15), %r12d
jge 0xe9f0
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x139f4
incl %r14d
cmpl 0x2d0(%r15), %r14d
jl 0xe9d6
cmpl $0x5, 0x294(%r15)
jne 0xea8f
xorl %eax, %eax
cmpl $0x1, 0x288(%r15)
sete %al
addl %r12d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13c3c
testl %r12d, %r12d
jle 0xea62
movq 0x10(%rsp), %rax
cmpq %r13, %rax
movq %r13, %r14
cmovlq %rax, %r14
xorl %r12d, %r12d
movslq 0x2b74(%r15), %rax
imulq %rbp, %rax
addq %r12, %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rbx,%rax,4), %xmm0
movq 0x2b20(%r15), %rdi
callq 0x13c3c
incq %r12
cmpl %r12d, %r14d
jne 0xea38
movl 0xc(%rsp), %r12d
movl %r12d, %r14d
cmpl 0x2d0(%r15), %r12d
jge 0xea8f
movq 0x2b20(%r15), %rdi
xorpd %xmm0, %xmm0
callq 0x13c3c
incl %r14d
cmpl 0x2d0(%r15), %r14d
jl 0xea73
cmpl $0xa, 0x294(%r15)
jne 0xeb21
xorl %esi, %esi
cmpl $0x1, 0x288(%r15)
sete %sil
addl %r12d, %esi
movq 0x2b20(%r15), %rdi
callq 0x13c82
testl %r12d, %r12d
jle 0xeaf6
movq 0x10(%rsp), %rax
cmpq %r13, %rax
movq %r13, %r14
cmovlq %rax, %r14
xorl %r12d, %r12d
movq 0x2b20(%r15), %rdi
movslq 0x2b74(%r15), %rax
imulq %rbp, %rax
addq %r12, %rax
movl (%rbx,%rax,4), %esi
callq 0x13c82
incq %r12
cmpl %r12d, %r14d
jne 0xead1
movl 0xc(%rsp), %r12d
movl %r12d, %r14d
cmpl 0x2d0(%r15), %r12d
jge 0xeb21
movq 0x2b20(%r15), %rdi
xorl %esi, %esi
callq 0x13c82
incl %r14d
cmpl 0x2d0(%r15), %r14d
jl 0xeb07
cmpl $-0x1, 0x294(%r15)
jne 0xeb84
xorl %eax, %eax
cmpl $0x1, 0x288(%r15)
sete %al
addl %r12d, %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x139f4
testl %r12d, %r12d
jle 0xeb84
movq 0x10(%rsp), %rax
cmpq %r13, %rax
cmovlq %rax, %r13
xorl %r14d, %r14d
movslq 0x2b74(%r15), %rax
imulq %rbp, %rax
addq %r14, %rax
movzwl (%rbx,%rax,4), %esi
movq 0x2b20(%r15), %rdi
callq 0x139f4
incq %r14
cmpl %r14d, %r13d
jne 0xeb5e
movq 0x20(%rsp), %rdx
incq %rdx
movslq 0x2c8(%r15), %rax
movslq 0x2c4(%r15), %rcx
addq %rax, %rcx
cmpq %rcx, %rdx
jl 0xe92f
cmpl $0x65, 0x28c(%r15)
movq 0x18(%rsp), %r14
jne 0xebe6
movl 0x2c4(%r15), %eax
testq %rax, %rax
je 0xebf5
xorl %ecx, %ecx
xorl %ebp, %ebp
movl (%r14,%rcx,4), %edx
addl %edx, %ebp
cmpl $0x1, %edx
sbbl $-0x1, %ebp
incq %rcx
cmpq %rcx, %rax
jne 0xebc5
jmp 0xebf7
movl $0xa, 0x12e0(%r15)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
cmpl $0x2, 0x294(%r15)
jne 0xec10
movq 0x2b20(%r15), %rdi
movzwl %bp, %esi
callq 0x139f4
cmpl $0xa, 0x294(%r15)
jne 0xec28
movq 0x2b20(%r15), %rdi
movl %ebp, %esi
callq 0x13968
cmpl $0x2, 0x294(%r15)
jne 0xec9b
cmpl $0x0, 0x2c4(%r15)
je 0xec9b
xorl %r12d, %r12d
movl (%r14,%r12,4), %eax
testl %eax, %eax
je 0xec8c
movl %r12d, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq 0x2b20(%r15), %rdi
movzwl %ax, %esi
callq 0x139f4
cmpl $0x0, (%r14,%r12,4)
je 0xec8c
xorl %ebp, %ebp
movl 0x2b74(%r15), %eax
imull %r12d, %eax
addl %ebp, %eax
movzwl (%rbx,%rax,4), %esi
movq 0x2b20(%r15), %rdi
callq 0x139f4
incl %ebp
cmpl (%r14,%r12,4), %ebp
jb 0xec67
incq %r12
movl 0x2c4(%r15), %eax
cmpq %rax, %r12
jb 0xec3f
cmpl $0xa, 0x294(%r15)
jne 0xebe6
cmpl $0x0, 0x2c4(%r15)
je 0xebe6
xorl %r12d, %r12d
movl (%r14,%r12,4), %esi
testl %esi, %esi
je 0xed03
movl %r12d, %eax
shll $0x18, %eax
addl %eax, %esi
movq 0x2b20(%r15), %rdi
callq 0x13c82
cmpl $0x0, (%r14,%r12,4)
je 0xed03
xorl %ebp, %ebp
movq 0x2b20(%r15), %rdi
movl 0x2b74(%r15), %eax
imull %r12d, %eax
addl %ebp, %eax
movl (%rbx,%rax,4), %esi
callq 0x13c82
incl %ebp
cmpl (%r14,%r12,4), %ebp
jb 0xecdf
incq %r12
movl 0x2c4(%r15), %eax
cmpq %rax, %r12
jb 0xecba
jmp 0xebe6
nop