// File: /workspace/github_cpp_makefile_star2_O3/myudelson[P]hmm-scalable/predicthmm.cpp
// Function: parse_arguments(int, char**, char*, char*, char*)
void parse_arguments(int argc, char **argv, char *input_file_name, char *model_file_name, char *predict_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, n;
    char * ch;
	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 'q':
				param.quiet = (NPAR)atoi(argv[i]);
				if(param.quiet!=0 && param.quiet!=1) {
					fprintf(stderr,"ERROR! Quiet param should be 0 or 1\n");
					exit_with_help();
				}
				break;
            case  'd':
				param.multiskill = argv[i][0]; // just grab first character (later, maybe several)
                break;
			case 'b':
                param.binaryinput = atoi( strtok(argv[i],"\t\n\r"));
                break;
            case  'p':
				param.predictions = atoi(argv[i]);
				if(param.predictions<0 || param.predictions>3) {
					fprintf(stderr,"a flag of whether to report predictions for training data (-p) should be 0, 1, 2, or 3\n");
					exit_with_help();
				}
                break;
			case 't':
				param.sliced = (NPAR)atoi(argv[i]);
				if(param.sliced!=0 && param.sliced!=1) {
					fprintf(stderr,"ERROR! Time parameter should be either 0 (off) or 1(on)\n");
					exit_with_help();
				}
				break;
            case  'U':
                param.update_known = *strtok(argv[i],",\t\n\r");
                ch = strtok(NULL, ",\t\n\r");
                param.update_unknown = ch[0];
                
                if( (param.update_known!='r' && param.update_known!='g') ||
                   (param.update_unknown!='t' && param.update_unknown!='g') ) {
                    fprintf(stderr,"specification of how probabilities of states should be updated (-U) is incorrect, it sould be r|g[,t|g] \n");
                    exit_with_help();
                }
                break;
            case '0': // what was init_params for 'trainhmm' is now default_params for 'predicthmm'
                int len;
                len = (int)strlen( argv[i] );
                // count delimiters
                n = 1; // start with 1
                for(int j=0;j<len;j++) {
                    n += (argv[i][j]==',')?1:0;
                    if( (argv[i][j] >= 'a' && argv[i][j] <= 'z') || (argv[i][j] >= 'A' && argv[i][j] <= 'Z') ) {
                        strcpy(param.initfile, argv[i]);
                        break;
                    }
                }
                // init parameters
                if(param.init_params!=NULL) free(param.init_params);
                param.init_params = Calloc(NUMBER, (size_t)n);
                param.init_params_n = (NPAR)n;
                // read params and write to params
                param.init_params[0] = atof( strtok(argv[i],",\t\n\r") );
                for(int j=1; j<n; j++) {
                    param.init_params[j] = atof( strtok(NULL,",\t\n\r") );
                }
                break;
			default:
				fprintf(stderr,"unknown option: -%c\n", argv[i-1][1]);
				exit_with_help();
				break;
		}
	}   
    if(param.cv_target_obs>0 && param.metrics>0) { // correct for 0-start coding
        fprintf(stderr,"values for -v and -m cannot be both non-zeros\n");
        exit_with_help();
    }
	
	// next argument should be input (training) file name
	if(i>=argc) // if not
		exit_with_help(); // leave
	
	strcpy(input_file_name, argv[i++]); // copy and advance
	
	if(i>=argc) { // no model file name specified
        fprintf(stderr,"no model file specified\n");
		exit_with_help(); // leave
	}
	else {
		strcpy(model_file_name,argv[i++]); // copy and advance
		if(i>=argc) {// no prediction file name specified
			//strcpy(predict_file_name,"predict_hmm.txt"); // the predict file too
            param.predictions = 0;
        }
		else {
            // param.predictions = 1;
			strcpy(predict_file_name,argv[i]);
        }
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, 0x20(%rsp)
cmpl $0x2, %edi
jl 0x624f
movq %rsi, %r14
movq %rdx, 0x18(%rsp)
movl %edi, 0xc(%rsp)
movl %edi, %ebp
movl $0x1, %r15d
movq (%r14,%r15,8), %rax
movb (%rax), %r12b
cmpb $0x2d, %r12b
jne 0x61a4
leaq 0x1(%r15), %rcx
cmpq %rbp, %rcx
jae 0x6266
movzbl 0x1(%rax), %edi
cmpl $0x63, %edi
jle 0x5fb6
cmpl $0x70, %edi
jg 0x5ff1
cmpl $0x64, %edi
je 0x60c6
cmpl $0x70, %edi
jne 0x624a
movq 0x8(%r14,%r15,8), %rdi
callq 0x43a0
movl %eax, 0x39350(%rip)     # 0x3f2f8
cmpl $0x4, %eax
jb 0x6197
jmp 0x6240
cmpl $0x30, %edi
je 0x607b
cmpl $0x55, %edi
je 0x6020
cmpl $0x62, %edi
jne 0x624a
movq 0x8(%r14,%r15,8), %rdi
leaq 0x2d218(%rip), %rsi     # 0x331f1
callq 0x43b0
movq %rax, %rdi
callq 0x43a0
movl %eax, 0x39314(%rip)     # 0x3f300
jmp 0x6197
cmpl $0x74, %edi
je 0x60d8
cmpl $0x71, %edi
jne 0x624a
movq 0x8(%r14,%r15,8), %rdi
callq 0x43a0
movb %al, 0x392c1(%rip)      # 0x3f2d4
testb $-0x2, %al
je 0x6197
jmp 0x6236
movq 0x8(%r14,%r15,8), %rdi
leaq 0x2d1c4(%rip), %rbx     # 0x331f0
movq %rbx, %rsi
callq 0x43b0
movb (%rax), %al
movb %al, 0x392c0(%rip)      # 0x3f2fc
xorl %edi, %edi
movq %rbx, %rsi
callq 0x43b0
movzbl (%rax), %eax
movb %al, 0x392ae(%rip)      # 0x3f2fd
movzbl 0x392a6(%rip), %ecx     # 0x3f2fc
cmpl $0x72, %ecx
je 0x6064
cmpl $0x67, %ecx
jne 0x6245
cmpl $0x67, %eax
je 0x6197
cmpl $0x74, %eax
je 0x6197
jmp 0x6245
movq 0x8(%r14,%r15,8), %rbx
movq %rbx, %rdi
callq 0x4100
testl %eax, %eax
jle 0x60f5
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x1, %r13d
xorl %ecx, %ecx
movl %r13d, %edx
movb (%rbx,%rcx), %sil
xorl %r13d, %r13d
cmpb $0x2c, %sil
sete %r13b
addl %edx, %r13d
andb $-0x21, %sil
addb $-0x41, %sil
cmpb $0x19, %sil
jbe 0x60fd
incq %rcx
cmpq %rcx, %rax
jne 0x6099
jmp 0x610c
movq 0x8(%r14,%r15,8), %rax
movb (%rax), %al
movb %al, 0x39add(%rip)      # 0x3fbb0
jmp 0x6197
movq 0x8(%r14,%r15,8), %rdi
callq 0x43a0
movb %al, 0x391e3(%rip)      # 0x3f2cb
testb $-0x2, %al
je 0x6197
jmp 0x623b
movl $0x1, %r13d
jmp 0x610c
leaq 0x39200(%rip), %rdi     # 0x3f304
movq %rbx, %rsi
callq 0x41f0
movq 0x3918d(%rip), %rdi     # 0x3f2a0
testq %rdi, %rdi
je 0x611d
callq 0x42a0
movslq %r13d, %rbx
movl $0x8, %esi
movq %rbx, %rdi
callq 0x4130
movq %rax, 0x3916c(%rip)     # 0x3f2a0
movb %bl, 0x3916e(%rip)      # 0x3f2a8
movq 0x8(%r14,%r15,8), %rdi
leaq 0x2d0aa(%rip), %rsi     # 0x331f0
callq 0x43b0
movq %rax, %rdi
callq 0x42d0
movq 0x39146(%rip), %rax     # 0x3f2a0
movsd %xmm0, (%rax)
cmpl $0x2, %ebx
jl 0x6197
movl %r13d, %ebx
movl $0x1, %r13d
xorl %edi, %edi
leaq 0x2d07b(%rip), %rsi     # 0x331f0
callq 0x43b0
movq %rax, %rdi
callq 0x42d0
movq 0x39117(%rip), %rax     # 0x3f2a0
movsd %xmm0, (%rax,%r13,8)
incq %r13
cmpq %r13, %rbx
jne 0x616c
addq $0x2, %r15
cmpq %rbp, %r15
jb 0x5f5a
cmpb $0x0, 0x3955b(%rip)     # 0x3f706
jle 0x61ba
cmpl $0x0, 0x3913c(%rip)     # 0x3f2f0
jg 0x6261
cmpb $0x2d, %r12b
je 0x6266
leal 0x1(%r15), %ebx
movl %r15d, %eax
movq (%r14,%rax,8), %rsi
movq 0x18(%rsp), %rdi
callq 0x41f0
movl 0xc(%rsp), %ebp
cmpl %ebp, %ebx
jge 0x627c
addl $0x2, %r15d
movl %ebx, %eax
movq (%r14,%rax,8), %rsi
movq 0x20(%rsp), %rdi
callq 0x41f0
cmpl %ebp, %r15d
jge 0x621d
movl %r15d, %eax
movq (%r14,%rax,8), %rsi
movq 0x10(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x41f0
movl $0x0, 0x390d1(%rip)     # 0x3f2f8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4557
callq 0x44f5
callq 0x4526
callq 0x44c4
callq 0x45ea
cmpb $0x0, 0x394b0(%rip)     # 0x3f706
jle 0x6266
cmpl $0x0, 0x39091(%rip)     # 0x3f2f0
jle 0x6266
callq 0x45b9
leaq 0x2d066(%rip), %rdi     # 0x332d3
callq 0x4380
movl $0x1, %edi
callq 0x42b0
callq 0x4588