// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movq 0x2b18(%rdi), %rax
testq %rax, %rax
je 0xee9f
movq %rax, 0x10(%rsp)
incq 0x260(%r14)
andq $0x0, 0x12d0(%r14)
cmpl $0x0, 0x2a8(%r14)
je 0xf08d
movl 0x290(%r14), %eax
cmpl $0x2, %eax
jne 0xeeaf
leaq 0xe(%rsp), %r15
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x10d54
movzwl (%r15), %ebx
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
callq 0x10d54
movzwl (%r15), %ebp
shll $0x10, %ebp
orq %rbx, %rbp
movl 0x290(%r14), %eax
jmp 0xeeb1
movl $0x9, 0x12e0(%r14)
jmp 0xf159
xorl %ebp, %ebp
cmpl $0x6, %eax
jne 0xef51
movq 0x2b18(%r14), %rdi
leaq 0xd(%rsp), %r15
movq %r15, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
leaq 0xc(%rsp), %r12
movq %r12, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
leaq 0xb(%rsp), %r13
movq %r13, %rsi
callq 0x10d42
movzbl (%r15), %eax
movzbl (%r12), %ecx
shll $0x8, %ecx
orq %rax, %rcx
movzbl (%r13), %ebx
shll $0x10, %ebx
orq %rcx, %rbx
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
movq %r12, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
movq %r13, %rsi
callq 0x10d42
movzbl (%r15), %ebp
movzbl (%r12), %eax
shll $0x18, %eax
shll $0x10, %ebp
orl %eax, %ebp
addq %rbx, %rbp
cmpl $0x2, 0x2a8(%r14)
jne 0xefa1
movl 0x290(%r14), %ecx
cmpl $0x2, %ecx
jne 0xefa8
movq 0x2b18(%r14), %rdi
leaq 0xe(%rsp), %r15
movq %r15, %rsi
callq 0x10d54
movzwl (%r15), %ebx
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
callq 0x10d54
movzwl (%r15), %eax
shll $0x10, %eax
orq %rbx, %rax
movl 0x290(%r14), %ecx
jmp 0xefaa
xorl %eax, %eax
jmp 0xf04a
xorl %eax, %eax
cmpl $0x6, %ecx
jne 0xf04a
movq 0x2b18(%r14), %rdi
leaq 0xd(%rsp), %r15
movq %r15, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
leaq 0xc(%rsp), %r12
movq %r12, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
leaq 0xb(%rsp), %r13
movq %r13, %rsi
callq 0x10d42
movzbl (%r15), %eax
movzbl (%r12), %ecx
shll $0x8, %ecx
orq %rax, %rcx
movzbl (%r13), %ebx
shll $0x10, %ebx
orq %rcx, %rbx
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
movq %r12, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
movq %r13, %rsi
callq 0x10d42
movzbl (%r15), %eax
movzbl (%r12), %ecx
shll $0x18, %ecx
shll $0x10, %eax
orl %ecx, %eax
addq %rbx, %rax
shlq $0x20, %rax
movl %ebp, %ecx
orq %rax, %rcx
movq %rcx, 0x12d8(%r14)
movq %rcx, %xmm0
punpckldq 0x2fe9(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2ff1(%rip), %xmm0     # 0x12060
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd 0x12c8(%r14), %xmm1
movsd %xmm1, 0x12d0(%r14)
xorl %ebx, %ebx
leaq 0xd(%rsp), %r15
leaq 0xc(%rsp), %r12
leaq 0xb(%rsp), %r13
leaq 0xe(%rsp), %rbp
movl 0x270(%r14), %eax
movl 0x2a8(%r14), %ecx
addl %ecx, %ecx
subl %ecx, %eax
cmpq %rax, %rbx
jae 0xf14c
movl 0x290(%r14), %eax
cmpl $0x6, %eax
jne 0xf121
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
movq %r12, %rsi
callq 0x10d42
movq 0x2b18(%r14), %rdi
movq %r13, %rsi
callq 0x10d42
movzbl 0xd(%rsp), %eax
movzbl 0xc(%rsp), %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl 0xb(%rsp), %eax
shll $0x10, %eax
orl %ecx, %eax
movq 0x2b78(%r14), %rcx
movl %eax, (%rcx,%rbx,4)
movl 0x290(%r14), %eax
cmpl $0x2, %eax
jne 0xf144
movq 0x2b18(%r14), %rdi
movq %rbp, %rsi
callq 0x10d54
movzwl 0xe(%rsp), %eax
movq 0x2b78(%r14), %rcx
movl %eax, (%rcx,%rbx,4)
incq %rbx
jmp 0xf0a3
movb $0x0, 0x2b4c(%r14)
movq 0x10(%rsp), %rax
testq %rax, %rax
setne %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq