// File: /workspace/github_cpp_makefile_star2_O2/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::WriteCAMACArray(double, unsigned int*)
void LMF_IO::WriteCAMACArray(double timestamp, unsigned __int32 data[])
/////////////////////////////////////////////////////////////////
{
	unsigned __int16 dummy_uint16;
	unsigned __int8  dummy_uint8;


	if (!output_lmf || !OutputFileIsOpen) {
		errorflag = 10;
		return;
	}
	
	++uint64_number_of_written_events;

	myLARGE_INTEGER LARGE_Timestamp;
	LARGE_Timestamp.QuadPart = (__int64)(timestamp * frequency);

	if (timestamp_format_output >= 1) {
		if (data_format_in_userheader_output == 2) {
			dummy_uint16 = (unsigned __int16)(LARGE_Timestamp.LowPart & 0x0000ffff); *output_lmf << dummy_uint16;			// 32 Bit Low part, lower  16 Bit
			dummy_uint16 = (unsigned __int16)(LARGE_Timestamp.LowPart & 0xffff0000); *output_lmf << dummy_uint16;			// 32 Bit Low part, higher 16 Bit
		}
		if (data_format_in_userheader_output == 6) {
			dummy_uint8 = (unsigned __int8)(LARGE_Timestamp.LowPart & 0x000000ff); *output_lmf << dummy_uint8;			// 32 Bit Low part, lower 16 Bit, lower 8 bit
			dummy_uint8 = (unsigned __int8)((LARGE_Timestamp.LowPart >> 8) & 0x000000ff); *output_lmf << dummy_uint8;	// 32 Bit Low part, lower 16 Bit, high 8 bit
			dummy_uint8 = (unsigned __int8)0; *output_lmf << dummy_uint8;	
			dummy_uint8 = (unsigned __int8)((LARGE_Timestamp.LowPart >> 16) & 0x000000ff); *output_lmf << dummy_uint8;	// 32 Bit Low part, lower 16 Bit, high 8 bit
			dummy_uint8 = (unsigned __int8)((LARGE_Timestamp.LowPart >> 24) & 0x000000ff); *output_lmf << dummy_uint8;	// 32 Bit Low part, lower 16 Bit, high 8 bit
			dummy_uint8 = (unsigned __int8)0; *output_lmf << dummy_uint8;
		}
	}
	if (timestamp_format_output == 2) {
		if (data_format_in_userheader_output == 2) {
			dummy_uint16 = (unsigned __int16)(LARGE_Timestamp.HighPart & 0x0000ffff); *output_lmf << dummy_uint16;			// 32 Bit High part, lower  16 Bit
			dummy_uint16 = (unsigned __int16)(LARGE_Timestamp.HighPart & 0xffff0000); *output_lmf << dummy_uint16;			// 32 Bit High part, higher 16 Bit
		}
		if (data_format_in_userheader_output == 6) {
			dummy_uint8 = (unsigned __int8)(LARGE_Timestamp.HighPart & 0x000000ff); *output_lmf << dummy_uint8;			// 32 Bit High part, lower 16 Bit, lower 8 bit
			dummy_uint8 = (unsigned __int8)((LARGE_Timestamp.HighPart >> 8) & 0x000000ff); *output_lmf << dummy_uint8;	// 32 Bit High part, lower 16 Bit, high 8 bit
			dummy_uint8 = (unsigned __int8)0; *output_lmf << dummy_uint8;	
			dummy_uint8 = (unsigned __int8)((LARGE_Timestamp.HighPart >> 16) & 0x000000ff); *output_lmf << dummy_uint8;	// 32 Bit High part, lower 16 Bit, high 8 bit
			dummy_uint8 = (unsigned __int8)((LARGE_Timestamp.HighPart >> 24) & 0x000000ff); *output_lmf << dummy_uint8;	// 32 Bit High part, lower 16 Bit, high 8 bit
			dummy_uint8 = (unsigned __int8)0; *output_lmf << dummy_uint8;
		}
	}

	unsigned __int32 i;

	for (i=0;i<Numberofcoordinates - timestamp_format_output * 2;++i) {
		if (data_format_in_userheader_output == 2) {
			dummy_uint16 = (unsigned __int16)( data[i]        & 0x0000ffff); *output_lmf << dummy_uint16;
		}
		if (data_format_in_userheader_output == 6) {
			dummy_uint8 = (unsigned __int8)( data[i]        & 0x000000ff); *output_lmf << dummy_uint8;
			dummy_uint8 = (unsigned __int8)((data[i] >>  8) & 0x000000ff); *output_lmf << dummy_uint8;
			dummy_uint8 = (unsigned __int8)((data[i] >> 16) & 0x000000ff); *output_lmf << dummy_uint8;
		}
	}

	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %r14
movq 0x2b20(%rdi), %rdi
testq %rdi, %rdi
je 0xee08
cmpb $0x0, 0x2b29(%r14)
je 0xee08
movq %rsi, %rbx
incq 0x2b10(%r14)
cmpl $0x0, 0x2ac(%r14)
je 0xed8b
mulsd 0x12c8(%r14), %xmm0
cvttsd2si %xmm0, %r15
movl 0x294(%r14), %eax
cmpl $0x2, %eax
jne 0xec5f
movzwl %r15w, %esi
callq 0x10df4
movq 0x2b20(%r14), %rdi
xorl %esi, %esi
callq 0x10df4
movl 0x294(%r14), %eax
cmpl $0x6, %eax
jne 0xecd0
movq 0x2b20(%r14), %rdi
movl $0xff, %ebp
movl %r15d, %esi
andl %ebp, %esi
callq 0x10dd0
movl %r15d, %esi
shrl $0x8, %esi
movq 0x2b20(%r14), %rdi
andl %ebp, %esi
callq 0x10dd0
movq 0x2b20(%r14), %rdi
xorl %esi, %esi
callq 0x10dd0
movl %r15d, %esi
shrl $0x10, %esi
movq 0x2b20(%r14), %rdi
andl %ebp, %esi
callq 0x10dd0
movl %r15d, %esi
shrl $0x18, %esi
movq 0x2b20(%r14), %rdi
callq 0x10dd0
movq 0x2b20(%r14), %rdi
xorl %esi, %esi
callq 0x10dd0
cmpl $0x2, 0x2ac(%r14)
jne 0xed8b
movq %r15, %r12
shrq $0x20, %r12
movl 0x294(%r14), %eax
cmpl $0x2, %eax
jne 0xed16
movq 0x2b20(%r14), %rdi
movzwl %r12w, %esi
callq 0x10df4
movq 0x2b20(%r14), %rdi
xorl %esi, %esi
callq 0x10df4
movl 0x294(%r14), %eax
cmpl $0x6, %eax
jne 0xed8b
movq 0x2b20(%r14), %rdi
movl $0xff, %ebp
andl %ebp, %r12d
movl %r12d, %esi
callq 0x10dd0
movq %r15, %rsi
shrq $0x28, %rsi
movq 0x2b20(%r14), %rdi
andl %ebp, %esi
callq 0x10dd0
movq 0x2b20(%r14), %rdi
xorl %esi, %esi
callq 0x10dd0
movq %r15, %rsi
shrq $0x30, %rsi
movq 0x2b20(%r14), %rdi
andl %ebp, %esi
callq 0x10dd0
shrq $0x38, %r15
movq 0x2b20(%r14), %rdi
movl %r15d, %esi
callq 0x10dd0
movq 0x2b20(%r14), %rdi
xorl %esi, %esi
callq 0x10dd0
xorl %r15d, %r15d
movl 0x270(%r14), %eax
movl 0x2ac(%r14), %ecx
addl %ecx, %ecx
subl %ecx, %eax
cmpq %rax, %r15
jae 0xee13
movl 0x294(%r14), %eax
cmpl $0x2, %eax
jne 0xedc9
movzwl (%rbx,%r15,4), %esi
movq 0x2b20(%r14), %rdi
callq 0x10df4
movl 0x294(%r14), %eax
cmpl $0x6, %eax
jne 0xee03
movzbl (%rbx,%r15,4), %esi
movq 0x2b20(%r14), %rdi
callq 0x10dd0
movzbl 0x1(%rbx,%r15,4), %esi
movq 0x2b20(%r14), %rdi
callq 0x10dd0
movzbl 0x2(%rbx,%r15,4), %esi
movq 0x2b20(%r14), %rdi
callq 0x10dd0
incq %r15
jmp 0xed8e
movl $0xa, 0x12e0(%r14)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq