// File: /workspace/github_c_makefile_star2_O3/DrYerzinia[P]C_DigiMode/src/psk31/main.cpp
// Function: main
int main(int argc, char **argv){

	std::string args;
	for(int i = 0; i < argc; i++) args += std::string(argv[i]) + std::string(" ");
	util::readInArguments(args);

	std::string filename = util::getArgument("--filename");

	std::string sample_rate = util::getArgument("--sample-rate");
	int sample_rate_int = 22050;
	if(sample_rate.compare("NULL")){
		sample_rate_int = atoi(sample_rate.c_str());
	}

	std::string bit_rate = util::getArgument("--bit-rate");
	float bit_rate_int = 31.25;
	if(bit_rate.compare("NULL")){
		bit_rate_int = atof(bit_rate.c_str());
	}

	std::string psk31freq = util::getArgument("--psk31freq");
	int psk31freq_int = 1900;
	if(psk31freq.compare("NULL")){
		psk31freq_int = atoi(psk31freq.c_str());
	}

	std::string demodmode = util::getArgument("--demod-mode");

	psk31 *psk;

	if(demodmode.compare("tdtl") == 0) psk = new psk31_tdtl(sample_rate_int, bit_rate_int, psk31freq_int);
	else if(demodmode.compare("wcpd") == 0) psk = new psk31_wcpd(sample_rate_int, bit_rate_int, psk31freq_int);
	else if(demodmode.compare("wpdd") == 0) psk = new psk31_wpdd(sample_rate_int, bit_rate_int, psk31freq_int);
	else psk = new psk31_tdtl(sample_rate_int, bit_rate_int, psk31freq_int);

	if(filename.compare("stdin") == 0){
		char c;
		while(std::cin.get(c)){
			if(psk->proccess_byte(c)){
				char lb = psk->getLastByte();
				if(lb == '\r') std::cout << '\n';
				std::cout << lb;
				std::cout.flush();
			}
		}

	} else {
		std::fstream input_file(filename.c_str(), std::fstream::in | std::fstream::binary);
		std::vector<char> input_data;
		char buffer[1000];
		while(!input_file.eof()){
			input_file.read(buffer, 1000);
			int count = input_file.gcount();
			for(int i = 0; i < count; i++){
				if(psk->proccess_byte(buffer[i])){
					char lb = psk->getLastByte();
					if(lb == '\r') std::cout << '\n';
					std::cout << lb;
					std::cout.flush();
				}
			}
		}
		input_file.close();
	}


	delete psk;

	std::cout << '\n';

	return 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x788, %rsp            # imm = 0x788
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
testl %edi, %edi
jle 0x273e
movq %rsi, %rbx
leaq 0x20(%rsp), %r13
leaq 0x3b0(%rsp), %r15
movl %edi, %ebp
xorl %r12d, %r12d
leaq 0x190(%rsp), %r14
movq (%rbx,%r12,8), %rsi
movq %r14, %rdi
leaq 0x70(%rsp), %rdx
callq 0x2fce
movq %r13, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x4a27(%rip), %rsi      # 0x7010
leaq 0x4a21(%rip), %rdx      # 0x7011
callq 0x30a2
movq 0x190(%rsp), %rcx
movl $0xf, %edi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rcx
je 0x2617
movq 0x1a0(%rsp), %rdi
movq 0x198(%rsp), %r8
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x2646
movl $0xf, %edi
cmpq %r13, %rsi
je 0x2641
movq 0x20(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x2650
movq %r14, %rdi
callq 0x20f0
jmp 0x265e
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2210
movq %r15, 0x3a0(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x2687
movq %rdx, 0x3a0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x3b0(%rsp)
jmp 0x268e
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x3a8(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x3a0(%rsp), %rsi
movq 0x3a8(%rsp), %rdx
leaq 0x30(%rsp), %rdi
callq 0x20f0
movq 0x3a0(%rsp), %rdi
cmpq %r15, %rdi
je 0x26e5
movq 0x3b0(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x26fc
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x2721
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x21f0
incq %r12
cmpq %r12, %rbp
jne 0x25c7
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0x40(%rsp), %r15
jmp 0x2743
xorl %edx, %edx
movq %r15, %rsi
leaq 0x180(%rsp), %r14
movq %r14, -0x10(%r14)
addq %rsi, %rdx
leaq 0x170(%rsp), %rdi
callq 0x300c
leaq 0x170(%rsp), %rdi
callq 0x4742
movq 0x170(%rsp), %rdi
cmpq %r14, %rdi
je 0x2789
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x160(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x4876(%rip), %rsi      # 0x7012
leaq 0x4879(%rip), %rdx      # 0x701c
leaq 0x150(%rsp), %rdi
callq 0x30a2
leaq 0x10(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x46e8
movq 0x150(%rsp), %rdi
cmpq %r14, %rdi
je 0x27df
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x140(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x482b(%rip), %rsi      # 0x701d
leaq 0x4831(%rip), %rdx      # 0x702a
leaq 0x130(%rsp), %rdi
callq 0x30a2
leaq 0x70(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x46e8
movq 0x130(%rsp), %rdi
cmpq %r14, %rdi
je 0x2835
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x47ef(%rip), %rsi      # 0x702b
leaq 0x70(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x285a
movq 0x70(%rsp), %rdi
callq 0x22c0
cvtsi2ss %eax, %xmm0
jmp 0x2862
movss 0x47a2(%rip), %xmm0     # 0x7004
movss %xmm0, 0xc(%rsp)
leaq 0x100(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x47b5(%rip), %rsi      # 0x7030
leaq 0x47b8(%rip), %rdx      # 0x703a
leaq 0xf0(%rsp), %rdi
callq 0x30a2
leaq 0x110(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x46e8
movq 0xf0(%rsp), %rdi
cmpq %r14, %rdi
je 0x28c1
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x4763(%rip), %rsi      # 0x702b
leaq 0x110(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x28ec
movq 0x110(%rsp), %rdi
callq 0x2230
cvtsd2ss %xmm0, %xmm0
jmp 0x28f4
movss 0x4714(%rip), %xmm0     # 0x7008
movss %xmm0, 0x8(%rsp)
leaq 0xc0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x472e(%rip), %rsi      # 0x703b
leaq 0x4732(%rip), %rdx      # 0x7046
leaq 0xb0(%rsp), %rdi
callq 0x30a2
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x46e8
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2953
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x46d1(%rip), %rsi      # 0x702b
leaq 0xd0(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2981
movq 0xd0(%rsp), %rdi
callq 0x22c0
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
jmp 0x2989
movss 0x4683(%rip), %xmm0     # 0x700c
movss %xmm0, 0x4(%rsp)
leaq 0xa0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x46a5(%rip), %rsi      # 0x7047
leaq 0x46aa(%rip), %rdx      # 0x7053
leaq 0x90(%rsp), %rdi
callq 0x30a2
leaq 0x50(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x46e8
movq 0x90(%rsp), %rdi
cmpq %r14, %rdi
je 0x29e5
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x4668(%rip), %rsi      # 0x7054
leaq 0x50(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2a4d
leaq 0x4658(%rip), %rsi      # 0x7059
leaq 0x50(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2a76
leaq 0x4648(%rip), %rsi      # 0x705e
leaq 0x50(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2a9f
movl $0xc0, %edi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x4e8e
jmp 0x2ac6
movl $0xc0, %edi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x4e8e
jmp 0x2ac6
movl $0xc0, %edi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x5616
jmp 0x2ac6
movl $0xc0, %edi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x5d9e
leaq 0x4596(%rip), %rsi      # 0x7063
leaq 0x10(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2ccb
movq 0x10(%rsp), %rsi
leaq 0x190(%rsp), %rdi
movl $0xc, %edx
callq 0x2270
movq 0x190(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x1b0(%rsp,%rax)
jne 0x2bc3
movq 0x74b1(%rip), %r12      # 0x9fc8
leaq 0x3(%rsp), %r13
movl $0x3e8, %edx            # imm = 0x3E8
leaq 0x190(%rsp), %rdi
leaq 0x3a0(%rsp), %rsi
callq 0x2240
movq 0x198(%rsp), %rbx
testl %ebx, %ebx
jle 0x2ba9
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
xorl %r15d, %r15d
movsbl 0x3a0(%rsp,%r15), %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
testb %al, %al
je 0x2ba1
movq %r14, %rdi
callq 0x3256
movl %eax, %ebp
cmpb $0xd, %al
jne 0x2b84
movb $0xa, 0x3(%rsp)
movl $0x1, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2220
movb %bpl, 0x3(%rsp)
movl $0x1, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2220
movq %r12, %rdi
callq 0x2160
incq %r15
cmpq %r15, %rbx
jne 0x2b4b
movq 0x190(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x1b0(%rsp,%rax)
je 0x2b1c
leaq 0x190(%rsp), %rdi
callq 0x2060
leaq 0x190(%rsp), %rdi
callq 0x20b0
leaq 0x40(%rsp), %r15
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
leaq 0x3a0(%rsp), %rsi
movb $0xa, (%rsi)
movq 0x73cb(%rip), %rdi      # 0x9fc8
movl $0x1, %edx
callq 0x2220
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c22
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c43
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c64
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c85
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ca0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x2cb7
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
xorl %eax, %eax
addq $0x788, %rsp            # imm = 0x788
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x730e(%rip), %rbx      # 0x9fe0
leaq 0x190(%rsp), %r15
movq 0x72e7(%rip), %r12      # 0x9fc8
leaq 0x3a0(%rsp), %r13
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2280
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2bdd
movsbl 0x190(%rsp), %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
testb %al, %al
je 0x2ce9
movq %r14, %rdi
callq 0x3256
movl %eax, %ebp
cmpb $0xd, %al
jne 0x2d41
movb $0xa, 0x3a0(%rsp)
movl $0x1, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2220
movb %bpl, 0x3a0(%rsp)
movl $0x1, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2220
movq %r12, %rdi
callq 0x2160
jmp 0x2ce9
jmp 0x2d69
jmp 0x2d69
jmp 0x2d69
movq %rax, %rbx
movl $0xc0, %esi
movq %r14, %rdi
callq 0x21f0
jmp 0x2f15
jmp 0x2f00
jmp 0x2ef9
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f30
movq 0xa0(%rsp), %rsi
jmp 0x2f28
movq %rax, %rbx
jmp 0x2f30
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f51
movq 0xc0(%rsp), %rsi
jmp 0x2f49
movq %rax, %rbx
jmp 0x2f51
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f72
movq 0x100(%rsp), %rsi
jmp 0x2f6a
movq %rax, %rbx
jmp 0x2f72
movq %rax, %rbx
movq 0x130(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f93
movq 0x140(%rsp), %rsi
jmp 0x2f8b
movq %rax, %rbx
jmp 0x2f93
movq %rax, %rbx
movq 0x150(%rsp), %rdi
cmpq %r14, %rdi
je 0x2fae
movq 0x160(%rsp), %rsi
jmp 0x2fa6
jmp 0x2e70
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r14, %rdi
je 0x2fae
movq 0x180(%rsp), %rsi
jmp 0x2fa6
movq %rax, %rbx
jmp 0x2fae
movq %rax, %rbx
jmp 0x2f15
jmp 0x2f00
movq %rax, %rbx
jmp 0x2eed
movq %rax, %rbx
jmp 0x2ec8
movq %rax, %rbx
jmp 0x2eb1
movq %rax, %rbx
movq 0x3a0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2eb1
movq 0x3b0(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2ec8
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x2eed
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x40(%rsp), %r15
jmp 0x2fae
jmp 0x2ef9
movq %rax, %rbx
jmp 0x2f10
jmp 0x2f00
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
callq 0x20b0
leaq 0x40(%rsp), %r15
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f30
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f51
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f72
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f93
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2fae
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x2fc5
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2350
nop