// File: /workspace/github_cpp_makefile_star2_O3/myudelson[P]hmm-scalable/trainhmm.cpp
// Function: main
int main (int argc, char ** argv) {
//    int array[] = {1, 2, 3, 4, 5, 6, 7};
//    NDAT lim = 0;
//    int v = 5;
//    NDAT ix = binsearch(&v, array, 7, sizeof(int)); // SparseArray2D<int>::binsearch(&v, array, 7, &lim);
//    fprintf(stderr,"%d found=%d, lim=%d\n",v, ix, lim);
//    
//    v = 8;
//    ix = SparseArray2D<int>::binsearch(&v, array, 7, &lim);
//    fprintf(stderr,"%d found=%d, lim=%d\n",v, ix, lim);
//    
//    v = 0;
//    ix = SparseArray2D<int>::binsearch(&v, array, 7, &lim);
//    fprintf(stderr,"%d found=%d, lim=%d\n",v, ix, lim);
//    
//    int c = (unsigned long)ceil((double)34600/20000);
    
	clock_t tm_all = clock();//overall time //SEQ
//    double _tm_all = omp_get_wtime(); //PAR
    
	char input_file[1024]; // data
	char output_file[1024]; // model
    char colsole_file[1024]; // console copy
	char predict_file[1024]; // predictions
    
	set_param_defaults(&param);
    
    
    // parse parameters, step 1
	parse_arguments_step1(argc, argv, input_file, output_file, predict_file, colsole_file);

    FILE *fid_console = NULL;
    if(param.duplicate_console==1)
        fid_console = fopen(colsole_file,"w");
    
    if(!param.quiet) {
        printf("trainhmm starting...\n");
        if(param.duplicate_console==1) fprintf(fid_console, "trainhmm starting...\n");
    }

    clock_t tm_read = clock();//overall time //SEQ
//    double _tm_read = omp_get_wtime(); //PAR
    int read_ok = read_and_structure_data(input_file, fid_console);
    tm_read = (clock_t)(clock()-tm_read);//SEQ
    
//    _tm_read = omp_get_wtime()-_tm_read;//PAR
    
//    // experimental
//    for(NCAT k=0; k<param.nK; k++) {
//        char fn [256];
//        sprintf (fn, "b89_kts_skill%d_A.txt", k);
//        InputUtil::writeInputMatrix(fn, &param, param.k_numg[k], param.k_g_data[k]);
//    }

    if( ! read_ok )
        return 0;
    
    // once we know nO (number of observations) parse parameters, step 2
    parse_arguments_step2(argc, argv, fid_console);
    
//    write_pLo_irt();
    
    
//    //
//    // read item mean % correct
//    //
//    FILE *fid = fopen("a89_kts_train01_voc_i.txt","r");
//	max_line_length = 1024;
//	char *col;
//    string item;
//    map<string,NCAT>::iterator it;
//    param.item_complexity = Calloc(NUMBER, param.map_step_bwd->size());
//    line = (char *)malloc(max_line_length);// Malloc(char,max_line_length);
//    while( readline(fid)!=NULL) {
//		// Group
//		col = strtok(line,"\t\n\r");
//		item = string( col );
//		it = param.map_step_fwd->find(item);
//		if( it==param.map_step_fwd->end() ) { // not found
//            fprintf(stderr,"DID NOT FIND THE STEP!!\n");
//            return false;
//		}
//		else {
////            if( it->second > param.map_step_bwd->size()) {
////                int z = 0 ;
////            }
//            NUMBER v = atof( strtok(NULL,"\t\n\r") );
//            param.item_complexity[ it->second ] = v;
//		}
//    }
//    free(line);
//    fclose(fid);

    if(!param.quiet) {
        printf("input read, nO=%d, nG=%d, nK=%d, nI=%d, nZ=%d\n",param.nO, param.nG, param.nK, param.nI, param.nZ);
        if(param.duplicate_console==1) fprintf(fid_console, "input read, nO=%d, nG=%d, nK=%d, nI=%d, nZ=%d\n",param.nO, param.nG, param.nK, param.nI, param.nZ);
    }
    
    //    // write time
    //    if(param.time==1) {
    //        const char * fn = "a89_kts_times.txt";
    ////        const char * fn = "a89_uskts_times.txt";
    //        write_time_interval_data(&param, fn);
    //    }
    
    // erase blocking labels
    zeroLabels(&param);

    clock_t tm_fit = 0; //SEQ
    clock_t tm_predict = 0; //SEQ
//    double _tm_fit;//PAR
//    double _tm_predict;//PAR
    
    if(param.cv_folds==0) { // not cross-validation
        // create problem
        HMMProblem *hmm = NULL;
        switch(param.structure)
        {
            case STRUCTURE_SKILL: // Conjugate Gradient Descent
//            case STRUCTURE_GROUP: // Conjugate Gradient Descent
                hmm = new HMMProblem(&param);
                break;
                //            case STRUCTURE_PIg: // Gradient Descent: PI by group, A,B by skill
                //                hmm = new HMMProblemPiG(&param);
                //                break;
            case STRUCTURE_SKABslc: // Conjugate Gradient Descent
                hmm = new HMMProblemSlicedAB(&param);
                break;
            case STRUCTURE_SKAslc: // Conjugate Gradient Descent
                hmm = new HMMProblemSlicedA(&param);
                break;
            case STRUCTURE_PIgk: // Gradient Descent, pLo=f(K,G), other by K
                hmm = new HMMProblemPiGK(&param);
                break;
            case STRUCTURE_PIgkww: // Gradient Descent, pLo=f(K,G), other by K
                hmm = new HMMProblemPiGKww(&param);
                break;
            case STRUCTURE_PIAgk: // Gradient Descent, pLo=f(K,G), pT=f(K,G), other by K
                hmm = new HMMProblemPiAGK(&param);
                break;
            case STRUCTURE_Agk: // Gradient Descent, pT=f(K,G), other by K
                hmm = new HMMProblemAGK(&param);
                break;
//                case STRUCTURE_Agki: // Gradient Descent, pT=f(K,G), other by K
//                    hmm = new HMMProblemAGKi(&param);
//                    break;
            case STRUCTURE_PIABgk: // Gradient Descent, pT=f(K,G), other by K
                hmm = new HMMProblemPiABGK(&param);
                break;
                //            case BKT_GD_T: // Gradient Descent with Transfer
                //                hmm = new HMMProblemKT(&param);
                //                break;
            case STRUCTURE_COMP: // Gradient Descent, pT=f(K,G), other by K
                hmm = new HMMProblemComp(&param);
                break;
//             case STRUCTURE_ELOK: // Gradient Descent, pT=f(K,G), other by K
//                 hmm = new HMMProblemEloK(&param);
//                 break;

        }
        tm_fit = clock(); //SEQ
//        _tm_fit = omp_get_wtime(); //PAR
        hmm->fit();
        tm_fit = clock()-tm_fit;//SEQ
//        _tm_fit = omp_get_wtime()-_tm_fit;//PAR
        
        // write model
        hmm->toFile(output_file);
        
        if(param.metrics>0 || param.predictions>0) {
            NUMBER* metrics = Calloc(NUMBER, (size_t)7); // LL, AIC, BIC, RMSE, RMSEnonull, Acc, Acc_nonull;
            // takes care of predictions and metrics, writes predictions if param.predictions==1
            
            // temporary
            if(param.per_kc_rmse_acc) {
                param.kc_counts = Calloc(NDAT, (size_t)param.nK);
                param.kc_rmse = Calloc(NUMBER, (size_t)param.nK);
                param.kc_acc  = Calloc(NUMBER, (size_t)param.nK);
            }

            // NUMBER l1 = hmm->getSumLogPOPara(param.nSeq, param.k_data);
//            printf("hmm-style ll_no_null %15.7f\n",l1);
            
            tm_predict = clock(); //SEQ
//            _tm_predict = omp_get_wtime(); //PAR
//            if(param.structure==STRUCTURE_SKAslc) {
//                ((HMMProblemSlicedA *)hmm)->predict(metrics, predict_file, param.dat_obs, param.dat_group, param.dat_skill, param.dat_skill_stacked, param.dat_skill_rcount, param.dat_skill_rix);
//            } else if(param.structure==STRUCTURE_SKABslc) {
//                ((HMMProblemSlicedAB *)hmm)->predict(metrics, predict_file, param.dat_obs, param.dat_group, param.dat_skill, param.dat_skill_stacked, param.dat_skill_rcount, param.dat_skill_rix);
//            } else {
                HMMProblem::predict(metrics, predict_file, param.dat_obs, param.dat_group, param.dat_skill, param.dat_skill_stacked, param.dat_skill_rcount, param.dat_skill_rix, &hmm, 1, NULL);
//            }
            tm_predict = clock()-tm_predict;//SEQ
//            _tm_predict = omp_get_wtime()-_tm_predict;//PAR
            
            if( param.metrics>0 /*&& !param.quiet*/) {
                printf("trained model LL=%15.7f (%15.7f), AIC=%8.6f, BIC=%8.6f, RMSE=%8.6f (%8.6f), Acc=%8.6f (%8.6f)\n",
                       metrics[0], metrics[1], // ll's
                       2*hmm->getNparams() + 2*metrics[0], // AIC
                       hmm->getNparams()*safelog(param.N) + 2*metrics[0], //BIC
                       metrics[2], metrics[3], // rmse's
                       metrics[4], metrics[5]); // acc's
                if(param.duplicate_console==1) fprintf(fid_console, "trained model LL=%15.7f (%15.7f), AIC=%8.6f, BIC=%8.6f, RMSE=%8.6f (%8.6f), Acc=%8.6f (%8.6f)\n",
                       metrics[0], metrics[1], // ll's
                       2*hmm->getNparams() + 2*metrics[0], // AIC
                       hmm->getNparams()*safelog(param.N) + 2*metrics[0],
                       metrics[2], metrics[3], // rmse's
                       metrics[4], metrics[5]); // acc's

            }
            free(metrics);

            // temporary
            if(param.per_kc_rmse_acc) {
                for(NCAT i=0; i<param.nK; i++) {
                    printf("KC %4u RMSE=%8.6f Acc=%8.6f\n",i,param.kc_rmse[i],param.kc_acc[i]);
                    if(param.duplicate_console==1) fprintf(fid_console, "KC %4u RMSE=%8.6f Acc=%8.6f\n",i,param.kc_rmse[i],param.kc_acc[i]);
                }
                free(param.kc_counts);
                free(param.kc_rmse);
                free(param.kc_acc);
            }
        
        } // if predict or metrics
        
        delete hmm;
    } else { // cross-validation
        NUMBER* metrics = Calloc(NUMBER, (size_t)7); // AIC, BIC, RMSE, RMSE no null
		NUMBER n_par = 0;
        switch (param.cv_strat) {
            case CV_GROUP:
                n_par = cross_validate(metrics, predict_file, output_file, &tm_fit, &tm_predict, fid_console);//SEQ
//                n_par = cross_validate(metrics, predict_file, output_file, &_tm_fit, &_tm_predict, fid_console);//PAR
                break;
            case CV_ITEM:
                n_par = cross_validate_item(metrics, predict_file, output_file, &tm_fit, &tm_predict, fid_console);//SEQ
//                n_par = cross_validate_item(metrics, predict_file, output_file, &_tm_fit, &_tm_predict, fid_console);//PAR
                break;
            case CV_NSTR:
                n_par = cross_validate_nstrat(metrics, predict_file, output_file, &tm_fit, &tm_predict, fid_console);//SEQ
//                n_par = cross_validate_nstrat(metrics, predict_file, output_file, &_tm_fit, &_tm_predict, fid_console);//PAR
                break;
            default:
                
                break;
        }

		printf("%d-fold cross-validation: LL=%15.7f (%15.7f), AIC=%8.6f, BIC=%8.6f, RMSE=%8.6f (%8.6f), Acc=%8.6f (%8.6f)\n",
			   param.cv_folds,
			   metrics[0], metrics[1], // ll's
			   2*n_par + 2*metrics[0], n_par*safelog(param.N) + 2*metrics[0],
			   metrics[2], metrics[3], // rmse's
			   metrics[4], metrics[5]); // acc's
		if(param.duplicate_console==1) fprintf(fid_console, "%d-fold cross-validation: LL=%15.7f (%15.7f), AIC=%8.6f, BIC=%8.6f, RMSE=%8.6f (%8.6f), Acc=%8.6f (%8.6f)\n",
											   param.cv_folds,
											   metrics[0], metrics[1], // ll's
											   2*n_par + 2*metrics[0], n_par*safelog(param.N) + 2*metrics[0],
											   metrics[2], metrics[3], // rmse's
											   metrics[4], metrics[5]); // acc's
		
		
        free(metrics);
    }
	// free data
	destroy_input_data(&param);
	
//	if(param.quiet == 0) {
        printf("timing: overall %f seconds, read %f, fit %f, predict %f\n",(NUMBER)((clock()-tm_all)/CLOCKS_PER_SEC), (NUMBER)tm_read/CLOCKS_PER_SEC,  (NUMBER)tm_fit/CLOCKS_PER_SEC,  (NUMBER)tm_predict/CLOCKS_PER_SEC);//SEQ
        if(param.duplicate_console==1) fprintf(fid_console, "timing: overall %f seconds, read %f, fit %f, predict %f\n",(NUMBER)((clock()-tm_all)/CLOCKS_PER_SEC), (NUMBER)tm_read/CLOCKS_PER_SEC,  (NUMBER)tm_fit/CLOCKS_PER_SEC,  (NUMBER)tm_predict/CLOCKS_PER_SEC);//SEQ
//        if(param.duplicate_console==1) fprintf(fid_console, "timing: overall %lf sec, read %lf sec, fit %lf sec, predict %lf sec\n",omp_get_wtime()-_tm_all, _tm_read, _tm_fit, _tm_predict);//PAR
//        printf("timing: overall %lf sec, read %lf sec, fit %lf sec, predict %lf sec\n",omp_get_wtime()-_tm_all, _tm_read, _tm_fit, _tm_predict);//PAR
//    }
    
    if(param.duplicate_console==1)
        fclose(fid_console);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1088, %rsp           # imm = 0x1088
movq %rsi, %r12
movl %edi, %ebp
callq 0x4150
movq %rax, 0x58(%rsp)
leaq 0x3ee25(%rip), %rdi     # 0x452a8
callq 0xd6da
leaq 0xc80(%rsp), %rdx
leaq 0x480(%rsp), %rcx
leaq 0x80(%rsp), %r8
leaq 0x880(%rsp), %r9
movl %ebp, %edi
movq %r12, %rsi
callq 0x6e21
cmpb $0x1, 0x3ee23(%rip)     # 0x452dc
jne 0x64d4
leaq 0x30d5e(%rip), %rsi     # 0x37220
leaq 0x880(%rsp), %rdi
callq 0x42c0
movq %rax, %r14
jmp 0x64d7
xorl %r14d, %r14d
cmpb $0x0, 0x3ee06(%rip)     # 0x452e4
jne 0x650e
leaq 0x31959(%rip), %rdi     # 0x37e40
callq 0x43b0
cmpb $0x1, 0x3ede9(%rip)     # 0x452dc
jne 0x650e
leaq 0x30d26(%rip), %rdi     # 0x37222
movl $0x15, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x44b0
callq 0x4150
movq %rax, %r13
leaq 0xc80(%rsp), %rdi
movq %r14, %rsi
callq 0x7540
movl %eax, %ebx
callq 0x4150
testb %bl, %bl
je 0x6dbb
movq %rax, %r15
movl %ebp, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x801f
cmpb $0x0, 0x3ed98(%rip)     # 0x452e4
jne 0x65bd
movsbl 0x3f60c(%rip), %esi     # 0x45b61
movl 0x3f609(%rip), %edx     # 0x45b64
movl 0x3f607(%rip), %ecx     # 0x45b68
movl 0x3f604(%rip), %r8d     # 0x45b6c
movsbl 0x3f600(%rip), %r9d     # 0x45b70
leaq 0x30cc1(%rip), %rdi     # 0x37238
xorl %eax, %eax
callq 0x4050
cmpb $0x1, 0x3ed57(%rip)     # 0x452dc
jne 0x65bd
movsbl 0x3f5d3(%rip), %edx     # 0x45b61
movl 0x3f5d0(%rip), %ecx     # 0x45b64
movl 0x3f5cd(%rip), %r8d     # 0x45b68
movl 0x3f5ca(%rip), %r9d     # 0x45b6c
movsbl 0x3f5c7(%rip), %eax     # 0x45b70
movl %eax, (%rsp)
leaq 0x30c85(%rip), %rsi     # 0x37238
movq %r14, %rdi
xorl %eax, %eax
callq 0x4360
leaq 0x3ece4(%rip), %rdi     # 0x452a8
callq 0xddb8
xorl %eax, %eax
movq %rax, 0x70(%rsp)
movq %rax, 0x68(%rsp)
cmpb $0x0, 0x3f138(%rip)     # 0x45714
movq %r13, 0x78(%rsp)
je 0x6645
movl $0x7, %edi
movl $0x8, %esi
callq 0x4140
movq %rax, %r12
movzbl 0x3f119(%rip), %eax     # 0x45715
cmpl $0x6e, %eax
je 0x66bf
cmpl $0x69, %eax
je 0x6698
xorpd %xmm0, %xmm0
cmpl $0x67, %eax
jne 0x66e4
leaq 0x80(%rsp), %rsi
leaq 0x480(%rsp), %rdx
leaq 0x70(%rsp), %rcx
leaq 0x68(%rsp), %r8
movq %r12, %rdi
movq %r14, %r9
callq 0x88bb
jmp 0x66e4
movq $0x0, 0x30(%rsp)
movzbl 0x3ec91(%rip), %eax     # 0x452e6
xorl %ebp, %ebp
decl %eax
cmpl $0xc, %eax
ja 0x6dcf
leaq 0x309b7(%rip), %rcx     # 0x37020
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq 0x58(%rsp), %r12
jmpq *%rax
movl $0x90, %edi
callq 0x4240
movq %rax, %rbp
leaq 0x3ec1d(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x144c6
jmp 0x694d
leaq 0x80(%rsp), %rsi
leaq 0x480(%rsp), %rdx
leaq 0x70(%rsp), %rcx
leaq 0x68(%rsp), %r8
movq %r12, %rdi
movq %r14, %r9
callq 0x8f38
jmp 0x66e4
leaq 0x80(%rsp), %rsi
leaq 0x480(%rsp), %rdx
leaq 0x70(%rsp), %rcx
leaq 0x68(%rsp), %r8
movq %r12, %rdi
movq %r14, %r9
callq 0x957a
movsd %xmm0, 0x38(%rsp)
movsbl 0x3f023(%rip), %ebx     # 0x45714
movsd (%r12), %xmm1
movsd %xmm1, 0x40(%rsp)
movsd 0x8(%r12), %xmm2
movsd %xmm2, 0x48(%rsp)
movapd %xmm1, %xmm2
addsd %xmm1, %xmm2
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
addsd %xmm1, %xmm2
movsd %xmm2, 0x60(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x3f423(%rip), %xmm0 # 0x45b58
callq 0xc895
movsd (%r12), %xmm3
movsd 0x10(%r12), %xmm4
addsd %xmm3, %xmm3
mulsd 0x38(%rsp), %xmm0
addsd %xmm0, %xmm3
movsd 0x18(%r12), %xmm5
movsd 0x20(%r12), %xmm6
movsd 0x28(%r12), %xmm7
leaq 0x30b72(%rip), %rdi     # 0x372e3
movl %ebx, %esi
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
movb $0x8, %al
callq 0x4050
cmpb $0x1, 0x3eb49(%rip)     # 0x452dc
jne 0x683a
movsbl 0x3ef74(%rip), %ebx     # 0x45714
movsd (%r12), %xmm1
movsd %xmm1, 0x40(%rsp)
movsd 0x8(%r12), %xmm0
movsd %xmm0, 0x48(%rsp)
movapd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd 0x50(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x3f37c(%rip), %xmm0 # 0x45b58
callq 0xc895
movsd (%r12), %xmm1
movsd 0x10(%r12), %xmm4
addsd %xmm1, %xmm1
movsd 0x38(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x18(%r12), %xmm5
movsd 0x20(%r12), %xmm6
movsd 0x28(%r12), %xmm7
leaq 0x30ac7(%rip), %rsi     # 0x372e3
movq %r14, %rdi
movl %ebx, %edx
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
movb $0x8, %al
callq 0x4360
movq %r12, %rdi
callq 0x42d0
movq 0x70(%rsp), %r13
movq 0x68(%rsp), %rbp
movq 0x58(%rsp), %r12
jmp 0x6cd5
movl $0xa0, %edi
callq 0x4240
movq %rax, %rbp
leaq 0x3ea3e(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x23600
jmp 0x694d
movl $0xa0, %edi
callq 0x4240
movq %rax, %rbp
leaq 0x3ea1d(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x1f538
jmp 0x694d
movl $0x98, %edi
callq 0x4240
movq %rax, %rbp
leaq 0x3e9fc(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x1d4d8
jmp 0x694d
movl $0xd0, %edi
callq 0x4240
movq %rax, %rbp
leaq 0x3e9db(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x28574
jmp 0x694d
movl $0xa8, %edi
callq 0x4240
movq %rax, %rbp
leaq 0x3e9bd(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x2e900
jmp 0x694d
movl $0x98, %edi
callq 0x4240
movq %rax, %rbp
leaq 0x3e99f(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x214b8
jmp 0x694d
movl $0xa8, %edi
callq 0x4240
movq %rax, %rbp
leaq 0x3e981(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x25b1c
jmp 0x694d
movl $0xa0, %edi
callq 0x4240
movq %rax, %rbp
leaq 0x3e963(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x34688
movq %rbp, 0x30(%rsp)
callq 0x4150
movq %rax, %rbx
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x48(%rax)
callq 0x4150
movq %rax, %r13
movq (%rbp), %rax
leaq 0x480(%rsp), %rsi
movq %rbp, %rdi
callq *0x40(%rax)
cmpl $0x0, 0x3e97b(%rip)     # 0x45300
jg 0x6997
cmpl $0x0, 0x3e97a(%rip)     # 0x45308
jg 0x6997
xorl %ebp, %ebp
jmp 0x6cc2
movl $0x7, %edi
movl $0x8, %esi
callq 0x4140
movq %rax, %r12
cmpb $0x1, 0x3f27c(%rip)     # 0x45c2c
jne 0x69fb
movq %rbx, %rbp
movslq 0x3f1ac(%rip), %rbx     # 0x45b68
movl $0x4, %esi
movq %rbx, %rdi
callq 0x4140
movq %rax, 0x3f270(%rip)     # 0x45c40
movl $0x8, %esi
movq %rbx, %rdi
callq 0x4140
movq %rax, 0x3f24c(%rip)     # 0x45c30
movl $0x8, %esi
movq %rbx, %rdi
movq %rbp, %rbx
callq 0x4140
movq %rax, 0x3f23d(%rip)     # 0x45c38
callq 0x4150
movq %rax, 0x38(%rsp)
movq 0x3f10c(%rip), %rdx     # 0x45b18
movq 0x3f10d(%rip), %rcx     # 0x45b20
movq 0x3f10e(%rip), %r8      # 0x45b28
movq 0x3f10f(%rip), %r9      # 0x45b30
movups 0x3f110(%rip), %xmm0    # 0x45b38
leaq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movups %xmm0, (%rsp)
movq $0x0, 0x20(%rsp)
movl $0x1, 0x18(%rsp)
leaq 0x80(%rsp), %rsi
movq %r12, %rdi
callq 0x16c8e
callq 0x4150
movq %rax, %rbp
cmpl $0x0, 0x3e89a(%rip)     # 0x45300
jle 0x6bf2
movsd (%r12), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x8(%r12), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x30(%rsp), %rdi
callq 0x17d50
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd (%r12), %xmm1
addsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
movq 0x30(%rsp), %rdi
callq 0x17d50
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x3f08a(%rip), %xmm0 # 0x45b58
callq 0xc895
movsd (%r12), %xmm1
movsd 0x10(%r12), %xmm4
addsd %xmm1, %xmm1
movsd 0x60(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x18(%r12), %xmm5
movsd 0x20(%r12), %xmm6
movsd 0x28(%r12), %xmm7
leaq 0x30759(%rip), %rdi     # 0x37267
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movb $0x8, %al
callq 0x4050
cmpb $0x1, 0x3e7ae(%rip)     # 0x452dc
jne 0x6bf2
movsd (%r12), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x8(%r12), %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x30(%rsp), %rdi
callq 0x17d50
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd (%r12), %xmm1
addsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
movq 0x30(%rsp), %rdi
callq 0x17d50
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x3efc2(%rip), %xmm0 # 0x45b58
callq 0xc895
movsd (%r12), %xmm1
movsd 0x10(%r12), %xmm4
addsd %xmm1, %xmm1
movsd 0x60(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x18(%r12), %xmm5
movsd 0x20(%r12), %xmm6
movsd 0x28(%r12), %xmm7
leaq 0x30691(%rip), %rsi     # 0x37267
movq %r14, %rdi
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movb $0x8, %al
callq 0x4360
subq 0x38(%rsp), %rbp
movq %r12, %rdi
callq 0x42d0
cmpb $0x1, 0x3f026(%rip)     # 0x45c2c
jne 0x6cbd
movq %rbx, 0x38(%rsp)
cmpl $0x0, 0x3ef50(%rip)     # 0x45b68
jle 0x6c8d
xorl %r12d, %r12d
leaq 0x306a2(%rip), %rbx     # 0x372c6
movq 0x3f005(%rip), %rax     # 0x45c30
movsd (%rax,%r12,8), %xmm0
movq 0x3f000(%rip), %rax     # 0x45c38
movsd (%rax,%r12,8), %xmm1
movq %rbx, %rdi
movl %r12d, %esi
movb $0x2, %al
callq 0x4050
cmpb $0x1, 0x3e68a(%rip)     # 0x452dc
jne 0x6c7e
movq 0x3efd5(%rip), %rax     # 0x45c30
movsd (%rax,%r12,8), %xmm0
movq 0x3efd0(%rip), %rax     # 0x45c38
movsd (%rax,%r12,8), %xmm1
movq %r14, %rdi
movq %rbx, %rsi
movl %r12d, %edx
movb $0x2, %al
callq 0x4360
incq %r12
movslq 0x3eee0(%rip), %rax     # 0x45b68
cmpq %rax, %r12
jl 0x6c24
movq 0x3efac(%rip), %rdi     # 0x45c40
callq 0x42d0
movq 0x3ef90(%rip), %rdi     # 0x45c30
callq 0x42d0
movq 0x3ef8c(%rip), %rdi     # 0x45c38
callq 0x42d0
movq 0x58(%rsp), %r12
movq 0x38(%rsp), %rbx
jmp 0x6cc2
movq 0x58(%rsp), %r12
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x6cd2
movq (%rdi), %rax
callq *0x8(%rax)
subq %rbx, %r13
subq 0x78(%rsp), %r15
leaq 0x3e5c7(%rip), %rdi     # 0x452a8
callq 0xd8cd
callq 0x4150
subq %r12, %rax
movabsq $0x431bde82d7b634db, %rbx # imm = 0x431BDE82D7B634DB
imulq %rbx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x12, %rdx
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r15, %xmm1
movsd 0x302e7(%rip), %xmm4    # 0x37008
divsd %xmm4, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r13, %xmm2
divsd %xmm4, %xmm2
xorps %xmm3, %xmm3
cvtsi2sd %rbp, %xmm3
divsd %xmm4, %xmm3
leaq 0x3060a(%rip), %rdi     # 0x3734e
movsd %xmm1, 0x58(%rsp)
movsd %xmm2, 0x78(%rsp)
movsd %xmm3, 0x38(%rsp)
movb $0x4, %al
callq 0x4050
cmpb $0x1, 0x3e578(%rip)     # 0x452dc
jne 0x6dbb
callq 0x4150
subq %r12, %rax
imulq %rbx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x12, %rdx
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
leaq 0x305c0(%rip), %rsi     # 0x3734e
movq %r14, %rdi
movsd 0x58(%rsp), %xmm1
movsd 0x78(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
movb $0x4, %al
callq 0x4360
cmpb $0x1, 0x3e52b(%rip)     # 0x452dc
jne 0x6dbb
movq %r14, %rdi
callq 0x4230
xorl %eax, %eax
addq $0x1088, %rsp           # imm = 0x1088
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x58(%rsp), %r12
jmp 0x6952
jmp 0x6dff
jmp 0x6ddf
jmp 0x6df3
movq %rax, %rbx
movl $0xa8, %esi
jmp 0x6e11
movq %rax, %rbx
movl $0xd0, %esi
jmp 0x6e11
movq %rax, %rbx
movl $0x98, %esi
jmp 0x6e11
jmp 0x6dff
movq %rax, %rbx
movl $0xa0, %esi
jmp 0x6e11
movq %rax, %rbx
movl $0x90, %esi
movq %rbp, %rdi
callq 0x4250
movq %rbx, %rdi
callq 0x4460