// File: /workspace/github_cpp_makefile_star2_O3/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::ReadNextfADC8Signal(fADC8_signal_info_struct&, bool&, unsigned int*, int)
bool LMF_IO::ReadNextfADC8Signal(fADC8_signal_info_struct& signal_info, bool& bEnd_of_group_detected, unsigned __int32 * ui32buffer, __int32 buffersize_in_32bit_words)
/////////////////////////////////////////////////////////////////
{
	if (!input_lmf) {
		errorflag = 9;
		return false;
	}
	if (errorflag) return false;

//L100:

	input_lmf->read((char*)(&signal_info),sizeof(signal_info));

	if (input_lmf->error) {
		if (input_lmf->eof) this->errorflag = 18; else this->errorflag = 1;
		return false;
	}

	if (signal_info.adc_channel == -1 && signal_info.ModuleIndex == -1) {
		goto L200;
	}

	if (signal_info.signal_type != 8) {
		__int32 leng = buffersize_in_32bit_words > signal_info.signallength_including_header_in_32bit_words ? signal_info.signallength_including_header_in_32bit_words : buffersize_in_32bit_words;
		input_lmf->read(ui32buffer, leng*4);
		if (input_lmf->error) {
			if (input_lmf->eof) this->errorflag = 18; else this->errorflag = 1;
			return false;
		}
		if (leng < signal_info.signallength_including_header_in_32bit_words) {
			__int8 byte_dummy;
			for (__int32 i=0;i<(signal_info.signallength_including_header_in_32bit_words-leng)*4;i++) input_lmf->read(&byte_dummy,1);
		}
	}


L200:

	__int32 header_word;
	*input_lmf >> header_word;

	if (header_word != 12345678 && header_word != 0) {
		errorflag = 2;
		return false;
	}

	if (header_word == fADC8.GroupEndMarker) { // end of group
		bEnd_of_group_detected = true;
		++uint64_number_of_read_events;
	} else bEnd_of_group_detected = false;

	if (bEnd_of_group_detected && fADC8.bReadCustomData) {
		*input_lmf >> number_of_bytes_in_PostEventData;
		if (input_lmf->error) {
			if (input_lmf->eof) this->errorflag = 18; else this->errorflag = 1;
			return false;
		}
		if (number_of_bytes_in_PostEventData > MAX_NUMBER_OF_BYTES_IN_POSTEVENTDATA) {
			input_lmf->error = 21;
			return false;
		}
		for (__int32 i=0;i<number_of_bytes_in_PostEventData;i++) {
			unsigned __int8 byte_dummy;
			*input_lmf >> byte_dummy;
			ui8_PostEventData[i] = byte_dummy;
		}
	}

	if (input_lmf->error) {
		if (input_lmf->eof) this->errorflag = 18; else this->errorflag = 1;
		return false;
	}

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x2b18(%rdi), %rdi
testq %rdi, %rdi
je 0x86a5
cmpl $0x0, 0x12e0(%rbx)
jne 0x86af
movl %r8d, %r15d
movq %rcx, %r13
movq %rdx, %r14
movq %rsi, %r12
movl $0x38, %edx
callq 0x133bc
movq 0x2b18(%rbx), %rdi
cmpl $0x0, 0x8(%rdi)
je 0x86c0
cmpb $0x0, 0xc(%rdi)
movl $0x12, %eax
movl $0x1, %ecx
cmovnel %eax, %ecx
movl %ecx, 0x12e0(%rbx)
jmp 0x86af
movl $0x9, 0x12e0(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpw $-0x1, 0x2e(%r12)
sete %al
cmpb $-0x1, (%r12)
sete %cl
testb %cl, %al
jne 0x8741
cmpb $0x8, 0x18(%r12)
je 0x8741
movl 0x28(%r12), %eax
cmpl %r15d, %eax
cmovll %eax, %r15d
leal (,%r15,4), %edx
movq %r13, %rsi
callq 0x136e6
movq 0x2b18(%rbx), %rdi
cmpl $0x0, 0x8(%rdi)
jne 0x868c
cmpl 0x28(%r12), %r15d
jge 0x8741
xorl %ebp, %ebp
leaq 0x3(%rsp), %r13
movq 0x2b18(%rbx), %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x133bc
incl %ebp
movl 0x28(%r12), %eax
subl %r15d, %eax
shll $0x2, %eax
cmpl %eax, %ebp
jl 0x8715
movq 0x2b18(%rbx), %rdi
leaq 0x4(%rsp), %r15
movq %r15, %rsi
movl $0x4, %edx
callq 0x133bc
movl (%r15), %eax
testl %eax, %eax
je 0x8761
cmpl $0xbc614e, %eax         # imm = 0xBC614E
jne 0x87d6
cmpl 0x15b8(%rbx), %eax
jne 0x87bc
incq 0x260(%rbx)
movb $0x1, (%r14)
cmpb $0x1, 0x1854(%rbx)
jne 0x87c0
movq 0x2b18(%rbx), %rdi
leaq 0x1280(%rbx), %r14
movq %r14, %rsi
movl $0x4, %edx
callq 0x133bc
movq 0x2b18(%rbx), %rax
cmpl $0x0, 0x8(%rax)
jne 0x87cd
movl (%r14), %ecx
cmpl $0xfa0, %ecx            # imm = 0xFA0
jle 0x87ec
movl $0x15, 0x8(%rax)
jmp 0x86af
movb $0x0, (%r14)
movq 0x2b18(%rbx), %rax
cmpl $0x0, 0x8(%rax)
je 0x87e5
cmpb $0x0, 0xc(%rax)
jmp 0x8690
movl $0x2, 0x12e0(%rbx)
jmp 0x86af
movb $0x1, %al
jmp 0x86b1
testl %ecx, %ecx
jle 0x87c0
xorl %r15d, %r15d
leaq 0x2(%rsp), %r14
movq 0x2b18(%rbx), %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x133bc
movb 0x2(%rsp), %al
movb %al, 0x2e0(%rbx,%r15)
incq %r15
movslq 0x1280(%rbx), %rax
cmpq %rax, %r15
jl 0x87f8
jmp 0x87c0
nop