// File: /workspace/github_c_makefile_star2_O1/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 0x4d8e
leaq 0x9d418(%rip), %rcx     # 0xa2190
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x1cfd1
jmp 0x51d2
addl $0xfffff830, %edi       # imm = 0xFFFFF830
cmpl $0x10, %edi
ja 0x5209
leaq 0x9d490(%rip), %rax     # 0xa2234
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rbx, %rdi
callq 0x75950
leaq 0x330084(%rip), %rax    # 0x334e40
movq $0x0, (%rax)
jmp 0x51d2
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7a9dc
jmp 0x51d2
movq %rbx, %rdi
callq 0x442bb
jmp 0x51d2
leaq 0x9d8d7(%rip), %rdi     # 0xa26d6
callq 0x5341c
testl %eax, %eax
jle 0x51d2
movl %eax, %r14d
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x1cfd1
movq (%rbx,%r15,8), %rdi
callq 0x39194
incq %r15
cmpq %r15, %r14
jne 0x4e12
jmp 0x51d2
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6e437
movups 0x80(%rbx), %xmm0
movups 0x90(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x8de37
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ddc0
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7a9dc
movq 0x30(%rbx), %rdi
callq 0x39194
cmpl $0x0, 0x1bc(%r14)
jle 0x4eec
leaq 0x30f08(%r14), %r15
movl $0x8, %r12d
xorl %r13d, %r13d
cmpl $0x1, (%r15)
jne 0x4ed2
movq 0x28(%rbx), %rax
movq -0x8(%rax,%r12), %rdi
movq (%rax,%r12), %rsi
callq 0x3dbad
incq %r13
movslq 0x1bc(%r14), %rax
addq $0x10, %r12
addq $0x340, %r15            # imm = 0x340
cmpq %rax, %r13
jl 0x4eba
movq 0x28(%rbx), %rdi
jmp 0x51cd
movq 0x10(%rbx), %rdi
callq 0x39194
movq 0x8(%rbx), %rdi
callq 0x39194
movq (%rbx), %rdi
movl 0x10(%r14), %esi
callq 0x3915f
cmpl $0x0, 0x10(%r14)
jle 0x51c9
leaq 0x30f08(%r14), %r15
xorl %r12d, %r12d
cmpl $0x0, 0x1bc(%r14)
jle 0x4f65
movq %r15, %r13
xorl %ebp, %ebp
cmpl $0x1, (%r13)
jne 0x4f4f
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rbp,8), %rdi
callq 0x39194
incq %rbp
movslq 0x1bc(%r14), %rax
addq $0x340, %r13            # imm = 0x340
cmpq %rax, %rbp
jl 0x4f37
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %rdi
callq 0x39194
incq %r12
movslq 0x10(%r14), %rax
cmpq %rax, %r12
jl 0x4f28
jmp 0x51c9
cmpl $0x0, 0x20(%rbx)
jle 0x4fdf
xorl %r14d, %r14d
movq 0x8(%rbx), %rax
cmpl $0x0, (%rax,%r14,4)
jle 0x4fba
xorl %r15d, %r15d
movq (%rbx), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %rdi
callq 0x39194
incq %r15
movq 0x8(%rbx), %rax
movslq (%rax,%r14,4), %rax
cmpq %rax, %r15
jl 0x4f9a
movq (%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x39194
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x39194
incq %r14
movslq 0x20(%rbx), %rax
cmpq %rax, %r14
jl 0x4f8c
movq (%rbx), %rdi
callq 0x39194
movq 0x18(%rbx), %rdi
callq 0x39194
movq 0x10(%rbx), %rdi
callq 0x39194
movq 0x8(%rbx), %rdi
jmp 0x51cd
movq 0x28(%rbx), %rdi
callq 0x39194
movq 0x8(%rbx), %rdi
callq 0x39194
movq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq 0x3dbad
cmpl $0x0, 0x10(%r14)
jle 0x510e
movl $0x8, %r15d
xorl %r12d, %r12d
movq 0x10(%rbx), %rax
movq -0x8(%rax,%r15), %rdi
movq (%rax,%r15), %rsi
callq 0x3dbad
incq %r12
movslq 0x10(%r14), %rax
addq $0x10, %r15
cmpq %rax, %r12
jl 0x5035
jmp 0x510e
leaq 0x9d67e(%rip), %rdi     # 0xa26e1
callq 0x535f7
movl 0x10(%r14), %ecx
testl %eax, %eax
jne 0x507f
leal -0x1(%rcx), %eax
imull %ecx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
testl %ecx, %ecx
jle 0x51d2
movl %ecx, %r14d
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x1cfd1
movq (%rbx,%r15,8), %rdi
callq 0x39194
incq %r15
cmpq %r15, %r14
jne 0x508d
jmp 0x51d2
cmpl $0x2, 0x10(%r14)
jne 0x5290
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x93035
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2f616
movl 0x10(%r14), %esi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3915f
movq (%rbx), %rdi
callq 0x2f616
movq 0x8(%rbx), %rdi
callq 0x39194
movq 0x10(%rbx), %rdi
jmp 0x51cd
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7a9dc
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x51d2
callq 0x2f616
jmp 0x51d2
movq 0x10(%rbx), %rdi
callq 0x39194
cmpl $0x0, 0x10(%r14)
jle 0x5186
movl $0x8, %r15d
xorl %r12d, %r12d
movq (%rbx), %rax
movq -0x8(%rax,%r15), %rdi
movq (%rax,%r15), %rsi
callq 0x3dbad
incq %r12
movslq 0x10(%r14), %rax
addq $0x10, %r15
cmpq %rax, %r12
jl 0x5165
movq (%rbx), %rdi
callq 0x39194
cmpl $0x0, 0x10(%r14)
jle 0x51c0
movl $0x8, %r15d
xorl %r12d, %r12d
movq 0x8(%rbx), %rax
movq -0x8(%rax,%r15), %rdi
movq (%rax,%r15), %rsi
callq 0x3dbad
incq %r12
movslq 0x10(%r14), %rax
addq $0x10, %r15
cmpq %rax, %r12
jl 0x519e
movq 0x8(%rbx), %rdi
callq 0x39194
movq 0x18(%rbx), %rdi
callq 0x39194
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39194
cmpl $0x0, 0x10(%r14)
jle 0x51d2
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0x2787b
incq %r15
movslq 0x10(%r14), %rax
cmpq %rax, %r15
jl 0x51f2
jmp 0x51d2
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, 0x1bc(%r14)
jl 0x52a6
movq 0x28(%rbx), %rdi
movl 0x40(%rbx), %esi
callq 0x3915f
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rsi
jmp 0x5270
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 0x73cef
jmp 0x51d2
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x3dbad
jmp 0x51d2
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x93054
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x93328
movq 0x20(%rbx), %rdi
jmp 0x51cd