// File: /workspace/github_cpp_makefile_star2_O1/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 0x11621
movq %rax, 0x10(%rsp)
incq 0x260(%r14)
movq $0x0, 0x12d0(%r14)
cmpl $0x0, 0x2a8(%r14)
je 0x11856
cmpl $0x2, 0x290(%r14)
jne 0x11631
leaq 0xe(%rsp), %r15
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x139ac
movzwl (%r15), %ebx
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x139ac
movzwl (%r15), %ebp
shll $0x10, %ebp
orq %rbx, %rbp
jmp 0x11633
movl $0x9, 0x12e0(%r14)
jmp 0x11943
xorl %ebp, %ebp
cmpl $0x6, 0x290(%r14)
jne 0x116f6
movq 0x2b18(%r14), %rdi
leaq 0xd(%rsp), %r15
movq %r15, %rsi
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
leaq 0xc(%rsp), %r12
movq %r12, %rsi
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
leaq 0xb(%rsp), %r13
movq %r13, %rsi
movl $0x1, %edx
callq 0x139ac
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
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x139ac
movzbl (%r15), %ebp
movzbl (%r12), %eax
shll $0x18, %eax
shll $0x10, %ebp
orl %eax, %ebp
addq %rbx, %rbp
cmpl $0x2, 0x2a8(%r14)
jne 0x11747
cmpl $0x2, 0x290(%r14)
jne 0x1174e
movq 0x2b18(%r14), %rdi
leaq 0xe(%rsp), %r15
movq %r15, %rsi
movl $0x2, %edx
callq 0x139ac
movzwl (%r15), %ebx
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x139ac
movzwl (%r15), %eax
shll $0x10, %eax
orq %rbx, %rax
jmp 0x11750
xorl %eax, %eax
jmp 0x11813
xorl %eax, %eax
cmpl $0x6, 0x290(%r14)
jne 0x11813
movq 0x2b18(%r14), %rdi
leaq 0xd(%rsp), %r15
movq %r15, %rsi
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
leaq 0xc(%rsp), %r12
movq %r12, %rsi
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
leaq 0xb(%rsp), %r13
movq %r13, %rsi
movl $0x1, %edx
callq 0x139ac
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
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x139ac
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 0x3800(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3808(%rip), %xmm0     # 0x15040
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd 0x12c8(%r14), %xmm1
movsd %xmm1, 0x12d0(%r14)
movl 0x2a8(%r14), %eax
addl %eax, %eax
cmpl %eax, 0x270(%r14)
je 0x11936
xorl %ebx, %ebx
leaq 0xd(%rsp), %r15
leaq 0xc(%rsp), %r12
leaq 0xb(%rsp), %r13
leaq 0xe(%rsp), %rbp
cmpl $0x6, 0x290(%r14)
jne 0x118eb
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x139ac
movq 0x2b18(%r14), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x139ac
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)
cmpl $0x2, 0x290(%r14)
jne 0x11918
movq 0x2b18(%r14), %rdi
movq %rbp, %rsi
movl $0x2, %edx
callq 0x139ac
movzwl 0xe(%rsp), %eax
movq 0x2b78(%r14), %rcx
movl %eax, (%rcx,%rbx,4)
incq %rbx
movl 0x270(%r14), %eax
movl 0x2a8(%r14), %ecx
addl %ecx, %ecx
subl %ecx, %eax
cmpq %rax, %rbx
jb 0x11882
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