// File: NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::ReadNextCAMACEvent()
bool LMF_IO::ReadNextCAMACEvent()
/////////////////////////////////////////////////////////////////
{
	unsigned __int32	i;

	if (!input_lmf) {
		errorflag = 9;
		return false;
	}

	++uint64_number_of_read_events;

	//-------------------------------
	//  Read Time Stamp
	DOUBLE_timestamp = 0.;
	
	unsigned __int32 time_temp;
	unsigned __int8 byte_1,byte_2,byte_3;
	unsigned __int16 unsigned_short;

	if (timestamp_format > 0) {
		//TRY
			myLARGE_INTEGER LARGE_timestamp;
			LARGE_timestamp.QuadPart = 0;
			if (timestamp_format >= 1 )
			{
				if (data_format_in_userheader == 2) {
					*input_lmf >> unsigned_short;
					time_temp = unsigned_short;
					*input_lmf >> unsigned_short;
					LARGE_timestamp.LowPart = time_temp + unsigned_short*256*256;
				}
				if (data_format_in_userheader == 6) {
					*input_lmf >> byte_1; *input_lmf >> byte_2; *input_lmf >> byte_3;
					time_temp = byte_1 + byte_2 * 256 + byte_3 * 256 * 256;
					LARGE_timestamp.LowPart = time_temp;

					*input_lmf >> byte_1; *input_lmf >> byte_2; *input_lmf >> byte_3;
					time_temp = byte_1 + byte_2 * 256 + byte_3 * 256 * 256;
					LARGE_timestamp.LowPart += time_temp * 256*256;
				}
			}
			if (timestamp_format == 2 ) {
				if (data_format_in_userheader == 2) {
					*input_lmf >> unsigned_short;
					time_temp = unsigned_short;
					*input_lmf >> unsigned_short;
					LARGE_timestamp.HighPart = time_temp + unsigned_short*256*256;
				}
				if (data_format_in_userheader == 6) {
					*input_lmf >> byte_1; *input_lmf >> byte_2; *input_lmf >> byte_3;
					time_temp = byte_1 + byte_2 * 256 + byte_3 * 256 * 256;
					LARGE_timestamp.HighPart = time_temp;

					*input_lmf >> byte_1; *input_lmf >> byte_2; *input_lmf >> byte_3;
					time_temp = byte_1 + byte_2 * 256 + byte_3 * 256 * 256;
					LARGE_timestamp.HighPart += time_temp * 256*256;
				}
			}
			ui64_timestamp = LARGE_timestamp.QuadPart;
/*		CATCH(CArchiveException,e)
			errorflag = 1;	// error reading timestamp
			return false;
		END_CATCH
		*/
		DOUBLE_timestamp = double(ui64_timestamp)/frequency;  // time stamp in seconds.
	}

//	TRY
		for (i=0;i<Numberofcoordinates - timestamp_format * 2;++i) {
			if (data_format_in_userheader == 6) {
				*input_lmf >> byte_1; *input_lmf >> byte_2; *input_lmf >> byte_3;
				CAMAC_Data[i] = byte_1 + byte_2 * 256 + byte_3 * 256 * 256;
			}
			if (data_format_in_userheader == 2) {
				*input_lmf >> unsigned_short;
				CAMAC_Data[i] = unsigned_short;
			}
		} // for i
/*	CATCH(CArchiveException,e)
		errorflag = 2; // error reading data
		return false;
	END_CATCH
	*/

	must_read_first = false;
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, 0x2b18(%rax)
jne 0x18fa5
movq -0x30(%rbp), %rax
movl $0x9, 0x12e0(%rax)
movb $0x0, -0x1(%rbp)
jmp 0x19380
movq -0x30(%rbp), %rax
movq 0x260(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x260(%rax)
xorps %xmm0, %xmm0
movsd %xmm0, 0x12d0(%rax)
cmpl $0x0, 0x2a8(%rax)
jbe 0x19292
movq -0x30(%rbp), %rax
movq $0x0, -0x28(%rbp)
cmpl $0x1, 0x2a8(%rax)
jb 0x19112
movq -0x30(%rbp), %rax
cmpl $0x2, 0x290(%rax)
jne 0x1903a
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1e(%rbp), %rsi
callq 0x1cb50
movq -0x30(%rbp), %rax
movzwl -0x1e(%rbp), %ecx
movl %ecx, -0x18(%rbp)
movq 0x2b18(%rax), %rdi
leaq -0x1e(%rbp), %rsi
callq 0x1cb50
movl -0x18(%rbp), %eax
movzwl -0x1e(%rbp), %ecx
shll $0x8, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, -0x28(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x6, 0x290(%rax)
jne 0x19110
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x19(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1a(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1b(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movzbl -0x19(%rbp), %ecx
movzbl -0x1a(%rbp), %edx
shll $0x8, %edx
addl %edx, %ecx
movzbl -0x1b(%rbp), %edx
shll $0x8, %edx
shll $0x8, %edx
addl %edx, %ecx
movl %ecx, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movl %ecx, -0x28(%rbp)
movq 0x2b18(%rax), %rdi
leaq -0x19(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1a(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1b(%rbp), %rsi
callq 0x1cb20
movzbl -0x19(%rbp), %eax
movzbl -0x1a(%rbp), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movzbl -0x1b(%rbp), %ecx
shll $0x8, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
shll $0x8, %eax
shll $0x8, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x19112
movq -0x30(%rbp), %rax
cmpl $0x2, 0x2a8(%rax)
jne 0x19249
movq -0x30(%rbp), %rax
cmpl $0x2, 0x290(%rax)
jne 0x19171
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1e(%rbp), %rsi
callq 0x1cb50
movq -0x30(%rbp), %rax
movzwl -0x1e(%rbp), %ecx
movl %ecx, -0x18(%rbp)
movq 0x2b18(%rax), %rdi
leaq -0x1e(%rbp), %rsi
callq 0x1cb50
movl -0x18(%rbp), %eax
movzwl -0x1e(%rbp), %ecx
shll $0x8, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x6, 0x290(%rax)
jne 0x19247
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x19(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1a(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1b(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movzbl -0x19(%rbp), %ecx
movzbl -0x1a(%rbp), %edx
shll $0x8, %edx
addl %edx, %ecx
movzbl -0x1b(%rbp), %edx
shll $0x8, %edx
shll $0x8, %edx
addl %edx, %ecx
movl %ecx, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movl %ecx, -0x24(%rbp)
movq 0x2b18(%rax), %rdi
leaq -0x19(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1a(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1b(%rbp), %rsi
callq 0x1cb20
movzbl -0x19(%rbp), %eax
movzbl -0x1a(%rbp), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movzbl -0x1b(%rbp), %ecx
shll $0x8, %ecx
shll $0x8, %ecx
addl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
shll $0x8, %eax
shll $0x8, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x19249
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, 0x12d8(%rax)
movq 0x12d8(%rax), %xmm0
movaps 0x5e09(%rip), %xmm1     # 0x1f070
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x5e0d(%rip), %xmm1     # 0x1f080
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
divsd 0x12c8(%rax), %xmm0
movsd %xmm0, 0x12d0(%rax)
movl $0x0, -0x14(%rbp)
movq -0x30(%rbp), %rdx
movl -0x14(%rbp), %eax
movl 0x270(%rdx), %ecx
movl 0x2a8(%rdx), %edx
shll %edx
subl %edx, %ecx
cmpl %ecx, %eax
jae 0x19371
movq -0x30(%rbp), %rax
cmpl $0x6, 0x290(%rax)
jne 0x1932b
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x19(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1a(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1b(%rbp), %rsi
callq 0x1cb20
movq -0x30(%rbp), %rax
movzbl -0x19(%rbp), %edx
movzbl -0x1a(%rbp), %ecx
shll $0x8, %ecx
addl %ecx, %edx
movzbl -0x1b(%rbp), %ecx
shll $0x8, %ecx
shll $0x8, %ecx
addl %ecx, %edx
movq 0x2b78(%rax), %rax
movl -0x14(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
cmpl $0x2, 0x290(%rax)
jne 0x19361
movq -0x30(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x1e(%rbp), %rsi
callq 0x1cb50
movq -0x30(%rbp), %rax
movzwl -0x1e(%rbp), %edx
movq 0x2b78(%rax), %rax
movl -0x14(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x19363
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x19299
movq -0x30(%rbp), %rax
movb $0x0, 0x2b4c(%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)