// File: myudelson[P]hmm-scalable/trainhmmst.cpp
// Function: cross_validate_item(double*, char const*, char const*, long*, long*, _IO_FILE*)
NUMBER cross_validate_item(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_item(NUMBER* metrics, const char *filename, const char *model_file_name, double *tm_fit, double *tm_predict, FILE *fid_console) {//PAR
    NPAR f;
    NCAT I; // item
    NDAT t;
    clock_t tm0;//SEQ
//    double _tm0;//PAR
    char *ch;
    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.nI);
    NDAT *fold_counts = Calloc(NDAT, (size_t)task.cv_folds);
    srand ( (unsigned int)time(NULL) ); // randomize

    // 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(I=0; I<task.nI; I++) {
        if( task.cv_folds_file[0]==0 || (task.cv_folds_file[0] > 0 && task.cv_inout_flag=='o') ) { // output or default
            folds[I] = (NPAR)(rand() % task.cv_folds); // produce folds
            if(task.cv_folds_file[0] > 0 )
                fprintf(fid_folds,"%i\n",folds[I]); // 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[I] = (NPAR)(atoi(ch));
        }
    }
    if(task.cv_folds_file[0] > 0) { // file is specified
        fclose(fid_folds);
        if(task.cv_inout_flag=='i')
            free(line);
    }
    
    // count number of items in each fold
    for(t=0; t<task.N; t++) fold_counts[ folds[task.dat_item[t]/*->get(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
                hmms[f] = new HMMProblemEloSt(&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
//                hmms[f] = new HMMProblemSlicedAB(&param);
//                break;
//            case STRUCTURE_SKAslc: // Conjugate Gradient Descent
//                hmms[f] = new HMMProblemSlicedA(&param);
//                break;
//            case STRUCTURE_PIgk: // Gradient Descent, pLo=f(K,G), other by K
//                hmms[f] = new HMMProblemPiGK(&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, pLo=f(K,G), 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_item[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_item[t]/*->get(t)*/ ] == f )
                task.dat_obs[t]=saved_obs[count_saved++];//->set(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);
    }
    free(fold_counts);
    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_item[t] ];
	//		predict
	HMMProblemSt::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");
    
    free(dat_fold);
	
	*(tm_predict) += (clock_t)(clock()- tm0);//SEQ
//    *(tm_predict) += omp_get_wtime()-_tm0;//PAR
    
    // delete problems
    NCAT 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);

	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, 0x20b4e(%rip)     # 0x27378
jle 0x6891
movq -0x10(%rbp), %rdi
leaq 0x1790d(%rip), %rsi     # 0x1e144
callq 0x3340
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x688f
movq 0x2078a(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x19601(%rip), %rsi     # 0x1fe5d
movb $0x0, %al
callq 0x33f0
movsbl 0x20ae2(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x6885
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x195df(%rip), %rsi     # 0x1fe5d
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
jmp 0x6891
movslq 0x2137c(%rip), %rdi     # 0x27c14
movl $0x1, %esi
callq 0x3180
movq %rax, -0x68(%rbp)
movsbq 0x20ed6(%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 0x20eb4(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x69f7
movsbl 0x212a4(%rip), %eax     # 0x27b87
cmpl $0x69, %eax
jne 0x6978
leaq 0x20a15(%rip), %rdi     # 0x27308
addq $0x47f, %rdi            # imm = 0x47F
leaq 0x1957e(%rip), %rsi     # 0x1fe7f
callq 0x3340
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x6959
movq 0x206c0(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x1955b(%rip), %rsi     # 0x1fe81
movb $0x0, %al
callq 0x33f0
movsbl 0x20a18(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x694f
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x19539(%rip), %rsi     # 0x1fe81
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
movl $0x400, 0x21335(%rip)   # imm = 0x400
movslq 0x2132e(%rip), %rdi     # 0x27c98
callq 0x33b0
movq %rax, 0x2132a(%rip)     # 0x27ca0
jmp 0x69f5
movsbl 0x21208(%rip), %eax     # 0x27b87
cmpl $0x6f, %eax
jne 0x69f3
leaq 0x2097d(%rip), %rdi     # 0x27308
addq $0x47f, %rdi            # imm = 0x47F
leaq 0x177ab(%rip), %rsi     # 0x1e144
callq 0x3340
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x69f1
movq 0x20628(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x194e9(%rip), %rsi     # 0x1fea7
movb $0x0, %al
callq 0x33f0
movsbl 0x20980(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x69e7
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x194c7(%rip), %rsi     # 0x1fea7
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
jmp 0x69f3
jmp 0x69f5
jmp 0x69f7
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl 0x2120d(%rip), %eax     # 0x27c14
jge 0x6b25
movsbl 0x20d73(%rip), %eax     # 0x27787
cmpl $0x0, %eax
je 0x6a31
movsbl 0x20d67(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x6a7a
movsbl 0x2115b(%rip), %eax     # 0x27b87
cmpl $0x6f, %eax
jne 0x6a7a
callq 0x30c0
movsbl 0x20d47(%rip), %ecx     # 0x27784
cltd
idivl %ecx
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
movsbl 0x20d35(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x6a75
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %edx
leaq 0x197cc(%rip), %rsi     # 0x2023a
movb $0x0, %al
callq 0x33f0
jmp 0x6b15
movsbl 0x20d06(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x6b13
movsbl 0x210f6(%rip), %eax     # 0x27b87
cmpl $0x69, %eax
jne 0x6b13
movq -0x60(%rbp), %rdi
callq 0x78c0
movq 0x211fa(%rip), %rdi     # 0x27ca0
leaq 0x189ac(%rip), %rsi     # 0x1f459
callq 0x3440
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x6afd
movq 0x20514(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
leaq 0x193ff(%rip), %rsi     # 0x1fecd
movb $0x0, %al
callq 0x33f0
movsbl 0x20870(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x6af3
movq -0x30(%rbp), %rdi
leaq 0x193e1(%rip), %rsi     # 0x1fecd
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
movq -0x50(%rbp), %rdi
callq 0x3430
movb %al, %dl
movq -0x68(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x6b15
jmp 0x6b17
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x69fe
movsbl 0x20c5b(%rip), %eax     # 0x27787
cmpl $0x0, %eax
jle 0x6b54
movq -0x60(%rbp), %rdi
callq 0x3290
movsbl 0x21046(%rip), %eax     # 0x27b87
cmpl $0x69, %eax
jne 0x6b52
movq 0x21153(%rip), %rdi     # 0x27ca0
callq 0x3350
jmp 0x6b54
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x2109c(%rip), %eax     # 0x27c00
jge 0x6b96
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x2104b(%rip), %rdx     # 0x27bc0
movslq -0x3c(%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 -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6b5b
movzbl 0x20be7(%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, -0x4c8(%rbp)
movq %rcx, %rsp
movq %rax, -0x80(%rbp)
movsbl 0x20785(%rip), %eax     # 0x27354
movl %eax, -0x84(%rbp)
movb $0x0, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movsbl 0x20ba0(%rip), %ecx     # 0x27784
cmpl %ecx, %eax
jge 0x6ee4
movsbl 0x20763(%rip), %eax     # 0x27356
movl %eax, -0x4cc(%rbp)
subl $0x1, %eax
je 0x6c10
jmp 0x6c00
movl -0x4cc(%rbp), %eax
subl $0xe, %eax
je 0x6c79
jmp 0x6cdf
movl $0xd0, %edi
callq 0x32a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4d8(%rbp)
leaq 0x206da(%rip), %rsi     # 0x27308
callq 0x14b20
jmp 0x6c35
movq -0x4c8(%rbp), %rax
movq -0x4d8(%rbp), %rdx
movsbq -0x31(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x6d08
movq -0x4d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
movl $0xd0, %esi
callq 0x32b0
jmp 0x7072
movl $0x110, %edi            # imm = 0x110
callq 0x32a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x4e0(%rbp)
leaq 0x20671(%rip), %rsi     # 0x27308
callq 0x1d1b0
jmp 0x6c9e
movq -0x4c8(%rbp), %rax
movq -0x4e0(%rbp), %rdx
movsbq -0x31(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x6d08
movq -0x4e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
movl $0x110, %esi            # imm = 0x110
callq 0x32b0
jmp 0x7072
movq 0x202f2(%rip), %rax     # 0x26fd8
movq (%rax), %rdi
movsbl 0x20666(%rip), %edx     # 0x27356
leaq 0x17496(%rip), %rsi     # 0x1e18d
movb $0x0, %al
callq 0x33f0
movl $0x1, %edi
callq 0x3360
movq -0x70(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movslq (%rax,%rcx,4), %rdi
movl $0x1, %esi
callq 0x3180
movq %rax, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x20ec0(%rip), %eax     # 0x27c00
jge 0x6da9
movq -0x68(%rbp), %rax
movq 0x20e73(%rip), %rcx     # 0x27bc0
movslq -0x3c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x31(%rbp), %ecx
cmpl %ecx, %eax
jne 0x6d9c
movq 0x20e20(%rip), %rax     # 0x27b88
movslq -0x3c(%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 0x20df4(%rip), %rax     # 0x27b88
movslq -0x3c(%rbp), %rcx
movb $-0x1, (%rax,%rcx)
jmp 0x6d9e
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6d37
callq 0x3190
movq %rax, %rcx
movq -0x4c8(%rbp), %rax
movq %rcx, -0x48(%rbp)
movsbq -0x31(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq (%rdi), %rax
callq *0x48(%rax)
callq 0x3190
movq %rax, %rcx
subq -0x48(%rbp), %rcx
movq -0x20(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
leaq -0x4b0(%rbp), %rdi
movq -0x18(%rbp), %rdx
movsbl -0x31(%rbp), %ecx
leaq 0x19118(%rip), %rsi     # 0x1ff0f
movb $0x0, %al
callq 0x30b0
movq -0x4c8(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x4b0(%rbp), %rsi
movq (%rdi), %rax
callq *0x40(%rax)
movl $0x0, -0xa4(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x20dcb(%rip), %eax     # 0x27c00
jge 0x6e8f
movq -0x68(%rbp), %rax
movq 0x20d7e(%rip), %rcx     # 0x27bc0
movslq -0x3c(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x31(%rbp), %ecx
cmpl %ecx, %eax
jne 0x6e82
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 0x20d0d(%rip), %rax     # 0x27b88
movslq -0x3c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x6e84
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6e2c
movq -0xa0(%rbp), %rdi
callq 0x3350
movsbl -0x31(%rbp), %esi
addl $0x1, %esi
leaq 0x1906c(%rip), %rdi     # 0x1ff15
movb $0x0, %al
callq 0x3060
movsbl 0x20495(%rip), %eax     # 0x2734c
cmpl $0x1, %eax
jne 0x6ed5
movq -0x30(%rbp), %rdi
movsbl -0x31(%rbp), %edx
addl $0x1, %edx
leaq 0x19047(%rip), %rsi     # 0x1ff15
movb $0x0, %al
callq 0x33f0
jmp 0x6ed7
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x6bd9
movq -0x70(%rbp), %rdi
callq 0x3350
movl -0x84(%rbp), %eax
movb %al, 0x2045b(%rip)      # 0x27354
callq 0x3190
movq %rax, -0x48(%rbp)
movslq 0x20cf7(%rip), %rdi     # 0x27c00
movl $0x1, %esi
callq 0x3180
movq %rax, -0x4b8(%rbp)
movl $0x0, -0x4bc(%rbp)
movl -0x4bc(%rbp), %eax
cmpl 0x20cd0(%rip), %eax     # 0x27c00
jge 0x6f6d
movq -0x68(%rbp), %rax
movq 0x20c83(%rip), %rcx     # 0x27bc0
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 0x6f24
movq -0x4c8(%rbp), %rcx
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movb 0x20802(%rip), %al      # 0x27784
movq -0x4b8(%rbp), %r9
leaq 0x20378(%rip), %rdx     # 0x27308
movsbl %al, %r8d
callq 0x18c10
leaq 0x18f86(%rip), %rdi     # 0x1ff26
movb $0x0, %al
callq 0x3060
movq -0x4b8(%rbp), %rdi
callq 0x3350
callq 0x3190
movq %rax, %rcx
subq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movl $0x0, -0x4c0(%rbp)
movb $0x0, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
movsbl 0x207a2(%rip), %ecx     # 0x27784
cmpl %ecx, %eax
jge 0x703f
movq -0x4c8(%rbp), %rax
movsbq -0x31(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x19440
movl %eax, %ecx
movq -0x4c8(%rbp), %rax
addl -0x4c0(%rbp), %ecx
movl %ecx, -0x4c0(%rbp)
movsbq -0x31(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4e8(%rbp)
cmpq $0x0, %rax
je 0x7033
movq -0x4e8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x7035
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x6fd7
movsbl 0x2073e(%rip), %ecx     # 0x27784
movl -0x4c0(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0x4c0(%rbp)
movq -0x68(%rbp), %rdi
callq 0x3350
cvtsi2sdl -0x4c0(%rbp), %xmm0
movq -0x78(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x34c0
nop