// File: myudelson[P]hmm-scalable/trainhmmst.cpp
// Function: cross_validate(double*, char const*, char const*, long*, long*, _IO_FILE*)
NUMBER cross_validate(NUMBER* metrics, const char *filename, const char *model_file_name, clock_t *tm_fit, clock_t *tm_predict, FILE *fid_console) {//SEQ
//NUMBER cross_validate(NUMBER* metrics, const char *filename, const char *model_file_name, double *tm_fit, double *tm_predict, FILE *fid_console) {//PAR
    clock_t tm0;//SEQ
//    double _tm0;//PAR
    char *ch;
    NPAR f;
    NCAT g;
    NDAT t;
    FILE *fid = NULL; // file for storing prediction should that be necessary
    FILE *fid_folds = NULL; // file for reading/writing folds
    if(task.predictions>0) {  // if we have to write the predictions file
        fid = fopen(filename,"w");
        if(fid == NULL)
        {
            fprintf(stderr, "Can't write output model file %s\n",filename);
            if(task.duplicate_console==1) fprintf(fid_console, "Can't write output model file %s\n",filename);
            exit(1);
        }
    }
    // produce folds
    NPAR *folds = Calloc(NPAR, (size_t)task.nG);//[task.nG];
    NDAT *fold_counts = Calloc(NDAT, (size_t)task.cv_folds);
    
    srand ( (unsigned int)time(NULL) );
    // folds file
    if(task.cv_folds_file[0] > 0) { // file is specified
        if(task.cv_inout_flag=='i') {
            fid_folds = fopen(task.cv_folds_file,"r");
            if(fid_folds == NULL)
            {
                fprintf(stderr, "Can't open folds file for reading %s\n",filename);
                if(task.duplicate_console==1) fprintf(fid_console, "Can't open folds file for reading %s\n",filename);
                exit(1);
            }
            max_line_length = 1024;
            line = (char *)malloc((size_t)max_line_length);// Malloc(char,max_line_length);
        } else if(task.cv_inout_flag=='o') {
            fid_folds = fopen(task.cv_folds_file,"w");
            if(fid_folds == NULL)
            {
                fprintf(stderr, "Can't open folds file for writing %s\n",filename);
                if(task.duplicate_console==1) fprintf(fid_console, "Can't open folds file for writing %s\n",filename);
                exit(1);
            }
        }
    }
    for(g=0; g<task.nG; g++) {
        if( task.cv_folds_file[0]==0 || (task.cv_folds_file[0] > 0 && task.cv_inout_flag=='o') ) { // output or default
            folds[g] = (NPAR)(rand() % task.cv_folds);
            if(task.cv_folds_file[0] > 0 )
                fprintf(fid_folds,"%i\n",folds[g]); // write out
        } else if( (task.cv_folds_file[0] > 0 && task.cv_inout_flag=='i') ) {
            readline(fid_folds);//
            ch = strtok(line,"\t\n\r");
            if(ch == NULL) {
                fprintf(stderr, "Error reading input folds file (potentialy wrong number of rows)\n");
                if(task.duplicate_console==1) fprintf(fid_console, "Error reading input folds file (potentialy wrong number of rows)\n");
                exit(1);
            }
            folds[g] = (NPAR)(atoi(ch));
        }
    }
    if(task.cv_folds_file[0] > 0) { // file is specified
        fclose(fid_folds);
        if(task.cv_inout_flag=='i')
            free(line);
    }
	task.metrics_target_obs = task.cv_target_obs;

    // count number of items in each fold
    for(t=0; t<task.N; t++) fold_counts[ folds[task.dat_group[t]] ]++;

    
    // create and fit multiple problems
    HMMProblemSt* hmms[task.cv_folds];
    int q = task.quiet;
//    task.quiet = 1;
    for(f=0; f<task.cv_folds; f++) {
        switch(task.structure)
        {
            case STRUCTURE_SKILL: // Conjugate Gradient Descent
//            case STRUCTURE_GROUP: // Conjugate Gradient Descent
                hmms[f] = new HMMProblemSt(&task);
                break;
            case STRUCTURE_ELO: // Conjugate Gradient Descent
//            case STRUCTURE_GROUP: // Conjugate Gradient Descent
                hmms[f] = new HMMProblemEloSt(&task);
                break;
//            case STRUCTURE_SKABslc: // Conjugate Gradient Descent
//                hmms[f] = new HMMProblemSlicedAB(&param);
//                break;
//            case STRUCTURE_SKAslc: // Conjugate Gradient Descent
//                hmms[f] = new HMMProblemSlicedA(&param);
//                break;
////            case STRUCTURE_PIg: // Gradient Descent: PI by group, A,B by skill
////                hmm = new HMMProblemPiG(&param);
////                break;
//            case STRUCTURE_PIgk: // Gradient Descent, pLo=f(K,G), other by K
//                hmms[f] = new HMMProblemPiGK(&param);
//                break;
//            case STRUCTURE_PIgkww: // Gradient Descent, pLo=f(K,G), other by K
//                hmms[f] = new HMMProblemPiGKww(&param);
//                break;
//            case STRUCTURE_PIAgk: // Gradient Descent, pLo=f(K,G), pT=f(K,G), other by K
//                hmms[f] = new HMMProblemPiAGK(&param);
//                break;
//            case STRUCTURE_Agk: // Gradient Descent, pT=f(K,G), other by K
//                hmms[f] = new HMMProblemAGK(&param);
//                break;
//            case STRUCTURE_PIABgk: // Gradient Descent, pT=f(K,G), other by K
//                hmms[f] = new HMMProblemPiABGK(&param);
//                break;
//            case BKT_GD_T: // Gradient Descent with Transfer
//                hmm = new HMMProblemKT(&param);
//                break;
            default:
                fprintf(stderr,"Solver specified (%d) is not supported!\n",task.structure);
                exit(1);
                break;
        }
        // block respective data - do not fit the data belonging to the fold
        NPAR *saved_obs = Calloc(NPAR, (size_t)fold_counts[f]);
        NDAT count_saved = 0;
        for(t=0; t<task.N; t++) {
            if( folds[ task.dat_group[t]/*->get(t)*/ ] == f ) {
                saved_obs[count_saved++] = task.dat_obs[t];
                task.dat_obs[t] = -1;//->set(t, -1);
            }
        }


        // now compute
        tm0 = clock(); //SEQ
//        _tm0 = omp_get_wtime(); //PAR
        hmms[f]->fit();
        *(tm_fit) += (clock_t)(clock()- tm0);//SEQ
//        *(tm_fit) += omp_get_wtime()-_tm0;//PAR
        
        // write model
        char fname[1024];
        sprintf(fname,"%s_%i",model_file_name,f);
        hmms[f]->toFile(fname);
        
        // UN-block respective data
        count_saved = 0;
        for(t=0; t<task.N; t++)
            if( folds[ task.dat_group[t]/*->get(t)*/ ] == f )
                task.dat_obs[t]=saved_obs[count_saved++];
        free(saved_obs);
        printf("fold %d is done\n",f+1);
        if(task.duplicate_console==1) fprintf(fid_console, "fold %d is done\n",f+1);
    }
    task.quiet = (NPAR)q;
    
    tm0 = clock();//SEQ
//    _tm0 = omp_get_wtime();//PAR
	
	// new prediction
	//		create a general fold-identifying array
	NPAR *dat_fold = Calloc(NPAR, task.N);
	for(NDAT t=0; t<task.N; t++) dat_fold[t] = folds[ task.dat_group[t] ];
	//		predict
	hmms[0]->predict(metrics, filename,
                     //task.N, task.dat_obs, task.dat_group, task.dat_skill, task.dat_skill_stacked, task.dat_skill_rcount, task.dat_skill_rix,
                     &task,
                     hmms, task.cv_folds/*nhmms*/, dat_fold);
	
    printf("Cross-validation is done wrong, if A or B matrices are 'sliced'\n");
    
//    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 {
//        HMMProblem::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, &hmm, 1, NULL);
//    }
    
    free(dat_fold);
	
	*(tm_predict) += (clock_t)(clock()- tm0);//SEQ
//    *(tm_predict) += omp_get_wtime()-_tm0;//PAR
	
	
    // delete problems
    NUMBER n_par = 0;
    for(f=0; f<task.cv_folds; f++) {
        n_par += hmms[f]->getModelParamN();
        delete hmms[f];
    }
    n_par /= task.cv_folds;
	
    free(folds);
    free(fold_counts);
	
	return (n_par);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4f0, %rsp            # imm = 0x4F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
cmpl $0x0, 0x213fe(%rip)     # 0x27378
jle 0x5fe1
movq -0x10(%rbp), %rdi
leaq 0x181bd(%rip), %rsi     # 0x1e144
callq 0x3340
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x5fdf
movq 0x2103a(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x19eb1(%rip), %rsi     # 0x1fe5d
movb $0x0, %al
callq 0x33f0
movsbl 0x21392(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x5fd5
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x19e8f(%rip), %rsi     # 0x1fe5d
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
jmp 0x5fe1
movslq 0x21c24(%rip), %rdi     # 0x27c0c
movl $0x1, %esi
callq 0x3180
movq %rax, -0x68(%rbp)
movsbq 0x21786(%rip), %rdi     # 0x27784
movl $0x4, %esi
callq 0x3180
movq %rax, -0x70(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x3260
movl %eax, %edi
callq 0x3280
movsbl 0x21764(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x6147
movsbl 0x21b54(%rip), %eax     # 0x27b87
cmpl $0x69, %eax
jne 0x60c8
leaq 0x212c5(%rip), %rdi     # 0x27308
addq $0x47f, %rdi            # imm = 0x47F
leaq 0x19e2e(%rip), %rsi     # 0x1fe7f
callq 0x3340
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x60a9
movq 0x20f70(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x19e0b(%rip), %rsi     # 0x1fe81
movb $0x0, %al
callq 0x33f0
movsbl 0x212c8(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x609f
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x19de9(%rip), %rsi     # 0x1fe81
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
movl $0x400, 0x21be5(%rip)   # imm = 0x400
movslq 0x21bde(%rip), %rdi     # 0x27c98
callq 0x33b0
movq %rax, 0x21bda(%rip)     # 0x27ca0
jmp 0x6145
movsbl 0x21ab8(%rip), %eax     # 0x27b87
cmpl $0x6f, %eax
jne 0x6143
leaq 0x2122d(%rip), %rdi     # 0x27308
addq $0x47f, %rdi            # imm = 0x47F
leaq 0x1805b(%rip), %rsi     # 0x1e144
callq 0x3340
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x6141
movq 0x20ed8(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x19d99(%rip), %rsi     # 0x1fea7
movb $0x0, %al
callq 0x33f0
movsbl 0x21230(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x6137
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x19d77(%rip), %rsi     # 0x1fea7
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
jmp 0x6143
jmp 0x6145
jmp 0x6147
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl 0x21ab5(%rip), %eax     # 0x27c0c
jge 0x6275
movsbl 0x21623(%rip), %eax     # 0x27787
cmpl $0x0, %eax
je 0x6181
movsbl 0x21617(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x61ca
movsbl 0x21a0b(%rip), %eax     # 0x27b87
cmpl $0x6f, %eax
jne 0x61ca
callq 0x30c0
movsbl 0x215f7(%rip), %ecx     # 0x27784
cltd
idivl %ecx
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb %dl, (%rax,%rcx)
movsbl 0x215e5(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x61c5
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %edx
leaq 0x1a07c(%rip), %rsi     # 0x2023a
movb $0x0, %al
callq 0x33f0
jmp 0x6265
movsbl 0x215b6(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x6263
movsbl 0x219a6(%rip), %eax     # 0x27b87
cmpl $0x69, %eax
jne 0x6263
movq -0x60(%rbp), %rdi
callq 0x78c0
movq 0x21aaa(%rip), %rdi     # 0x27ca0
leaq 0x1925c(%rip), %rsi     # 0x1f459
callq 0x3440
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x624d
movq 0x20dc4(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
leaq 0x19caf(%rip), %rsi     # 0x1fecd
movb $0x0, %al
callq 0x33f0
movsbl 0x21120(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x6243
movq -0x30(%rbp), %rdi
leaq 0x19c91(%rip), %rsi     # 0x1fecd
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
movq -0x40(%rbp), %rdi
callq 0x3430
movb %al, %dl
movq -0x68(%rbp), %rax
movslq -0x48(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x6265
jmp 0x6267
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x614e
movsbl 0x2150b(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x62a4
movq -0x60(%rbp), %rdi
callq 0x3290
movsbl 0x218f6(%rip), %eax     # 0x27b87
cmpl $0x69, %eax
jne 0x62a2
movq 0x21a03(%rip), %rdi     # 0x27ca0
callq 0x3350
jmp 0x62a4
movb 0x214dc(%rip), %al      # 0x27786
movb %al, 0x210c4(%rip)      # 0x27374
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl 0x21940(%rip), %eax     # 0x27c00
jge 0x62f2
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x218c7(%rip), %rdx     # 0x27b98
movslq -0x4c(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
movsbq (%rcx,%rdx), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x62b7
movzbl 0x2148b(%rip), %edx     # 0x27784
movl %edx, %eax
movq %rsp, %rcx
movq %rcx, -0x78(%rbp)
movl %edx, %ecx
leal 0xf(,%rcx,8), %ecx
andl $-0x10, %ecx
movl %ecx, %edx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x4d0(%rbp)
movq %rcx, %rsp
movq %rax, -0x80(%rbp)
movsbl 0x21029(%rip), %eax     # 0x27354
movl %eax, -0x84(%rbp)
movb $0x0, -0x41(%rbp)
movsbl -0x41(%rbp), %eax
movsbl 0x21444(%rip), %ecx     # 0x27784
cmpl %ecx, %eax
jge 0x6640
movsbl 0x21007(%rip), %eax     # 0x27356
movl %eax, -0x4d4(%rbp)
subl $0x1, %eax
je 0x636c
jmp 0x635c
movl -0x4d4(%rbp), %eax
subl $0xe, %eax
je 0x63d5
jmp 0x643b
movl $0xd0, %edi
callq 0x32a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4e0(%rbp)
leaq 0x20f7e(%rip), %rsi     # 0x27308
callq 0x14b20
jmp 0x6391
movq -0x4d0(%rbp), %rax
movq -0x4e0(%rbp), %rdx
movsbq -0x41(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x6464
movq -0x4e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
movl $0xd0, %esi
callq 0x32b0
jmp 0x67e0
movl $0x110, %edi            # imm = 0x110
callq 0x32a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4e8(%rbp)
leaq 0x20f15(%rip), %rsi     # 0x27308
callq 0x1d1b0
jmp 0x63fa
movq -0x4d0(%rbp), %rax
movq -0x4e8(%rbp), %rdx
movsbq -0x41(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x6464
movq -0x4e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
movl $0x110, %esi            # imm = 0x110
callq 0x32b0
jmp 0x67e0
movq 0x20b96(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
movsbl 0x20f0a(%rip), %edx     # 0x27356
leaq 0x17d3a(%rip), %rsi     # 0x1e18d
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
movq -0x70(%rbp), %rax
movsbq -0x41(%rbp), %rcx
movslq (%rax,%rcx,4), %rdi
movl $0x1, %esi
callq 0x3180
movq %rax, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl 0x21764(%rip), %eax     # 0x27c00
jge 0x6505
movq -0x68(%rbp), %rax
movq 0x216ef(%rip), %rcx     # 0x27b98
movslq -0x4c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x41(%rbp), %ecx
cmpl %ecx, %eax
jne 0x64f8
movq 0x216c4(%rip), %rax     # 0x27b88
movslq -0x4c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0xa0(%rbp), %rax
movl -0xa4(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0xa4(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq 0x21698(%rip), %rax     # 0x27b88
movslq -0x4c(%rbp), %rcx
movb $-0x1, (%rax,%rcx)
jmp 0x64fa
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6493
callq 0x3190
movq %rax, %rcx
movq -0x4d0(%rbp), %rax
movq %rcx, -0x38(%rbp)
movsbq -0x41(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
callq 0x3190
movq %rax, %rcx
subq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
leaq -0x4b0(%rbp), %rdi
movq -0x18(%rbp), %rdx
movsbl -0x41(%rbp), %ecx
leaq 0x199bc(%rip), %rsi     # 0x1ff0f
movb $0x0, %al
callq 0x30b0
movq -0x4d0(%rbp), %rax
movsbq -0x41(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x4b0(%rbp), %rsi
movq (%rdi), %rax
callq *0x40(%rax)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl 0x2166f(%rip), %eax     # 0x27c00
jge 0x65eb
movq -0x68(%rbp), %rax
movq 0x215fa(%rip), %rcx     # 0x27b98
movslq -0x4c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x41(%rbp), %ecx
cmpl %ecx, %eax
jne 0x65de
movq -0xa0(%rbp), %rax
movl -0xa4(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0xa4(%rbp)
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq 0x215b1(%rip), %rax     # 0x27b88
movslq -0x4c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x65e0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6588
movq -0xa0(%rbp), %rdi
callq 0x3350
movsbl -0x41(%rbp), %esi
addl $0x1, %esi
leaq 0x19910(%rip), %rdi     # 0x1ff15
movb $0x0, %al
callq 0x3060
movsbl 0x20d39(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x6631
movq -0x30(%rbp), %rdi
movsbl -0x41(%rbp), %edx
addl $0x1, %edx
leaq 0x198eb(%rip), %rsi     # 0x1ff15
movb $0x0, %al
callq 0x33f0
jmp 0x6633
movb -0x41(%rbp), %al
addb $0x1, %al
movb %al, -0x41(%rbp)
jmp 0x6335
movl -0x84(%rbp), %eax
movb %al, 0x20d08(%rip)      # 0x27354
callq 0x3190
movq %rax, -0x38(%rbp)
movslq 0x215a4(%rip), %rdi     # 0x27c00
movl $0x1, %esi
callq 0x3180
movq %rax, -0x4b8(%rbp)
movl $0x0, -0x4bc(%rbp)
movl -0x4bc(%rbp), %eax
cmpl 0x2157d(%rip), %eax     # 0x27c00
jge 0x66c0
movq -0x68(%rbp), %rax
movq 0x21508(%rip), %rcx     # 0x27b98
movslq -0x4bc(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movb (%rax,%rcx), %dl
movq -0x4b8(%rbp), %rax
movslq -0x4bc(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x4bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4bc(%rbp)
jmp 0x6677
movq -0x4d0(%rbp), %rcx
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movb 0x210af(%rip), %al      # 0x27784
movq -0x4b8(%rbp), %r9
leaq 0x20c25(%rip), %rdx     # 0x27308
movsbl %al, %r8d
callq 0x18c10
leaq 0x19833(%rip), %rdi     # 0x1ff26
movb $0x0, %al
callq 0x3060
movq -0x4b8(%rbp), %rdi
callq 0x3350
callq 0x3190
movq %rax, %rcx
subq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
xorps %xmm0, %xmm0
movsd %xmm0, -0x4c8(%rbp)
movb $0x0, -0x41(%rbp)
movsbl -0x41(%rbp), %eax
movsbl 0x2104e(%rip), %ecx     # 0x27784
cmpl %ecx, %eax
jge 0x679b
movq -0x4d0(%rbp), %rax
movsbq -0x41(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x19440
movl %eax, %ecx
movq -0x4d0(%rbp), %rax
cvtsi2sd %ecx, %xmm0
addsd -0x4c8(%rbp), %xmm0
movsd %xmm0, -0x4c8(%rbp)
movsbq -0x41(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4f0(%rbp)
cmpq $0x0, %rax
je 0x678f
movq -0x4f0(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x6791
movb -0x41(%rbp), %al
addb $0x1, %al
movb %al, -0x41(%rbp)
jmp 0x672b
movsbl 0x20fe2(%rip), %eax     # 0x27784
cvtsi2sd %eax, %xmm1
movsd -0x4c8(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x4c8(%rbp)
movq -0x68(%rbp), %rdi
callq 0x3350
movq -0x70(%rbp), %rdi
callq 0x3350
movsd -0x4c8(%rbp), %xmm0
movq -0x78(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x34c0
nopl (%rax)