// File: /workspace/github_cpp_makefile_star2_O2/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::WriteHM1Header()
__int32	LMF_IO::WriteHM1Header()
/////////////////////////////////////////////////////////////////
{
	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());

	if (DAQVersion_output >= 20020408 && HM1.use_normal_method) {*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);
	if (DAQ_ID_output == DAQ_ID_HM1 || DAQ_ID_output == DAQ_ID_HM1_ABM) {
		*output_lmf << HM1.FAK_DLL_Value; byte_counter += sizeof(__int32);
		*output_lmf << HM1.Resolution_Flag; byte_counter += sizeof(__int32);
		*output_lmf << HM1.trigger_mode_for_start; byte_counter += sizeof(__int32);
		*output_lmf << HM1.trigger_mode_for_stop; byte_counter += sizeof(__int32);
	}
	*output_lmf << tdcresolution_output; byte_counter += sizeof(double);		// tdc resolution in ns

	TDCDataType = 1;
	if (DAQVersion_output >= 20020408 && HM1.use_normal_method) {*output_lmf << TDCDataType; byte_counter += sizeof(__int32);}
	
	if (DAQ_ID_output == DAQ_ID_HM1 || DAQ_ID_output == DAQ_ID_HM1_ABM) {
		*output_lmf << HM1.Even_open_time; byte_counter += sizeof(__int32);
		*output_lmf << HM1.Auto_Trigger; byte_counter += sizeof(__int32);
	}

	if (DAQVersion_output >= 20080507) {
		unsigned __int64 dummy = number_of_channels_output;
		*output_lmf << dummy; byte_counter += sizeof(__int64);			// number of channels
		if (DAQ_ID_output == DAQ_ID_HM1_ABM) {
			dummy = 0;
			*output_lmf << dummy; byte_counter += sizeof(__int64);
		} else { 
			dummy = max_number_of_hits_output;
			*output_lmf << dummy; byte_counter += sizeof(__int64);		// number of hits
		}
	} else {
	*output_lmf << number_of_channels_output; byte_counter += sizeof(__int32);			// number of channels
	if (DAQ_ID_output == DAQ_ID_HM1_ABM) {
			*output_lmf << __int32(0); byte_counter += sizeof(__int32);
	} else { 
		*output_lmf << max_number_of_hits_output; byte_counter += sizeof(__int32);			// number of hits
	}
	}
	
	if (DAQ_ID_output == DAQ_ID_HM1 || DAQ_ID_output == DAQ_ID_HM1_ABM) {
		*output_lmf << HM1.set_bits_for_GP1; byte_counter += sizeof(__int32);
	}
	*output_lmf << data_format_in_userheader_output;	byte_counter += sizeof(__int32);				// data format (2=short integer)

	if (DAQ_ID_output == DAQ_ID_HM1 || DAQ_ID_output == DAQ_ID_HM1_ABM) {*output_lmf << module_2nd;	byte_counter += sizeof(__int32);}	// indicator for 2nd module data

	if (DAQ_ID_output == DAQ_ID_2HM1) {
		*output_lmf << DAQSubVersion;						byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_FAK_DLL_Value;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_Resolution_Flag;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_trigger_mode_for_start;	byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_trigger_mode_for_stop;	byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_res_adjust;				byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_tdcresolution;			byte_counter += sizeof(double);
		*output_lmf << HM1.TWOHM1_test_overflow;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_number_of_channels;		byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_number_of_hits;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_set_bits_for_GP1;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_HM1_ID_1;					byte_counter += sizeof(__int32);
		*output_lmf << HM1.TWOHM1_HM1_ID_2;					byte_counter += sizeof(__int32);
	}

	if (DAQ_ID_output == DAQ_ID_HM1_ABM) {
		*output_lmf << HM1.ABM_m_xFrom;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_xTo;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_yFrom;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_yTo;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_xMin;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_xMax;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_yMin;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_yMax;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_xOffset;		byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_yOffset;		byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_m_zOffset;		byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_Mode;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_OsziDarkInvert;	byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_ErrorHisto;		byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_XShift;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_YShift;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_ZShift;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_ozShift;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_wdShift;			byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_ucLevelXY;		byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_ucLevelZ;		byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_uiABMXShift;		byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_uiABMYShift;		byte_counter += sizeof(__int32);
		*output_lmf << HM1.ABM_uiABMZShift;		byte_counter += sizeof(__int32);
	}

	return byte_counter;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x2b20(%rdi), %rdi
movsd 0x12c8(%rbx), %xmm0
callq 0x11072
movq 0x2b20(%rbx), %rdi
movl 0x2a4(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x2ac(%rbx), %esi
callq 0x10d1e
movl 0xa8(%rbx), %esi
movq 0x2b20(%rbx), %rdi
callq 0x10d1e
movq 0x2b20(%rbx), %rdi
movq 0xa0(%rbx), %rsi
movl 0xa8(%rbx), %edx
callq 0x10e3c
movl 0xa8(%rbx), %r15d
leal 0x14(%r15), %r14d
cmpl $0x1317cb8, 0x284(%rbx) # imm = 0x1317CB8
jb 0xb4ac
cmpb $0x1, 0x13bc(%rbx)
jne 0xb4ac
movq 0x2b20(%rbx), %rdi
movl 0x12a8(%rbx), %esi
callq 0x11094
addl $0x18, %r15d
movl %r15d, %r14d
movq 0x2b20(%rbx), %rdi
movl 0x1290(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x244(%rbx), %esi
callq 0x11094
movl 0x28c(%rbx), %eax
cmpl $0x6, %eax
je 0xb4e0
cmpl $0x1, %eax
jne 0xb52e
movq 0x2b20(%rbx), %rdi
movl 0x1340(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1344(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1348(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x134c(%rbx), %esi
callq 0x11094
addl $0x18, %r14d
jmp 0xb532
addl $0x8, %r14d
movq 0x2b20(%rbx), %rdi
movsd 0x12c0(%rbx), %xmm0
callq 0x11072
leal 0x8(%r14), %ebp
movl $0x1, 0x12ac(%rbx)
cmpl $0x1317cb8, 0x284(%rbx) # imm = 0x1317CB8
jb 0xb57f
cmpb $0x1, 0x13bc(%rbx)
jne 0xb57f
movq 0x2b20(%rbx), %rdi
pushq $0x1
popq %rsi
callq 0x11094
addl $0xc, %r14d
movl %r14d, %ebp
movl 0x28c(%rbx), %eax
cmpl $0x6, %eax
je 0xb58f
cmpl $0x1, %eax
jne 0xb5b6
movq 0x2b20(%rbx), %rdi
movl 0x1350(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1354(%rbx), %esi
callq 0x11094
addl $0x8, %ebp
cmpl $0x132677b, 0x284(%rbx) # imm = 0x132677B
jb 0xb5f9
movslq 0x2c4(%rbx), %rsi
movq 0x2b20(%rbx), %rdi
callq 0x10e18
xorl %eax, %eax
cmpl $0x6, 0x28c(%rbx)
je 0xb5e6
movl 0x2cc(%rbx), %eax
movslq %eax, %rsi
movq 0x2b20(%rbx), %rdi
callq 0x10e18
pushq $0x10
jmp 0xb62c
movq 0x2b20(%rbx), %rdi
movl 0x2c4(%rbx), %esi
callq 0x11094
cmpl $0x6, 0x28c(%rbx)
movq 0x2b20(%rbx), %rdi
jne 0xb61f
xorl %esi, %esi
jmp 0xb625
movl 0x2cc(%rbx), %esi
callq 0x11094
pushq $0x8
popq %rax
addl %eax, %ebp
movl 0x28c(%rbx), %eax
cmpl $0x6, %eax
je 0xb63f
cmpl $0x1, %eax
jne 0xb654
movq 0x2b20(%rbx), %rdi
movl 0x1358(%rbx), %esi
callq 0x11094
addl $0x4, %ebp
movq 0x2b20(%rbx), %rdi
movl 0x294(%rbx), %esi
callq 0x11094
movl 0x28c(%rbx), %eax
cmpl $0x6, %eax
je 0xb676
cmpl $0x1, %eax
jne 0xb693
movq 0x2b20(%rbx), %rdi
movl 0x1288(%rbx), %esi
callq 0x11094
addl $0x8, %ebp
movl 0x28c(%rbx), %eax
jmp 0xb696
addl $0x4, %ebp
cmpl $0x4, %eax
jne 0xb794
movq 0x2b20(%rbx), %rdi
movl 0x1284(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13c0(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13c4(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13c8(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13cc(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13d0(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movsd 0x13d8(%rbx), %xmm0
callq 0x11072
movq 0x2b20(%rbx), %rdi
movl 0x13e0(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13e4(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13e8(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13ec(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13f0(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13f4(%rbx), %esi
callq 0x11094
addl $0x38, %ebp
movl 0x28c(%rbx), %eax
cmpl $0x6, %eax
jne 0xb950
movq 0x2b20(%rbx), %rdi
movl 0x135c(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1360(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1364(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1368(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x136c(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1370(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1374(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1378(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x137c(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1380(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1384(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1388(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x138c(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1390(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1394(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x1398(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x139c(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13a0(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13a4(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13a8(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13ac(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13b0(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13b4(%rbx), %esi
callq 0x11094
movq 0x2b20(%rbx), %rdi
movl 0x13b8(%rbx), %esi
callq 0x11094
addl $0x60, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop