// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl $0xffffffff, (%r8)      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
cmpb $0x7, 0x18(%rsi)
movl $0x0, %eax
jne 0x13369
movl 0x28(%rsi), %eax
leal -0x4(%rax), %edi
leal 0x4(%rcx), %r10d
cmpl %ecx, %edi
cmovll %eax, %r10d
movl %r10d, %eax
movzwl 0x32(%rsi), %ecx
xorl %r14d, %r14d
cmpl $0x1388, %ecx           # imm = 0x1388
je 0x1326b
movl 0x58(%rsp), %r10d
movq 0x50(%rsp), %rsi
cmpl $0x9c4, %ecx            # imm = 0x9C4
je 0x13169
cmpl $0x4e2, %ecx            # imm = 0x4E2
jne 0x13367
movl 0x68(%rsp), %ecx
movl 0x48(%rsp), %r11d
movl %eax, %edi
addl $-0x10, %edi
movl 0x38(%rsp), %eax
cmpl %r11d, %eax
cmovll %eax, %r11d
cmpl %r11d, %r10d
cmovll %r10d, %r11d
cmpl %r11d, %ecx
cmovll %ecx, %r11d
movl %r11d, -0x1c(%rsp)
movb $0x1, %al
movl %edi, -0x20(%rsp)
cmpl $0x5, %edi
jb 0x13369
movq 0x60(%rsp), %rbx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x4, %edi
movl $0x3ff, %r12d           # imm = 0x3FF
movq %rdx, -0x8(%rsp)
leal 0xd(%r14), %ecx
cmpl -0x1c(%rsp), %ecx
jg 0x13161
leal 0xc(%rdi), %ecx
movq %rdi, -0x10(%rsp)
movl %edi, %eax
movq %rax, -0x18(%rsp)
leaq (%rdx,%rax,4), %r13
addq $0x10, %r13
leaq (%rdx,%rcx,4), %rdi
xorl %ebp, %ebp
movq %rbp, %r10
orq -0x18(%rsp), %r10
movl $0x1e, %ecx
movq 0x50(%rsp), %rsi
movq -0x8(%rsp), %rdx
movl %r14d, %eax
leal 0x1(%rax), %r14d
movl %r14d, (%r8)
movl (%rdx,%r10,4), %r11d
addl $-0xa, %ecx
shrl %cl, %r11d
andl %r12d, %r11d
testl %eax, %eax
movl %r14d, %eax
movq %rdi, %r15
movl $0x0, %edi
cmovsl %edi, %eax
movq %r15, %rdi
movw %r11w, (%r9,%rax,2)
movl (%r13,%rbp,4), %r11d
shrl %cl, %r11d
andl %r12d, %r11d
movq 0x40(%rsp), %r15
movw %r11w, (%r15,%rax,2)
movl 0x10(%r13,%rbp,4), %r11d
shrl %cl, %r11d
andl %r12d, %r11d
movw %r11w, (%rsi,%rax,2)
movl (%rdi,%rbp,4), %r11d
shrl %cl, %r11d
andl %r12d, %r11d
movw %r11w, (%rbx,%rax,2)
cmpl $0x9, %ecx
ja 0x130d3
incq %rbp
cmpq $0x4, %rbp
jne 0x130bc
movq -0x10(%rsp), %rdi
addl $0x10, %edi
cmpl -0x20(%rsp), %edi
movb $0x1, %al
movq -0x8(%rsp), %rdx
jb 0x13091
incl %r14d
jmp 0x13369
movl %eax, %ecx
addl $-0x10, %ecx
movl 0x38(%rsp), %eax
cmpl %r10d, %eax
cmovll %eax, %r10d
movl %r10d, -0x1c(%rsp)
movb $0x1, %al
movl %ecx, -0x20(%rsp)
cmpl $0x5, %ecx
jb 0x13369
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x4, %eax
xorl %r15d, %r15d
movl $0x3ff, %ebp            # imm = 0x3FF
leal 0x19(%r14), %ecx
cmpl -0x1c(%rsp), %ecx
jg 0x13360
leal 0xc(%rax), %ecx
movq %rax, -0x10(%rsp)
movl %eax, %eax
movq %rax, -0x18(%rsp)
leaq (%rdx,%rax,4), %r12
addq $0x20, %r12
leaq (%rdx,%rcx,4), %r13
xorl %ebx, %ebx
movq %rbx, %rdi
orq -0x18(%rsp), %rdi
movl $0x1e, %ecx
movl %r14d, %r10d
leal 0x1(%r10), %eax
movl %eax, (%r8)
movl (%rdx,%rdi,4), %r11d
addl $-0xa, %ecx
shrl %cl, %r11d
andl %ebp, %r11d
testl %r14d, %r14d
cmovsl %r15d, %eax
movw %r11w, (%r9,%rax,2)
movl (%r12,%rbx,4), %r11d
shrl %cl, %r11d
andl %ebp, %r11d
movw %r11w, (%rsi,%rax,2)
leal 0x2(%r10), %r14d
movl %r14d, (%r8)
movl -0x10(%r12,%rbx,4), %r11d
shrl %cl, %r11d
andl %ebp, %r11d
movl $0x0, %r15d
cmpl $-0x1, %r10d
cmovgel %r14d, %r15d
movw %r11w, (%r9,%r15,2)
movl (%r13,%rbx,4), %r10d
shrl %cl, %r10d
andl %ebp, %r10d
movw %r10w, (%rsi,%r15,2)
xorl %r15d, %r15d
cmpl $0x9, %ecx
ja 0x131d8
incq %rbx
cmpq $0x4, %rbx
jne 0x131cb
movq -0x10(%rsp), %rax
addl $0x10, %eax
cmpl -0x20(%rsp), %eax
jb 0x131a0
jmp 0x13360
movl %eax, %ecx
addl $-0x10, %ecx
movb $0x1, %al
movl %ecx, -0x20(%rsp)
cmpl $0x5, %ecx
jb 0x13369
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x4, %eax
xorl %ebx, %ebx
movl $0x3ff, %ebp            # imm = 0x3FF
leal 0x31(%r14), %ecx
cmpl 0x38(%rsp), %ecx
jg 0x13360
leal 0xc(%rax), %ecx
movq %rax, -0x18(%rsp)
movl %eax, %esi
leaq (%rdx,%rsi,4), %r15
addq $0x20, %r15
leaq (%rdx,%rcx,4), %r12
xorl %r13d, %r13d
movq %r13, %r11
orq %rsi, %r11
movl $0x1e, %ecx
movl %r14d, %r10d
addl $-0xa, %ecx
movl (%rdx,%r11,4), %eax
shrl %cl, %eax
andl %ebp, %eax
leal 0x1(%r10), %edi
movl %edi, (%r8)
testl %r14d, %r14d
cmovsl %ebx, %edi
movw %ax, (%r9,%rdi,2)
movl (%r15,%r13,4), %eax
shrl %cl, %eax
andl %ebp, %eax
leal 0x2(%r10), %edi
movl %edi, (%r8)
cmpl $-0x1, %r14d
cmovll %ebx, %edi
movw %ax, (%r9,%rdi,2)
movl -0x10(%r15,%r13,4), %eax
shrl %cl, %eax
andl %ebp, %eax
leal 0x3(%r10), %edi
movl %edi, (%r8)
cmpl $-0x2, %r14d
cmovll %ebx, %edi
movw %ax, (%r9,%rdi,2)
movl (%r12,%r13,4), %edi
shrl %cl, %edi
andl %ebp, %edi
cmpl $-0x3, %r14d
leal 0x4(%r10), %r14d
movl %r14d, (%r8)
movl $0x0, %r10d
cmovgel %r14d, %r10d
movw %di, (%r9,%r10,2)
cmpl $0x9, %ecx
ja 0x132c3
incq %r13
cmpq $0x4, %r13
jne 0x132b8
movq -0x18(%rsp), %rax
addl $0x10, %eax
cmpl -0x20(%rsp), %eax
jb 0x13291
incl %r14d
movb $0x1, %al
jmp 0x13369
xorl %eax, %eax
movl %r14d, (%r8)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop