// File: /workspace/github_cpp_makefile_star2_O1/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::WriteTDC8PCI2Header()
__int32	LMF_IO::WriteTDC8PCI2Header()
/////////////////////////////////////////////////////////////////
{
	unsigned __int32 byte_counter;
	byte_counter = 0;
	__int32 int_Dummy = 0;

	*output_lmf << frequency;	byte_counter += sizeof(double);		// frequency is always 4th value
	*output_lmf << IOaddress;	byte_counter += sizeof(__int32);		// IO address (parameter 1) always 5th value
	*output_lmf << timestamp_format_output;	byte_counter += sizeof(__int32);		// TimeInfo (parameter 2) always 6th value  (0,1,2)*32Bit

	int_Dummy = __int32(DAQ_info.length());
	*output_lmf << int_Dummy;
	byte_counter += sizeof(__int32);		// Length of DAQInfo always 7th value
	output_lmf->write(DAQ_info.c_str(), __int32(DAQ_info.length()));	// DAQInfo always 8th value
	byte_counter += (unsigned __int32)(DAQ_info.length());

	if ((DAQVersion_output >= 20020408 && TDC8PCI2.use_normal_method)) {
		*output_lmf << LMF_Version_output; byte_counter += sizeof(__int32);
	}

	if (LMF_Version_output >= 0x9) {
		if ((number_of_DAQ_source_strings_output < 0) || (!DAQ_source_strings_output)) number_of_DAQ_source_strings_output = 0;
		*output_lmf << number_of_DAQ_source_strings_output;  byte_counter += sizeof(__int32);

		for (__int32 i=0;i<number_of_DAQ_source_strings_output;++i) {
			unsigned __int32 unsigned_int_Dummy = (unsigned __int32)(DAQ_source_strings_output[i]->length());
			*output_lmf << unsigned_int_Dummy;   byte_counter += sizeof(__int32);
			output_lmf->write(DAQ_source_strings_output[i]->c_str(),__int32(DAQ_source_strings_output[i]->length()));
			byte_counter += (unsigned __int32)(DAQ_source_strings_output[i]->length());
		}
	}

	*output_lmf << system_timeout_output; byte_counter += sizeof(__int32);		//   system time-out
	*output_lmf << time_reference_output; byte_counter += sizeof(__int32);
	*output_lmf << common_mode_output; byte_counter += sizeof(__int32);		//   0 common start    1 common stop
	*output_lmf << tdcresolution_output; byte_counter += sizeof(double);		// tdc resolution in ns

	TDCDataType = 1;
	if (DAQVersion_output >= 20020408 && TDC8PCI2.use_normal_method) {*output_lmf << TDCDataType; byte_counter += sizeof(__int32);}
	*output_lmf << timerange; byte_counter += sizeof(__int32);	// time range of the tdc in microseconds

	if (DAQVersion_output < 20080507) {
		*output_lmf << number_of_channels_output; byte_counter += sizeof(__int32);			// number of channels
		*output_lmf << max_number_of_hits_output; byte_counter += sizeof(__int32);			// number of hits
	} else {
		__int64 i64_temp = number_of_channels_output;
		*output_lmf << i64_temp; byte_counter += sizeof(__int64);			// number of channels
		i64_temp = max_number_of_hits_output;
		*output_lmf << i64_temp; byte_counter += sizeof(__int64);			// number of hits
	}

	*output_lmf << data_format_in_userheader_output;	byte_counter += sizeof(__int32);				// data format (2=short integer)

	*output_lmf << module_2nd;	byte_counter += sizeof(__int32);	// indicator for 2nd module data
	
	if (DAQVersion_output >= 20020408 && TDC8PCI2.use_normal_method && (DAQ_ID_output == DAQ_ID_TDC8)) {
		*output_lmf << TDC8PCI2.GateDelay_1st_card;			byte_counter += sizeof(__int32); // gate delay 1st card
		*output_lmf << TDC8PCI2.OpenTime_1st_card;			byte_counter += sizeof(__int32); // open time 1st card
		*output_lmf << TDC8PCI2.WriteEmptyEvents_1st_card;	byte_counter += sizeof(__int32); // write empty events 1st card
		*output_lmf << TDC8PCI2.TriggerFalling_1st_card;	byte_counter += sizeof(__int32); // trigger falling edge 1st card
		*output_lmf << TDC8PCI2.TriggerRising_1st_card;		byte_counter += sizeof(__int32); // trigger rising edge 1st card
		*output_lmf << TDC8PCI2.EmptyCounter_1st_card;		byte_counter += sizeof(__int32); // EmptyCounter 1st card
		*output_lmf << TDC8PCI2.EmptyCounter_since_last_Event_1st_card;	byte_counter += sizeof(__int32); // Empty Counter since last event 1st card
	} 

	return byte_counter;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x2b20(%rdi), %rdi
movsd 0x12c8(%rbx), %xmm0
callq 0x13c3c
movq 0x2b20(%rbx), %rdi
movl 0x2a4(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x2ac(%rbx), %esi
callq 0x13968
movl 0xa8(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movq 0xa0(%rbx), %rsi
movl 0xa8(%rbx), %edx
callq 0x13a7c
movl 0xa8(%rbx), %r14d
leal 0x14(%r14), %r15d
cmpl $0x1317cb8, 0x284(%rbx) # imm = 0x1317CB8
jb 0x7e5c
cmpb $0x1, 0x1574(%rbx)
jne 0x7e5c
movq 0x2b20(%rbx), %rdi
movl 0x12a8(%rbx), %esi
callq 0x13c82
addl $0x18, %r14d
movl %r14d, %r15d
cmpl $0x9, 0x12a8(%rbx)
jl 0x7f03
cmpl $0x0, 0x132c(%rbx)
js 0x7e7c
cmpq $0x0, 0x1338(%rbx)
jne 0x7e86
movl $0x0, 0x132c(%rbx)
movq 0x2b20(%rbx), %rdi
movl 0x132c(%rbx), %esi
callq 0x13c82
addl $0x4, %r15d
cmpl $0x0, 0x132c(%rbx)
jle 0x7f03
xorl %r14d, %r14d
movq 0x1338(%rbx), %rax
movq (%rax,%r14,8), %rax
movl 0x8(%rax), %esi
movq 0x2b20(%rbx), %rdi
callq 0x13968
movq 0x2b20(%rbx), %rdi
movq 0x1338(%rbx), %rax
movq (%rax,%r14,8), %rax
movq (%rax), %rsi
movl 0x8(%rax), %edx
callq 0x13a7c
movq 0x1338(%rbx), %rax
movq (%rax,%r14,8), %rax
movl 0x8(%rax), %eax
addl %eax, %r15d
addl $0x4, %r15d
incq %r14
movslq 0x132c(%rbx), %rax
cmpq %rax, %r14
jl 0x7ea8
movq 0x2b20(%rbx), %rdi
movl 0x1290(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x244(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x1298(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movsd 0x12c0(%rbx), %xmm0
callq 0x13c3c
leal 0x14(%r15), %r14d
movl $0x1, 0x12ac(%rbx)
cmpl $0x1317cb8, 0x284(%rbx) # imm = 0x1317CB8
jb 0x7f88
cmpb $0x1, 0x1574(%rbx)
jne 0x7f88
movq 0x2b20(%rbx), %rdi
movl $0x1, %esi
callq 0x13c82
addl $0x18, %r15d
movl %r15d, %r14d
movq 0x2b20(%rbx), %rdi
movl 0x2b0(%rbx), %esi
callq 0x13c82
cmpl $0x132677a, 0x284(%rbx) # imm = 0x132677A
ja 0x7fd2
movq 0x2b20(%rbx), %rdi
movl 0x2c4(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x2cc(%rbx), %esi
callq 0x13c82
movl $0xc, %r15d
jmp 0x7ffe
movslq 0x2c4(%rbx), %rsi
movq 0x2b20(%rbx), %rdi
callq 0x13cc6
movslq 0x2cc(%rbx), %rsi
movq 0x2b20(%rbx), %rdi
callq 0x13cc6
movl $0x14, %r15d
movq 0x2b20(%rbx), %rdi
movl 0x294(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x1288(%rbx), %esi
callq 0x13c82
leal (%r14,%r15), %eax
addl $0x8, %eax
cmpl $0x1317cb8, 0x284(%rbx) # imm = 0x1317CB8
jb 0x80db
cmpb $0x1, 0x1574(%rbx)
jne 0x80db
cmpl $0x2, 0x28c(%rbx)
jne 0x80db
addl %r15d, %r14d
movq 0x2b20(%rbx), %rdi
movl 0x1558(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x155c(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x1560(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x1564(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x1568(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x156c(%rbx), %esi
callq 0x13c82
movq 0x2b20(%rbx), %rdi
movl 0x1570(%rbx), %esi
callq 0x13c82
addl $0x24, %r14d
movl %r14d, %eax
popq %rbx
popq %r14
popq %r15
retq
nop