// File: 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 %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq 0x2b20(%rax), %rdi
movsd 0x12c8(%rax), %xmm0
callq 0x1d130
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x8, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x2a4(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x2ac(%rax), %esi
callq 0x1caf0
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %eax
addq $0x4, %rax
movl %eax, -0xc(%rbp)
addq $0xa0, %rdi
callq 0x22b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movl %ecx, -0x10(%rbp)
movq 0x2b20(%rax), %rdi
movl -0x10(%rbp), %esi
callq 0x1d170
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %eax
addq $0x4, %rax
movl %eax, -0xc(%rbp)
movq 0x2b20(%rdi), %rax
movq %rax, -0x38(%rbp)
addq $0xa0, %rdi
callq 0x20b0
movq -0x28(%rbp), %rdi
movq %rax, -0x30(%rbp)
addq $0xa0, %rdi
callq 0x22b0
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl %eax, %edx
callq 0x1cd10
movq -0x28(%rbp), %rdi
addq $0xa0, %rdi
callq 0x22b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
addl -0xc(%rbp), %ecx
movl %ecx, -0xc(%rbp)
cmpl $0x1317cb8, 0x284(%rax) # imm = 0x1317CB8
jb 0xa337
movq -0x28(%rbp), %rax
testb $0x1, 0x1574(%rax)
je 0xa337
movq -0x28(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x12a8(%rax), %esi
callq 0x1d170
movl -0xc(%rbp), %eax
addq $0x4, %rax
movl %eax, -0xc(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x9, 0x12a8(%rax)
jl 0xa465
movq -0x28(%rbp), %rax
cmpl $0x0, 0x132c(%rax)
jl 0xa363
movq -0x28(%rbp), %rax
cmpq $0x0, 0x1338(%rax)
jne 0xa371
movq -0x28(%rbp), %rax
movl $0x0, 0x132c(%rax)
movq -0x28(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x132c(%rax), %esi
callq 0x1d170
movl -0xc(%rbp), %eax
addq $0x4, %rax
movl %eax, -0xc(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x28(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x132c(%rcx), %eax
jge 0xa463
movq -0x28(%rbp), %rax
movq 0x1338(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movl %ecx, -0x18(%rbp)
movq 0x2b20(%rax), %rdi
movl -0x18(%rbp), %esi
callq 0x1caf0
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x1338(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x20b0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, -0x40(%rbp)
movq 0x1338(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22b0
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl %eax, %edx
callq 0x1cd10
movq -0x28(%rbp), %rax
movq 0x1338(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x22b0
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xa398
jmp 0xa465
movq -0x28(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x1290(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x244(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x1298(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movsd 0x12c0(%rax), %xmm0
callq 0x1d130
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x8, %rcx
movl %ecx, -0xc(%rbp)
movl $0x1, 0x12ac(%rax)
cmpl $0x1317cb8, 0x284(%rax) # imm = 0x1317CB8
jb 0xa52e
movq -0x28(%rbp), %rax
testb $0x1, 0x1574(%rax)
je 0xa52e
movq -0x28(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x12ac(%rax), %esi
callq 0x1d170
movl -0xc(%rbp), %eax
addq $0x4, %rax
movl %eax, -0xc(%rbp)
movq -0x28(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x2b0(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
cmpl $0x132677b, 0x284(%rax) # imm = 0x132677B
jae 0xa5a0
movq -0x28(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x2c4(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x2cc(%rax), %esi
callq 0x1d170
movl -0xc(%rbp), %eax
addq $0x4, %rax
movl %eax, -0xc(%rbp)
jmp 0xa5f2
movq -0x28(%rbp), %rax
movslq 0x2c4(%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x2b20(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x1d1a0
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x8, %rcx
movl %ecx, -0xc(%rbp)
movslq 0x2cc(%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x2b20(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x1d1a0
movl -0xc(%rbp), %eax
addq $0x8, %rax
movl %eax, -0xc(%rbp)
movq -0x28(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x294(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x1288(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
cmpl $0x1317cb8, 0x284(%rax) # imm = 0x1317CB8
jb 0xa748
movq -0x28(%rbp), %rax
testb $0x1, 0x1574(%rax)
je 0xa748
movq -0x28(%rbp), %rax
cmpl $0x2, 0x28c(%rax)
jne 0xa748
movq -0x28(%rbp), %rax
movq 0x2b20(%rax), %rdi
movl 0x1558(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x155c(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x1560(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x1564(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x1568(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x156c(%rax), %esi
callq 0x1d170
movq -0x28(%rbp), %rax
movl -0xc(%rbp), %ecx
addq $0x4, %rcx
movl %ecx, -0xc(%rbp)
movq 0x2b20(%rax), %rdi
movl 0x1570(%rax), %esi
callq 0x1d170
movl -0xc(%rbp), %eax
addq $0x4, %rax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)