// File: /workspace/github_c_makefile_star2_O2/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 0x4d6b
leaq 0x9043b(%rip), %rcx     # 0x95190
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x1b2aa
jmp 0x515b
addl $0xfffff830, %edi       # imm = 0xFFFFF830
cmpl $0x10, %edi
ja 0x518b
leaq 0x904b3(%rip), %rax     # 0x95234
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rbx, %rdi
callq 0x6d0db
leaq 0x32b0a7(%rip), %rax    # 0x32fe40
andq $0x0, (%rax)
jmp 0x515b
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x71c3d
jmp 0x515b
movq %rbx, %rdi
callq 0x3eeb2
jmp 0x515b
leaq 0x908fd(%rip), %rdi     # 0x956d6
callq 0x4cd35
movl %eax, %r14d
xorl %r15d, %r15d
testl %eax, %eax
cmovlel %r15d, %r14d
cmpq %r15, %r14
je 0x515b
movq (%rbx,%r15,8), %rdi
callq 0x1b2aa
movq (%rbx,%r15,8), %rdi
callq 0x34ff7
incq %r15
jmp 0x4dea
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6666b
movups 0x80(%rbx), %xmm0
movups 0x90(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x8297b
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8290c
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x71c3d
movq 0x30(%rbx), %rdi
callq 0x34ff7
leaq 0x30f08(%r14), %r15
pushq $0x8
popq %r12
xorl %r13d, %r13d
movslq 0x1bc(%r14), %rax
cmpq %rax, %r13
jge 0x4ebb
cmpl $0x1, (%r15)
jne 0x4eab
movq 0x28(%rbx), %rax
movq -0x8(%rax,%r12), %rdi
movq (%rax,%r12), %rsi
callq 0x3929f
incq %r13
addq $0x10, %r12
addq $0x340, %r15            # imm = 0x340
jmp 0x4e87
movq 0x28(%rbx), %rdi
jmp 0x5156
movq 0x10(%rbx), %rdi
callq 0x34ff7
movq 0x8(%rbx), %rdi
callq 0x34ff7
movq (%rbx), %rdi
movl 0x10(%r14), %esi
callq 0x34fc3
leaq 0x30f08(%r14), %r15
xorl %r12d, %r12d
movslq 0x10(%r14), %rax
cmpq %rax, %r12
jge 0x5152
movq %r15, %r13
xorl %ebp, %ebp
movslq 0x1bc(%r14), %rax
cmpq %rax, %rbp
jge 0x4f2e
cmpl $0x1, (%r13)
jne 0x4f22
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rbp,8), %rdi
callq 0x34ff7
incq %rbp
addq $0x340, %r13            # imm = 0x340
jmp 0x4efe
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %rdi
callq 0x34ff7
incq %r12
jmp 0x4eec
xorl %r14d, %r14d
movslq 0x20(%rbx), %rax
cmpq %rax, %r14
jge 0x4f88
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movslq (%rcx,%r14,4), %rcx
movq (%rax,%r14,8), %rdi
cmpq %rcx, %r15
jge 0x4f71
movq (%rdi,%r15,8), %rdi
callq 0x34ff7
incq %r15
jmp 0x4f4f
callq 0x34ff7
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x34ff7
incq %r14
jmp 0x4f43
movq (%rbx), %rdi
callq 0x34ff7
movq 0x18(%rbx), %rdi
callq 0x34ff7
movq 0x10(%rbx), %rdi
callq 0x34ff7
movq 0x8(%rbx), %rdi
jmp 0x5156
movq 0x28(%rbx), %rdi
callq 0x34ff7
movq 0x8(%rbx), %rdi
callq 0x34ff7
movq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq 0x3929f
pushq $0x8
popq %r15
xorl %r12d, %r12d
movslq 0x10(%r14), %rax
movq 0x10(%rbx), %rdi
cmpq %rax, %r12
jge 0x5156
movq -0x8(%rdi,%r15), %rax
movq (%rdi,%r15), %rsi
movq %rax, %rdi
callq 0x3929f
incq %r12
addq $0x10, %r15
jmp 0x4fd1
leaq 0x906de(%rip), %rdi     # 0x956e1
callq 0x4cf11
movl 0x10(%r14), %r14d
testl %eax, %eax
jne 0x5021
leal -0x1(%r14), %eax
imull %r14d, %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, %r14d
xorl %r15d, %r15d
testl %r14d, %r14d
cmovlel %r15d, %r14d
cmpq %r15, %r14
je 0x515b
movq (%rbx,%r15,8), %rdi
callq 0x1b2aa
movq (%rbx,%r15,8), %rdi
callq 0x34ff7
incq %r15
jmp 0x502b
cmpl $0x2, 0x10(%r14)
jne 0x5212
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8754e
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c010
movl 0x10(%r14), %esi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34fc3
movq (%rbx), %rdi
callq 0x2c010
movq 0x8(%rbx), %rdi
callq 0x34ff7
movq 0x10(%rbx), %rdi
jmp 0x5156
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x71c3d
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x515b
callq 0x2c010
jmp 0x515b
movq 0x10(%rbx), %rdi
callq 0x34ff7
pushq $0x8
popq %r15
xorl %r12d, %r12d
movslq 0x10(%r14), %rax
movq (%rbx), %rdi
cmpq %rax, %r12
jge 0x511a
movq -0x8(%rdi,%r15), %rax
movq (%rdi,%r15), %rsi
movq %rax, %rdi
callq 0x3929f
incq %r12
addq $0x10, %r15
jmp 0x50f4
callq 0x34ff7
pushq $0x8
popq %r15
xorl %r12d, %r12d
movslq 0x10(%r14), %rax
movq 0x8(%rbx), %rdi
cmpq %rax, %r12
jge 0x514d
movq -0x8(%rdi,%r15), %rax
movq (%rdi,%r15), %rsi
movq %rax, %rdi
callq 0x3929f
incq %r12
addq $0x10, %r15
jmp 0x5126
callq 0x34ff7
movq 0x18(%rbx), %rdi
callq 0x34ff7
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34ff7
xorl %r15d, %r15d
movslq 0x10(%r14), %rax
cmpq %rax, %r15
jge 0x515b
movq (%rbx,%r15,8), %rdi
callq 0x24a32
incq %r15
jmp 0x5174
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, 0x1bc(%r14)
jl 0x5228
movq 0x28(%rbx), %rdi
movl 0x40(%rbx), %esi
callq 0x34fc3
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rsi
jmp 0x51f2
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 0x6b6c3
jmp 0x515b
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x3929f
jmp 0x515b
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8756d
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x877e8
movq 0x20(%rbx), %rdi
jmp 0x5156