// File: /workspace/github_c_makefile_star2_O3/DrYerzinia[P]C_DigiMode/src/psk31/psk31_wcpd.cpp
// Function: psk31_wcpd::proccess_byte(char)
bool psk31_wcpd::proccess_byte(char next_data_point){

	bool newByte = false;

	input_data[input_position] = next_data_point;

	if(input_count > input_data_width){


		int pos;
		int postmp;

		pos = input_position+1;

		int topsum1, topsum2;
		float max;

		float phasesum[(int)ninty_deg_phase_width];

		for(int i = 0; i < ninty_deg_phase_width; i++)
			phasesum[i] = 0.0f;

		for(int i = 0; i < ninty_deg_phase_width; i++){

			postmp = pos + i;
			if(postmp < 0) postmp = input_data_width + postmp;
			else if(postmp >= input_data_width) postmp = postmp - input_data_width;

			for(int j = 0; j < ninty_deg_phase_width; j++){
				phasesum[j] += input_data[postmp]*sin(((input_count+i)/ninty_deg_phase_width)*2*PI+(j*2*PI/ninty_deg_phase_width));
			}

		}

		max = -100000;
		for(int i = 0; i < ninty_deg_phase_width; i++){
			if(phasesum[i] > max){
				max = phasesum[i];
				topsum1 = i;
			}
		}

		pos = (int)floor(input_position-ninty_deg_phase_width+1.5);

		for(int i = 0; i < ninty_deg_phase_width; i++)
			phasesum[i] = 0.0f;

		for(int i = 0; i < ninty_deg_phase_width; i++){

			postmp = pos + i;
			if(postmp < 0) postmp = input_data_width + postmp;
			else if(postmp >= input_data_width) postmp = postmp - input_data_width;

			for(int j = 0; j < ninty_deg_phase_width; j++){
				phasesum[j] += input_data[postmp]*sin(((input_count+i)/ninty_deg_phase_width)*2*PI+(j*2*PI/ninty_deg_phase_width));
			}

		}

		max = -100000;
		for(int i = 0; i < ninty_deg_phase_width; i++){
			if(phasesum[i] > max){
				max = phasesum[i];
				topsum2 = i;
			}
		}

		float pd = std::abs(topsum1-topsum2);
		if(pd > ninty_deg_phase_width/2) pd = std::abs(pd-ninty_deg_phase_width);
 		phase_change_data.push_back(pd);

	}

	input_position++;
	input_count++;

	if(input_position > input_data_width) input_position = 0;

	if(phase_change_data.size() >= bitwidth/4){

		float phase_change_sum = 0.0;

		for(std::list<float>::iterator it = phase_change_data.begin(); it != phase_change_data.end(); it++){

			phase_change_sum += (*it);

		}

		if(phase_change_sum > max) max = phase_change_sum;

		int current_value;

		if(phase_change_sum > threshhold_value*max)
			current_value = 1;
		else
			current_value = 0;

		if(last == -1) last = current_value;

		if(current_value != last){

			for(int i = 0; i < floor(((float)countlast)/((float)bitwidth)+0.5); i++)
				bit_sequence.push_back(current_value);

			if(bit_sequence.size() >= 2 && bit_sequence[bit_sequence.size()-1] == 0 && bit_sequence[bit_sequence.size()-2] == 0){
				int one = 1;
				int val = 0;
				for(int i = bit_sequence.size()-3; i >= 0; i--){
					if(bit_sequence[i] == 1)
						val |= one;
					one <<= 1;
				}

				newByte = true;

				byte_sequence.push_back(getVaricode(val));
				bit_sequence.clear();
			}

			last = current_value;
			countlast = 1;

		} else countlast++;

		phase_change_data.pop_front();

	}

	return newByte;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq 0x60(%rdi), %rax
movl 0x50(%rdi), %ecx
movb %sil, (%rax,%rcx)
movl 0x54(%rdi), %eax
movl 0x58(%rdi), %ecx
cmpl %ecx, %eax
movq %rdi, -0x30(%rbp)
jbe 0x5afa
movq %rsp, -0x68(%rbp)
cvttss2si 0x18(%rdi), %eax
movq %rsp, %r14
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movss 0x18(%rdi), %xmm3
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm3
jbe 0x58c2
movl 0x50(%rdi), %eax
incl %eax
movq %rax, -0x58(%rbp)
xorl %eax, %eax
movl $0x0, (%r14,%rax,4)
incq %rax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
ucomiss %xmm0, %xmm3
ja 0x57b2
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm3
jbe 0x58c2
movsd 0x1903(%rip), %xmm4     # 0x70e0
xorl %r15d, %r15d
ucomiss 0x1939(%rip), %xmm3     # 0x7120
jbe 0x58ae
movq -0x58(%rbp), %rax
addl %r15d, %eax
movl 0x58(%rdi), %ecx
cmpl %ecx, %eax
movl %ecx, %edx
movl $0x0, %esi
cmovbl %esi, %edx
negl %edx
testl %eax, %eax
cmovsl %ecx, %edx
addl %eax, %edx
movslq %edx, %r13
movl $0x1, %r12d
xorl %ebx, %ebx
movl 0x54(%rdi), %eax
addl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movq 0x60(%rdi), %rax
movsbl (%rax,%r13), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, -0x50(%rbp)
divss %xmm3, %xmm0
addss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
mulsd %xmm4, %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm3, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
callq 0x20a0
movsd 0x186f(%rip), %xmm4     # 0x70e0
movq -0x30(%rbp), %rdi
xorps %xmm1, %xmm1
cvtss2sd (%r14,%rbx,2), %xmm1
mulsd -0x50(%rbp), %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r14,%rbx,2)
xorps %xmm0, %xmm0
cvtsi2ss %r12d, %xmm0
movss 0x18(%rdi), %xmm3
addq $0x2, %rbx
incl %r12d
ucomiss %xmm0, %xmm3
ja 0x5817
incl %r15d
xorps %xmm0, %xmm0
cvtsi2ss %r15d, %xmm0
ucomiss %xmm0, %xmm3
ja 0x57e0
ucomiss 0x1857(%rip), %xmm3     # 0x7120
jbe 0x58f7
movss 0x1845(%rip), %xmm0     # 0x7118
xorl %eax, %eax
movss (%r14,%rax,4), %xmm1
ucomiss %xmm0, %xmm1
cmoval %eax, %ecx
incq %rax
xorps %xmm2, %xmm2
cvtsi2ss %eax, %xmm2
maxss %xmm0, %xmm1
ucomiss %xmm2, %xmm3
movaps %xmm1, %xmm0
ja 0x58d5
movl %ecx, -0x5c(%rbp)
movl 0x50(%rdi), %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
subss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x17c3(%rip), %xmm0     # 0x70d8
movaps %xmm3, -0x50(%rbp)
callq 0x2320
movaps -0x50(%rbp), %xmm3
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm3
jbe 0x5a4f
cvttsd2si %xmm0, %eax
movq %rax, -0x58(%rbp)
xorl %eax, %eax
movl $0x0, (%r14,%rax,4)
incq %rax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
ucomiss %xmm0, %xmm3
ja 0x5938
xorpd %xmm0, %xmm0
ucomiss %xmm0, %xmm3
movq -0x30(%rbp), %rsi
jbe 0x5a53
movsd 0x1778(%rip), %xmm4     # 0x70e0
xorl %r15d, %r15d
ucomiss 0x17ae(%rip), %xmm3     # 0x7120
jbe 0x5a39
movq -0x58(%rbp), %rax
addl %r15d, %eax
movl 0x58(%rsi), %ecx
cmpl %ecx, %eax
movl %ecx, %edx
movl $0x0, %edi
cmovbl %edi, %edx
negl %edx
testl %eax, %eax
cmovsl %ecx, %edx
addl %eax, %edx
movslq %edx, %r13
movl $0x1, %r12d
xorl %ebx, %ebx
movl 0x54(%rsi), %eax
addl %r15d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movq 0x60(%rsi), %rax
movsbl (%rax,%r13), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, -0x50(%rbp)
divss %xmm3, %xmm0
addss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
mulsd %xmm4, %xmm1
xorps %xmm2, %xmm2
cvtss2sd %xmm3, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm4, %xmm0
addsd %xmm1, %xmm0
callq 0x20a0
movsd 0x16e4(%rip), %xmm4     # 0x70e0
movq -0x30(%rbp), %rsi
xorps %xmm1, %xmm1
cvtss2sd (%r14,%rbx,2), %xmm1
mulsd -0x50(%rbp), %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r14,%rbx,2)
xorps %xmm0, %xmm0
cvtsi2ss %r12d, %xmm0
movss 0x18(%rsi), %xmm3
addq $0x2, %rbx
incl %r12d
ucomiss %xmm0, %xmm3
ja 0x59a2
incl %r15d
xorps %xmm0, %xmm0
cvtsi2ss %r15d, %xmm0
ucomiss %xmm0, %xmm3
ja 0x596b
jmp 0x5a53
movq -0x30(%rbp), %rsi
ucomiss 0x16c6(%rip), %xmm3     # 0x7120
jbe 0x5a88
movss 0x16b4(%rip), %xmm0     # 0x7118
xorl %ecx, %ecx
movss (%r14,%rcx,4), %xmm1
ucomiss %xmm0, %xmm1
cmoval %ecx, %eax
incq %rcx
xorps %xmm2, %xmm2
cvtsi2ss %ecx, %xmm2
maxss %xmm0, %xmm1
ucomiss %xmm2, %xmm3
movaps %xmm1, %xmm0
ja 0x5a66
movl -0x5c(%rbp), %ecx
subl %eax, %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movaps %xmm0, %xmm1
subss %xmm3, %xmm1
mulss 0x1672(%rip), %xmm3     # 0x711c
andps 0x160f(%rip), %xmm1     # 0x70c0
cmpltss %xmm0, %xmm3
movaps %xmm3, %xmm2
andnps %xmm0, %xmm2
andps %xmm1, %xmm3
orps %xmm2, %xmm3
movaps %xmm3, -0x50(%rbp)
leaq 0x68(%rsi), %r14
movl $0x18, %edi
callq 0x21e0
movaps -0x50(%rbp), %xmm0
movss %xmm0, 0x10(%rax)
movq %rax, %rdi
movq %r14, %rsi
callq 0x2070
movq -0x30(%rbp), %rdi
incq 0x78(%rdi)
movq -0x68(%rbp), %rsp
movl 0x54(%rdi), %eax
movl 0x58(%rdi), %ecx
movl 0x50(%rdi), %edx
incl %edx
movl %edx, 0x50(%rdi)
incl %eax
movl %eax, 0x54(%rdi)
cmpl %ecx, %edx
jbe 0x5b12
movl $0x0, 0x50(%rdi)
movl 0x1c(%rdi), %ecx
leal 0x3(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
movq 0x78(%rdi), %rax
sarl $0x2, %edx
movslq %edx, %rdx
cmpq %rdx, %rax
jae 0x5b34
xorl %r14d, %r14d
jmp 0x5cc5
leaq 0x68(%rdi), %rdx
movq (%rdx), %r15
xorps %xmm0, %xmm0
cmpq %rdx, %r15
je 0x5b53
movq %r15, %rsi
addss 0x10(%rsi), %xmm0
movq (%rsi), %rsi
cmpq %rdx, %rsi
jne 0x5b46
xorps %xmm1, %xmm1
cvtsi2ssl 0x9c(%rdi), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x5b74
cvttss2si %xmm0, %edx
movl %edx, 0x9c(%rdi)
cvttps2dq %xmm0, %xmm1
cvtdq2ps %xmm1, %xmm1
mulss 0x14(%rdi), %xmm1
xorl %edx, %edx
ucomiss %xmm1, %xmm0
seta %dl
movl %edx, -0x34(%rbp)
movl 0x98(%rdi), %esi
cmpl $-0x1, %esi
je 0x5c9a
cmpl %edx, %esi
je 0x5ca0
xorps %xmm0, %xmm0
cvtsi2ssl 0xa0(%rdi), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x1513(%rip), %xmm0     # 0x70d0
callq 0x2320
movq -0x30(%rbp), %rdi
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5c55
leaq 0x80(%rdi), %r14
movl $0x1, %ebx
leaq -0x34(%rbp), %r15
movq 0x88(%rdi), %rsi
cmpq 0x90(%rdi), %rsi
je 0x5c05
movl -0x34(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x88(%rdi)
jmp 0x5c14
movq %r14, %rdi
movq %r15, %rdx
callq 0x5364
movq -0x30(%rbp), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
cvtsi2ssl 0xa0(%rdi), %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x1c(%rdi), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x148d(%rip), %xmm0     # 0x70d0
callq 0x2320
movq -0x30(%rbp), %rdi
incl %ebx
ucomisd -0x50(%rbp), %xmm0
ja 0x5be3
movq 0x80(%rdi), %rax
movq 0x88(%rdi), %rdx
subq %rax, %rdx
movq %rdx, %rcx
sarq $0x2, %rcx
cmpq $0x1, %rcx
jbe 0x5c7a
cmpl $0x0, -0x4(%rax,%rdx)
je 0x5cd7
xorl %r14d, %r14d
movl -0x34(%rbp), %eax
movl %eax, 0x98(%rdi)
movl $0x1, 0xa0(%rdi)
movq 0x68(%rdi), %r15
movq 0x78(%rdi), %rax
jmp 0x5ca9
movl %edx, 0x98(%rdi)
incl 0xa0(%rdi)
xorl %r14d, %r14d
decq %rax
movq %rax, 0x78(%rdi)
movq %r15, %rdi
callq 0x2300
movl $0x18, %esi
movq %r15, %rdi
callq 0x21f0
movl %r14d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
cmpl $0x0, -0x8(%rax,%rdx)
jne 0x5c7d
addl $-0x3, %ecx
js 0x5d07
movl %ecx, %ecx
movl $0x1, %edx
xorl %r14d, %r14d
cmpl $0x1, (%rax,%rcx,4)
movl $0x0, %esi
cmovel %edx, %esi
orl %esi, %r14d
addl %edx, %edx
addq $-0x1, %rcx
jb 0x5cf0
leaq 0xa8(%rdi), %r15
movq -0x30(%rbp), %rdi
movl %r14d, %esi
callq 0x3398
leaq -0x35(%rbp), %rsi
movb %al, (%rsi)
movq %r15, %rdi
callq 0x54a0
movq -0x30(%rbp), %rdi
movq 0x80(%rdi), %rax
movb $0x1, %r14b
cmpq %rax, 0x88(%rdi)
je 0x5c7d
movq %rax, 0x88(%rdi)
jmp 0x5c7d
nop