// File: myudelson[P]hmm-scalable/trainhmm.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,k;
    FILE *fid = NULL; // file for storing prediction should that be necessary
    FILE *fid_folds = NULL; // file for reading/writing folds
    if(param.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(param.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)param.nG);//[param.nG];
    srand ( (unsigned int)time(NULL) );
    // folds file
    if(param.cv_folds_file[0] > 0) { // file is specified
        if(param.cv_inout_flag=='i') {
            fid_folds = fopen(param.cv_folds_file,"r");
            if(fid_folds == NULL)
            {
                fprintf(stderr, "Can't open folds file for reading %s\n",filename);
                if(param.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(param.cv_inout_flag=='o') {
            fid_folds = fopen(param.cv_folds_file,"w");
            if(fid_folds == NULL)
            {
                fprintf(stderr, "Can't open folds file for writing %s\n",filename);
                if(param.duplicate_console==1) fprintf(fid_console, "Can't open folds file for writing %s\n",filename);
                exit(1);
            }
        }
    }
    for(g=0; g<param.nG; g++) {
        if( param.cv_folds_file[0]==0 || (param.cv_folds_file[0] > 0 && param.cv_inout_flag=='o') ) { // output or default
            folds[g] = (NPAR)(rand() % param.cv_folds);
            if(param.cv_folds_file[0] > 0 )
                fprintf(fid_folds,"%i\n",folds[g]); // write out
        } else if( (param.cv_folds_file[0] > 0 && param.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(param.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(param.cv_folds_file[0] > 0) { // file is specified
        fclose(fid_folds);
        if(param.cv_inout_flag=='i')
            free(line);
    }
	param.metrics_target_obs = param.cv_target_obs;

    
    // create and fit multiple problems
    HMMProblem* hmms[param.cv_folds];
    int q = param.quiet;
//    param.quiet = 1;
    for(f=0; f<param.cv_folds; f++) {
        switch(param.structure)
        {
            case STRUCTURE_SKILL: // Conjugate Gradient Descent
//            case STRUCTURE_GROUP: // Conjugate Gradient Descent
                hmms[f] = new HMMProblem(&param);
                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;
        }
        // block respective data - do not fit the data belonging to the fold
        for(g=0; g<param.nG; g++) // for all groups
            if(folds[g]==f) { // if in current fold
                for(k=0; k<param.g_numk[g]; k++) // for all skills in it
                    param.g_k_data[g][k]->cnt = 1; // block it
            }
        // block nulls
        for(NCAT x=0; x<param.n_null_skill_group; x++) {
            if( param.null_skills[x].g == f)
                param.null_skills[x].cnt = 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
        for(g=0; g<param.nG; g++) // for all groups
            if(folds[g]==f) { // if in current fold
                for(k=0; k<param.g_numk[g]; k++) // for all skills in it
                    param.g_k_data[g][k]->cnt = 0; // UN-block it
            }
        // UN-block nulls
        for(NCAT x=0; x<param.n_null_skill_group; x++) {
            if( param.null_skills[x].g == f)
                param.null_skills[x].cnt = 0;
        }
//        if(q == 0) {
            printf("fold %d is done\n",f+1);
            if(param.duplicate_console==1) fprintf(fid_console,"fold %d is done\n",f+1);
//        }
    }
    param.quiet = (NPAR)q;
    
    tm0 = clock();//SEQ
//    _tm0 = omp_get_wtime();//PAR
	
	// new prediction
	//		create a general fold-identifying array
	NPAR *dat_fold = Calloc(NPAR, param.N);
	for(NDAT t=0; t<param.N; t++) dat_fold[t] = folds[ param.dat_group[t] ];
	//		predict
	hmms[0]->predict(metrics, filename, param.dat_obs, param.dat_group, param.dat_skill, param.dat_skill_stacked, param.dat_skill_rcount, param.dat_skill_rix, hmms, param.cv_folds/*nhmms*/, dat_fold);
	
    printf("Cross-validation is done wrong, if A or B matrices are 'sliced'\n");
    
//    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);
//    }
    
    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<param.cv_folds; f++) {
        n_par += hmms[f]->getNparams();
        delete hmms[f];
    }
    n_par /= param.cv_folds;
	
    free(folds);
	
	return (n_par);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x510, %rsp            # imm = 0x510
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
cmpl $0x0, 0x57f5b(%rip)     # 0x613b8
jle 0x94c4
movq -0x20(%rbp), %rdi
leaq 0x4ad9e(%rip), %rsi     # 0x54208
callq 0x53a0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x94c2
movq 0x57b57(%rip), %rax     # 0x60fd8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x4ca55(%rip), %rsi     # 0x55ee4
movb $0x0, %al
callq 0x5470
movsbl 0x57eef(%rip), %eax     # 0x6138c
cmpl $0x1, %eax
jne 0x94b8
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x4ca33(%rip), %rsi     # 0x55ee4
movb $0x0, %al
callq 0x5470
movl $0x1, %edi
callq 0x53c0
jmp 0x94c4
movslq 0x58749(%rip), %rdi     # 0x61c14
movl $0x1, %esi
callq 0x5190
movq %rax, -0x78(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x52a0
movl %eax, %edi
callq 0x52c0
movsbl 0x582d7(%rip), %eax     # 0x617c7
cmpl $0x0, %eax
jle 0x9614
movsbl 0x586c7(%rip), %eax     # 0x61bc7
cmpl $0x69, %eax
jne 0x9595
leaq 0x57e48(%rip), %rdi     # 0x61358
addq $0x46f, %rdi            # imm = 0x46F
leaq 0x4c9e8(%rip), %rsi     # 0x55f06
callq 0x53a0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x9576
movq 0x57aa3(%rip), %rax     # 0x60fd8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x4c9c5(%rip), %rsi     # 0x55f08
movb $0x0, %al
callq 0x5470
movsbl 0x57e3b(%rip), %eax     # 0x6138c
cmpl $0x1, %eax
jne 0x956c
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x4c9a3(%rip), %rsi     # 0x55f08
movb $0x0, %al
callq 0x5470
movl $0x1, %edi
callq 0x53c0
movl $0x400, 0x58780(%rip)   # imm = 0x400
movslq 0x58779(%rip), %rdi     # 0x61d00
callq 0x5410
movq %rax, 0x58775(%rip)     # 0x61d08
jmp 0x9612
movsbl 0x5862b(%rip), %eax     # 0x61bc7
cmpl $0x6f, %eax
jne 0x9610
leaq 0x57db0(%rip), %rdi     # 0x61358
addq $0x46f, %rdi            # imm = 0x46F
leaq 0x4ac52(%rip), %rsi     # 0x54208
callq 0x53a0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x960e
movq 0x57a0b(%rip), %rax     # 0x60fd8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x4c953(%rip), %rsi     # 0x55f2e
movb $0x0, %al
callq 0x5470
movsbl 0x57da3(%rip), %eax     # 0x6138c
cmpl $0x1, %eax
jne 0x9604
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x4c931(%rip), %rsi     # 0x55f2e
movb $0x0, %al
callq 0x5470
movl $0x1, %edi
callq 0x53c0
jmp 0x9610
jmp 0x9612
jmp 0x9614
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl 0x585f0(%rip), %eax     # 0x61c14
jge 0x9742
movsbl 0x58196(%rip), %eax     # 0x617c7
cmpl $0x0, %eax
je 0x964e
movsbl 0x5818a(%rip), %eax     # 0x617c7
cmpl $0x0, %eax
jle 0x9697
movsbl 0x5857e(%rip), %eax     # 0x61bc7
cmpl $0x6f, %eax
jne 0x9697
callq 0x50d0
movsbl 0x5816a(%rip), %ecx     # 0x617c4
cltd
idivl %ecx
movq -0x78(%rbp), %rax
movslq -0x58(%rbp), %rcx
movb %dl, (%rax,%rcx)
movsbl 0x58158(%rip), %eax     # 0x617c7
cmpl $0x0, %eax
jle 0x9692
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rax
movslq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %edx
leaq 0x4cc2b(%rip), %rsi     # 0x562b6
movb $0x0, %al
callq 0x5470
jmp 0x9732
movsbl 0x58129(%rip), %eax     # 0x617c7
cmpl $0x0, %eax
jle 0x9730
movsbl 0x58519(%rip), %eax     # 0x61bc7
cmpl $0x69, %eax
jne 0x9730
movq -0x70(%rbp), %rdi
callq 0xb520
movq 0x58645(%rip), %rdi     # 0x61d08
leaq 0x4be43(%rip), %rsi     # 0x5550d
callq 0x54d0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x971a
movq 0x578f7(%rip), %rax     # 0x60fd8
movq (%rax), %rdi
leaq 0x4c869(%rip), %rsi     # 0x55f54
movb $0x0, %al
callq 0x5470
movsbl 0x57c93(%rip), %eax     # 0x6138c
cmpl $0x1, %eax
jne 0x9710
movq -0x40(%rbp), %rdi
leaq 0x4c84b(%rip), %rsi     # 0x55f54
movb $0x0, %al
callq 0x5470
movl $0x1, %edi
callq 0x53c0
movq -0x50(%rbp), %rdi
callq 0x54c0
movb %al, %dl
movq -0x78(%rbp), %rax
movslq -0x58(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x9732
jmp 0x9734
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x961b
movsbl 0x5807e(%rip), %eax     # 0x617c7
cmpl $0x0, %eax
jle 0x9771
movq -0x70(%rbp), %rdi
callq 0x52f0
movsbl 0x58469(%rip), %eax     # 0x61bc7
cmpl $0x69, %eax
jne 0x976f
movq 0x5859e(%rip), %rdi     # 0x61d08
callq 0x53b0
jmp 0x9771
movb 0x5804f(%rip), %al      # 0x617c6
movb %al, 0x57c37(%rip)      # 0x613b4
movzbl 0x58040(%rip), %edx     # 0x617c4
movl %edx, %eax
movq %rsp, %rcx
movq %rcx, -0x80(%rbp)
movl %edx, %ecx
leal 0xf(,%rcx,8), %ecx
andl $-0x10, %ecx
movl %ecx, %edx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x4c8(%rbp)
movq %rcx, %rsp
movq %rax, -0x88(%rbp)
movsbl 0x57bdb(%rip), %eax     # 0x61394
movl %eax, -0x8c(%rbp)
movb $0x0, -0x51(%rbp)
movsbl -0x51(%rbp), %eax
movsbl 0x57ff6(%rip), %ecx     # 0x617c4
cmpl %ecx, %eax
jge 0x9dc6
movsbl 0x57bb9(%rip), %eax     # 0x61396
decl %eax
movl %eax, %ecx
movq %rcx, -0x4d0(%rbp)
subl $0xb, %eax
ja 0x9b4d
movq -0x4d0(%rbp), %rax
leaq 0x4a979(%rip), %rcx     # 0x54178
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x90, %edi
callq 0x5300
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4d8(%rbp)
leaq 0x57b32(%rip), %rsi     # 0x61358
callq 0x1e660
jmp 0x982d
movq -0x4c8(%rbp), %rax
movq -0x4d8(%rbp), %rdx
movsbq -0x51(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x9b4d
movq -0x4d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
movl $0x90, %esi
callq 0x5310
jmp 0x9fa5
movl $0xd0, %edi
callq 0x5300
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4e0(%rbp)
leaq 0x57ac9(%rip), %rsi     # 0x61358
callq 0x3d840
jmp 0x9896
movq -0x4c8(%rbp), %rax
movq -0x4e0(%rbp), %rdx
movsbq -0x51(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x9b4d
movq -0x4e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
movl $0xd0, %esi
callq 0x5310
jmp 0x9fa5
movl $0xa8, %edi
callq 0x5300
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4e8(%rbp)
leaq 0x57a60(%rip), %rsi     # 0x61358
callq 0x47550
jmp 0x98ff
movq -0x4c8(%rbp), %rax
movq -0x4e8(%rbp), %rdx
movsbq -0x51(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x9b4d
movq -0x4e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
movl $0xa8, %esi
callq 0x5310
jmp 0x9fa5
movl $0x98, %edi
callq 0x5300
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4f0(%rbp)
leaq 0x579f7(%rip), %rsi     # 0x61358
callq 0x2cfa0
jmp 0x9968
movq -0x4c8(%rbp), %rax
movq -0x4f0(%rbp), %rdx
movsbq -0x51(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x9b4d
movq -0x4f0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
movl $0x98, %esi
callq 0x5310
jmp 0x9fa5
movl $0xa0, %edi
callq 0x5300
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4f8(%rbp)
leaq 0x5798e(%rip), %rsi     # 0x61358
callq 0x2fea0
jmp 0x99d1
movq -0x4c8(%rbp), %rax
movq -0x4f8(%rbp), %rdx
movsbq -0x51(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x9b4d
movq -0x4f8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
movl $0xa0, %esi
callq 0x5310
jmp 0x9fa5
movl $0xa0, %edi
callq 0x5300
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x500(%rbp)
leaq 0x57925(%rip), %rsi     # 0x61358
callq 0x35eb0
jmp 0x9a3a
movq -0x4c8(%rbp), %rax
movq -0x500(%rbp), %rdx
movsbq -0x51(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x9b4d
movq -0x500(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
movl $0xa0, %esi
callq 0x5310
jmp 0x9fa5
movl $0x98, %edi
callq 0x5300
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x508(%rbp)
leaq 0x578bc(%rip), %rsi     # 0x61358
callq 0x32c80
jmp 0x9aa3
movq -0x4c8(%rbp), %rax
movq -0x508(%rbp), %rdx
movsbq -0x51(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x9b4d
movq -0x508(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
movl $0x98, %esi
callq 0x5310
jmp 0x9fa5
movl $0xa8, %edi
callq 0x5300
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x510(%rbp)
leaq 0x57853(%rip), %rsi     # 0x61358
callq 0x396f0
jmp 0x9b0c
movq -0x4c8(%rbp), %rax
movq -0x510(%rbp), %rdx
movsbq -0x51(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x9b4d
movq -0x510(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
movl $0xa8, %esi
callq 0x5310
jmp 0x9fa5
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl 0x580b7(%rip), %eax     # 0x61c14
jge 0x9bc5
movq -0x78(%rbp), %rax
movslq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x51(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9bb8
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq 0x580d4(%rip), %rcx     # 0x61c58
movslq -0x58(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x9bb6
movq 0x580d4(%rip), %rax     # 0x61c68
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, 0x4(%rax)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x9b7a
jmp 0x9bb8
jmp 0x9bba
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x9b54
movl $0x0, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
cmpl 0x58055(%rip), %eax     # 0x61c30
jge 0x9c2c
movq 0x58044(%rip), %rax     # 0x61c28
movslq -0xa0(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x5c(%rax), %eax
movsbl -0x51(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9c19
movq 0x58024(%rip), %rax     # 0x61c28
movslq -0xa0(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x4(%rax)
jmp 0x9c1b
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x9bcf
callq 0x51a0
movq %rax, %rcx
movq -0x4c8(%rbp), %rax
movq %rcx, -0x48(%rbp)
movsbq -0x51(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
callq 0x51a0
movq %rax, %rcx
subq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
leaq -0x4a0(%rbp), %rdi
movq -0x28(%rbp), %rdx
movsbl -0x51(%rbp), %ecx
leaq 0x4c31c(%rip), %rsi     # 0x55f96
movb $0x0, %al
callq 0x50c0
movq -0x4c8(%rbp), %rax
movsbq -0x51(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x4a0(%rbp), %rsi
movq (%rdi), %rax
callq *0x40(%rax)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl 0x57f66(%rip), %eax     # 0x61c14
jge 0x9d16
movq -0x78(%rbp), %rax
movslq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x51(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9d09
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq 0x57f83(%rip), %rcx     # 0x61c58
movslq -0x58(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x9d07
movq 0x57f83(%rip), %rax     # 0x61c68
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x0, 0x4(%rax)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x9ccb
jmp 0x9d09
jmp 0x9d0b
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x9ca5
movl $0x0, -0x4a4(%rbp)
movl -0x4a4(%rbp), %eax
cmpl 0x57f04(%rip), %eax     # 0x61c30
jge 0x9d7d
movq 0x57ef3(%rip), %rax     # 0x61c28
movslq -0x4a4(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl 0x5c(%rax), %eax
movsbl -0x51(%rbp), %ecx
cmpl %ecx, %eax
jne 0x9d6a
movq 0x57ed3(%rip), %rax     # 0x61c28
movslq -0x4a4(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x4(%rax)
jmp 0x9d6c
movl -0x4a4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4a4(%rbp)
jmp 0x9d20
movsbl -0x51(%rbp), %esi
addl $0x1, %esi
leaq 0x4c211(%rip), %rdi     # 0x55f9c
movb $0x0, %al
callq 0x5060
movsbl 0x575f3(%rip), %eax     # 0x6138c
cmpl $0x1, %eax
jne 0x9db7
movq -0x40(%rbp), %rdi
movsbl -0x51(%rbp), %edx
addl $0x1, %edx
leaq 0x4c1ec(%rip), %rsi     # 0x55f9c
movb $0x0, %al
callq 0x5470
jmp 0x9db9
movb -0x51(%rbp), %al
addb $0x1, %al
movb %al, -0x51(%rbp)
jmp 0x97c3
movl -0x8c(%rbp), %eax
movb %al, 0x575c2(%rip)      # 0x61394
callq 0x51a0
movq %rax, -0x48(%rbp)
movslq 0x57e26(%rip), %rdi     # 0x61c08
movl $0x1, %esi
callq 0x5190
movq %rax, -0x4b0(%rbp)
movl $0x0, -0x4b4(%rbp)
movl -0x4b4(%rbp), %eax
cmpl 0x57dff(%rip), %eax     # 0x61c08
jge 0x9e46
movq -0x78(%rbp), %rax
movq 0x57dba(%rip), %rcx     # 0x61bd0
movslq -0x4b4(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movb (%rax,%rcx), %dl
movq -0x4b0(%rbp), %rax
movslq -0x4b4(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x4b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4b4(%rbp)
jmp 0x9dfd
movq -0x4c8(%rbp), %r11
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq 0x57d6c(%rip), %rdx     # 0x61bc8
movq 0x57d6d(%rip), %rcx     # 0x61bd0
movq 0x57d6e(%rip), %r8      # 0x61bd8
movq 0x57d6f(%rip), %r9      # 0x61be0
movq 0x57d70(%rip), %r14     # 0x61be8
movq 0x57d71(%rip), %rbx     # 0x61bf0
movb 0x5793e(%rip), %r10b    # 0x617c4
movq -0x4b0(%rbp), %rax
subq $0x30, %rsp
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movsbl %r10b, %r10d
movl %r10d, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x224d0
addq $0x30, %rsp
leaq 0x4c0f0(%rip), %rdi     # 0x55fad
movb $0x0, %al
callq 0x5060
movq -0x4b0(%rbp), %rdi
callq 0x53b0
callq 0x51a0
movq %rax, %rcx
subq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
xorps %xmm0, %xmm0
movsd %xmm0, -0x4c0(%rbp)
movb $0x0, -0x51(%rbp)
movsbl -0x51(%rbp), %eax
movsbl 0x578c4(%rip), %ecx     # 0x617c4
cmpl %ecx, %eax
jge 0x9f65
movq -0x4c8(%rbp), %rax
movsbq -0x51(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x23820
movl %eax, %ecx
movq -0x4c8(%rbp), %rax
cvtsi2sd %ecx, %xmm0
addsd -0x4c0(%rbp), %xmm0
movsd %xmm0, -0x4c0(%rbp)
movsbq -0x51(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x518(%rbp)
cmpq $0x0, %rax
je 0x9f59
movq -0x518(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x9f5b
movb -0x51(%rbp), %al
addb $0x1, %al
movb %al, -0x51(%rbp)
jmp 0x9ef5
movsbl 0x57858(%rip), %eax     # 0x617c4
cvtsi2sd %eax, %xmm1
movsd -0x4c0(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x4c0(%rbp)
movq -0x78(%rbp), %rdi
callq 0x53b0
movsd -0x4c0(%rbp), %xmm0
movq -0x80(%rbp), %rax
movq %rax, %rsp
leaq -0x10(%rbp), %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq -0x98(%rbp), %rdi
callq 0x5570
nopw %cs:(%rax,%rax)