// File: /workspace/github_cpp_makefile_star2_O2/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::decompress_asynchronous_fADC8_signal(fADC8_signal_info_struct&, unsigned int*, unsigned int, short*, int, int&)
bool LMF_IO::decompress_asynchronous_fADC8_signal(fADC8_signal_info_struct &signal_info, unsigned __int32 source_buffer[], unsigned __int32 source_buffer_size_in_32bit_words, __int16 i16bit_target_buffer[], __int32 target_buffer_size_in_16bit_words, __int32 &number_of_filled_16bit_words)
{
	number_of_filled_16bit_words = -signal_info.timestamp_subindex - 1;

	if ((signal_info.signal_type == FADC8_HEADER_EVENT_ID_TDC) || (signal_info.signal_type == FADC8_HEADER_EVENT_ID_END_MARKER)) {
		number_of_filled_16bit_words = 0;
		return false;
	}

	unsigned __int32 limit_;
	if (signal_info.signallength_including_header_in_32bit_words - 4 < __int32(source_buffer_size_in_32bit_words)) {
		limit_ = signal_info.signallength_including_header_in_32bit_words - 4;
	} else {
		limit_ = source_buffer_size_in_32bit_words;
	}

	if (   (signal_info.signal_type == FADC8_HEADER_EVENT_ID_1_25G_ADC1)
		|| (signal_info.signal_type == FADC8_HEADER_EVENT_ID_1_25G_ADC2)
		|| (signal_info.signal_type == FADC8_HEADER_EVENT_ID_1_25G_ADC3)
		|| (signal_info.signal_type == FADC8_HEADER_EVENT_ID_1_25G_ADC4)) {

		for (unsigned __int32 i=4;i<limit_ + 4;i+=4)  {
			if (target_buffer_size_in_16bit_words < number_of_filled_16bit_words +1 + 4*3) {
				break;
			}
			for (__int32 j=0; j<4; j++) {
				i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+j] >> 20) & 0x3ff;
				i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+j] >> 10) & 0x3ff;
				i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+j]      ) & 0x3ff;
			}
		}

		number_of_filled_16bit_words++;
		//trace_filter(i16bit_target_buffer,number_of_filled_16bit_words, signal_info);
		return true;
	} // endif 1.25 GS mode


	if (   (signal_info.signal_type == FADC8_HEADER_EVENT_ID_2_5G_ADC12)
		|| (signal_info.signal_type == FADC8_HEADER_EVENT_ID_2_5G_ADC34)) {
	
		for (unsigned __int32 i=4;i<limit_ + 4;i+=8)  {
			if (target_buffer_size_in_16bit_words < number_of_filled_16bit_words +1 + 2*4*3) {
				break;
			}

			for (__int32 j=0; j<4; j++) {
				i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+0+j] >> 20) & 0x3ff;
				i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+4+j] >> 20) & 0x3ff;
				i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+0+j] >> 10) & 0x3ff;
				i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+4+j] >> 10) & 0x3ff;
				i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+0+j]      ) & 0x3ff;
				i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+4+j]      ) & 0x3ff;
			}
			
		}

		number_of_filled_16bit_words++;
		//trace_filter(i16bit_target_buffer,number_of_filled_16bit_words, signal_info);
		return true;
	} // endif 2.5 Gs mode

	if (signal_info.signal_type == FADC8_HEADER_EVENT_ID_5G_ADC1234) {

		for (unsigned __int32 i=4;i<limit_ + 4;i+=16)  {
			if (target_buffer_size_in_16bit_words < number_of_filled_16bit_words +1 + 4*4*3) {
				break;
			}

			for (__int32 j=0; j<4; j++) {
				for (__int32 shift_ = 20;shift_ >= 0;shift_-=10) {
					i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+0 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+8 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+4 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+12+j] >> shift_) & 0x3ff;
				}
			}

		}

		number_of_filled_16bit_words++;
		//trace_filter(i16bit_target_buffer,number_of_filled_16bit_words, signal_info);
		return true;
	} // endif 5 Gs mode

	return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %r9d, -0x24(%rsp)
movq 0x38(%rsp), %rdi
movsbl 0x2c(%rsi), %r9d
notl %r9d
movl %r9d, (%rdi)
movzbl 0x18(%rsi), %r10d
xorl %r11d, %r11d
movl $0x0, %eax
cmpl $0x8, %r10d
je 0x10931
cmpl $0xf, %r10d
je 0x10931
movl 0x28(%rsi), %eax
leal -0x4(%rax), %esi
leal 0x4(%rcx), %r11d
cmpl %ecx, %esi
cmovll %eax, %r11d
movl %r11d, -0x28(%rsp)
xorl %eax, %eax
cmpl $0x4, %r10d
jae 0x106bb
movl $0x4, %ecx
movabsq $-0xc, %rsi
movl $0x3ff, %r10d           # imm = 0x3FF
cmpl -0x28(%rsp), %ecx
jae 0x10929
leal 0xd(%r9), %r11d
cmpl -0x24(%rsp), %r11d
jg 0x10929
movl %ecx, %r11d
leaq (%rdx,%r11,4), %rbx
movl %r9d, %r14d
movq %rsi, %r11
testq %r11, %r11
je 0x106ac
leaq (%r14,%r11), %r15
addq $0xc, %r15
movl (%rbx), %ebp
shrl $0x14, %ebp
andl %r10d, %ebp
leal (%r14,%r11), %r12d
addl $0xd, %r12d
movl %r12d, (%rdi)
testl %r15d, %r15d
cmovsl %eax, %r12d
movw %bp, (%r8,%r12,2)
movl (%rbx), %ebp
shrl $0xa, %ebp
andl %r10d, %ebp
leal (%r14,%r11), %r12d
addl $0xe, %r12d
movl %r12d, (%rdi)
cmpl $-0x1, %r15d
cmovll %eax, %r12d
movw %bp, (%r8,%r12,2)
movzwl (%rbx), %ebp
andl %r10d, %ebp
leal (%r14,%r11), %r12d
addl $0xf, %r12d
movl %r12d, (%rdi)
cmpl $-0x2, %r15d
cmovll %eax, %r12d
movw %bp, (%r8,%r12,2)
addq $0x3, %r11
addq $0x4, %rbx
jmp 0x10638
addl $0x4, %ecx
addl %r11d, %r9d
addl $0xc, %r9d
jmp 0x10612
leal -0x4(%r10), %ecx
cmpl $0x2, %ecx
jae 0x10802
movl $0x4, %eax
movl $0x8, %ecx
xorl %r11d, %r11d
movl $0x3ff, %ebp            # imm = 0x3FF
xorl %r14d, %r14d
cmpl -0x28(%rsp), %eax
jae 0x10929
leal 0x19(%r9), %esi
cmpl -0x24(%rsp), %esi
jg 0x10929
movl %ecx, %ecx
movl %r14d, %r14d
movl %r9d, %esi
movq %rdx, %r12
movabsq $-0x18, %r15
testq %r15, %r15
je 0x107ec
leaq (%rsi,%r15), %r10
addq $0x18, %r10
movl 0x10(%r12,%r14,4), %r13d
shrl $0x14, %r13d
andl %ebp, %r13d
leal (%rsi,%r15), %ebx
addl $0x19, %ebx
movl %ebx, (%rdi)
testl %r10d, %r10d
cmovsl %r11d, %ebx
movw %r13w, (%r8,%rbx,2)
movl (%r12,%rcx,4), %ebx
shrl $0x14, %ebx
andl %ebp, %ebx
leal (%rsi,%r15), %r13d
addl $0x1a, %r13d
movl %r13d, (%rdi)
cmpl $-0x1, %r10d
cmovll %r11d, %r13d
movw %bx, (%r8,%r13,2)
movl 0x10(%r12,%r14,4), %ebx
shrl $0xa, %ebx
andl %ebp, %ebx
leal (%rsi,%r15), %r13d
addl $0x1b, %r13d
movl %r13d, (%rdi)
cmpl $-0x2, %r10d
cmovll %r11d, %r13d
movw %bx, (%r8,%r13,2)
movl (%r12,%rcx,4), %ebx
shrl $0xa, %ebx
andl %ebp, %ebx
leal (%rsi,%r15), %r13d
addl $0x1c, %r13d
movl %r13d, (%rdi)
cmpl $-0x3, %r10d
cmovll %r11d, %r13d
movw %bx, (%r8,%r13,2)
movzwl 0x10(%r12,%r14,4), %ebx
andl %ebp, %ebx
leal (%rsi,%r15), %r13d
addl $0x1d, %r13d
movl %r13d, (%rdi)
cmpl $-0x4, %r10d
cmovll %r11d, %r13d
movw %bx, (%r8,%r13,2)
movzwl (%r12,%rcx,4), %ebx
andl %ebp, %ebx
leal (%rsi,%r15), %r13d
addl $0x1e, %r13d
movl %r13d, (%rdi)
cmpl $-0x5, %r10d
cmovll %r11d, %r13d
movw %bx, (%r8,%r13,2)
addq $0x6, %r15
addq $0x4, %r12
jmp 0x1070a
addl $0x8, %eax
addl $0x8, %ecx
addl $0x8, %r14d
addl %r15d, %r9d
addl $0x18, %r9d
jmp 0x106dd
cmpl $0x7, %r10d
jne 0x10934
movl $0x4, %ecx
xorl %r11d, %r11d
movl $0x3ff, %ebp            # imm = 0x3FF
cmpl -0x28(%rsp), %ecx
jae 0x10929
leal 0x31(%r9), %eax
cmpl -0x24(%rsp), %eax
jg 0x10929
leal 0x8(%rcx), %eax
movq %rax, -0x8(%rsp)
leal 0x4(%rcx), %eax
movq %rax, -0x10(%rsp)
leal 0xc(%rcx), %eax
movq %rax, -0x18(%rsp)
movq %rcx, -0x20(%rsp)
movl %ecx, %r13d
xorl %r15d, %r15d
movl %r9d, %r10d
cmpq $0x4, %r15
je 0x1091c
movq %r15, %rsi
orq %r13, %rsi
movq %r15, %rax
orq -0x8(%rsp), %rax
movq %r15, %rbx
orq -0x10(%rsp), %rbx
movq %r15, %r14
orq -0x18(%rsp), %r14
movl $0x14, %ecx
testl %ecx, %ecx
js 0x10914
movl (%rdx,%rsi,4), %r9d
shrl %cl, %r9d
andl %ebp, %r9d
leal 0x1(%r10), %r12d
movl %r12d, (%rdi)
testl %r10d, %r10d
cmovsl %r11d, %r12d
movw %r9w, (%r8,%r12,2)
movl (%rdx,%rax,4), %r9d
shrl %cl, %r9d
andl %ebp, %r9d
leal 0x2(%r10), %r12d
movl %r12d, (%rdi)
cmpl $-0x1, %r10d
cmovll %r11d, %r12d
movw %r9w, (%r8,%r12,2)
movl (%rdx,%rbx,4), %r9d
shrl %cl, %r9d
andl %ebp, %r9d
leal 0x3(%r10), %r12d
movl %r12d, (%rdi)
cmpl $-0x2, %r10d
cmovll %r11d, %r12d
movw %r9w, (%r8,%r12,2)
movl (%rdx,%r14,4), %r12d
shrl %cl, %r12d
andl %ebp, %r12d
leal 0x4(%r10), %r9d
cmpl $-0x3, %r10d
movl $0x0, %r10d
cmovgel %r9d, %r10d
movl %r9d, (%rdi)
movw %r12w, (%r8,%r10,2)
addl $-0xa, %ecx
movl %r9d, %r10d
jmp 0x10884
incq %r15
jmp 0x10857
movq -0x20(%rsp), %rcx
addl $0x10, %ecx
jmp 0x10819
incl %r9d
movb $0x1, %al
movl %r9d, %r11d
movl %r11d, (%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop