// File: /workspace/github_cpp_makefile_star2_O1/NichtJens[P]lmf2txt/LMF_IO.cpp
// Function: LMF_IO::decompress_synchronous_fADC8_signal(fADC8_signal_info_struct&, unsigned int*, unsigned int, int&, short*, int, short*, int, short*, int, short*, int)
bool LMF_IO::decompress_synchronous_fADC8_signal(fADC8_signal_info_struct &signal_info, unsigned __int32 source_buffer[], unsigned __int32 source_buffer_size_in_32bit_words, __int32 &number_of_filled_16bit_words,
												__int16 i16bit_target_buffer1[], __int32 target_buffer1_size_in_16bit_words,
												__int16 i16bit_target_buffer2[], __int32 target_buffer2_size_in_16bit_words,
												__int16 i16bit_target_buffer3[], __int32 target_buffer3_size_in_16bit_words,
												__int16 i16bit_target_buffer4[], __int32 target_buffer4_size_in_16bit_words)
{

	number_of_filled_16bit_words = -1;

	if (signal_info.signal_type != FADC8_HEADER_EVENT_ID_5G_ADC1234) {
		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.megasamples_per_second == 5000) {

		for (unsigned __int32 i=4;i<limit_ + 4-16;i+=16)  { // xxx stimmt -16?
			if (target_buffer1_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_buffer1[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+0 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer1[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+8 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer1[(++number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+4 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer1[(++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_buffer1,number_of_filled_16bit_words, signal_info);
		return true;
	}





	if (signal_info.megasamples_per_second == 2500) {
		for (unsigned __int32 i=4;i<limit_ + 4-16;i+=16)  {
			if (target_buffer1_size_in_16bit_words < number_of_filled_16bit_words +1 + 2*4*3) break;
			if (target_buffer3_size_in_16bit_words < number_of_filled_16bit_words +1 + 2*4*3) break;

			for (__int32 j=0; j<4; j++) {
				for (__int32 shift_ = 20;shift_ >= 0;shift_-=10) {
					++number_of_filled_16bit_words;
					i16bit_target_buffer1[(number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+0 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer3[(number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+8 +j] >> shift_) & 0x3ff;

					++number_of_filled_16bit_words;
					i16bit_target_buffer1[(number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+4 +j] >> shift_) & 0x3ff;					
					i16bit_target_buffer3[(number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+12+j] >> shift_) & 0x3ff;
				}	
			}

		}
		//trace_filter(i16bit_target_buffer1,number_of_filled_16bit_words, signal_info);
		//trace_filter(i16bit_target_buffer3,number_of_filled_16bit_words, signal_info);
		number_of_filled_16bit_words++;
		return true;
	}


		if (signal_info.megasamples_per_second == 1250) {
		for (unsigned __int32 i=4;i<limit_ + 4-16;i+=16)  {
			if (target_buffer1_size_in_16bit_words < number_of_filled_16bit_words +1 + 4*3) break;
			if (target_buffer2_size_in_16bit_words < number_of_filled_16bit_words +1 + 4*3) break;
			if (target_buffer3_size_in_16bit_words < number_of_filled_16bit_words +1 + 4*3) break;
			if (target_buffer4_size_in_16bit_words < number_of_filled_16bit_words +1 + 4*3) break;

			for (__int32 j=0; j<4; j++) {
				for (__int32 shift_ = 20;shift_ >= 0;shift_-=10) {
					++number_of_filled_16bit_words;
					i16bit_target_buffer1[(number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+0 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer2[(number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+4 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer3[(number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+8 +j] >> shift_) & 0x3ff;
					i16bit_target_buffer4[(number_of_filled_16bit_words) > 0 ? number_of_filled_16bit_words : 0] = (source_buffer[i+12+j] >> shift_) & 0x3ff;
				}
			}

		}
		//trace_filter(i16bit_target_buffer1,number_of_filled_16bit_words, signal_info);
		//trace_filter(i16bit_target_buffer2,number_of_filled_16bit_words, signal_info);
		//trace_filter(i16bit_target_buffer3,number_of_filled_16bit_words, signal_info);
		//trace_filter(i16bit_target_buffer4,number_of_filled_16bit_words, signal_info);
		number_of_filled_16bit_words++;
		return true;
	}

	number_of_filled_16bit_words = 0;
	return false;
}

// Assembly:
movl $0xffffffff, (%r8)      # imm = 0xFFFFFFFF
xorl %edi, %edi
cmpb $0x7, 0x18(%rsi)
movl $0x0, %eax
jne 0x13964
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0x28(%rsi), %eax
leal -0x4(%rax), %edi
leal 0x4(%rcx), %r10d
cmpl %ecx, %edi
cmovll %eax, %r10d
movzwl 0x32(%rsi), %ecx
cmpl $0x1388, %ecx           # imm = 0x1388
je 0x13870
movl 0x58(%rsp), %r11d
movq 0x50(%rsp), %rsi
cmpl $0x9c4, %ecx            # imm = 0x9C4
je 0x13786
xorl %edi, %edi
movl $0x0, %eax
cmpl $0x4e2, %ecx            # imm = 0x4E2
jne 0x1395a
movl 0x48(%rsp), %ecx
addl $-0x10, %r10d
movl 0x38(%rsp), %eax
cmpl %ecx, %eax
cmovll %eax, %ecx
movl 0x68(%rsp), %eax
cmpl %ecx, %r11d
cmovll %r11d, %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
movl %ecx, -0x14(%rsp)
movl %r10d, -0x18(%rsp)
cmpl $0x5, %r10d
jb 0x13953
movq 0x60(%rsp), %r10
movq 0x40(%rsp), %r11
movl (%r8), %ebx
movl $0x4, %ecx
movl $0x3ff, %ebp            # imm = 0x3FF
leal 0xd(%rbx), %eax
cmpl -0x14(%rsp), %eax
jg 0x13953
leal 0xc(%rcx), %eax
movq %rcx, -0x10(%rsp)
movl %ecx, %ecx
movq %rcx, -0x8(%rsp)
leaq (%rdx,%rcx,4), %r12
addq $0x10, %r12
leaq (%rdx,%rax,4), %r13
xorl %edi, %edi
movq %rdi, %rax
orq -0x8(%rsp), %rax
movl $0x1e, %ecx
movl %ebx, %r14d
leal 0x1(%r14), %ebx
movl %ebx, (%r8)
movl (%rdx,%rax,4), %r15d
addl $-0xa, %ecx
shrl %cl, %r15d
andl %ebp, %r15d
testl %r14d, %r14d
movl $0x0, %r14d
cmovnsq %rbx, %r14
movw %r15w, (%r9,%r14,2)
movl (%r12,%rdi,4), %r15d
shrl %cl, %r15d
andl %ebp, %r15d
movw %r15w, (%r11,%r14,2)
movl 0x10(%r12,%rdi,4), %r15d
shrl %cl, %r15d
andl %ebp, %r15d
movw %r15w, (%rsi,%r14,2)
movl (%r13,%rdi,4), %r15d
shrl %cl, %r15d
andl %ebp, %r15d
movw %r15w, (%r10,%r14,2)
cmpl $0x9, %ecx
ja 0x13709
incq %rdi
cmpq $0x4, %rdi
jne 0x136fc
movq -0x10(%rsp), %rcx
addl $0x10, %ecx
cmpl -0x18(%rsp), %ecx
jb 0x136d2
jmp 0x13953
addl $-0x10, %r10d
movl 0x38(%rsp), %eax
cmpl %r11d, %eax
cmovll %eax, %r11d
movl %r11d, -0x14(%rsp)
movl %r10d, -0x18(%rsp)
cmpl $0x5, %r10d
jb 0x13953
movl (%r8), %r14d
movl $0x4, %eax
xorl %r10d, %r10d
movl $0x3ff, %ebx            # imm = 0x3FF
leal 0x19(%r14), %ecx
cmpl -0x14(%rsp), %ecx
jg 0x13953
leal 0xc(%rax), %ecx
movq %rax, -0x10(%rsp)
movl %eax, %eax
movq %rax, -0x8(%rsp)
leaq (%rdx,%rax,4), %r15
addq $0x20, %r15
leaq (%rdx,%rcx,4), %r12
xorl %ebp, %ebp
movq %rbp, %rdi
orq -0x8(%rsp), %rdi
movl $0x1e, %ecx
movl %r14d, %r13d
leal 0x1(%r13), %r11d
movl %r11d, (%r8)
movl (%rdx,%rdi,4), %eax
addl $-0xa, %ecx
shrl %cl, %eax
andl %ebx, %eax
testl %r14d, %r14d
cmovsq %r10, %r11
movw %ax, (%r9,%r11,2)
movl (%r15,%rbp,4), %eax
shrl %cl, %eax
andl %ebx, %eax
movw %ax, (%rsi,%r11,2)
leal 0x2(%r13), %r14d
movl %r14d, (%r8)
movl -0x10(%r15,%rbp,4), %eax
shrl %cl, %eax
andl %ebx, %eax
movq %r14, %r11
cmpl $-0x1, %r13d
cmovlq %r10, %r11
movw %ax, (%r9,%r11,2)
movl (%r12,%rbp,4), %eax
shrl %cl, %eax
andl %ebx, %eax
movw %ax, (%rsi,%r11,2)
cmpl $0x9, %ecx
ja 0x137f1
incq %rbp
cmpq $0x4, %rbp
jne 0x137e4
movq -0x10(%rsp), %rax
addl $0x10, %eax
cmpl -0x18(%rsp), %eax
jb 0x137b9
jmp 0x13953
addl $-0x10, %r10d
movl %r10d, -0x18(%rsp)
cmpl $0x5, %r10d
jb 0x13953
movl (%r8), %edi
movl $0x4, %eax
xorl %esi, %esi
movl $0x3ff, %r11d           # imm = 0x3FF
leal 0x31(%rdi), %ecx
cmpl 0x38(%rsp), %ecx
jg 0x13953
leal 0xc(%rax), %ecx
movl %eax, %ebx
leaq (%rdx,%rbx,4), %r14
addq $0x20, %r14
leaq (%rdx,%rcx,4), %r15
xorl %r12d, %r12d
movq %r12, %r13
orq %rbx, %r13
movl $0x1e, %ecx
addl $-0xa, %ecx
movl (%rdx,%r13,4), %ebp
shrl %cl, %ebp
andl %r11d, %ebp
leal 0x1(%rdi), %r10d
movl %r10d, (%r8)
testl %edi, %edi
cmovsl %esi, %r10d
movw %bp, (%r9,%r10,2)
movl (%r14,%r12,4), %r10d
shrl %cl, %r10d
andl %r11d, %r10d
leal 0x2(%rdi), %ebp
movl %ebp, (%r8)
cmpl $-0x1, %edi
cmovll %esi, %ebp
movw %r10w, (%r9,%rbp,2)
movl -0x10(%r14,%r12,4), %r10d
shrl %cl, %r10d
andl %r11d, %r10d
leal 0x3(%rdi), %ebp
movl %ebp, (%r8)
cmpl $-0x2, %edi
cmovll %esi, %ebp
movw %r10w, (%r9,%rbp,2)
movl (%r15,%r12,4), %r10d
shrl %cl, %r10d
andl %r11d, %r10d
cmpl $-0x3, %edi
leal 0x4(%rdi), %edi
movl %edi, (%r8)
movl $0x0, %ebp
cmovgel %edi, %ebp
movw %r10w, (%r9,%rbp,2)
cmpl $0x9, %ecx
ja 0x138bf
incq %r12
cmpq $0x4, %r12
jne 0x138b4
addl $0x10, %eax
cmpl -0x18(%rsp), %eax
jb 0x13893
movl (%r8), %edi
incl %edi
movb $0x1, %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl %edi, (%r8)
retq