// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/poly.c
// Function: polylearnvalidation
int polylearnvalidation(char* definitionfile, int maxdegree, int regression)
{
 /*!Last Changed 23.01.2005*/
	char polyst[MAXLENGTH];
 char varname[MAXLENGTH];
 char varvalue[MAXLENGTH], pst[READLINELENGTH];
	double** traindata, **testdata, besterror = +LONG_MAX, beststdev, trainerror, *testerror, *mean, *stdev, bayeserror;
	int i, bestdegree, functioncount, j, traincount, testcount;
	Functionptr fx;
	Mixtureptr mix;
	Polynomptr p;
	if (regression)
		 fx = read_function_definition(definitionfile, &functioncount);
	else
		 mix = read_mixture_from_file(definitionfile);
	testerror = safemalloc(100 * sizeof(double), "polylearnvalidation", 14);
	mean = safemalloc(maxdegree * sizeof(double), "polylearnvalidation", 15);
	stdev = safemalloc(maxdegree * sizeof(double), "polylearnvalidation", 16);
	traincount = 100;
	testcount = 1000;
	if (!regression)
	 {
   testdata = generate_data_from_mixture_model(mix, testcount);
			bayeserror = 0.0;
			for (i = 0; i < testcount; i++)
				 if (mixture_class_at_value(mix, testdata[i][0]) != testdata[i][1])
						 bayeserror++;
			set_default_variable("out2", bayeserror / testcount);
	 }
	for (i = 1; i <= maxdegree; i++)
	 {
		 trainerror = 0;
		 for (j = 0; j < 100; j++)
			 {
				 if (regression)
					 {
						 traindata = functiondatagenerate(traincount, fx, functioncount, 1);
							testdata = functiondatagenerate(testcount, fx, functioncount, 1);
		     p = polyfit(traindata, traincount, i);
					 }
					else
					 {
						 traindata = generate_data_from_mixture_model(mix, traincount);
						 testdata = generate_data_from_mixture_model(mix, testcount);
		     p = polyfitcls(traindata, traincount, i);
					 }
					if (j == 0)
					 {
    			print_polynom(p, polyst);
      	sprintf(varname,"aout3[%d]", i);
	    		set_variable(varname, polyst);
					 }
					if (regression)
					 {
			    trainerror += calculate_mse(traindata, traincount, p);
  	  		testerror[j] = calculate_mse(testdata, testcount, p);
					 }
					else
					 {
						 trainerror += calculate_poly_clserror(traindata, traincount, p);
							testerror[j] = calculate_poly_clserror(testdata, testcount, p);
					 }
			  free_polynom(p);
					free_2d((void**)traindata, traincount);
					free_2d((void**)testdata, testcount);
			 }
  	sprintf(varname,"aout1[%d]", i);
			set_precision(pst, NULL, NULL);
  	sprintf(varvalue, pst, trainerror / traincount);
  	set_variable(varname, varvalue); 
			mean[i - 1] = find_mean_stdev_of_list(testerror, 100, &(stdev[i - 1]));
			if (mean[i - 1] < besterror)
			 {
				 besterror = mean[i - 1];
					beststdev = stdev[i - 1];
			 }
  	sprintf(varname,"aout2[%d]", i);
			set_precision(pst, NULL, NULL);
  	sprintf(varvalue, pst, mean[i - 1]);
  	set_variable(varname, varvalue); 
  	sprintf(varname,"aout4[%d]", i);
			set_precision(pst, NULL, NULL);
  	sprintf(varvalue, pst, stdev[i - 1]);
  	set_variable(varname, varvalue); 
	 }
	bestdegree = 0;
	while (mean[bestdegree] - stdev[bestdegree] > besterror + beststdev)
		 bestdegree++;
	safe_free(mean);
	safe_free(stdev);
 safe_free(testerror);
	if (regression)
	 {
  	for (i = 0;i < functioncount; i++)
	  	 free_function(fx[i]);
	  safe_free(fx);
	 }
	else
		 free_mixture(mix);
	return bestdegree;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e8530, %rsp         # imm = 0x1E8530
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movsd 0x5efb3(%rip), %xmm0    # 0xe2fb0
movsd %xmm0, -0x1e84a8(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0x84024
movq -0x8(%rbp), %rdi
leaq -0x1e84e4(%rbp), %rsi
callq 0x81360
movq %rax, -0x1e84f8(%rbp)
jmp 0x84034
movq -0x8(%rbp), %rdi
callq 0x60d90
movq %rax, -0x1e8500(%rbp)
movl $0x320, %edi            # imm = 0x320
leaq 0x63862(%rip), %rsi     # 0xe78a2
movl $0xe, %edx
callq 0x52d70
movq %rax, -0x1e84c0(%rbp)
movslq -0xc(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x63842(%rip), %rsi     # 0xe78a2
movl $0xf, %edx
callq 0x52d70
movq %rax, -0x1e84c8(%rbp)
movslq -0xc(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x63822(%rip), %rsi     # 0xe78a2
movl $0x10, %edx
callq 0x52d70
movq %rax, -0x1e84d0(%rbp)
movl $0x64, -0x1e84ec(%rbp)
movl $0x3e8, -0x1e84f0(%rbp) # imm = 0x3E8
cmpl $0x0, -0x10(%rbp)
jne 0x84179
movq -0x1e8500(%rbp), %rdi
movl -0x1e84f0(%rbp), %esi
callq 0x613e0
movq %rax, -0x1e84a0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x1e84d8(%rbp)
movl $0x0, -0x1e84dc(%rbp)
movl -0x1e84dc(%rbp), %eax
cmpl -0x1e84f0(%rbp), %eax
jge 0x84159
movq -0x1e8500(%rbp), %rdi
movq -0x1e84a0(%rbp), %rax
movslq -0x1e84dc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax), %xmm0
callq 0x610f0
cvtsi2sd %eax, %xmm0
movq -0x1e84a0(%rbp), %rax
movslq -0x1e84dc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
ucomisd 0x8(%rax), %xmm0
jne 0x8412e
jp 0x8412e
jmp 0x84146
movsd 0x5dee2(%rip), %xmm0    # 0xe2018
addsd -0x1e84d8(%rbp), %xmm0
movsd %xmm0, -0x1e84d8(%rbp)
jmp 0x84148
movl -0x1e84dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e84dc(%rbp)
jmp 0x840dd
movsd -0x1e84d8(%rbp), %xmm0
cvtsi2sdl -0x1e84f0(%rbp), %xmm1
divsd %xmm1, %xmm0
leaq 0x61a1a(%rip), %rdi     # 0xe5b8e
callq 0x4b070
movl $0x1, -0x1e84dc(%rbp)
movl -0x1e84dc(%rbp), %eax
cmpl -0xc(%rbp), %eax
jg 0x845b6
xorps %xmm0, %xmm0
movsd %xmm0, -0x1e84b8(%rbp)
movl $0x0, -0x1e84e8(%rbp)
cmpl $0x64, -0x1e84e8(%rbp)
jge 0x843b4
cmpl $0x0, -0x10(%rbp)
je 0x84223
movl -0x1e84ec(%rbp), %edi
movq -0x1e84f8(%rbp), %rsi
movl -0x1e84e4(%rbp), %edx
movl $0x1, %ecx
callq 0x81020
movq %rax, -0x1e8498(%rbp)
movl -0x1e84f0(%rbp), %edi
movq -0x1e84f8(%rbp), %rsi
movl -0x1e84e4(%rbp), %edx
movl $0x1, %ecx
callq 0x81020
movq %rax, -0x1e84a0(%rbp)
movq -0x1e8498(%rbp), %rdi
movl -0x1e84ec(%rbp), %esi
movl -0x1e84dc(%rbp), %edx
callq 0x82990
movq %rax, -0x1e8508(%rbp)
jmp 0x84274
movq -0x1e8500(%rbp), %rdi
movl -0x1e84ec(%rbp), %esi
callq 0x613e0
movq %rax, -0x1e8498(%rbp)
movq -0x1e8500(%rbp), %rdi
movl -0x1e84f0(%rbp), %esi
callq 0x613e0
movq %rax, -0x1e84a0(%rbp)
movq -0x1e8498(%rbp), %rdi
movl -0x1e84ec(%rbp), %esi
movl -0x1e84dc(%rbp), %edx
callq 0x82ca0
movq %rax, -0x1e8508(%rbp)
cmpl $0x0, -0x1e84e8(%rbp)
jne 0x842be
movq -0x1e8508(%rbp), %rdi
leaq -0x7a130(%rbp), %rsi
callq 0x82390
leaq -0xf4250(%rbp), %rdi
movl -0x1e84dc(%rbp), %edx
leaq 0x63612(%rip), %rsi     # 0xe78b6
movb $0x0, %al
callq 0x4170
leaq -0xf4250(%rbp), %rdi
leaq -0x7a130(%rbp), %rsi
callq 0x493b0
cmpl $0x0, -0x10(%rbp)
je 0x8431b
movq -0x1e8498(%rbp), %rdi
movl -0x1e84ec(%rbp), %esi
movq -0x1e8508(%rbp), %rdx
callq 0x82780
addsd -0x1e84b8(%rbp), %xmm0
movsd %xmm0, -0x1e84b8(%rbp)
movq -0x1e84a0(%rbp), %rdi
movl -0x1e84f0(%rbp), %esi
movq -0x1e8508(%rbp), %rdx
callq 0x82780
movq -0x1e84c0(%rbp), %rax
movslq -0x1e84e8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x84370
movq -0x1e8498(%rbp), %rdi
movl -0x1e84ec(%rbp), %esi
movq -0x1e8508(%rbp), %rdx
callq 0x82580
addsd -0x1e84b8(%rbp), %xmm0
movsd %xmm0, -0x1e84b8(%rbp)
movq -0x1e84a0(%rbp), %rdi
movl -0x1e84f0(%rbp), %esi
movq -0x1e8508(%rbp), %rdx
callq 0x82580
movq -0x1e84c0(%rbp), %rax
movslq -0x1e84e8(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x1e8508(%rbp), %rdi
callq 0x815c0
movq -0x1e8498(%rbp), %rdi
movl -0x1e84ec(%rbp), %esi
callq 0x52e20
movq -0x1e84a0(%rbp), %rdi
movl -0x1e84f0(%rbp), %esi
callq 0x52e20
movl -0x1e84e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e84e8(%rbp)
jmp 0x841a7
leaq -0xf4250(%rbp), %rdi
movl -0x1e84dc(%rbp), %edx
leaq 0x61dab(%rip), %rsi     # 0xe6173
movb $0x0, %al
callq 0x4170
leaq -0x1e8490(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x53310
leaq -0x16e370(%rbp), %rdi
leaq -0x1e8490(%rbp), %rsi
movsd -0x1e84b8(%rbp), %xmm0
cvtsi2sdl -0x1e84ec(%rbp), %xmm1
divsd %xmm1, %xmm0
movb $0x1, %al
callq 0x4170
leaq -0xf4250(%rbp), %rdi
leaq -0x16e370(%rbp), %rsi
callq 0x493b0
movq -0x1e84c0(%rbp), %rdi
movq -0x1e84d0(%rbp), %rdx
movl -0x1e84dc(%rbp), %eax
subl $0x1, %eax
cltq
shlq $0x3, %rax
addq %rax, %rdx
movl $0x64, %esi
callq 0x50350
movq -0x1e84c8(%rbp), %rax
movl -0x1e84dc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x1e84c8(%rbp), %rax
movl -0x1e84dc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x1e84a8(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x844c6
movq -0x1e84c8(%rbp), %rax
movl -0x1e84dc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x1e84a8(%rbp)
movq -0x1e84d0(%rbp), %rax
movl -0x1e84dc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x1e84b0(%rbp)
leaq -0xf4250(%rbp), %rdi
movl -0x1e84dc(%rbp), %edx
leaq 0x62ab0(%rip), %rsi     # 0xe6f8a
movb $0x0, %al
callq 0x4170
leaq -0x1e8490(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x53310
leaq -0x16e370(%rbp), %rdi
leaq -0x1e8490(%rbp), %rsi
movq -0x1e84c8(%rbp), %rax
movl -0x1e84dc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movb $0x1, %al
callq 0x4170
leaq -0xf4250(%rbp), %rdi
leaq -0x16e370(%rbp), %rsi
callq 0x493b0
leaq -0xf4250(%rbp), %rdi
movl -0x1e84dc(%rbp), %edx
leaq 0x63378(%rip), %rsi     # 0xe78c0
movb $0x0, %al
callq 0x4170
leaq -0x1e8490(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x53310
leaq -0x16e370(%rbp), %rdi
leaq -0x1e8490(%rbp), %rsi
movq -0x1e84d0(%rbp), %rax
movl -0x1e84dc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movb $0x1, %al
callq 0x4170
leaq -0xf4250(%rbp), %rdi
leaq -0x16e370(%rbp), %rsi
callq 0x493b0
movl -0x1e84dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e84dc(%rbp)
jmp 0x84183
movl $0x0, -0x1e84e0(%rbp)
movq -0x1e84c8(%rbp), %rax
movslq -0x1e84e0(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x1e84d0(%rbp), %rax
movslq -0x1e84e0(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm0
movsd -0x1e84a8(%rbp), %xmm1
addsd -0x1e84b0(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x8460d
movl -0x1e84e0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e84e0(%rbp)
jmp 0x845c0
movq -0x1e84c8(%rbp), %rdi
callq 0x52e80
movq -0x1e84d0(%rbp), %rdi
callq 0x52e80
movq -0x1e84c0(%rbp), %rdi
callq 0x52e80
cmpl $0x0, -0x10(%rbp)
je 0x846aa
movl $0x0, -0x1e84dc(%rbp)
movl -0x1e84dc(%rbp), %eax
cmpl -0x1e84e4(%rbp), %eax
jge 0x8469c
movq -0x1e84f8(%rbp), %rax
movslq -0x1e84dc(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0x814b0
movl -0x1e84dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e84dc(%rbp)
jmp 0x84641
movq -0x1e84f8(%rbp), %rdi
callq 0x52e80
jmp 0x846b6
movq -0x1e8500(%rbp), %rdi
callq 0x61330
movl -0x1e84e0(%rbp), %eax
addq $0x1e8530, %rsp         # imm = 0x1E8530
popq %rbp
retq
nopw %cs:(%rax,%rax)