// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %rcx, %r13
movq %rdx, 0x20(%rsp)
movq %rsi, %r14
movl %edi, %ebp
movl $0x1, %r15d
cmpl $0x2, %edi
setge %al
jl 0x62aa
movq 0x8(%r14), %rcx
cmpb $0x2d, (%rcx)
jne 0x62aa
movq %r13, 0x10(%rsp)
movq %r12, 0x18(%rsp)
movl %ebp, 0xc(%rsp)
movl %ebp, %r12d
movl $0x1, %r15d
leaq 0x2e182(%rip), %r13     # 0x341f0
leaq 0x1(%r15), %rax
cmpq %r12, %rax
jae 0x632a
movzbl 0x1(%rcx), %edi
cmpl $0x63, %edi
jle 0x60b9
cmpl $0x70, %edi
jg 0x60f4
cmpl $0x64, %edi
je 0x61be
cmpl $0x70, %edi
jne 0x635e
movq 0x8(%r14,%r15,8), %rdi
callq 0x43a0
movl %eax, 0x3a24d(%rip)     # 0x402f8
cmpl $0x4, %eax
jb 0x6283
jmp 0x6354
cmpl $0x30, %edi
je 0x6177
cmpl $0x55, %edi
je 0x6123
cmpl $0x62, %edi
jne 0x635e
movq 0x8(%r14,%r15,8), %rdi
leaq 0x2e115(%rip), %rsi     # 0x341f1
callq 0x43b0
movq %rax, %rdi
callq 0x43a0
movl %eax, 0x3a211(%rip)     # 0x40300
jmp 0x6283
cmpl $0x74, %edi
je 0x61d0
cmpl $0x71, %edi
jne 0x635e
movq 0x8(%r14,%r15,8), %rdi
callq 0x43a0
movb %al, 0x3a1be(%rip)      # 0x402d4
testb $-0x2, %al
je 0x6283
jmp 0x634a
movq 0x8(%r14,%r15,8), %rdi
movq %r13, %rsi
callq 0x43b0
movb (%rax), %al
movb %al, 0x3a1c4(%rip)      # 0x402fc
xorl %edi, %edi
movq %r13, %rsi
callq 0x43b0
movzbl (%rax), %eax
movb %al, 0x3a1b2(%rip)      # 0x402fd
movzbl 0x3a1aa(%rip), %ecx     # 0x402fc
cmpl $0x72, %ecx
je 0x6160
cmpl $0x67, %ecx
jne 0x6359
cmpl $0x67, %eax
je 0x6283
cmpl $0x74, %eax
je 0x6283
jmp 0x6359
movq 0x8(%r14,%r15,8), %rbx
movq %rbx, %rdi
callq 0x4100
testl %eax, %eax
jle 0x61ed
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x1, %ebp
xorl %ecx, %ecx
movl %ebp, %edx
movb (%rbx,%rcx), %sil
xorl %ebp, %ebp
cmpb $0x2c, %sil
sete %bpl
addl %edx, %ebp
andb $-0x21, %sil
addb $-0x41, %sil
cmpb $0x19, %sil
jbe 0x61f4
incq %rcx
cmpq %rcx, %rax
jne 0x6194
jmp 0x6203
movq 0x8(%r14,%r15,8), %rax
movb (%rax), %al
movb %al, 0x3a9e5(%rip)      # 0x40bb0
jmp 0x6283
movq 0x8(%r14,%r15,8), %rdi
callq 0x43a0
movb %al, 0x3a0eb(%rip)      # 0x402cb
testb $-0x2, %al
je 0x6283
jmp 0x634f
movl $0x1, %ebp
jmp 0x6203
leaq 0x3a109(%rip), %rdi     # 0x40304
movq %rbx, %rsi
callq 0x41f0
movq 0x3a096(%rip), %rdi     # 0x402a0
testq %rdi, %rdi
je 0x6214
callq 0x42a0
movslq %ebp, %rbx
movl $0x8, %esi
movq %rbx, %rdi
callq 0x4130
movq %rax, 0x3a075(%rip)     # 0x402a0
movb %bl, 0x3a077(%rip)      # 0x402a8
movq 0x8(%r14,%r15,8), %rdi
movq %r13, %rsi
callq 0x43b0
movq %rax, %rdi
callq 0x42d0
movq 0x3a053(%rip), %rax     # 0x402a0
movsd %xmm0, (%rax)
cmpl $0x2, %ebx
jl 0x6283
movl %ebp, %ebx
movl $0x1, %ebp
xorl %edi, %edi
movq %r13, %rsi
callq 0x43b0
movq %rax, %rdi
callq 0x42d0
movq 0x3a02a(%rip), %rax     # 0x402a0
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
cmpq %rbp, %rbx
jne 0x625d
addq $0x2, %r15
cmpq %r12, %r15
setb %al
jae 0x629c
movq (%r14,%r15,8), %rcx
cmpb $0x2d, (%rcx)
je 0x606e
movq 0x18(%rsp), %r12
movl 0xc(%rsp), %ebp
movq 0x10(%rsp), %r13
cmpb $0x0, 0x3a455(%rip)     # 0x40706
jle 0x62c0
cmpl $0x0, 0x3a036(%rip)     # 0x402f0
jg 0x6340
testb %al, %al
je 0x632a
leal 0x1(%r15), %ebx
movl %r15d, %eax
movq (%r14,%rax,8), %rsi
movq 0x20(%rsp), %rdi
callq 0x41f0
cmpl %ebp, %ebx
jge 0x6345
addl $0x2, %r15d
movl %ebx, %eax
movq (%r14,%rax,8), %rsi
movq %r13, %rdi
callq 0x41f0
cmpl %ebp, %r15d
jge 0x6311
movl %r15d, %eax
movq (%r14,%rax,8), %rsi
movq %r12, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x41f0
movl $0x0, 0x39fdd(%rip)     # 0x402f8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2dfa2(%rip), %rdi     # 0x342d3
callq 0x4380
movl $0x1, %edi
callq 0x42b0
callq 0x45b9
callq 0x4588
callq 0x4557
callq 0x44f5
callq 0x4526
callq 0x44c4
callq 0x45ea