// File: /workspace/github_cpp_makefile_star2_O3/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), %rdi
testq %rdi, %rdi
je 0x1146d
incq 0x260(%r14)
movq $0x0, 0x12d0(%r14)
cmpl $0x0, 0x2a8(%r14)
movq %rdi, 0x10(%rsp)
je 0x1147d
movl 0x290(%r14), %eax
cmpl $0x2, %eax
jne 0x11484
leaq 0xe(%rsp), %r15
movq %r15, %rsi
movl $0x2, %edx
callq 0x133bc
movzwl (%r15), %ebx
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x133bc
movzwl (%r15), %ebp
shll $0x10, %ebp
orq %rbx, %rbp
movl 0x290(%r14), %eax
jmp 0x11486
movl $0x9, 0x12e0(%r14)
jmp 0x11799
xorl %eax, %eax
jmp 0x116b1
xorl %ebp, %ebp
cmpl $0x6, %eax
jne 0x11544
movq 0x2b18(%r14), %rdi
leaq 0xd(%rsp), %r15
movq %r15, %rsi
movl $0x1, %edx
callq 0x133bc
movq 0x2b18(%r14), %rdi
leaq 0xc(%rsp), %r12
movq %r12, %rsi
movl $0x1, %edx
callq 0x133bc
movq 0x2b18(%r14), %rdi
leaq 0xb(%rsp), %r13
movq %r13, %rsi
movl $0x1, %edx
callq 0x133bc
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 0x133bc
movq 0x2b18(%r14), %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x133bc
movq 0x2b18(%r14), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x133bc
movzbl (%r15), %ebp
movzbl (%r12), %eax
shll $0x18, %eax
shll $0x10, %ebp
orl %eax, %ebp
addq %rbx, %rbp
cmpl $0x2, 0x2a8(%r14)
jne 0x1159e
movl 0x290(%r14), %ecx
cmpl $0x2, %ecx
jne 0x115a5
movq 0x2b18(%r14), %rdi
leaq 0xe(%rsp), %r15
movq %r15, %rsi
movl $0x2, %edx
callq 0x133bc
movzwl (%r15), %ebx
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
movl $0x2, %edx
callq 0x133bc
movzwl (%r15), %eax
shll $0x10, %eax
orq %rbx, %rax
movl 0x290(%r14), %ecx
jmp 0x115a7
xorl %eax, %eax
jmp 0x11665
xorl %eax, %eax
cmpl $0x6, %ecx
jne 0x11665
movq 0x2b18(%r14), %rdi
leaq 0xd(%rsp), %r15
movq %r15, %rsi
movl $0x1, %edx
callq 0x133bc
movq 0x2b18(%r14), %rdi
leaq 0xc(%rsp), %r12
movq %r12, %rsi
movl $0x1, %edx
callq 0x133bc
movq 0x2b18(%r14), %rdi
leaq 0xb(%rsp), %r13
movq %r13, %rsi
movl $0x1, %edx
callq 0x133bc
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 0x133bc
movq 0x2b18(%r14), %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x133bc
movq 0x2b18(%r14), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x133bc
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, %xmm0
punpckldq 0x2a05(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
movq %rcx, 0x12d8(%r14)
subpd 0x2a06(%rip), %xmm0     # 0x14090
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 0x1178c
xorl %ebx, %ebx
leaq 0xd(%rsp), %r15
leaq 0xc(%rsp), %r12
leaq 0xb(%rsp), %r13
leaq 0xe(%rsp), %rbp
movl 0x290(%r14), %eax
cmpl $0x6, %eax
jne 0x11746
movq 0x2b18(%r14), %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x133bc
movq 0x2b18(%r14), %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x133bc
movq 0x2b18(%r14), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x133bc
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 0x1176e
movq 0x2b18(%r14), %rdi
movq %rbp, %rsi
movl $0x2, %edx
callq 0x133bc
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 0x116d4
movb $0x0, 0x2b4c(%r14)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
setne %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq