// File: myudelson[P]hmm-scalable/inputconvert.cpp
// Function: parse_arguments(int, char**, char*, char*)
void parse_arguments(int argc, char **argv, char *input_file_name, char *output_file_name) {
	// parse command line options, starting from 1 (0 is path to executable)
	// go in pairs, looking at whether first in pair starts with '-', if not, stop parsing arguments
	int i;
	for(i=1;i<argc;i++)
	{
		if(argv[i][0] != '-') break; // end of options stop parsing
		if(++i>=argc)
			exit_with_help();
		switch(argv[i-1][1])
		{
			case 's':
				source_format = argv[i][0];
                if( source_format!='t' && source_format!='b') {
					fprintf(stderr,"ERROR! source format should be either text 't', or binary 'b'\n");
					exit_with_help();
				}
				break;
			case 't':
				target_format = argv[i][0];
                if( target_format!='t' && target_format!='b') {
					fprintf(stderr,"ERROR! target format should be either text 't', or binary 'b'\n");
					exit_with_help();
				}
				break;
            case  'd':
				task.multiskill = argv[i][0]; // just grab first character (later, maybe several)
                break;
            case 'z':
                task.sliced = (NPAR)atoi(argv[i]);
                if(task.sliced!=0 && task.sliced!=1) {
                    fprintf(stderr,"ERROR! Multiplexing parameter should be either 0 (off) or 1(on)\n");
                    exit_with_help();
                }
                break;
			default:
				fprintf(stderr,"unknown option: -%c\n", argv[i-1][1]);
				exit_with_help();
				break;
		}
	}
//    post-argument checks
    if( source_format == target_format) {
        fprintf(stderr,"ERROR! source and target formats should not be the same");
        exit_with_help();
    }
	
	// next argument should be input file name
	if(i>=argc) // if not
		exit_with_help(); // leave
	
	strcpy(input_file_name, argv[i++]); // copy and advance
	
	if(i>=argc) { // no output file name specified
        if(target_format=='b')
            strcpy(output_file_name,"output.bin");
        else
            strcpy(output_file_name,"output.txt");
	} else {
		strcpy(output_file_name,argv[i++]); // copy and advance
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x3855
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x36c3
jmp 0x3855
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl -0x4(%rbp), %eax
jl 0x36d6
callq 0x3660
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
decl %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
addl $-0x64, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x16, %eax
ja 0x3813
movq -0x30(%rbp), %rax
leaq 0xc8fd(%rip), %rcx      # 0x10004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb (%rax), %al
movb %al, 0x12b7c(%rip)      # 0x162a0
movsbl 0x12b75(%rip), %eax     # 0x162a0
cmpl $0x74, %eax
je 0x3759
movsbl 0x12b69(%rip), %eax     # 0x162a0
cmpl $0x62, %eax
je 0x3759
movq 0x12895(%rip), %rax     # 0x15fd8
movq (%rax), %rdi
leaq 0xca85(%rip), %rsi      # 0x101d2
movb $0x0, %al
callq 0x33a0
callq 0x3660
jmp 0x3845
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb (%rax), %al
movb %al, 0x12b2f(%rip)      # 0x162a1
movsbl 0x12b28(%rip), %eax     # 0x162a1
cmpl $0x74, %eax
je 0x37a7
movsbl 0x12b1c(%rip), %eax     # 0x162a1
cmpl $0x62, %eax
je 0x37a7
movq 0x12847(%rip), %rax     # 0x15fd8
movq (%rax), %rdi
leaq 0xca76(%rip), %rsi      # 0x10211
movb $0x0, %al
callq 0x33a0
callq 0x3660
jmp 0x3845
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb (%rax), %al
movb %al, 0x13438(%rip)      # 0x16bf8
jmp 0x3845
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x33e0
movb %al, 0x12b3f(%rip)      # 0x1631b
movsbl 0x12b38(%rip), %eax     # 0x1631b
cmpl $0x0, %eax
je 0x3811
movsbl 0x12b2c(%rip), %eax     # 0x1631b
cmpl $0x1, %eax
je 0x3811
movq 0x127dd(%rip), %rax     # 0x15fd8
movq (%rax), %rdi
leaq 0xca4b(%rip), %rsi      # 0x10250
movb $0x0, %al
callq 0x33a0
callq 0x3660
jmp 0x3845
movq 0x127be(%rip), %rax     # 0x15fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %edx
leaq 0xca58(%rip), %rsi      # 0x10291
movb $0x0, %al
callq 0x33a0
callq 0x3660
jmp 0x3847
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x369e
movsbl 0x12a44(%rip), %eax     # 0x162a0
movsbl 0x12a3e(%rip), %ecx     # 0x162a1
cmpl %ecx, %eax
jne 0x3884
movq 0x1276a(%rip), %rax     # 0x15fd8
movq (%rax), %rdi
leaq 0xca2e(%rip), %rsi      # 0x102a6
movb $0x0, %al
callq 0x33a0
callq 0x3660
movl -0x24(%rbp), %eax
cmpl -0x4(%rbp), %eax
jl 0x3891
callq 0x3660
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x24(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
callq 0x3240
movl -0x24(%rbp), %eax
cmpl -0x4(%rbp), %eax
jl 0x38e8
movsbl 0x129e2(%rip), %eax     # 0x162a1
cmpl $0x62, %eax
jne 0x38d6
movq -0x20(%rbp), %rdi
leaq 0xca0f(%rip), %rsi      # 0x102de
callq 0x3240
jmp 0x38e6
movq -0x20(%rbp), %rdi
leaq 0xca08(%rip), %rsi      # 0x102e9
callq 0x3240
jmp 0x3907
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x24(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
callq 0x3240
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)