// File: /workspace/github_cpp_makefile_star2_O2/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:
orl $-0x1, (%r8)
xorl %r11d, %r11d
cmpb $0x7, 0x18(%rsi)
movl $0x0, %eax
jne 0x10d19
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
movl %r10d, -0x3c(%rsp)
movzwl 0x32(%rsi), %ecx
cmpl $0x1388, %ecx           # imm = 0x1388
je 0x10be4
movl 0x58(%rsp), %edi
movq 0x50(%rsp), %rsi
cmpl $0x9c4, %ecx            # imm = 0x9C4
je 0x10ad7
xorl %r11d, %r11d
movl $0x0, %eax
cmpl $0x4e2, %ecx            # imm = 0x4E2
jne 0x10d0f
movl 0x68(%rsp), %ecx
movl 0x48(%rsp), %r10d
addl $-0x10, -0x3c(%rsp)
movl 0x38(%rsp), %eax
cmpl %r10d, %eax
cmovll %eax, %r10d
cmpl %r10d, %edi
cmovll %edi, %r10d
cmpl %r10d, %ecx
cmovll %ecx, %r10d
movl %r10d, -0x4(%rsp)
movl $0x4, %eax
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movl $0x3ff, %r12d           # imm = 0x3FF
cmpl -0x3c(%rsp), %eax
jae 0x10d0a
leal 0xd(%r11), %ecx
cmpl -0x4(%rsp), %ecx
jg 0x10d0a
leal 0x4(%rax), %ecx
movq %rcx, -0x28(%rsp)
leal 0x8(%rax), %ecx
movq %rcx, -0x30(%rsp)
leal 0xc(%rax), %ecx
movq %rcx, -0x38(%rsp)
movq %rax, -0x18(%rsp)
movl %eax, %eax
movq %rax, -0x10(%rsp)
xorl %ebp, %ebp
movl %r11d, %r13d
cmpq $0x4, %rbp
je 0x10aca
movq %rbp, %r15
orq -0x10(%rsp), %r15
movq %rbp, %rdi
orq -0x28(%rsp), %rdi
movq %rbp, %r10
orq -0x30(%rsp), %r10
movq %rbp, -0x20(%rsp)
orq -0x38(%rsp), %rbp
movl $0x14, %ecx
testl %ecx, %ecx
js 0x10abd
leal 0x1(%r13), %r11d
movl %r11d, (%r8)
movl (%rdx,%r15,4), %eax
shrl %cl, %eax
andl %r12d, %eax
testl %r13d, %r13d
movl %r11d, %r13d
cmovsl %r14d, %r13d
movw %ax, (%r9,%r13,2)
movl (%rdx,%rdi,4), %eax
shrl %cl, %eax
andl %r12d, %eax
movq 0x40(%rsp), %rbx
movw %ax, (%rbx,%r13,2)
movl (%rdx,%r10,4), %eax
shrl %cl, %eax
andl %r12d, %eax
movw %ax, (%rsi,%r13,2)
movl (%rdx,%rbp,4), %eax
shrl %cl, %eax
andl %r12d, %eax
movq 0x60(%rsp), %rbx
movw %ax, (%rbx,%r13,2)
addl $-0xa, %ecx
movl %r11d, %r13d
jmp 0x10a60
movq -0x20(%rsp), %rbp
incq %rbp
jmp 0x10a2f
movq -0x18(%rsp), %rax
addl $0x10, %eax
jmp 0x109ee
addl $-0x10, -0x3c(%rsp)
movl 0x38(%rsp), %eax
cmpl %edi, %eax
cmovll %eax, %edi
movl %edi, -0x18(%rsp)
movl $0x4, %ecx
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movl $0x3ff, %r14d           # imm = 0x3FF
cmpl -0x3c(%rsp), %ecx
jae 0x10d0a
leal 0x19(%r11), %eax
cmpl -0x18(%rsp), %eax
jg 0x10d0a
leal 0x8(%rcx), %eax
movq %rax, -0x20(%rsp)
leal 0x4(%rcx), %eax
movq %rax, -0x28(%rsp)
leal 0xc(%rcx), %eax
movq %rax, -0x30(%rsp)
movq %rcx, -0x10(%rsp)
movl %ecx, %eax
movq %rax, -0x38(%rsp)
xorl %ebp, %ebp
movl %r11d, %edi
cmpq $0x4, %rbp
je 0x10bd7
movq %rbp, %r10
orq -0x38(%rsp), %r10
movq %rbp, %rax
orq -0x20(%rsp), %rax
movq %rbp, %r15
orq -0x28(%rsp), %r15
movq %rbp, %r12
orq -0x30(%rsp), %r12
movl $0x14, %ecx
testl %ecx, %ecx
js 0x10bcf
leal 0x1(%rdi), %r11d
movl %r11d, (%r8)
movl (%rdx,%r10,4), %ebx
shrl %cl, %ebx
andl %r14d, %ebx
testl %edi, %edi
cmovsl %r13d, %r11d
movw %bx, (%r9,%r11,2)
movl (%rdx,%rax,4), %ebx
shrl %cl, %ebx
andl %r14d, %ebx
movw %bx, (%rsi,%r11,2)
leal 0x2(%rdi), %r11d
movl %r11d, (%r8)
movl (%rdx,%r15,4), %ebx
shrl %cl, %ebx
andl %r14d, %ebx
cmpl $-0x1, %edi
movl $0x0, %edi
cmovgel %r11d, %edi
movw %bx, (%r9,%rdi,2)
movl (%rdx,%r12,4), %ebx
shrl %cl, %ebx
andl %r14d, %ebx
movw %bx, (%rsi,%rdi,2)
addl $-0xa, %ecx
movl %r11d, %edi
jmp 0x10b6d
incq %rbp
jmp 0x10b3e
movq -0x10(%rsp), %rcx
addl $0x10, %ecx
jmp 0x10afd
addl $-0x10, -0x3c(%rsp)
movl $0x4, %ecx
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
xorl %esi, %esi
movl $0x3ff, %ebp            # imm = 0x3FF
cmpl -0x3c(%rsp), %ecx
jae 0x10d0a
leal 0x31(%r11), %eax
cmpl 0x38(%rsp), %eax
jg 0x10d0a
leal 0x8(%rcx), %eax
movq %rax, -0x20(%rsp)
leal 0x4(%rcx), %eax
movq %rax, -0x28(%rsp)
leal 0xc(%rcx), %eax
movq %rax, -0x30(%rsp)
movq %rcx, -0x38(%rsp)
movl %ecx, %edi
xorl %r15d, %r15d
movl %r11d, %r10d
cmpq $0x4, %r15
je 0x10cfd
movq %r15, %r13
orq %rdi, %r13
movq %r15, %rax
orq -0x20(%rsp), %rax
movq %r15, %rbx
orq -0x28(%rsp), %rbx
movq %r15, %r14
orq -0x30(%rsp), %r14
movl $0x14, %ecx
testl %ecx, %ecx
js 0x10cf5
movl (%rdx,%r13,4), %r11d
shrl %cl, %r11d
andl %ebp, %r11d
leal 0x1(%r10), %r12d
movl %r12d, (%r8)
testl %r10d, %r10d
cmovsl %esi, %r12d
movw %r11w, (%r9,%r12,2)
movl (%rdx,%rax,4), %r11d
shrl %cl, %r11d
andl %ebp, %r11d
leal 0x2(%r10), %r12d
movl %r12d, (%r8)
cmpl $-0x1, %r10d
cmovll %esi, %r12d
movw %r11w, (%r9,%r12,2)
movl (%rdx,%rbx,4), %r11d
shrl %cl, %r11d
andl %ebp, %r11d
leal 0x3(%r10), %r12d
movl %r12d, (%r8)
cmpl $-0x2, %r10d
cmovll %esi, %r12d
movw %r11w, (%r9,%r12,2)
movl (%rdx,%r14,4), %r12d
shrl %cl, %r12d
andl %ebp, %r12d
leal 0x4(%r10), %r11d
cmpl $-0x3, %r10d
movl $0x0, %r10d
cmovgel %r11d, %r10d
movl %r11d, (%r8)
movw %r12w, (%r9,%r10,2)
addl $-0xa, %ecx
movl %r11d, %r10d
jmp 0x10c65
incq %r15
jmp 0x10c38
movq -0x38(%rsp), %rcx
addl $0x10, %ecx
jmp 0x10bfb
incl %r11d
movb $0x1, %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl %r11d, (%r8)
retq
nop