// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, 0x2b18(%rax)
jne 0xb0d5
movq -0x50(%rbp), %rax
movl $0x9, 0x12e0(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xb3ff
movq -0x50(%rbp), %rax
cmpl $0x0, 0x12e0(%rax)
je 0xb0eb
movb $0x0, -0x1(%rbp)
jmp 0xb3ff
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rdi
movq -0x18(%rbp), %rsi
movl $0x38, %edx
callq 0x1cbe0
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0xb14d
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rax
testb $0x1, 0xc(%rax)
je 0xb136
movq -0x50(%rbp), %rax
movl $0x12, 0x12e0(%rax)
jmp 0xb144
movq -0x50(%rbp), %rax
movl $0x1, 0x12e0(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xb3ff
movq -0x18(%rbp), %rax
movswl 0x2e(%rax), %eax
cmpl $-0x1, %eax
jne 0xb16b
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $-0x1, %eax
jne 0xb16b
jmp 0xb254
movq -0x18(%rbp), %rax
movsbl 0x18(%rax), %eax
cmpl $0x8, %eax
je 0xb252
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jle 0xb194
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x54(%rbp)
jmp 0xb19a
movl -0x2c(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movl -0x54(%rbp), %ecx
movl %ecx, -0x30(%rbp)
movq 0x2b18(%rax), %rdi
movq -0x28(%rbp), %rsi
movl -0x30(%rbp), %edx
shll $0x2, %edx
callq 0x1d250
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0xb203
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rax
testb $0x1, 0xc(%rax)
je 0xb1ec
movq -0x50(%rbp), %rax
movl $0x12, 0x12e0(%rax)
jmp 0xb1fa
movq -0x50(%rbp), %rax
movl $0x1, 0x12e0(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xb3ff
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0xb250
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
movl 0x28(%rcx), %ecx
subl -0x30(%rbp), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
jge 0xb24e
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x31(%rbp), %rsi
movl $0x1, %edx
callq 0x1cbe0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xb216
jmp 0xb250
jmp 0xb252
jmp 0xb254
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x1cf60
cmpl $0xbc614e, -0x3c(%rbp)  # imm = 0xBC614E
je 0xb28e
cmpl $0x0, -0x3c(%rbp)
je 0xb28e
movq -0x50(%rbp), %rax
movl $0x2, 0x12e0(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xb3ff
movq -0x50(%rbp), %rcx
movl -0x3c(%rbp), %eax
cmpl 0x15b8(%rcx), %eax
jne 0xb2bc
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
movb $0x1, (%rcx)
movq 0x260(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x260(%rax)
jmp 0xb2c3
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
testb $0x1, (%rax)
je 0xb3b5
movq -0x50(%rbp), %rax
testb $0x1, 0x1854(%rax)
je 0xb3b5
movq -0x50(%rbp), %rsi
movq 0x2b18(%rsi), %rdi
addq $0x1280, %rsi           # imm = 0x1280
callq 0x1cf60
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0xb341
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rax
testb $0x1, 0xc(%rax)
je 0xb32a
movq -0x50(%rbp), %rax
movl $0x12, 0x12e0(%rax)
jmp 0xb338
movq -0x50(%rbp), %rax
movl $0x1, 0x12e0(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xb3ff
movq -0x50(%rbp), %rax
cmpl $0xfa0, 0x1280(%rax)    # imm = 0xFA0
jle 0xb36c
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rax
movl $0x15, 0x8(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xb3ff
movl $0x0, -0x40(%rbp)
movq -0x50(%rbp), %rcx
movl -0x40(%rbp), %eax
cmpl 0x1280(%rcx), %eax
jge 0xb3b3
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rdi
leaq -0x41(%rbp), %rsi
callq 0x1cb20
movq -0x50(%rbp), %rax
movb -0x41(%rbp), %dl
movslq -0x40(%rbp), %rcx
movb %dl, 0x2e0(%rax,%rcx)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xb373
jmp 0xb3b5
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rax
cmpl $0x0, 0x8(%rax)
je 0xb3fb
movq -0x50(%rbp), %rax
movq 0x2b18(%rax), %rax
testb $0x1, 0xc(%rax)
je 0xb3e7
movq -0x50(%rbp), %rax
movl $0x12, 0x12e0(%rax)
jmp 0xb3f5
movq -0x50(%rbp), %rax
movl $0x1, 0x12e0(%rax)
movb $0x0, -0x1(%rbp)
jmp 0xb3ff
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)