// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x918, %rsp            # imm = 0x918
movl $0x0, 0x914(%rsp)
movl %edi, 0x910(%rsp)
movq %rsi, 0x908(%rsp)
leaq 0x8e8(%rsp), %rdi
callq 0x3370
movl $0x0, 0x8e4(%rsp)
movl 0x8e4(%rsp), %eax
cmpl 0x910(%rsp), %eax
jge 0x38d9
movq 0x908(%rsp), %rax
movslq 0x8e4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x90(%rsp)
leaq 0x89f(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x3480
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rdx
leaq 0x8a0(%rsp), %rdi
callq 0x4470
jmp 0x377d
leaq 0x867(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x3480
movq 0x88(%rsp), %rdx
leaq 0xb867(%rip), %rsi      # 0xf008
leaq 0x868(%rsp), %rdi
callq 0x4470
jmp 0x37b0
leaq 0x8c0(%rsp), %rdi
leaq 0x8a0(%rsp), %rsi
leaq 0x868(%rsp), %rdx
callq 0x4380
jmp 0x37cf
leaq 0x8e8(%rsp), %rdi
leaq 0x8c0(%rsp), %rsi
callq 0x3330
jmp 0x37e6
leaq 0x8c0(%rsp), %rdi
callq 0x3180
leaq 0x868(%rsp), %rdi
callq 0x3180
leaq 0x867(%rsp), %rdi
callq 0x32a0
leaq 0x8a0(%rsp), %rdi
callq 0x3180
leaq 0x89f(%rsp), %rdi
callq 0x32a0
movl 0x8e4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8e4(%rsp)
jmp 0x3719
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x38c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x38ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x38a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
leaq 0x8c0(%rsp), %rdi
callq 0x3180
leaq 0x868(%rsp), %rdi
callq 0x3180
leaq 0x867(%rsp), %rdi
callq 0x32a0
leaq 0x8a0(%rsp), %rdi
callq 0x3180
leaq 0x89f(%rsp), %rdi
callq 0x32a0
jmp 0x435a
leaq 0x840(%rsp), %rdi
leaq 0x8e8(%rsp), %rsi
callq 0x3130
jmp 0x38f0
leaq 0x840(%rsp), %rdi
callq 0x9fc0
jmp 0x38ff
leaq 0x840(%rsp), %rdi
callq 0x3180
leaq 0x7ff(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x3480
movq 0x80(%rsp), %rdx
leaq 0xb6da(%rip), %rsi      # 0xf00a
leaq 0x800(%rsp), %rdi
callq 0x4470
jmp 0x393f
leaq 0x820(%rsp), %rdi
leaq 0x800(%rsp), %rsi
callq 0x9ef0
jmp 0x3956
leaq 0x800(%rsp), %rdi
callq 0x3180
leaq 0x7ff(%rsp), %rdi
callq 0x32a0
leaq 0x7b7(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x3480
movq 0x78(%rsp), %rdx
leaq 0xb687(%rip), %rsi      # 0xf015
leaq 0x7b8(%rsp), %rdi
callq 0x4470
jmp 0x399d
leaq 0x7d8(%rsp), %rdi
leaq 0x7b8(%rsp), %rsi
callq 0x9ef0
jmp 0x39b4
leaq 0x7b8(%rsp), %rdi
callq 0x3180
leaq 0x7b7(%rsp), %rdi
callq 0x32a0
movl $0x5622, 0x7b0(%rsp) # imm = 0x5622
leaq 0x7d8(%rsp), %rdi
leaq 0xb63b(%rip), %rsi      # 0xf023
callq 0x30f0
cmpl $0x0, %eax
je 0x3ae8
leaq 0x7d8(%rsp), %rdi
callq 0x3120
movq %rax, %rdi
callq 0x33c0
movl %eax, 0x7b0(%rsp)
jmp 0x3ae8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x435a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
leaq 0x840(%rsp), %rdi
callq 0x3180
jmp 0x435a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x3a8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
leaq 0x800(%rsp), %rdi
callq 0x3180
leaq 0x7ff(%rsp), %rdi
callq 0x32a0
jmp 0x435a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x3ad6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
leaq 0x7b8(%rsp), %rdi
callq 0x3180
leaq 0x7b7(%rsp), %rdi
callq 0x32a0
jmp 0x434d
leaq 0x76f(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x3480
movq 0x70(%rsp), %rdx
leaq 0xb522(%rip), %rsi      # 0xf028
leaq 0x770(%rsp), %rdi
callq 0x4470
jmp 0x3b15
leaq 0x790(%rsp), %rdi
leaq 0x770(%rsp), %rsi
callq 0x9ef0
jmp 0x3b2c
leaq 0x770(%rsp), %rdi
callq 0x3180
leaq 0x76f(%rsp), %rdi
callq 0x32a0
movss 0xb4b6(%rip), %xmm0     # 0xf004
movss %xmm0, 0x768(%rsp)
leaq 0x790(%rsp), %rdi
leaq 0xb4bd(%rip), %rsi      # 0xf023
callq 0x30f0
cmpl $0x0, %eax
je 0x3bdd
leaq 0x790(%rsp), %rdi
callq 0x3120
movq %rax, %rdi
callq 0x3300
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x768(%rsp)
jmp 0x3bdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x3bcb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
leaq 0x770(%rsp), %rdi
callq 0x3180
leaq 0x76f(%rsp), %rdi
callq 0x32a0
jmp 0x4340
leaq 0x727(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x3480
movq 0x68(%rsp), %rdx
leaq 0xb438(%rip), %rsi      # 0xf033
leaq 0x728(%rsp), %rdi
callq 0x4470
jmp 0x3c0a
leaq 0x748(%rsp), %rdi
leaq 0x728(%rsp), %rsi
callq 0x9ef0
jmp 0x3c21
leaq 0x728(%rsp), %rdi
callq 0x3180
leaq 0x727(%rsp), %rdi
callq 0x32a0
movl $0x76c, 0x720(%rsp) # imm = 0x76C
leaq 0x748(%rsp), %rdi
leaq 0xb3ce(%rip), %rsi      # 0xf023
callq 0x30f0
cmpl $0x0, %eax
je 0x3cc6
leaq 0x748(%rsp), %rdi
callq 0x3120
movq %rax, %rdi
callq 0x33c0
movl %eax, 0x720(%rsp)
jmp 0x3cc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x3cb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
leaq 0x728(%rsp), %rdi
callq 0x3180
leaq 0x727(%rsp), %rdi
callq 0x32a0
jmp 0x4333
leaq 0x6df(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x3480
movq 0x60(%rsp), %rdx
leaq 0xb35b(%rip), %rsi      # 0xf03f
leaq 0x6e0(%rsp), %rdi
callq 0x4470
jmp 0x3cf3
leaq 0x700(%rsp), %rdi
leaq 0x6e0(%rsp), %rsi
callq 0x9ef0
jmp 0x3d0a
leaq 0x6e0(%rsp), %rdi
callq 0x3180
leaq 0x6df(%rsp), %rdi
callq 0x32a0
leaq 0x700(%rsp), %rdi
leaq 0xb319(%rip), %rsi      # 0xf04c
callq 0x30f0
cmpl $0x0, %eax
jne 0x3e15
movl $0xc0, %edi
callq 0x3260
movq %rax, 0x58(%rsp)
jmp 0x3d52
movq 0x58(%rsp), %rdi
cvtsi2ssl 0x7b0(%rsp), %xmm0
movss 0x768(%rsp), %xmm1
cvtsi2ssl 0x720(%rsp), %xmm2
callq 0xb2f0
jmp 0x3d79
movq 0x58(%rsp), %rax
movq %rax, 0x6d0(%rsp)
jmp 0x3f9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x3dc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
leaq 0x6e0(%rsp), %rdi
callq 0x3180
leaq 0x6df(%rsp), %rdi
callq 0x32a0
jmp 0x4326
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
jmp 0x4319
movq 0x58(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
movl $0xc0, %esi
callq 0x3270
jmp 0x4319
leaq 0x700(%rsp), %rdi
leaq 0xb22d(%rip), %rsi      # 0xf051
callq 0x30f0
cmpl $0x0, %eax
jne 0x3ea0
movl $0xc0, %edi
callq 0x3260
movq %rax, 0x50(%rsp)
jmp 0x3e3f
movq 0x50(%rsp), %rdi
cvtsi2ssl 0x7b0(%rsp), %xmm0
movss 0x768(%rsp), %xmm1
cvtsi2ssl 0x720(%rsp), %xmm2
callq 0xcf50
jmp 0x3e66
movq 0x50(%rsp), %rax
movq %rax, 0x6d0(%rsp)
jmp 0x3f9c
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
movl $0xc0, %esi
callq 0x3270
jmp 0x4319
leaq 0x700(%rsp), %rdi
leaq 0xb1a7(%rip), %rsi      # 0xf056
callq 0x30f0
cmpl $0x0, %eax
jne 0x3f2b
movl $0xc0, %edi
callq 0x3260
movq %rax, 0x48(%rsp)
jmp 0x3eca
movq 0x48(%rsp), %rdi
cvtsi2ssl 0x7b0(%rsp), %xmm0
movss 0x768(%rsp), %xmm1
cvtsi2ssl 0x720(%rsp), %xmm2
callq 0xda20
jmp 0x3ef1
movq 0x48(%rsp), %rax
movq %rax, 0x6d0(%rsp)
jmp 0x3f9a
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
movl $0xc0, %esi
callq 0x3270
jmp 0x4319
movl $0xc0, %edi
callq 0x3260
movq %rax, 0x40(%rsp)
jmp 0x3f3c
movq 0x40(%rsp), %rdi
cvtsi2ssl 0x7b0(%rsp), %xmm0
movss 0x768(%rsp), %xmm1
cvtsi2ssl 0x720(%rsp), %xmm2
callq 0xb2f0
jmp 0x3f63
movq 0x40(%rsp), %rax
movq %rax, 0x6d0(%rsp)
jmp 0x3f9a
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
movl $0xc0, %esi
callq 0x3270
jmp 0x4319
jmp 0x3f9c
jmp 0x3f9e
leaq 0x820(%rsp), %rdi
leaq 0xb0ae(%rip), %rsi      # 0xf05b
callq 0x30f0
cmpl $0x0, %eax
jne 0x4098
jmp 0x3fbd
movq 0x1001c(%rip), %rdi     # 0x13fe0
leaq 0x6cf(%rsp), %rsi
callq 0x3360
movq %rax, 0x38(%rsp)
jmp 0x3fd8
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3310
movb %al, 0x37(%rsp)
jmp 0x3ff2
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x3fff
jmp 0x4093
movq 0x6d0(%rsp), %rdi
movsbl 0x6cf(%rsp), %esi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movb %al, 0x36(%rsp)
jmp 0x401e
movb 0x36(%rsp), %al
testb $0x1, %al
jne 0x4028
jmp 0x408e
movq 0x6d0(%rsp), %rdi
callq 0x4b90
movb %al, 0x35(%rsp)
jmp 0x403b
movb 0x35(%rsp), %al
movb %al, 0x6ce(%rsp)
movsbl 0x6ce(%rsp), %eax
cmpl $0xd, %eax
jne 0x4068
movq 0xff6e(%rip), %rdi      # 0x13fc8
movl $0xa, %esi
callq 0x32e0
jmp 0x4066
jmp 0x4068
movsbl 0x6ce(%rsp), %esi
movq 0xff51(%rip), %rdi      # 0x13fc8
callq 0x32e0
jmp 0x407e
movq 0xff43(%rip), %rdi      # 0x13fc8
callq 0x3190
jmp 0x408c
jmp 0x408e
jmp 0x3fbd
jmp 0x4280
leaq 0x820(%rsp), %rdi
callq 0x3120
movq %rax, 0x28(%rsp)
movl $0x8, %edi
movl $0x4, %esi
callq 0x4530
movl %eax, 0x30(%rsp)
jmp 0x40bf
movl 0x30(%rsp), %edx
movq 0x28(%rsp), %rsi
leaq 0x4b8(%rsp), %rdi
callq 0x3350
jmp 0x40d7
leaq 0x4a0(%rsp), %rdi
callq 0x4550
movq 0x4b8(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x4b8(%rsp,%rax), %rdi
callq 0x34a0
movb %al, 0x27(%rsp)
jmp 0x4103
movb 0x27(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x4112
jmp 0x4257
leaq 0x4b8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x3320
jmp 0x412e
leaq 0x4b8(%rsp), %rdi
callq 0x34e0
movq %rax, 0x18(%rsp)
jmp 0x4142
movq 0x18(%rsp), %rax
movl %eax, 0xac(%rsp)
movl $0x0, 0xa8(%rsp)
movl 0xa8(%rsp), %eax
cmpl 0xac(%rsp), %eax
jge 0x4252
movq 0x6d0(%rsp), %rdi
movslq 0xa8(%rsp), %rax
movsbl 0xb0(%rsp,%rax), %esi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movb %al, 0x17(%rsp)
jmp 0x4194
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x41a1
jmp 0x423a
movq 0x6d0(%rsp), %rdi
callq 0x4b90
movb %al, 0x16(%rsp)
jmp 0x41b4
movb 0x16(%rsp), %al
movb %al, 0xa7(%rsp)
movsbl 0xa7(%rsp), %eax
cmpl $0xd, %eax
jne 0x4214
movq 0xfdf5(%rip), %rdi      # 0x13fc8
movl $0xa, %esi
callq 0x32e0
jmp 0x41df
jmp 0x4214
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x890(%rsp)
movl %eax, 0x88c(%rsp)
leaq 0x4a0(%rsp), %rdi
callq 0x4560
leaq 0x4b8(%rsp), %rdi
callq 0x30d0
jmp 0x4319
movsbl 0xa7(%rsp), %esi
movq 0xfda5(%rip), %rdi      # 0x13fc8
callq 0x32e0
jmp 0x422a
movq 0xfd97(%rip), %rdi      # 0x13fc8
callq 0x3190
jmp 0x4238
jmp 0x423a
jmp 0x423c
movl 0xa8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa8(%rsp)
jmp 0x4159
jmp 0x40e4
leaq 0x4b8(%rsp), %rdi
callq 0x3070
jmp 0x4266
leaq 0x4a0(%rsp), %rdi
callq 0x4560
leaq 0x4b8(%rsp), %rdi
callq 0x30d0
movq 0x6d0(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x429e
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq 0xfd23(%rip), %rdi      # 0x13fc8
movl $0xa, %esi
callq 0x32e0
jmp 0x42b1
movl $0x0, 0x914(%rsp)
leaq 0x700(%rsp), %rdi
callq 0x3180
leaq 0x748(%rsp), %rdi
callq 0x3180
leaq 0x790(%rsp), %rdi
callq 0x3180
leaq 0x7d8(%rsp), %rdi
callq 0x3180
leaq 0x820(%rsp), %rdi
callq 0x3180
leaq 0x8e8(%rsp), %rdi
callq 0x3180
movl 0x914(%rsp), %eax
addq $0x918, %rsp            # imm = 0x918
retq
leaq 0x700(%rsp), %rdi
callq 0x3180
leaq 0x748(%rsp), %rdi
callq 0x3180
leaq 0x790(%rsp), %rdi
callq 0x3180
leaq 0x7d8(%rsp), %rdi
callq 0x3180
leaq 0x820(%rsp), %rdi
callq 0x3180
leaq 0x8e8(%rsp), %rdi
callq 0x3180
movq 0x890(%rsp), %rdi
callq 0x3470
nopw %cs:(%rax,%rax)
nop