// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/algorithm.c
// Function: free_model_of_supervised_algorithm
void free_model_of_supervised_algorithm(int algorithm, void* model, Datasetptr current_dataset)
{
 /*!Last Changed 19.08.2007 added RBF and RBFREG algorithms*/
 /*!Last Changed 11.08.2007 added NAIVEBAYES algorithm*/
 /*!Last Changed 05.08.2007 added QDACLASS algorithm*/
 /*!Last Changed 02.04.2007 added HMM algorithm*/
 /*!Last Changed 14.08.2005*/
 int i, j, treecount;
 Model_ldaclassptr mlda;
 Model_qdaclassptr mqda;
 Model_quantizeregptr mqua;
 Model_gaussianptr mgau;
 Model_selectmaxptr msel;
 Model_naivebayesptr mnaive;
 Model_divsptr mdivs;
 Model_riseptr mrise;
 Hmmptr* mhmm;
 Decisionnodeptr* forest;
 switch (algorithm)
  {
   case ONEFEATURE    :
   case SELECTAVERAGE :safe_free(model);
                       break;
   case SELECTMAX     :msel = (Model_selectmaxptr)model;
                       safe_free(msel->priors);
                       safe_free(msel);
                       break;
   case LOGISTIC      :free_2d((void**)((double**)model), current_dataset->classno);
                       break;
   case LINEARREG     :matrix_free(((Model_linearregressionptr) model)->w);
                       safe_free(model);
                       break;
   case NEARESTMEAN   :deallocate((Instanceptr)model);
                       break;
   case GAUSSIAN      :mgau = (Model_gaussianptr)model;
                       deallocate(mgau->mean);
                       safe_free(mgau->variance);
                       safe_free(mgau->priors);
                       safe_free(mgau);
                       break;
   case LDT           :
   case C45           :
   case MULTILDT      :
   case OMNILDT       :
   case NBTREE        :
   case SOFTTREE      :
   case CART          :
   case KTREE         :
   case C45STUMP      :
   case LDTSTUMP      :
   case MULTILDTSTUMP :
   case SOFTSTUMP     :deallocate_tree((Decisionnodeptr)model);
                       safe_free((Decisionnodeptr)model);
                       break;
   case SVMTREE       :forest = (Decisionnodeptr*) model;
                       if (get_parameter_l("multiclasstype") == ONE_VS_ONE)
                        treecount = (current_dataset->classno * (current_dataset->classno - 1))/ 2;
                       else
                         treecount = current_dataset->classno;
                       for (i = 0; i < treecount; i++)
                        {
                         deallocate_tree(forest[i]);
                         safe_free(forest[i]);
                        }
                       safe_free(forest);
                       break;
   case SVMREGTREE    :
   case REGTREE       :
   case SOFTREGTREE   :
   case REGSTUMP      :
   case SOFTREGSTUMP  :deallocate_regression_tree((Regressionnodeptr)model);
                       cvdata = NULL;
                       safe_free((Regressionnodeptr)model);
                       break;
   case REGRULE       :free_regression_ruleset(*((Regressionrulesetptr) model));
                       safe_free(model);
                       break;
   case NAIVEBAYES    :mnaive = (Model_naivebayesptr) model;
                       safe_free(mnaive->priors);
                       safe_free(mnaive->s);
                       free_2d((void **) mnaive->m, current_dataset->classno);
                       for (i = 0; i < current_dataset->classno; i++)
                        {
                         for (j = 0; j < current_dataset->featurecount; j++)
                           if (current_dataset->features[j].type == STRING)
                             safe_free(mnaive->p[i][j]);
                         safe_free(mnaive->p[i]);
                        }
                       safe_free(mnaive->p);
                       safe_free(mnaive);
                       break;
   case QDACLASS      :mqda = (Model_qdaclassptr) model;
                       safe_free(mqda->w0);
                       for (i = 0; i < current_dataset->classno; i++)
                         matrix_free(mqda->W[i]);
                       safe_free(mqda->W);
                       for (i = 0; i < current_dataset->classno; i++)
                         matrix_free(mqda->w[i]);
                       safe_free(mqda->w);
                       safe_free(mqda->priors);
                       safe_free(mqda);
                       break;
   case LDACLASS      :mlda = (Model_ldaclassptr) model;
                       safe_free(mlda->eigenvalues);
                       safe_free(mlda->w0);
                       matrix_free(mlda->eigenvectors);
                       for (i = 0; i < current_dataset->classno; i++)
                         matrix_free(mlda->w[i]);
                       safe_free(mlda->w);
                       safe_free(mlda);
                       break;
   case QUANTIZEREG   :mqua = (Model_quantizeregptr) model;
                       if (current_dataset->featurecount > 2)
                        {
                         free_2d((void**)(mqua->meanstwo), mqua->partitioncount);
                         matrix_free(mqua->eigenvectors);
                        }
                       else
                         safe_free(mqua->meansone);                      
                       safe_free(mqua);
                       break;
   case RISE          :mrise = (Model_riseptr) model;
                       free_ruleset(mrise->rules);
                       safe_free(mrise->counts);
                       for (i = 0; i < current_dataset->featurecount; i++)
                         if (current_dataset->features[i].type == STRING)
                           matrix_free(mrise->svdm[i]);
                       safe_free(mrise->svdm);
                       safe_free(mrise);
                       break;
   case IREP          :
   case IREP2         :
   case RIPPER        :
   case MULTIRIPPER   :
   case HYBRIDRIPPER  :
   case CN2           :
   case LERILS        :
   case PART          :free_ruleset(*((Ruleset*)model));
                       safe_free(model);
                       break;
   case DIVS          :mdivs = (Model_divsptr)model;
                       for (i = 0; i < mdivs->datacount; i++)
                        {
                         for (j = 0; j < mdivs->rulecounts[i]; j++)
                           safe_free(mdivs->hypotheses[i][j]);
                         safe_free(mdivs->hypotheses[i]);
                         safe_free(mdivs->conditioncounts[i]);                        
                        }
                       safe_free(mdivs->hypotheses);
                       safe_free(mdivs->conditioncounts);
                       safe_free(mdivs->classno);
                       safe_free(mdivs->rulecounts);
                       safe_free(mdivs);
                       break;
   case REXRIPPER     :free_ruleset(((Model_rexripperptr)model)->r);
                       if (((Model_rexripperptr)model)->exceptiondata)
                         deallocate(((Model_rexripperptr)model)->exceptiondata);
                       safe_free(model);
                       break;
   case C45RULES      :free_ruleset(*((Ruleset*)model));
                       safe_free(model);
                       break;
   case RBF           :
   case RBFREG        :free_rbfnetwork((Rbfnetworkptr) model);
                       break;
   case MLPGENERIC    :
   case MLPGENERICREG :
   case DNC           :
   case DNCREG        :free_mlpnnetwork((Mlpnetworkptr) model);
                       safe_free(model);
                       break;
   case GPROCESSREG   :safe_free(((Model_gprocessregressionptr) model)->weights);
                       safe_free(model);
                       break;
   case SVM           :
   case SVMREG        :free_svm_problem(((Svm_modelptr)model)->prob);
                       free_svm_model((Svm_modelptr)model);
                       break;
   case SIMPLEXSVM    :if (current_dataset->classno == 2)
                         free_svm_binary_model((Svm_binary_modelptr) model);
                       else
                         free_svm_simplex_model((Svm_simplex_modelptr) model);
                       break;
   case SIMPLEXSVMREG :free_svm_regression_model((Svm_regression_modelptr) model);
                       break;
   case HMM           :mhmm = (Hmmptr*) model;
                       for (i = 0; i < current_dataset->classno; i++)
                         free_hmm(mhmm[i]);
                       safe_free(mhmm);
                       break;
   case RANDOMFOREST  :
   case KFOREST       :forest = (Decisionnodeptr*) model;
                       treecount = get_parameter_i("forestsize");
                       for (i = 0; i < treecount; i++)
                        {
                         deallocate_tree(forest[i]);
                         safe_free(forest[i]);
                        }
                       safe_free(forest);
                       break;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r14
movq %rsi, %rbx
leal -0x3e8(%rdi), %eax
cmpl $0x28, %eax
ja 0x4d74
leaq 0xa0432(%rip), %rcx     # 0xa5190
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x1d74c
jmp 0x51c0
addl $0xfffff830, %edi       # imm = 0xFFFFF830
cmpl $0x10, %edi
ja 0x51f7
leaq 0xa04aa(%rip), %rax     # 0xa5234
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rbx, %rdi
callq 0x772d9
leaq 0x33309e(%rip), %rax    # 0x337e40
movq $0x0, (%rax)
jmp 0x51c0
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7c2a4
jmp 0x51c0
movq %rbx, %rdi
callq 0x45646
jmp 0x51c0
leaq 0xa08f1(%rip), %rdi     # 0xa56d6
callq 0x54920
testl %eax, %eax
jle 0x51c0
movl %eax, %r14d
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x1d74c
movq (%rbx,%r15,8), %rdi
callq 0x3a180
incq %r15
cmpq %r15, %r14
jne 0x4df8
jmp 0x51c0
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6fba7
movups 0x80(%rbx), %xmm0
movups 0x90(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x9060a
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x90593
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7c2a4
movq 0x30(%rbx), %rdi
callq 0x3a180
movl 0x1bc(%r14), %eax
testl %eax, %eax
jle 0x4ed6
leaq 0x30f08(%r14), %r15
movl $0x8, %r12d
xorl %r13d, %r13d
cmpl $0x1, (%r15)
jne 0x4ec0
movq 0x28(%rbx), %rax
movq -0x8(%rax,%r12), %rdi
movq (%rax,%r12), %rsi
callq 0x3ed51
movl 0x1bc(%r14), %eax
incq %r13
movslq %eax, %rcx
addq $0x10, %r12
addq $0x340, %r15            # imm = 0x340
cmpq %rcx, %r13
jl 0x4ea1
movq 0x28(%rbx), %rdi
jmp 0x51bb
movq 0x10(%rbx), %rdi
callq 0x3a180
movq 0x8(%rbx), %rdi
callq 0x3a180
movq (%rbx), %rdi
movl 0x10(%r14), %esi
callq 0x3a14b
cmpl $0x0, 0x10(%r14)
jle 0x51b7
leaq 0x30f08(%r14), %r15
xorl %r12d, %r12d
movl 0x1bc(%r14), %eax
testl %eax, %eax
jle 0x4f53
movq %r15, %r13
xorl %ebp, %ebp
cmpl $0x1, (%r13)
jne 0x4f41
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rbp,8), %rdi
callq 0x3a180
movl 0x1bc(%r14), %eax
incq %rbp
movslq %eax, %rcx
addq $0x340, %r13            # imm = 0x340
cmpq %rcx, %rbp
jl 0x4f22
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %rdi
callq 0x3a180
incq %r12
movslq 0x10(%r14), %rax
cmpq %rax, %r12
jl 0x4f12
jmp 0x51b7
cmpl $0x0, 0x20(%rbx)
jle 0x4fcd
xorl %r14d, %r14d
movq 0x8(%rbx), %rax
cmpl $0x0, (%rax,%r14,4)
jle 0x4fa8
xorl %r15d, %r15d
movq (%rbx), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rdi
callq 0x3a180
incq %r15
movq 0x8(%rbx), %rax
movslq (%rax,%r14,4), %rax
cmpq %rax, %r15
jl 0x4f88
movq (%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x3a180
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x3a180
incq %r14
movslq 0x20(%rbx), %rax
cmpq %rax, %r14
jl 0x4f7a
movq (%rbx), %rdi
callq 0x3a180
movq 0x18(%rbx), %rdi
callq 0x3a180
movq 0x10(%rbx), %rdi
callq 0x3a180
movq 0x8(%rbx), %rdi
jmp 0x51bb
movq 0x28(%rbx), %rdi
callq 0x3a180
movq 0x8(%rbx), %rdi
callq 0x3a180
movq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq 0x3ed51
cmpl $0x0, 0x10(%r14)
jle 0x50fc
movl $0x8, %r15d
xorl %r12d, %r12d
movq 0x10(%rbx), %rax
movq -0x8(%rax,%r15), %rdi
movq (%rax,%r15), %rsi
callq 0x3ed51
incq %r12
movslq 0x10(%r14), %rax
addq $0x10, %r15
cmpq %rax, %r12
jl 0x5023
jmp 0x50fc
leaq 0xa0690(%rip), %rdi     # 0xa56e1
callq 0x54afc
movl 0x10(%r14), %ecx
testl %eax, %eax
jne 0x506d
leal -0x1(%rcx), %eax
imull %ecx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
testl %ecx, %ecx
jle 0x51c0
movl %ecx, %r14d
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x1d74c
movq (%rbx,%r15,8), %rdi
callq 0x3a180
incq %r15
cmpq %r15, %r14
jne 0x507b
jmp 0x51c0
cmpl $0x2, 0x10(%r14)
jne 0x527e
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x95b65
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2ff55
movl 0x10(%r14), %esi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3a14b
movq (%rbx), %rdi
callq 0x2ff55
movq 0x8(%rbx), %rdi
callq 0x3a180
movq 0x10(%rbx), %rdi
jmp 0x51bb
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7c2a4
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x51c0
callq 0x2ff55
jmp 0x51c0
movq 0x10(%rbx), %rdi
callq 0x3a180
cmpl $0x0, 0x10(%r14)
jle 0x5174
movl $0x8, %r15d
xorl %r12d, %r12d
movq (%rbx), %rax
movq -0x8(%rax,%r15), %rdi
movq (%rax,%r15), %rsi
callq 0x3ed51
incq %r12
movslq 0x10(%r14), %rax
addq $0x10, %r15
cmpq %rax, %r12
jl 0x5153
movq (%rbx), %rdi
callq 0x3a180
cmpl $0x0, 0x10(%r14)
jle 0x51ae
movl $0x8, %r15d
xorl %r12d, %r12d
movq 0x8(%rbx), %rax
movq -0x8(%rax,%r15), %rdi
movq (%rax,%r15), %rsi
callq 0x3ed51
incq %r12
movslq 0x10(%r14), %rax
addq $0x10, %r15
cmpq %rax, %r12
jl 0x518c
movq 0x8(%rbx), %rdi
callq 0x3a180
movq 0x18(%rbx), %rdi
callq 0x3a180
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3a180
cmpl $0x0, 0x10(%r14)
jle 0x51c0
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x27f8a
incq %r15
movslq 0x10(%r14), %rax
cmpq %rax, %r15
jl 0x51e0
jmp 0x51c0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, 0x1bc(%r14)
jl 0x5294
movq 0x28(%rbx), %rdi
movl 0x40(%rbx), %esi
callq 0x3a14b
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rsi
jmp 0x525e
movq 0x30(%rbx), %rax
movq %rax, 0x30(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x755be
jmp 0x51c0
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x3ed51
jmp 0x51c0
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x95b84
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x95e55
movq 0x20(%rbx), %rdi
jmp 0x51bb