// File: /workspace/github_c_makefile_star2_O2/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 $0x7a8, %rsp            # imm = 0x7A8
movq %rsi, %rbx
movl %edi, %r14d
leaq 0xe0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %r12d, %r12d
testl %edi, %edi
cmovlel %r12d, %r14d
movb $0x0, (%rax)
leaq 0x1b0(%rsp), %r15
leaq 0x10(%rsp), %rbp
leaq 0x3c0(%rsp), %r13
cmpq %r12, %r14
je 0x261a
movq (%rbx,%r12,8), %rsi
movq %r15, %rdi
leaq 0x70(%rsp), %rdx
callq 0x2c9c
movq %rbp, %rdi
leaq 0x3a3b(%rip), %rsi      # 0x6010
leaq 0x50(%rsp), %rdx
callq 0x2c9c
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2c35
leaq 0xd0(%rsp), %rdi
movq %r13, %rsi
callq 0x23a0
movq %r13, %rdi
callq 0x2130
movq %rbp, %rdi
callq 0x2130
movq %r15, %rdi
callq 0x2130
incq %r12
jmp 0x25b5
leaq 0x190(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x2280
leaq 0x190(%rsp), %rdi
callq 0x433c
leaq 0x190(%rsp), %rdi
callq 0x2130
leaq 0x39c2(%rip), %rsi      # 0x6012
leaq 0x170(%rsp), %rdi
leaq 0x3c0(%rsp), %rdx
callq 0x2c9c
leaq 0x10(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x42ee
leaq 0x170(%rsp), %rdi
callq 0x2130
leaq 0x3992(%rip), %rsi      # 0x601d
leaq 0x150(%rsp), %rdi
leaq 0x3c0(%rsp), %rdx
callq 0x2c9c
leaq 0x70(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x42ee
leaq 0x150(%rsp), %rdi
callq 0x2130
leaq 0x3965(%rip), %rsi      # 0x602b
leaq 0x70(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x26e4
movq 0x70(%rsp), %rdi
callq 0x22d0
cvtsi2ss %eax, %xmm0
jmp 0x26ec
movss 0x3918(%rip), %xmm0     # 0x6004
movss %xmm0, 0xc(%rsp)
leaq 0x3937(%rip), %rsi      # 0x6030
leaq 0x130(%rsp), %rdi
leaq 0x3c0(%rsp), %rdx
callq 0x2c9c
leaq 0x50(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x42ee
leaq 0x130(%rsp), %rdi
callq 0x2130
leaq 0x38f7(%rip), %rsi      # 0x602b
leaq 0x50(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2752
movq 0x50(%rsp), %rdi
callq 0x2220
cvtsd2ss %xmm0, %xmm0
jmp 0x275a
movss 0x38ae(%rip), %xmm0     # 0x6008
movss %xmm0, 0x8(%rsp)
leaq 0x38d4(%rip), %rsi      # 0x603b
leaq 0x110(%rsp), %rdi
leaq 0x3c0(%rsp), %rdx
callq 0x2c9c
leaq 0xb0(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x42ee
leaq 0x110(%rsp), %rdi
callq 0x2130
leaq 0x3886(%rip), %rsi      # 0x602b
leaq 0xb0(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x27c9
movq 0xb0(%rsp), %rdi
callq 0x22d0
cvtsi2ss %eax, %xmm0
jmp 0x27d1
movss 0x383b(%rip), %xmm0     # 0x600c
movss %xmm0, 0x4(%rsp)
leaq 0x3869(%rip), %rsi      # 0x6047
leaq 0xf0(%rsp), %rdi
leaq 0x3c0(%rsp), %rdx
callq 0x2c9c
leaq 0x30(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x42ee
leaq 0xf0(%rsp), %rdi
callq 0x2130
leaq 0x383b(%rip), %rsi      # 0x6054
leaq 0x30(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x287a
leaq 0x382b(%rip), %rsi      # 0x6059
leaq 0x30(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x28a3
leaq 0x381b(%rip), %rsi      # 0x605e
leaq 0x30(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x28cc
movl $0xc0, %edi
callq 0x21e0
movq %rax, %rbx
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x48d2
jmp 0x28f3
movl $0xc0, %edi
callq 0x21e0
movq %rax, %rbx
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x48d2
jmp 0x28f3
movl $0xc0, %edi
callq 0x21e0
movq %rax, %rbx
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x50a6
jmp 0x28f3
movl $0xc0, %edi
callq 0x21e0
movq %rax, %rbx
movq %rax, %rdi
movss 0xc(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
movss 0x4(%rsp), %xmm2
callq 0x56da
leaq 0x3769(%rip), %rsi      # 0x6063
leaq 0x10(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
je 0x2a68
movq 0x10(%rsp), %rsi
leaq 0x1b0(%rsp), %rdi
pushq $0xc
popq %rdx
callq 0x2270
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
andq $0x0, 0xa0(%rsp)
movq 0x668c(%rip), %r12      # 0x8fc8
pushq $0xa
popq %rbp
movq 0x1b0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x1d0(%rsp,%rax)
jne 0x29d3
movl $0x3e8, %edx            # imm = 0x3E8
leaq 0x1b0(%rsp), %rdi
leaq 0x3c0(%rsp), %rsi
callq 0x2230
movl 0x1b8(%rsp), %r15d
testl %r15d, %r15d
movl $0x0, %eax
cmovlel %eax, %r15d
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x293f
movsbl 0x3c0(%rsp,%r14), %esi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
testb %al, %al
je 0x29ce
movq %rbx, %rdi
callq 0x2e7e
movl %eax, %r13d
cmpb $0xd, %al
jne 0x29ba
movq %r12, %rdi
movl %ebp, %esi
callq 0x2210
movsbl %r13b, %esi
movq %r12, %rdi
callq 0x2210
movq %r12, %rdi
callq 0x2150
incq %r14
jmp 0x2986
leaq 0x1b0(%rsp), %rdi
callq 0x2060
leaq 0x90(%rsp), %rdi
callq 0x2d78
leaq 0x1b0(%rsp), %rdi
callq 0x20b0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq 0x65be(%rip), %rdi      # 0x8fc8
pushq $0xa
popq %rsi
callq 0x2210
leaq 0x30(%rsp), %rdi
callq 0x2130
leaq 0xb0(%rsp), %rdi
callq 0x2130
leaq 0x50(%rsp), %rdi
callq 0x2130
leaq 0x70(%rsp), %rdi
callq 0x2130
leaq 0x10(%rsp), %rdi
callq 0x2130
leaq 0xd0(%rsp), %rdi
callq 0x2130
xorl %eax, %eax
addq $0x7a8, %rsp            # imm = 0x7A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6571(%rip), %r14      # 0x8fe0
leaq 0x3c0(%rsp), %r15
movq 0x654a(%rip), %r12      # 0x8fc8
pushq $0xa
popq %rbp
movq %r14, %rdi
movq %r15, %rsi
callq 0x2290
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x29fa
movsbl 0x3c0(%rsp), %esi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
testb %al, %al
je 0x2a81
movq %rbx, %rdi
callq 0x2e7e
movl %eax, %r13d
cmpb $0xd, %al
jne 0x2acc
movq %r12, %rdi
movl %ebp, %esi
callq 0x2210
movsbl %r13b, %esi
movq %r12, %rdi
callq 0x2210
movq %r12, %rdi
callq 0x2150
jmp 0x2a81
jmp 0x2ae8
jmp 0x2ae8
jmp 0x2ae8
movq %rax, %r14
movl $0xc0, %esi
movq %rbx, %rdi
callq 0x21f0
jmp 0x2beb
jmp 0x2bce
jmp 0x2b91
movq %rax, %r14
leaq 0xf0(%rsp), %rdi
jmp 0x2bf0
movq %rax, %r14
jmp 0x2bf5
movq %rax, %r14
leaq 0x110(%rsp), %rdi
jmp 0x2bfd
movq %rax, %r14
jmp 0x2c02
movq %rax, %r14
leaq 0x130(%rsp), %rdi
jmp 0x2c07
movq %rax, %r14
jmp 0x2c0c
movq %rax, %r14
leaq 0x150(%rsp), %rdi
jmp 0x2c11
movq %rax, %r14
jmp 0x2c16
movq %rax, %r14
leaq 0x170(%rsp), %rdi
jmp 0x2c1b
jmp 0x2b96
movq %rax, %r14
leaq 0x190(%rsp), %rdi
jmp 0x2c1b
jmp 0x2b96
jmp 0x2b91
jmp 0x2bce
jmp 0x2b91
movq %rax, %r14
jmp 0x2beb
movq %rax, %r14
jmp 0x2c20
movq %rax, %r14
jmp 0x2bc2
movq %rax, %r14
jmp 0x2bb8
movq %rax, %r14
leaq 0x3c0(%rsp), %rdi
callq 0x2130
leaq 0x10(%rsp), %rdi
callq 0x2130
leaq 0x1b0(%rsp), %rdi
jmp 0x2c1b
jmp 0x2bce
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x2d78
leaq 0x1b0(%rsp), %rdi
callq 0x20b0
leaq 0x30(%rsp), %rdi
callq 0x2130
leaq 0xb0(%rsp), %rdi
callq 0x2130
leaq 0x50(%rsp), %rdi
callq 0x2130
leaq 0x70(%rsp), %rdi
callq 0x2130
leaq 0x10(%rsp), %rdi
callq 0x2130
leaq 0xd0(%rsp), %rdi
callq 0x2130
movq %r14, %rdi
callq 0x2370