// File: myudelson[P]hmm-scalable/utilsSt.cpp
// Function: destroy_input_data(task*)
void destroy_input_data(struct task *task) {
	if(task->init_param_values != NULL) free(task->init_param_values);
	if(task->param_values_lb != NULL) free(task->param_values_lb);
	if(task->param_values_ub != NULL) free(task->param_values_ub);
    
    if(task->elo_param_values != NULL) free(task->elo_param_values);

    // data - checks if pointers to data are null anyway (whether we delete linear columns of data or not)
    if(task->dat_obs != NULL) free( task->dat_obs );
    if(task->dat_obs_stacked != NULL) free( task->dat_obs_stacked );
	if(task->dat_group != NULL) free( task->dat_group );
	if(task->dat_item != NULL) free( task->dat_item );
	if(task->dat_skill != NULL) free( task->dat_skill );
//	if(task->dat_multiskill != NULL) delete task->dat_multiskill;
    if(task->dat_skill_stacked != NULL) free( task->dat_skill_stacked );
    if(task->dat_skill_rcount != NULL) free( task->dat_skill_rcount );
    if(task->dat_skill_rix != NULL) free( task->dat_skill_rix );
	if(task->dat_slice != NULL) free( task->dat_slice );
    if(task->dat_predict != NULL) free2D(task->dat_predict, task->N);
    if(task->dat_predict_k != NULL) free(task->dat_predict_k  );
    if( task->Cslices>0 ) {
        free( task->Cw );
        free( task->Ccenters );
    }
    
//    // not null skills
//    for(NDAT kg=0;kg<task->nSeq; kg++) {
//		free(task->all_data[kg].ix); // was obs;
//		if( task->all_data[kg].ix_stacked != NULL ) free(task->all_data[kg].ix_stacked); // was obs;
////        if(task->sliced) // handled via one global array and ix indexing
////            free(task->all_data[kg].time);
//    }
//    if(task->all_data != NULL) free(task->all_data); // ndat of them
//    if(task->k_data != NULL)   free(task->k_data); // ndat of them (reordered by k)
//    if(task->g_data != NULL)   free(task->g_data); // ndat of them (reordered by g)
//    if(task->k_g_data != NULL) free(task->k_g_data); // nK of them
//    if(task->g_k_data != NULL) free(task->g_k_data); // nG of them
//
//	if(task->k_numg != NULL)   free(task->k_numg);
//	if(task->g_numk != NULL)   free(task->g_numk);
//    // null skills
//    for(NCAT g=0;g<task->n_null_skill_group; g++)
//        free(task->null_skills[g].ix); // was obs
//    if(task->null_skills != NULL) free(task->null_skills);
    // vocabularies
    delete task->map_group_fwd;
    delete task->map_group_bwd;
    delete task->map_step_fwd;
    delete task->map_step_bwd;
    delete task->map_skill_fwd;
    delete task->map_skill_bwd;
    
    // destroy connectivities
    if(task->connectivities != NULL) {
        for(NPAR i=0; i<task->n_connectivities; i++) {
            free2D<NPAR>(task->connectivities[i], task->n_connectivity_X[i]);
        }
        free(task->connectivities);
        free(task->n_connectivity_X);
        free(task->n_connectivity_Y);
        task->connectivities = NULL;
        task->n_connectivity_X = NULL;
        task->n_connectivity_Y = NULL;
        task->n_connectivities = 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x93f2
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x940a
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x9422
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x943a
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x880(%rax)
je 0x9458
movq -0x8(%rbp), %rax
movq 0x880(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x888(%rax)
je 0x9476
movq -0x8(%rbp), %rax
movq 0x888(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x890(%rax)
je 0x9494
movq -0x8(%rbp), %rax
movq 0x890(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8b8(%rax)
je 0x94b2
movq -0x8(%rbp), %rax
movq 0x8b8(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x898(%rax)
je 0x94d0
movq -0x8(%rbp), %rax
movq 0x898(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8a0(%rax)
je 0x94ee
movq -0x8(%rbp), %rax
movq 0x8a0(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8a8(%rax)
je 0x950c
movq -0x8(%rbp), %rax
movq 0x8a8(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8b0(%rax)
je 0x952a
movq -0x8(%rbp), %rax
movq 0x8b0(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8c0(%rax)
je 0x9548
movq -0x8(%rbp), %rax
movq 0x8c0(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8c8(%rax)
je 0x9570
movq -0x8(%rbp), %rax
movq 0x8c8(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8f8(%rax), %esi
callq 0xa1d0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8d0(%rax)
je 0x958e
movq -0x8(%rbp), %rax
movq 0x8d0(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
movsbl 0x52(%rax), %eax
cmpl $0x0, %eax
jle 0x95b5
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
movq 0x928(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x95e1
movq -0x18(%rbp), %rdi
callq 0x4450
movq -0x18(%rbp), %rdi
movl $0x30, %esi
callq 0x3280
movq -0x8(%rbp), %rax
movq 0x930(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x960d
movq -0x20(%rbp), %rdi
callq 0x4490
movq -0x20(%rbp), %rdi
movl $0x30, %esi
callq 0x3280
movq -0x8(%rbp), %rax
movq 0x938(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x9639
movq -0x28(%rbp), %rdi
callq 0x4450
movq -0x28(%rbp), %rdi
movl $0x30, %esi
callq 0x3280
movq -0x8(%rbp), %rax
movq 0x940(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x9665
movq -0x30(%rbp), %rdi
callq 0x4490
movq -0x30(%rbp), %rdi
movl $0x30, %esi
callq 0x3280
movq -0x8(%rbp), %rax
movq 0x948(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x9691
movq -0x38(%rbp), %rdi
callq 0x4450
movq -0x38(%rbp), %rdi
movl $0x30, %esi
callq 0x3280
movq -0x8(%rbp), %rax
movq 0x950(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x96bd
movq -0x40(%rbp), %rdi
callq 0x4490
movq -0x40(%rbp), %rdi
movl $0x30, %esi
callq 0x3280
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8f0(%rax)
je 0x9784
movb $0x0, -0x9(%rbp)
movsbl -0x9(%rbp), %eax
movq -0x8(%rbp), %rcx
movsbl 0x8d8(%rcx), %ecx
cmpl %ecx, %eax
jge 0x971c
movq -0x8(%rbp), %rax
movq 0x8f0(%rax), %rax
movsbq -0x9(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x8(%rbp), %rax
movq 0x8e0(%rax), %rax
movsbq -0x9(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0xa220
movb -0x9(%rbp), %al
addb $0x1, %al
movb %al, -0x9(%rbp)
jmp 0x96d3
movq -0x8(%rbp), %rax
movq 0x8f0(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
movq 0x8e0(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
movq 0x8e8(%rax), %rdi
callq 0x3320
movq -0x8(%rbp), %rax
movq $0x0, 0x8f0(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x8e0(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x8e8(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x8d8(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)