// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1078, %rsp           # imm = 0x1078
movq %rsi, %r13
movl %edi, %ebp
callq 0x4150
movq %rax, %rbx
leaq 0x3ed37(%rip), %rdi     # 0x452a8
callq 0xd450
leaq 0xc70(%rsp), %rdx
leaq 0x470(%rsp), %rcx
leaq 0x70(%rsp), %r8
leaq 0x870(%rsp), %r9
movl %ebp, %edi
movq %r13, %rsi
callq 0x6ebc
cmpb $0x1, 0x3ed38(%rip)     # 0x452dc
jne 0x65bf
leaq 0x30c23(%rip), %rsi     # 0x371d0
leaq 0x870(%rsp), %rdi
callq 0x42c0
movq %rax, %r14
jmp 0x65c2
xorl %r14d, %r14d
cmpb $0x0, 0x3ed1b(%rip)     # 0x452e4
jne 0x65f9
leaq 0x3181e(%rip), %rdi     # 0x37df0
callq 0x43b0
cmpb $0x1, 0x3ecfe(%rip)     # 0x452dc
jne 0x65f9
leaq 0x30beb(%rip), %rdi     # 0x371d2
movl $0x15, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x44b0
callq 0x4150
movq %rax, 0x60(%rsp)
leaq 0xc70(%rsp), %rdi
movq %r14, %rsi
callq 0x75e3
movl %eax, %r12d
callq 0x4150
testb %r12b, %r12b
je 0x6e60
movq %rax, %r15
movl %ebp, %edi
movq %r13, %rsi
movq %r14, %rdx
callq 0x8007
cmpb $0x0, 0x3eca9(%rip)     # 0x452e4
jne 0x66ac
movsbl 0x3f51d(%rip), %esi     # 0x45b61
movl 0x3f51a(%rip), %edx     # 0x45b64
movl 0x3f518(%rip), %ecx     # 0x45b68
movl 0x3f515(%rip), %r8d     # 0x45b6c
movsbl 0x3f511(%rip), %r9d     # 0x45b70
leaq 0x30b82(%rip), %rdi     # 0x371e8
xorl %eax, %eax
callq 0x4050
cmpb $0x1, 0x3ec68(%rip)     # 0x452dc
jne 0x66ac
movsbl 0x3f4e4(%rip), %edx     # 0x45b61
movl 0x3f4e1(%rip), %ecx     # 0x45b64
movl 0x3f4de(%rip), %r8d     # 0x45b68
movl 0x3f4db(%rip), %r9d     # 0x45b6c
movsbl 0x3f4d8(%rip), %eax     # 0x45b70
movl %eax, (%rsp)
leaq 0x30b46(%rip), %rsi     # 0x371e8
movq %r14, %rdi
xorl %eax, %eax
callq 0x4360
leaq 0x3ebf5(%rip), %rdi     # 0x452a8
callq 0xdb9b
xorl %eax, %eax
movq %rax, 0x58(%rsp)
movq %rax, 0x50(%rsp)
cmpb $0x0, 0x3f049(%rip)     # 0x45714
je 0x672c
movl $0x7, %edi
movl $0x8, %esi
callq 0x4140
movq %rax, %r13
movzbl 0x3f02f(%rip), %eax     # 0x45715
cmpl $0x6e, %eax
je 0x679c
cmpl $0x69, %eax
je 0x6778
xorpd %xmm0, %xmm0
cmpl $0x67, %eax
jne 0x67be
leaq 0x70(%rsp), %rsi
leaq 0x470(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0x50(%rsp), %r8
movq %r13, %rdi
movq %r14, %r9
callq 0x87cc
jmp 0x67be
movq $0x0, 0x28(%rsp)
movzbl 0x3ebaa(%rip), %eax     # 0x452e6
decl %eax
cmpl $0xc, %eax
ja 0x6a13
leaq 0x308d2(%rip), %rcx     # 0x37020
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x90, %edi
callq 0x4240
movq %rax, %r13
leaq 0x3eb3d(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x1447e
jmp 0x6a0e
leaq 0x70(%rsp), %rsi
leaq 0x470(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0x50(%rsp), %r8
movq %r13, %rdi
movq %r14, %r9
callq 0x8e4f
jmp 0x67be
leaq 0x70(%rsp), %rsi
leaq 0x470(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0x50(%rsp), %r8
movq %r13, %rdi
movq %r14, %r9
callq 0x9471
movsd %xmm0, 0x38(%rsp)
movsbl 0x3ef49(%rip), %ebp     # 0x45714
movsd (%r13), %xmm1
movsd %xmm1, 0x40(%rsp)
movsd 0x8(%r13), %xmm2
movsd %xmm2, 0x48(%rsp)
movapd %xmm1, %xmm2
addsd %xmm1, %xmm2
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
addsd %xmm1, %xmm2
movsd %xmm2, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x3f34a(%rip), %xmm0 # 0x45b58
callq 0xc615
movsd (%r13), %xmm3
movsd 0x10(%r13), %xmm4
addsd %xmm3, %xmm3
mulsd 0x38(%rsp), %xmm0
addsd %xmm0, %xmm3
movsd 0x18(%r13), %xmm5
movsd 0x20(%r13), %xmm6
movsd 0x28(%r13), %xmm7
leaq 0x30a4d(%rip), %rdi     # 0x37293
movl %ebp, %esi
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x68(%rsp), %xmm2
movb $0x8, %al
callq 0x4050
cmpb $0x1, 0x3ea74(%rip)     # 0x452dc
jne 0x690a
movsbl 0x3ee9f(%rip), %ebp     # 0x45714
movsd (%r13), %xmm1
movsd %xmm1, 0x40(%rsp)
movsd 0x8(%r13), %xmm0
movsd %xmm0, 0x48(%rsp)
movapd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x3f2a8(%rip), %xmm0 # 0x45b58
callq 0xc615
movsd (%r13), %xmm1
movsd 0x10(%r13), %xmm4
addsd %xmm1, %xmm1
movsd 0x38(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x18(%r13), %xmm5
movsd 0x20(%r13), %xmm6
movsd 0x28(%r13), %xmm7
leaq 0x309a7(%rip), %rsi     # 0x37293
movq %r14, %rdi
movl %ebp, %edx
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movb $0x8, %al
callq 0x4360
movq %r13, %rdi
callq 0x42d0
jmp 0x6d76
movl $0xa0, %edi
callq 0x4240
movq %rax, %r13
leaq 0x3e97d(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x23774
jmp 0x6a0e
movl $0xa0, %edi
callq 0x4240
movq %rax, %r13
leaq 0x3e95c(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x1f558
jmp 0x6a0e
movl $0x98, %edi
callq 0x4240
movq %rax, %r13
leaq 0x3e93b(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x1d500
jmp 0x6a0e
movl $0xd0, %edi
callq 0x4240
movq %rax, %r13
leaq 0x3e91a(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x28868
jmp 0x6a0e
movl $0xa8, %edi
callq 0x4240
movq %rax, %r13
leaq 0x3e8fc(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x2ec4c
jmp 0x6a0e
movl $0x98, %edi
callq 0x4240
movq %rax, %r13
leaq 0x3e8de(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x2157c
jmp 0x6a0e
movl $0xa8, %edi
callq 0x4240
movq %rax, %r13
leaq 0x3e8c0(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x25d4c
jmp 0x6a0e
movl $0xa0, %edi
callq 0x4240
movq %rax, %r13
leaq 0x3e8a2(%rip), %rsi     # 0x452a8
movq %rax, %rdi
callq 0x3491c
movq %r13, 0x28(%rsp)
callq 0x4150
movq %rax, %r12
movq %rax, 0x58(%rsp)
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
callq 0x4150
subq %r12, %rax
movq %rax, 0x58(%rsp)
movq 0x28(%rsp), %rdi
movq (%rdi), %rax
leaq 0x470(%rsp), %rsi
callq *0x40(%rax)
cmpl $0x0, 0x3e8ae(%rip)     # 0x45300
jg 0x6a61
cmpl $0x0, 0x3e8ad(%rip)     # 0x45308
jle 0x6d66
movl $0x7, %edi
movl $0x8, %esi
callq 0x4140
movq %rax, %r13
cmpb $0x1, 0x3f1b2(%rip)     # 0x45c2c
jne 0x6abf
movslq 0x3f0e5(%rip), %r12     # 0x45b68
movl $0x4, %esi
movq %r12, %rdi
callq 0x4140
movq %rax, 0x3f1a9(%rip)     # 0x45c40
movl $0x8, %esi
movq %r12, %rdi
callq 0x4140
movq %rax, 0x3f185(%rip)     # 0x45c30
movl $0x8, %esi
movq %r12, %rdi
callq 0x4140
movq %rax, 0x3f179(%rip)     # 0x45c38
callq 0x4150
movq %rax, %r12
movq %rax, 0x50(%rsp)
movq 0x3f045(%rip), %rdx     # 0x45b18
movq 0x3f046(%rip), %rcx     # 0x45b20
movq 0x3f047(%rip), %r8      # 0x45b28
movq 0x3f048(%rip), %r9      # 0x45b30
movups 0x3f049(%rip), %xmm0    # 0x45b38
leaq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movups %xmm0, (%rsp)
movq $0x0, 0x20(%rsp)
movl $0x1, 0x18(%rsp)
leaq 0x70(%rsp), %rsi
movq %r13, %rdi
callq 0x16c6a
callq 0x4150
subq %r12, %rax
movq %rax, 0x50(%rsp)
cmpl $0x0, 0x3e7d1(%rip)     # 0x45300
jle 0x6cb1
movsd (%r13), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x8(%r13), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x28(%rsp), %rdi
callq 0x17ce0
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd (%r13), %xmm1
addsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
movq 0x28(%rsp), %rdi
callq 0x17ce0
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x3efc2(%rip), %xmm0 # 0x45b58
callq 0xc615
movsd (%r13), %xmm1
movsd 0x10(%r13), %xmm4
addsd %xmm1, %xmm1
movsd 0x40(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x18(%r13), %xmm5
movsd 0x20(%r13), %xmm6
movsd 0x28(%r13), %xmm7
leaq 0x30645(%rip), %rdi     # 0x37217
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
movb $0x8, %al
callq 0x4050
cmpb $0x1, 0x3e6ea(%rip)     # 0x452dc
jne 0x6cb1
movsd (%r13), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x8(%r13), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x28(%rsp), %rdi
callq 0x17ce0
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd (%r13), %xmm1
addsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
movq 0x28(%rsp), %rdi
callq 0x17ce0
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x3eeff(%rip), %xmm0 # 0x45b58
callq 0xc615
movsd (%r13), %xmm1
movsd 0x10(%r13), %xmm4
addsd %xmm1, %xmm1
movsd 0x40(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x18(%r13), %xmm5
movsd 0x20(%r13), %xmm6
movsd 0x28(%r13), %xmm7
leaq 0x30582(%rip), %rsi     # 0x37217
movq %r14, %rdi
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x48(%rsp), %xmm2
movb $0x8, %al
callq 0x4360
movq %r13, %rdi
callq 0x42d0
cmpb $0x1, 0x3ef6c(%rip)     # 0x45c2c
jne 0x6d66
cmpl $0x0, 0x3ee9b(%rip)     # 0x45b68
jle 0x6d42
xorl %r13d, %r13d
leaq 0x3059d(%rip), %rbp     # 0x37276
movq 0x3ef50(%rip), %rax     # 0x45c30
movsd (%rax,%r13,8), %xmm0
movq 0x3ef4b(%rip), %rax     # 0x45c38
movsd (%rax,%r13,8), %xmm1
movq %rbp, %rdi
movl %r13d, %esi
movb $0x2, %al
callq 0x4050
cmpb $0x1, 0x3e5d5(%rip)     # 0x452dc
jne 0x6d33
movq 0x3ef20(%rip), %rax     # 0x45c30
movsd (%rax,%r13,8), %xmm0
movq 0x3ef1b(%rip), %rax     # 0x45c38
movsd (%rax,%r13,8), %xmm1
movq %r14, %rdi
movq %rbp, %rsi
movl %r13d, %edx
movb $0x2, %al
callq 0x4360
incq %r13
movslq 0x3ee2b(%rip), %rax     # 0x45b68
cmpq %rax, %r13
jl 0x6cd9
movq 0x3eef7(%rip), %rdi     # 0x45c40
callq 0x42d0
movq 0x3eedb(%rip), %rdi     # 0x45c30
callq 0x42d0
movq 0x3eed7(%rip), %rdi     # 0x45c38
callq 0x42d0
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x6d76
movq (%rdi), %rax
callq *0x8(%rax)
subq 0x60(%rsp), %r15
leaq 0x3e526(%rip), %rdi     # 0x452a8
callq 0xd6aa
callq 0x4150
subq %rbx, %rax
movabsq $0x431bde82d7b634db, %r12 # imm = 0x431BDE82D7B634DB
imulq %r12
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 0x30246(%rip), %xmm4    # 0x37008
divsd %xmm4, %xmm1
xorps %xmm2, %xmm2
cvtsi2sdq 0x58(%rsp), %xmm2
divsd %xmm4, %xmm2
xorps %xmm3, %xmm3
cvtsi2sdq 0x50(%rsp), %xmm3
divsd %xmm4, %xmm3
leaq 0x30515(%rip), %rdi     # 0x372fe
movsd %xmm1, 0x60(%rsp)
movsd %xmm2, 0x38(%rsp)
movsd %xmm3, 0x30(%rsp)
movb $0x4, %al
callq 0x4050
cmpb $0x1, 0x3e4d3(%rip)     # 0x452dc
jne 0x6e4f
callq 0x4150
subq %rbx, %rax
imulq %r12
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x12, %rdx
addq %rax, %rdx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
leaq 0x304cb(%rip), %rsi     # 0x372fe
movq %r14, %rdi
movsd 0x60(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
movsd 0x30(%rsp), %xmm3
movb $0x4, %al
callq 0x4360
cmpb $0x1, 0x3e486(%rip)     # 0x452dc
jne 0x6e60
movq %r14, %rdi
callq 0x4230
xorl %eax, %eax
addq $0x1078, %rsp           # imm = 0x1078
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6e9a
jmp 0x6e7a
jmp 0x6e8e
movq %rax, %rbx
movl $0xa8, %esi
jmp 0x6eac
movq %rax, %rbx
movl $0xd0, %esi
jmp 0x6eac
movq %rax, %rbx
movl $0x98, %esi
jmp 0x6eac
jmp 0x6e9a
movq %rax, %rbx
movl $0xa0, %esi
jmp 0x6eac
movq %rax, %rbx
movl $0x90, %esi
movq %r13, %rdi
callq 0x4250
movq %rbx, %rdi
callq 0x4460