// File: /workspace/github_cpp_makefile_star2_O3/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::Write2TDC8PCI2Header()
__int32	LMF_IO::Write2TDC8PCI2Header()
/////////////////////////////////////////////////////////////////
{
	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

	unsigned __int32 dummy = (unsigned __int32)(DAQ_info.length());
	*output_lmf << 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 += __int32(DAQ_info.length());

	*output_lmf << LMF_Version_output; byte_counter += sizeof(__int32);

	*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;
	*output_lmf << TDCDataType; byte_counter += sizeof(__int32);
	*output_lmf << timerange; byte_counter += sizeof(__int32);	// time range of the tdc in microseconds

	*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
	*output_lmf << number_of_channels2_output; byte_counter += sizeof(__int32);	// number of channels2
	*output_lmf << max_number_of_hits2_output; byte_counter += sizeof(__int32);	// number of hits2
	*output_lmf << data_format_in_userheader_output;	byte_counter += sizeof(__int32);				// data format (2=short integer)

	if (TDC8PCI2.use_normal_method_2nd_card) {
		if (DAQVersion_output >= 20020408) {
			*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
		}
		*output_lmf << TDC8PCI2.sync_test_on_off;			byte_counter += sizeof(__int32); // sync test on/off
		*output_lmf << TDC8PCI2.io_address_2nd_card;		byte_counter += sizeof(__int32); // io address 2nd card
		*output_lmf << TDC8PCI2.GateDelay_2nd_card;			byte_counter += sizeof(__int32); // gate delay 2nd card
		*output_lmf << TDC8PCI2.OpenTime_2nd_card;			byte_counter += sizeof(__int32); // open time 2nd card
		*output_lmf << TDC8PCI2.WriteEmptyEvents_2nd_card;	byte_counter += sizeof(__int32); // write empty events 2nd card
		*output_lmf << TDC8PCI2.TriggerFallingEdge_2nd_card;	byte_counter += sizeof(__int32); // trigger falling edge 2nd card
		*output_lmf << TDC8PCI2.TriggerRisingEdge_2nd_card;	byte_counter += sizeof(__int32); // trigger rising edge 2nd card
		*output_lmf << TDC8PCI2.EmptyCounter_2nd_card;		byte_counter += sizeof(__int32); // EmptyCounter 2nd card
		*output_lmf << TDC8PCI2.EmptyCounter_since_last_Event_2nd_card;	byte_counter += sizeof(__int32); // Empty Counter since last event 2nd card
	} else {
		*output_lmf << module_2nd;							byte_counter += sizeof(__int32); // indicator for 2nd module data
		*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.GateDelay_2nd_card;			byte_counter += sizeof(__int32); // gate delay 2nd card
		*output_lmf << TDC8PCI2.OpenTime_2nd_card;			byte_counter += sizeof(__int32); // open time 2nd card
		*output_lmf << TDC8PCI2.WriteEmptyEvents_2nd_card;	byte_counter += sizeof(__int32); // write empty events 2nd card
		*output_lmf << TDC8PCI2.TriggerFallingEdge_2nd_card;	byte_counter += sizeof(__int32); // trigger falling edge 2nd card
		*output_lmf << TDC8PCI2.TriggerRisingEdge_2nd_card;	byte_counter += sizeof(__int32); // trigger rising edge 2nd card
	}
	return byte_counter;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x2b20(%rdi), %rdi
movsd 0x12c8(%rbx), %xmm0
callq 0x13618
movq 0x2b20(%rbx), %rdi
movl 0x2a4(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x2ac(%rbx), %esi
callq 0x13378
movl 0xa8(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x13378
movq 0x2b20(%rbx), %rdi
movq 0xa0(%rbx), %rsi
movl 0xa8(%rbx), %edx
callq 0x1348c
movq 0xa8(%rbx), %r14
movq 0x2b20(%rbx), %rdi
movl 0x12a8(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1290(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x244(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1298(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movsd 0x12c0(%rbx), %xmm0
callq 0x13618
movl $0x1, 0x12ac(%rbx)
movq 0x2b20(%rbx), %rdi
movl $0x1, %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x2b0(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x2c4(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x2cc(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x2c8(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x2d0(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x294(%rbx), %esi
callq 0x1365e
cmpb $0x1, 0x1575(%rbx)
jne 0xb67b
cmpl $0x1317cb8, 0x284(%rbx) # imm = 0x1317CB8
jb 0xb70f
movq 0x2b20(%rbx), %rdi
movl 0x1558(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x155c(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1560(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1564(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1568(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x156c(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1570(%rbx), %esi
callq 0x1365e
addq $0x64, %r14
jmp 0xb713
movq %r14, (%rsp)
movq 0x2b20(%rbx), %rdi
movl 0x1288(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1558(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x155c(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1560(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1564(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1568(%rbx), %esi
callq 0x1365e
movl $0x74, %ebp
movl $0x1590, %r15d          # imm = 0x1590
movl $0x158c, %r12d          # imm = 0x158C
movl $0x1588, %r13d          # imm = 0x1588
movl $0x1584, %r14d          # imm = 0x1584
movl $0x1580, %eax           # imm = 0x1580
jmp 0xb781
addq $0x48, %r14
movq %r14, (%rsp)
movq 0x2b20(%rbx), %rdi
movl 0x1578(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x157c(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1580(%rbx), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl 0x1584(%rbx), %esi
callq 0x1365e
movl $0x24, %ebp
movl $0x1598, %r15d          # imm = 0x1598
movl $0x1594, %r12d          # imm = 0x1594
movl $0x1590, %r13d          # imm = 0x1590
movl $0x158c, %r14d          # imm = 0x158C
movl $0x1588, %eax           # imm = 0x1588
movq 0x2b20(%rbx), %rdi
movl (%rbx,%rax), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl (%rbx,%r14), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl (%rbx,%r13), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl (%rbx,%r12), %esi
callq 0x1365e
movq 0x2b20(%rbx), %rdi
movl (%rbx,%r15), %esi
callq 0x1365e
movq (%rsp), %rax
addl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop