// File: /workspace/github_c_makefile_star2_O1/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), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
testl %edi, %edi
jle 0x272e
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 0x2fb0
movq %r13, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x4a28(%rip), %rsi      # 0x7010
leaq 0x4a22(%rip), %rdx      # 0x7011
callq 0x307e
movq 0x190(%rsp), %rcx
movl $0xf, %esi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rcx
je 0x2616
movq 0x1a0(%rsp), %rsi
movq 0x198(%rsp), %r8
movq 0x18(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x2642
movl $0xf, %esi
cmpq %r13, 0x10(%rsp)
je 0x263d
movq 0x20(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x2651
movq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x20f0
jmp 0x265f
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 0x2688
movq %rdx, 0x3a0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x3b0(%rsp)
jmp 0x268f
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 0x26e6
movq 0x3b0(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x26fd
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x2722
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x21f0
incq %r12
cmpq %r12, %rbp
jne 0x25c6
leaq 0x180(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0x170(%rsp), %rdi
callq 0x2fee
leaq 0x170(%rsp), %rdi
callq 0x469a
movq 0x170(%rsp), %rdi
cmpq %r14, %rdi
je 0x277e
movq 0x180(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x160(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x4881(%rip), %rsi      # 0x7012
leaq 0x4884(%rip), %rdx      # 0x701c
leaq 0x150(%rsp), %rdi
callq 0x307e
leaq 0x10(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x4640
movq 0x150(%rsp), %rdi
cmpq %r14, %rdi
je 0x27d4
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x140(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x4836(%rip), %rsi      # 0x701d
leaq 0x483c(%rip), %rdx      # 0x702a
leaq 0x130(%rsp), %rdi
callq 0x307e
leaq 0x70(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x4640
movq 0x130(%rsp), %rdi
cmpq %r14, %rdi
je 0x282a
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x47fa(%rip), %rsi      # 0x702b
leaq 0x70(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x284f
movq 0x70(%rsp), %rdi
callq 0x22c0
cvtsi2ss %eax, %xmm0
jmp 0x2857
movss 0x47ad(%rip), %xmm0     # 0x7004
movss %xmm0, 0xc(%rsp)
leaq 0x100(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x47c0(%rip), %rsi      # 0x7030
leaq 0x47c3(%rip), %rdx      # 0x703a
leaq 0xf0(%rsp), %rdi
callq 0x307e
leaq 0x110(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x4640
movq 0xf0(%rsp), %rdi
cmpq %r14, %rdi
je 0x28b6
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x476e(%rip), %rsi      # 0x702b
leaq 0x110(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x28e1
movq 0x110(%rsp), %rdi
callq 0x2230
cvtsd2ss %xmm0, %xmm0
jmp 0x28e9
movss 0x471f(%rip), %xmm0     # 0x7008
movss %xmm0, 0x8(%rsp)
leaq 0xc0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x4739(%rip), %rsi      # 0x703b
leaq 0x473d(%rip), %rdx      # 0x7046
leaq 0xb0(%rsp), %rdi
callq 0x307e
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x4640
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2948
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x46dc(%rip), %rsi      # 0x702b
leaq 0xd0(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2976
movq 0xd0(%rsp), %rdi
callq 0x22c0
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
jmp 0x297e
movss 0x468e(%rip), %xmm0     # 0x700c
movss %xmm0, 0x4(%rsp)
leaq 0xa0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x46b0(%rip), %rsi      # 0x7047
leaq 0x46b5(%rip), %rdx      # 0x7053
leaq 0x90(%rsp), %rdi
callq 0x307e
leaq 0x50(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x4640
movq 0x90(%rsp), %rdi
cmpq %r14, %rdi
je 0x29da
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x4673(%rip), %rsi      # 0x7054
leaq 0x50(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2a42
leaq 0x4663(%rip), %rsi      # 0x7059
leaq 0x50(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2a6b
leaq 0x4653(%rip), %rsi      # 0x705e
leaq 0x50(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2a94
movl $0xc0, %edi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x4de6
jmp 0x2abb
movl $0xc0, %edi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x4de6
jmp 0x2abb
movl $0xc0, %edi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x5562
jmp 0x2abb
movl $0xc0, %edi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x5cee
leaq 0x45a1(%rip), %rsi      # 0x7063
leaq 0x10(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2cc0
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 0x2bb8
movq 0x74bc(%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 0x2b9e
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 0x2b96
movq %r14, %rdi
callq 0x322e
movl %eax, %ebp
cmpb $0xd, %al
jne 0x2b79
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 0x2b40
movq 0x190(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x1b0(%rsp,%rax)
je 0x2b11
leaq 0x190(%rsp), %rdi
callq 0x2060
leaq 0x190(%rsp), %rdi
callq 0x20b0
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
leaq 0x3a0(%rsp), %rsi
movb $0xa, (%rsi)
movq 0x73db(%rip), %rdi      # 0x9fc8
movl $0x1, %edx
callq 0x2220
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c12
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c33
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c54
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c75
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c90
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2cac
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 0x7319(%rip), %rbx      # 0x9fe0
leaq 0x190(%rsp), %r15
movq 0x72f2(%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 0x2bd2
movsbl 0x190(%rsp), %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
testb %al, %al
je 0x2cde
movq %r14, %rdi
callq 0x322e
movl %eax, %ebp
cmpb $0xd, %al
jne 0x2d36
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 0x2cde
jmp 0x2d5e
jmp 0x2d5e
jmp 0x2d5e
movq %rax, %rbx
movl $0xc0, %esi
movq %r14, %rdi
callq 0x21f0
jmp 0x2ef3
jmp 0x2ee3
jmp 0x2edc
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f0e
movq 0xa0(%rsp), %rsi
jmp 0x2f06
movq %rax, %rbx
jmp 0x2f0e
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f2f
movq 0xc0(%rsp), %rsi
jmp 0x2f27
movq %rax, %rbx
jmp 0x2f2f
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f50
movq 0x100(%rsp), %rsi
jmp 0x2f48
movq %rax, %rbx
jmp 0x2f50
movq %rax, %rbx
movq 0x130(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f71
movq 0x140(%rsp), %rsi
jmp 0x2f69
movq %rax, %rbx
jmp 0x2f71
movq %rax, %rbx
movq 0x150(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f8c
movq 0x160(%rsp), %rsi
jmp 0x2f84
jmp 0x2e6b
movq %rax, %rbx
movq 0x170(%rsp), %rdi
cmpq %r14, %rdi
je 0x2f8c
movq 0x180(%rsp), %rsi
jmp 0x2f84
jmp 0x2e6b
jmp 0x2edc
jmp 0x2ee3
movq %rax, %rbx
jmp 0x2f8c
movq %rax, %rbx
jmp 0x2eb4
movq %rax, %rbx
jmp 0x2e9d
movq %rax, %rbx
movq 0x3a0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e9d
movq 0x3b0(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2eb4
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x2f8c
movq 0x1a0(%rsp), %rsi
jmp 0x2f84
jmp 0x2edc
movq %rax, %rbx
jmp 0x2ef3
jmp 0x2ee3
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
callq 0x20b0
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f0e
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0xe0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f2f
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f50
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f71
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f8c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2fa8
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2350