// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, 0x2b20(%rax)
je 0x18bd4
movq -0x38(%rbp), %rax
testb $0x1, 0x2b29(%rax)
jne 0x18be7
movq -0x38(%rbp), %rax
movl $0xa, 0x12e0(%rax)
jmp 0x18f5c
movq -0x38(%rbp), %rax
movq 0x2b10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x2b10(%rax)
movsd -0x10(%rbp), %xmm0
mulsd 0x12c8(%rax), %xmm0
cvttsd2si %xmm0, %rcx
movq %rcx, -0x28(%rbp)
cmpl $0x1, 0x2ac(%rax)
jb 0x18d3b
movq -0x38(%rbp), %rax
cmpl $0x2, 0x294(%rax)
jne 0x18c6f
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movw %cx, -0x1a(%rbp)
movq 0x2b20(%rax), %rdi
movzwl -0x1a(%rbp), %esi
callq 0x1cca0
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
movw %cx, -0x1a(%rbp)
movq 0x2b20(%rax), %rdi
movzwl -0x1a(%rbp), %esi
callq 0x1cca0
movq -0x38(%rbp), %rax
cmpl $0x6, 0x294(%rax)
jne 0x18d39
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
shrl $0x8, %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movb $0x0, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
shrl $0x10, %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
shrl $0x18, %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movb $0x0, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
jmp 0x18d3b
movq -0x38(%rbp), %rax
cmpl $0x2, 0x2ac(%rax)
jne 0x18e67
movq -0x38(%rbp), %rax
cmpl $0x2, 0x294(%rax)
jne 0x18d9b
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movw %cx, -0x1a(%rbp)
movq 0x2b20(%rax), %rdi
movzwl -0x1a(%rbp), %esi
callq 0x1cca0
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
movw %cx, -0x1a(%rbp)
movq 0x2b20(%rax), %rdi
movzwl -0x1a(%rbp), %esi
callq 0x1cca0
movq -0x38(%rbp), %rax
cmpl $0x6, 0x294(%rax)
jne 0x18e65
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
sarl $0x8, %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movb $0x0, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
sarl $0x10, %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movl -0x24(%rbp), %ecx
sarl $0x18, %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movb $0x0, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
jmp 0x18e67
movl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rdx
movl -0x2c(%rbp), %eax
movl 0x270(%rdx), %ecx
movl 0x2ac(%rdx), %edx
shll %edx
subl %edx, %ecx
cmpl %ecx, %eax
jae 0x18f5a
movq -0x38(%rbp), %rax
cmpl $0x2, 0x294(%rax)
jne 0x18ec2
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movw %cx, -0x1a(%rbp)
movq 0x2b20(%rax), %rdi
movzwl -0x1a(%rbp), %esi
callq 0x1cca0
movq -0x38(%rbp), %rax
cmpl $0x6, 0x294(%rax)
jne 0x18f4a
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl $0x8, %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl $0x10, %ecx
andl $0xff, %ecx
movb %cl, -0x1b(%rbp)
movq 0x2b20(%rax), %rdi
movzbl -0x1b(%rbp), %esi
callq 0x1cc60
jmp 0x18f4c
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x18e6e
jmp 0x18f5c
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)