// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1058, %rsp           # imm = 0x1058
movq %rsi, %r13
movl %edi, %ebp
callq 0x3120
movq %rax, %rbx
leaq 0x16c67(%rip), %rdi     # 0x1a278
callq 0x869d
leaq 0xc50(%rsp), %rdx
leaq 0x450(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x850(%rsp), %r9
movl %ebp, %edi
movq %r13, %rsi
callq 0x3cde
cmpb $0x1, 0x16c78(%rip)     # 0x1a2bc
jne 0x365f
leaq 0xeac3(%rip), %rsi      # 0x12110
leaq 0x850(%rsp), %rdi
callq 0x3250
movq %rax, %r14
jmp 0x3662
xorl %r14d, %r14d
movq %rbx, 0x48(%rsp)
cmpb $0x0, 0x16c56(%rip)     # 0x1a2c4
jne 0x369a
leaq 0xf6f4(%rip), %rdi      # 0x12d6b
callq 0x3340
cmpb $0x1, 0x16c39(%rip)     # 0x1a2bc
jne 0x369a
leaq 0xea86(%rip), %rdi      # 0x12112
pushq $0x17
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x3430
callq 0x3120
movq %rax, %r12
leaq 0xc50(%rsp), %rdi
callq 0x45bc
movl %eax, %ebx
callq 0x3120
testb %bl, %bl
je 0x3c85
movq %rax, %r15
movl %ebp, %edi
movq %r13, %rsi
movq %r14, %rdx
callq 0x4665
cmpb $0x0, 0x16bef(%rip)     # 0x1a2c4
jne 0x3746
movsbl 0x1749b(%rip), %esi     # 0x1ab79
movl 0x17498(%rip), %edx     # 0x1ab7c
movl 0x17496(%rip), %ecx     # 0x1ab80
movl 0x17493(%rip), %r8d     # 0x1ab84
movsbl 0x1748f(%rip), %r9d     # 0x1ab88
leaq 0xea2a(%rip), %rdi      # 0x1212a
xorl %eax, %eax
callq 0x3050
cmpb $0x1, 0x16bae(%rip)     # 0x1a2bc
jne 0x3746
movsbl 0x17462(%rip), %edx     # 0x1ab79
movl 0x1745f(%rip), %ecx     # 0x1ab7c
movl 0x1745c(%rip), %r8d     # 0x1ab80
movl 0x17459(%rip), %r9d     # 0x1ab84
movsbl 0x17456(%rip), %eax     # 0x1ab88
movl %eax, (%rsp)
leaq 0xe9ee(%rip), %rsi      # 0x1212a
movq %r14, %rdi
xorl %eax, %eax
callq 0x3300
andq $0x0, 0x38(%rsp)
andq $0x0, 0x30(%rsp)
cmpb $0x0, 0x16f9b(%rip)     # 0x1a6f4
je 0x37b6
pushq $0x7
popq %rdi
pushq $0x8
popq %rsi
callq 0x3110
movq %rax, %r13
movzbl 0x16f85(%rip), %eax     # 0x1a6f5
cmpl $0x6e, %eax
je 0x3a54
cmpl $0x69, %eax
je 0x3a30
xorpd %xmm0, %xmm0
cmpl $0x67, %eax
jne 0x3a76
leaq 0x50(%rsp), %rsi
leaq 0x450(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
movq %r13, %rdi
movq %r14, %r9
callq 0x5072
jmp 0x3a76
movzbl 0x16b09(%rip), %eax     # 0x1a2c6
cmpl $0xe, %eax
je 0x37e9
cmpl $0x1, %eax
jne 0x3c99
movl $0xd0, %edi
callq 0x31f0
movq %rax, %r13
leaq 0x16a99(%rip), %rsi     # 0x1a278
movq %rax, %rdi
callq 0xc0c4
jmp 0x3805
movl $0x110, %edi            # imm = 0x110
callq 0x31f0
movq %rax, %r13
leaq 0x16a7b(%rip), %rsi     # 0x1a278
movq %rax, %rdi
callq 0x1154e
movq %r13, 0x28(%rsp)
callq 0x3120
movq %rax, %rbx
movq (%r13), %rax
movq %r13, %rdi
callq *0x48(%rax)
callq 0x3120
subq %rbx, %rax
movq %rax, 0x38(%rsp)
movq (%r13), %rax
leaq 0x450(%rsp), %rsi
movq %r13, %rdi
callq *0x40(%rax)
cmpl $0x0, 0x16a9e(%rip)     # 0x1a2e0
jg 0x3851
cmpl $0x0, 0x16a9d(%rip)     # 0x1a2e8
jle 0x3a21
pushq $0x8
popq %rdi
movq %rdi, %rsi
callq 0x3110
movq %rax, %r13
callq 0x3120
movq %rax, %rbx
leaq 0x16a0a(%rip), %rdx     # 0x1a278
leaq 0x50(%rsp), %rsi
leaq 0x28(%rsp), %rcx
pushq $0x1
popq %r8
movq %r13, %rdi
xorl %r9d, %r9d
callq 0xec30
callq 0x3120
subq %rbx, %rax
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x16a45(%rip)     # 0x1a2e0
jle 0x3a0b
movsd (%r13), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%r13), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %rdi
callq 0xf140
addl %eax, %eax
cvtsi2sd %eax, %xmm0
movsd (%r13), %xmm1
addsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq 0x28(%rsp), %rdi
callq 0xf140
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x20(%rsp)
cvtsi2sdl 0x17277(%rip), %xmm0 # 0x1ab70
callq 0x79d9
movsd (%r13), %xmm1
movsd 0x10(%r13), %xmm4
addsd %xmm1, %xmm1
movsd 0x20(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x18(%r13), %xmm5
movsd 0x20(%r13), %xmm6
movsd 0x28(%r13), %xmm7
leaq 0xe84d(%rip), %rdi      # 0x12182
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movb $0x8, %al
callq 0x3050
cmpb $0x1, 0x16967(%rip)     # 0x1a2bc
jne 0x3a0b
movsd (%r13), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%r13), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %rdi
callq 0xf140
addl %eax, %eax
cvtsi2sd %eax, %xmm0
movsd (%r13), %xmm1
addsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq 0x28(%rsp), %rdi
callq 0xf140
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x20(%rsp)
cvtsi2sdl 0x171bd(%rip), %xmm0 # 0x1ab70
callq 0x79d9
movsd (%r13), %xmm1
movsd 0x10(%r13), %xmm4
addsd %xmm1, %xmm1
movsd 0x20(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x18(%r13), %xmm5
movsd 0x20(%r13), %xmm6
movsd 0x28(%r13), %xmm7
leaq 0xe793(%rip), %rsi      # 0x12182
movq %r14, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
movb $0x8, %al
callq 0x3300
movq %r13, %rdi
callq 0x3260
movq 0x28(%rsp), %r13
testq %r13, %r13
je 0x3bc4
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
jmp 0x3bc4
leaq 0x50(%rsp), %rsi
leaq 0x450(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
movq %r13, %rdi
movq %r14, %r9
callq 0x5682
jmp 0x3a76
leaq 0x50(%rsp), %rsi
leaq 0x450(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
movq %r13, %rdi
movq %r14, %r9
callq 0x5c71
movsd %xmm0, 0x18(%rsp)
movsbl 0x16c71(%rip), %ebx     # 0x1a6f4
movsd (%r13), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x8(%r13), %xmm2
movsd %xmm2, 0x8(%rsp)
movapd %xmm1, %xmm2
addsd %xmm1, %xmm2
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
addsd %xmm1, %xmm2
movsd %xmm2, 0x40(%rsp)
cvtsi2sdl 0x170ad(%rip), %xmm0 # 0x1ab70
callq 0x79d9
movsd (%r13), %xmm3
movsd 0x10(%r13), %xmm4
addsd %xmm3, %xmm3
mulsd 0x18(%rsp), %xmm0
addsd %xmm0, %xmm3
movsd 0x18(%r13), %xmm5
movsd 0x20(%r13), %xmm6
movsd 0x28(%r13), %xmm7
leaq 0xe6e6(%rip), %rdi      # 0x121e1
movl %ebx, %esi
movsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movb $0x8, %al
callq 0x3050
cmpb $0x1, 0x1679f(%rip)     # 0x1a2bc
jne 0x3bbc
movsbl 0x16bca(%rip), %ebx     # 0x1a6f4
movsd (%r13), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x8(%r13), %xmm0
movsd %xmm0, 0x8(%rsp)
movapd %xmm1, %xmm0
addsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
cvtsi2sdl 0x1700e(%rip), %xmm0 # 0x1ab70
callq 0x79d9
movsd (%r13), %xmm1
movsd 0x10(%r13), %xmm4
addsd %xmm1, %xmm1
movsd 0x18(%rsp), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x18(%r13), %xmm5
movsd 0x20(%r13), %xmm6
movsd 0x28(%r13), %xmm7
leaq 0xe643(%rip), %rsi      # 0x121e1
movq %r14, %rdi
movl %ebx, %edx
movsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movb $0x8, %al
callq 0x3300
movq %r13, %rdi
callq 0x3260
subq %r12, %r15
leaq 0x166aa(%rip), %rdi     # 0x1a278
callq 0x88a6
callq 0x3120
movq 0x48(%rsp), %r12
subq %r12, %rax
movl $0xf4240, %ebx          # imm = 0xF4240
cqto
idivq %rbx
cvtsi2sd %rax, %xmm0
cvtsi2sd %r15, %xmm1
movsd 0xe40c(%rip), %xmm4     # 0x12008
divsd %xmm4, %xmm1
cvtsi2sdq 0x38(%rsp), %xmm2
divsd %xmm4, %xmm2
cvtsi2sdq 0x30(%rsp), %xmm3
divsd %xmm4, %xmm3
leaq 0xe62f(%rip), %rdi      # 0x1224c
movsd %xmm1, 0x18(%rsp)
movsd %xmm2, 0x10(%rsp)
movsd %xmm3, 0x8(%rsp)
movb $0x4, %al
callq 0x3050
cmpb $0x1, 0x1667f(%rip)     # 0x1a2bc
jne 0x3c85
callq 0x3120
subq %r12, %rax
cqto
idivq %rbx
cvtsi2sd %rax, %xmm0
leaq 0xe5f4(%rip), %rsi      # 0x1224c
movq %r14, %rdi
movsd 0x18(%rsp), %xmm1
movsd 0x10(%rsp), %xmm2
movsd 0x8(%rsp), %xmm3
movb $0x4, %al
callq 0x3300
cmpb $0x1, 0x16641(%rip)     # 0x1a2bc
jne 0x3c85
movq %r14, %rdi
callq 0x31e0
xorl %eax, %eax
addq $0x1058, %rsp           # imm = 0x1058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbl %al, %edx
movq 0x16335(%rip), %rax     # 0x19fd8
movq (%rax), %rdi
leaq 0xe4ac(%rip), %rsi      # 0x12159
xorl %eax, %eax
callq 0x3300
pushq $0x1
popq %rdi
callq 0x3270
movq %rax, %rbx
movl $0x110, %esi            # imm = 0x110
jmp 0x3cce
movq %rax, %rbx
movl $0xd0, %esi
movq %r13, %rdi
callq 0x3200
movq %rbx, %rdi
callq 0x33c0