// File: myudelson[P]hmm-scalable/trainhmmst.cpp
// Function: main
int main (int argc, char ** argv) {
	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_task_defaults(&task);
    
    
    // parse parameters, step 1
	parse_arguments_step1(argc, argv, input_file, output_file, predict_file, colsole_file);

    FILE *fid_console = NULL;
    if(task.duplicate_console==1)
        fid_console = fopen(colsole_file,"w");
    
    if(!task.quiet) {
        printf("trainhmmst starting...\n");
        if(task.duplicate_console==1) fprintf(fid_console, "trainhmmst 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

    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;
//    task.item_complexity = Calloc(NUMBER, task.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 = task.map_step_fwd->find(item);
//		if( it==task.map_step_fwd->end() ) { // not found
//            fprintf(stderr,"DID NOT FIND THE STEP!!\n");
//            return false;
//		}
//		else {
////            if( it->second > task.map_step_bwd->size()) {
////                int z = 0 ;
////            }
//            NUMBER v = atof( strtok(NULL,"\t\n\r") );
//            task.item_complexity[ it->second ] = v;
//		}
//    }
//    free(line);
//    fclose(fid);

    if(!task.quiet) {
        printf("input read, nO=%d, nG=%d, nK=%d, nI=%d, nZ=%d\n",task.nO, task.nG, task.nK, task.nI, task.nZ);
        if(task.duplicate_console==1) fprintf(fid_console, "input read, nO=%d, nG=%d, nK=%d, nI=%d, nZ=%d\n",task.nO, task.nG, task.nK, task.nI, task.nZ);
    }
    
    //    // write time
    //    if(task.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(&task);

    clock_t tm_fit = 0; //SEQ
    clock_t tm_predict = 0; //SEQ
//    double _tm_fit;//PAR
//    double _tm_predict;//PAR
    
    if(task.cv_folds==0) { // not cross-validation
        // create problem
        HMMProblemSt *hmm = NULL;
        switch(task.structure)
        {
            case STRUCTURE_SKILL: // Conjugate Gradient Descent
//            case STRUCTURE_GROUP: // Conjugate Gradient Descent
                hmm = new HMMProblemSt(&task);
                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_ELO: // Gradient Descent, pT=f(K,G), other by K
                hmm = new HMMProblemEloSt(&task);
                break;
            default:
                fprintf(stderr,"Solver specified (%d) is not supported!\n",task.structure);
                exit(1);
                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(task.metrics>0 || task.predictions>0) {
            NUMBER* metrics = Calloc(NUMBER, (size_t)8); // LL, LLnonull, RMSE, RMSEnonull, Acc, Acc_nonull, AIC, BIC;
            // takes care of predictions and metrics, writes predictions if task.predictions==1
            
            // temporary
//            if(task.per_kc_rmse_acc) {
//                task.kc_counts = Calloc(NDAT, (size_t)task.nK);
//                task.kc_rmse = Calloc(NUMBER, (size_t)task.nK);
//                task.kc_acc  = Calloc(NUMBER, (size_t)task.nK);
//            }

            // NUMBER l1 = hmm->getSumLogPOPara(task.nSeq, task.k_data);
//            printf("hmm-style ll_no_null %15.7f\n",l1);
            
            tm_predict = clock(); //SEQ
//            _tm_predict = omp_get_wtime(); //PAR
//            if(task.structure==STRUCTURE_SKAslc) {
//                ((HMMProblemSlicedA *)hmm)->predict(metrics, predict_file, task.dat_obs, task.dat_group, task.dat_skill, task.dat_skill_stacked, task.dat_skill_rcount, task.dat_skill_rix);
//            } else if(task.structure==STRUCTURE_SKABslc) {
//                ((HMMProblemSlicedAB *)hmm)->predict(metrics, predict_file, task.dat_obs, task.dat_group, task.dat_skill, task.dat_skill_stacked, task.dat_skill_rcount, task.dat_skill_rix);
//            } else {
                HMMProblemSt::predict(metrics, predict_file,
                                      //task.N, task.dat_obs, task.dat_group, task.dat_skill, task.dat_skill_stacked, task.dat_skill_rcount, task.dat_skill_rix,
                                      &task,
                                      &hmm, 1, NULL);
            
//            }
            tm_predict = clock()-tm_predict;//SEQ
//            _tm_predict = omp_get_wtime()-_tm_predict;//PAR
            
            if( task.metrics>0 /*&& !task.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->getModelParamN() + 2*metrics[0], // AIC
                       hmm->getModelParamN()*safelog(task.N) + 2*metrics[0], //BIC
                       metrics[2], metrics[3], // rmse's
                       metrics[4], metrics[5]); // acc's
                if(task.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->getModelParamN()+ 2*metrics[0], // AIC
                       hmm->getModelParamN()*safelog(task.N) + 2*metrics[0],
                       metrics[2], metrics[3], // rmse's
                       metrics[4], metrics[5]); // acc's

            }
            free(metrics);

            // temporary
//            if(task.per_kc_rmse_acc) {
//                for(NCAT i=0; i<task.nK; i++) {
//                    printf("KC %4u RMSE=%8.6f Acc=%8.6f\n",i,task.kc_rmse[i],task.kc_acc[i]);
//                    if(task.duplicate_console==1) fprintf(fid_console, "KC %4u RMSE=%8.6f Acc=%8.6f\n",i,task.kc_rmse[i],task.kc_acc[i]);
//                }
//                free(task.kc_counts);
//                free(task.kc_rmse);
//                free(task.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 (task.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",
			   task.cv_folds,
			   metrics[0], metrics[1], // ll's
			   2*n_par + 2*metrics[0], n_par*safelog(task.N) + 2*metrics[0],
			   metrics[2], metrics[3], // rmse's
			   metrics[4], metrics[5]); // acc's
		if(task.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",
											   task.cv_folds,
											   metrics[0], metrics[1], // ll's
											   2*n_par + 2*metrics[0], n_par*safelog(task.N) + 2*metrics[0],
											   metrics[2], metrics[3], // rmse's
											   metrics[4], metrics[5]); // acc's
		
		
        free(metrics);
    }
	// free data
	destroy_input_data(&task);
	
//	if(task.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(task.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(task.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(task.duplicate_console==1)
        fclose(fid_console);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1150, %rsp           # imm = 0x1150
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x3190
movq %rax, -0x18(%rbp)
leaq 0x23b5f(%rip), %rdi     # 0x27308
callq 0xbc90
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x420(%rbp), %rdx
leaq -0x820(%rbp), %rcx
leaq -0x1020(%rbp), %r8
leaq -0xc20(%rbp), %r9
callq 0x41d0
movq $0x0, -0x1028(%rbp)
movsbl 0x23b64(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x3807
leaq -0xc20(%rbp), %rdi
leaq 0x1a949(%rip), %rsi     # 0x1e144
callq 0x3340
movq %rax, -0x1028(%rbp)
cmpb $0x0, 0x23b46(%rip)     # 0x27354
jne 0x3841
leaq 0x1a92f(%rip), %rdi     # 0x1e146
movb $0x0, %al
callq 0x3060
movsbl 0x23b27(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x383f
movq -0x1028(%rbp), %rdi
leaq 0x1a90e(%rip), %rsi     # 0x1e146
movb $0x0, %al
callq 0x33f0
jmp 0x3841
callq 0x3190
movq %rax, -0x1030(%rbp)
leaq -0x420(%rbp), %rdi
movq -0x1028(%rbp), %rsi
callq 0x4e70
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1034(%rbp)
callq 0x3190
subq -0x1030(%rbp), %rax
movq %rax, -0x1030(%rbp)
cmpl $0x0, -0x1034(%rbp)
jne 0x3893
movl $0x0, -0x4(%rbp)
jmp 0x41a9
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x1028(%rbp), %rdx
callq 0x4f70
cmpb $0x0, 0x23aa7(%rip)     # 0x27354
jne 0x3927
movsbl 0x24353(%rip), %esi     # 0x27c09
movl 0x24350(%rip), %edx     # 0x27c0c
movl 0x2434e(%rip), %ecx     # 0x27c10
movl 0x2434b(%rip), %r8d     # 0x27c14
movsbl 0x24347(%rip), %r9d     # 0x27c18
leaq 0x1a886(%rip), %rdi     # 0x1e15e
movb $0x0, %al
callq 0x3060
movsbl 0x23a66(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x3925
movq -0x1028(%rbp), %rdi
movsbl 0x24310(%rip), %edx     # 0x27c09
movl 0x2430d(%rip), %ecx     # 0x27c0c
movl 0x2430a(%rip), %r8d     # 0x27c10
movl 0x24307(%rip), %r9d     # 0x27c14
movsbl 0x24304(%rip), %eax     # 0x27c18
leaq 0x1a843(%rip), %rsi     # 0x1e15e
movl %eax, (%rsp)
movb $0x0, %al
callq 0x33f0
jmp 0x3927
movq $0x0, -0x1040(%rbp)
movq $0x0, -0x1048(%rbp)
movsbl 0x23e40(%rip), %eax     # 0x27784
cmpl $0x0, %eax
jne 0x3d67
movq $0x0, -0x1050(%rbp)
movsbl 0x239f7(%rip), %eax     # 0x27356
movl %eax, -0x107c(%rbp)
subl $0x1, %eax
je 0x397c
jmp 0x396c
movl -0x107c(%rbp), %eax
subl $0xe, %eax
je 0x39dc
jmp 0x3a39
movl $0xd0, %edi
callq 0x32a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1088(%rbp)
leaq 0x2396e(%rip), %rsi     # 0x27308
callq 0x14b20
jmp 0x39a1
movq -0x1088(%rbp), %rax
movq %rax, -0x1050(%rbp)
jmp 0x3a62
movq -0x1088(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1058(%rbp)
movl %eax, -0x105c(%rbp)
movl $0xd0, %esi
callq 0x32b0
jmp 0x41b5
movl $0x110, %edi            # imm = 0x110
callq 0x32a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1090(%rbp)
leaq 0x2390e(%rip), %rsi     # 0x27308
callq 0x1d1b0
jmp 0x3a01
movq -0x1090(%rbp), %rax
movq %rax, -0x1050(%rbp)
jmp 0x3a62
movq -0x1090(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1058(%rbp)
movl %eax, -0x105c(%rbp)
movl $0x110, %esi            # imm = 0x110
callq 0x32b0
jmp 0x41b5
movq 0x23598(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
movsbl 0x2390c(%rip), %edx     # 0x27356
leaq 0x1a73c(%rip), %rsi     # 0x1e18d
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
callq 0x3190
movq %rax, -0x1040(%rbp)
movq -0x1050(%rbp), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
callq 0x3190
subq -0x1040(%rbp), %rax
movq %rax, -0x1040(%rbp)
movq -0x1050(%rbp), %rdi
leaq -0x820(%rbp), %rsi
movq (%rdi), %rax
callq *0x40(%rax)
cmpl $0x0, 0x238c7(%rip)     # 0x27370
jg 0x3ab8
cmpl $0x0, 0x238c6(%rip)     # 0x27378
jle 0x3d41
movl $0x8, %esi
movq %rsi, %rdi
callq 0x3180
movq %rax, -0x1068(%rbp)
callq 0x3190
movq %rax, -0x1048(%rbp)
movq -0x1068(%rbp), %rdi
leaq -0x1020(%rbp), %rsi
leaq 0x2381b(%rip), %rdx     # 0x27308
leaq -0x1050(%rbp), %rcx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
callq 0x18c10
callq 0x3190
subq -0x1048(%rbp), %rax
movq %rax, -0x1048(%rbp)
cmpl $0x0, 0x23852(%rip)     # 0x27370
jle 0x3d35
movq -0x1068(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1098(%rbp)
movq -0x1068(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x10a8(%rbp)
movq -0x1050(%rbp), %rdi
callq 0x19440
shll %eax
cvtsi2sd %eax, %xmm1
movq -0x1068(%rbp), %rax
movsd (%rax), %xmm0
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10a0(%rbp)
movq -0x1050(%rbp), %rdi
callq 0x19440
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x10b0(%rbp)
cvtsi2sdl 0x24068(%rip), %xmm0 # 0x27c00
callq 0xa590
movsd -0x10b0(%rbp), %xmm3
movsd -0x10a8(%rbp), %xmm1
movsd -0x10a0(%rbp), %xmm2
movaps %xmm0, %xmm5
movsd -0x1098(%rbp), %xmm0
movq -0x1068(%rbp), %rax
movsd 0x1a439(%rip), %xmm4    # 0x1e008
mulsd (%rax), %xmm4
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
movq -0x1068(%rbp), %rax
movsd 0x10(%rax), %xmm4
movq -0x1068(%rbp), %rax
movsd 0x18(%rax), %xmm5
movq -0x1068(%rbp), %rax
movsd 0x20(%rax), %xmm6
movq -0x1068(%rbp), %rax
movsd 0x28(%rax), %xmm7
leaq 0x1a5a4(%rip), %rdi     # 0x1e1b6
movb $0x8, %al
callq 0x3060
movsbl 0x2372c(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x3d33
movq -0x1028(%rbp), %rax
movq %rax, -0x10d0(%rbp)
movq -0x1068(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x10b8(%rbp)
movq -0x1068(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x10c8(%rbp)
movq -0x1050(%rbp), %rdi
callq 0x19440
shll %eax
cvtsi2sd %eax, %xmm1
movq -0x1068(%rbp), %rax
movsd (%rax), %xmm0
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10c0(%rbp)
movq -0x1050(%rbp), %rdi
callq 0x19440
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x10d8(%rbp)
cvtsi2sdl 0x23f55(%rip), %xmm0 # 0x27c00
callq 0xa590
movsd -0x10d8(%rbp), %xmm3
movq -0x10d0(%rbp), %rdi
movsd -0x10c8(%rbp), %xmm1
movsd -0x10c0(%rbp), %xmm2
movaps %xmm0, %xmm5
movsd -0x10b8(%rbp), %xmm0
movq -0x1068(%rbp), %rax
movsd 0x1a31f(%rip), %xmm4    # 0x1e008
mulsd (%rax), %xmm4
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
movq -0x1068(%rbp), %rax
movsd 0x10(%rax), %xmm4
movq -0x1068(%rbp), %rax
movsd 0x18(%rax), %xmm5
movq -0x1068(%rbp), %rax
movsd 0x20(%rax), %xmm6
movq -0x1068(%rbp), %rax
movsd 0x28(%rax), %xmm7
leaq 0x1a48a(%rip), %rsi     # 0x1e1b6
movb $0x8, %al
callq 0x33f0
jmp 0x3d35
movq -0x1068(%rbp), %rdi
callq 0x3350
movq -0x1050(%rbp), %rax
movq %rax, -0x10e0(%rbp)
cmpq $0x0, %rax
je 0x3d62
movq -0x10e0(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x4093
movl $0x7, %edi
movl $0x8, %esi
callq 0x3180
movq %rax, -0x1070(%rbp)
movq $0x0, -0x1078(%rbp)
movsbl 0x239f6(%rip), %eax     # 0x27785
movl %eax, -0x10e4(%rbp)
subl $0x67, %eax
je 0x3db9
jmp 0x3d9c
movl -0x10e4(%rbp), %eax
subl $0x69, %eax
je 0x3df2
jmp 0x3da9
movl -0x10e4(%rbp), %eax
subl $0x6e, %eax
je 0x3e2b
jmp 0x3e64
movq -0x1070(%rbp), %rdi
leaq -0x1020(%rbp), %rsi
leaq -0x820(%rbp), %rdx
movq -0x1028(%rbp), %r9
leaq -0x1040(%rbp), %rcx
leaq -0x1048(%rbp), %r8
callq 0x5f40
movsd %xmm0, -0x1078(%rbp)
jmp 0x3e66
movq -0x1070(%rbp), %rdi
leaq -0x1020(%rbp), %rsi
leaq -0x820(%rbp), %rdx
movq -0x1028(%rbp), %r9
leaq -0x1040(%rbp), %rcx
leaq -0x1048(%rbp), %r8
callq 0x67f0
movsd %xmm0, -0x1078(%rbp)
jmp 0x3e66
movq -0x1070(%rbp), %rdi
leaq -0x1020(%rbp), %rsi
leaq -0x820(%rbp), %rdx
movq -0x1028(%rbp), %r9
leaq -0x1040(%rbp), %rcx
leaq -0x1048(%rbp), %r8
callq 0x7080
movsd %xmm0, -0x1078(%rbp)
jmp 0x3e66
jmp 0x3e66
movsbl 0x23917(%rip), %eax     # 0x27784
movl %eax, -0x1104(%rbp)
movq -0x1070(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x10f0(%rbp)
movq -0x1070(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x1100(%rbp)
movsd -0x1078(%rbp), %xmm0
movq -0x1070(%rbp), %rax
movsd 0x1a157(%rip), %xmm1    # 0x1e008
mulsd (%rax), %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10f8(%rbp)
movsd -0x1078(%rbp), %xmm0
movsd %xmm0, -0x1110(%rbp)
cvtsi2sdl 0x23d23(%rip), %xmm0 # 0x27c00
callq 0xa590
movsd -0x1110(%rbp), %xmm3
movl -0x1104(%rbp), %esi
movsd -0x1100(%rbp), %xmm1
movsd -0x10f8(%rbp), %xmm2
movaps %xmm0, %xmm5
movsd -0x10f0(%rbp), %xmm0
movq -0x1070(%rbp), %rax
movsd 0x1a0ee(%rip), %xmm4    # 0x1e008
mulsd (%rax), %xmm4
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
movq -0x1070(%rbp), %rax
movsd 0x10(%rax), %xmm4
movq -0x1070(%rbp), %rax
movsd 0x18(%rax), %xmm5
movq -0x1070(%rbp), %rax
movsd 0x20(%rax), %xmm6
movq -0x1070(%rbp), %rax
movsd 0x28(%rax), %xmm7
leaq 0x1a2b8(%rip), %rdi     # 0x1e215
movb $0x8, %al
callq 0x3060
movsbl 0x233e1(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x4087
movq -0x1028(%rbp), %rax
movq %rax, -0x1138(%rbp)
movsbl 0x237fb(%rip), %eax     # 0x27784
movl %eax, -0x112c(%rbp)
movq -0x1070(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1118(%rbp)
movq -0x1070(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x1128(%rbp)
movsd -0x1078(%rbp), %xmm0
movq -0x1070(%rbp), %rax
movsd 0x1a03b(%rip), %xmm1    # 0x1e008
mulsd (%rax), %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x1120(%rbp)
movsd -0x1078(%rbp), %xmm0
movsd %xmm0, -0x1140(%rbp)
cvtsi2sdl 0x23c07(%rip), %xmm0 # 0x27c00
callq 0xa590
movsd -0x1140(%rbp), %xmm3
movq -0x1138(%rbp), %rdi
movl -0x112c(%rbp), %edx
movsd -0x1128(%rbp), %xmm1
movsd -0x1120(%rbp), %xmm2
movaps %xmm0, %xmm5
movsd -0x1118(%rbp), %xmm0
movq -0x1070(%rbp), %rax
movsd 0x19fcb(%rip), %xmm4    # 0x1e008
mulsd (%rax), %xmm4
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
movq -0x1070(%rbp), %rax
movsd 0x10(%rax), %xmm4
movq -0x1070(%rbp), %rax
movsd 0x18(%rax), %xmm5
movq -0x1070(%rbp), %rax
movsd 0x20(%rax), %xmm6
movq -0x1070(%rbp), %rax
movsd 0x28(%rax), %xmm7
leaq 0x1a195(%rip), %rsi     # 0x1e215
movb $0x8, %al
callq 0x33f0
movq -0x1070(%rbp), %rdi
callq 0x3350
leaq 0x2326e(%rip), %rdi     # 0x27308
callq 0xc2d0
callq 0x3190
subq -0x18(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
cvtsi2sd %rax, %xmm0
cvtsi2sdq -0x1030(%rbp), %xmm1
movsd 0x19f48(%rip), %xmm2    # 0x1e010
divsd %xmm2, %xmm1
cvtsi2sdq -0x1040(%rbp), %xmm2
movsd 0x19f33(%rip), %xmm3    # 0x1e010
divsd %xmm3, %xmm2
cvtsi2sdq -0x1048(%rbp), %xmm3
movsd 0x19f1e(%rip), %xmm4    # 0x1e010
divsd %xmm4, %xmm3
leaq 0x1a183(%rip), %rdi     # 0x1e280
movb $0x4, %al
callq 0x3060
movsbl 0x23241(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x418a
movq -0x1028(%rbp), %rax
movq %rax, -0x1148(%rbp)
callq 0x3190
movq -0x1148(%rbp), %rdi
subq -0x18(%rbp), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
cvtsi2sd %rax, %xmm0
cvtsi2sdq -0x1030(%rbp), %xmm1
movsd 0x19ec2(%rip), %xmm2    # 0x1e010
divsd %xmm2, %xmm1
cvtsi2sdq -0x1040(%rbp), %xmm2
movsd 0x19ead(%rip), %xmm3    # 0x1e010
divsd %xmm3, %xmm2
cvtsi2sdq -0x1048(%rbp), %xmm3
movsd 0x19e98(%rip), %xmm4    # 0x1e010
divsd %xmm4, %xmm3
leaq 0x1a0fd(%rip), %rsi     # 0x1e280
movb $0x4, %al
callq 0x33f0
movsbl 0x231bb(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x41a2
movq -0x1028(%rbp), %rdi
callq 0x3290
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1150, %rsp           # imm = 0x1150
popq %rbp
retq
movq -0x1058(%rbp), %rdi
callq 0x34c0
nopw %cs:(%rax,%rax)