// File: /workspace/github_cpp_makefile_star2_O3/qmmlib[P]QmmLibrary/predict.c
// Function: do_predict(_IO_FILE*, _IO_FILE*)
void do_predict(FILE *input, FILE *output)
{
	int correct = 0;
	int total = 0;
	double error = 0;
	double sump = 0, sumt = 0, sumpp = 0, sumtt = 0, sumpt = 0;

	int nr_class=get_nr_class(model_);
	double *prob_estimates=NULL;
	int j, n;
	int nr_feature=get_nr_feature(model_);
	if(model_->bias>=0)
		n=nr_feature+1;
	else
		n=nr_feature;

	if(flag_predict_probability)
	{
		int *labels;

		if(!check_probability_model(model_))
		{
			fprintf(stderr, "probability output is only supported for logistic regression\n");
			exit(1);
		}

		labels=(int *) malloc(nr_class*sizeof(int));
		get_labels(model_,labels);
		prob_estimates = (double *) malloc(nr_class*sizeof(double));
		fprintf(output,"labels");		
		for(j=0;j<nr_class;j++)
			fprintf(output," %d",labels[j]);
		fprintf(output,"\n");
		free(labels);
	}

	max_line_len = 1024;
	line = (char *)malloc(max_line_len*sizeof(char));
	while(readline(input) != NULL)
	{
		int i = 0;
		double target_label, predict_label;
		char *idx, *val, *label, *endptr;
		int inst_max_index = 0; // strtol gives 0 if wrong format

		label = strtok(line," \t\n");
		if(label == NULL) // empty line
			exit_input_error(total+1);

		target_label = strtod(label,&endptr);
		if(endptr == label || *endptr != '\0')
			exit_input_error(total+1);

		while(1)
		{
			if(i>=max_nr_attr-2)	// need one more for index = -1
			{
				max_nr_attr *= 2;
				x = (struct feature_node *) realloc(x,max_nr_attr*sizeof(struct feature_node));
			}

			idx = strtok(NULL,":");
			val = strtok(NULL," \t");

			if(val == NULL)
				break;
			errno = 0;
			x[i].index = (int) strtol(idx,&endptr,10);
			if(endptr == idx || errno != 0 || *endptr != '\0' || x[i].index <= inst_max_index)
				exit_input_error(total+1);
			else
				inst_max_index = x[i].index;

			errno = 0;
			x[i].value = strtod(val,&endptr);
			if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr)))
				exit_input_error(total+1);

			// feature indices larger than those in training are not used
			if(x[i].index <= nr_feature)
				++i;
		}

		if(model_->bias>=0)
		{
			x[i].index = n;
			x[i].value = model_->bias;
			i++;
		}
		x[i].index = -1;

		if(flag_predict_probability)
		{
			int j;
			predict_label = predict_probability(model_,x,prob_estimates);
			fprintf(output,"%g",predict_label);
			for(j=0;j<model_->nr_class;j++)
				fprintf(output," %g",prob_estimates[j]);
			fprintf(output,"\n");
		}
		else
		{
			predict_label = predict(model_,x);
			fprintf(output,"%g\n",predict_label);
		}

		if(predict_label == target_label)
			++correct;
		error += (predict_label-target_label)*(predict_label-target_label);
                sump += predict_label;
                sumt += target_label;
                sumpp += predict_label*predict_label;
                sumtt += target_label*target_label;
                sumpt += predict_label*target_label;
                ++total;
        }
        if(model_->param.solver_type==L2R_L2LOSS_SVR || 
           model_->param.solver_type==L2R_L1LOSS_SVR_DUAL || 
           model_->param.solver_type==L2R_L2LOSS_SVR_DUAL)
        {
                printf("Mean squared error = %g (regression)\n",error/total);
                printf("Squared correlation coefficient = %g (regression)\n",
                       ((total*sumpt-sump*sumt)*(total*sumpt-sump*sumt))/
                       ((total*sumpp-sump*sump)*(total*sumtt-sumt*sumt))
                       );
        }
	else
		printf("Accuracy = %g%% (%d/%d)\n",(double) correct/total*100,correct,total);
	if(flag_predict_probability)
		free(prob_estimates);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r12
movq %rdi, 0x30(%rsp)
movq 0x18707(%rip), %rdi     # 0x1c248
callq 0x145d2
movl %eax, %ebx
movq 0x186f9(%rip), %rdi     # 0x1c248
callq 0x145cb
movq 0x186ed(%rip), %rdi     # 0x1c248
movsd 0xc8(%rdi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movl %eax, 0x3c(%rsp)
sbbl $-0x1, %eax
movl %eax, 0x38(%rsp)
xorl %ebp, %ebp
cmpl $0x0, 0x186d1(%rip)     # 0x1c250
je 0x3c24
callq 0x13d27
testl %eax, %eax
je 0x4161
movslq %ebx, %r15
leaq (,%r15,4), %rdi
callq 0x32b0
movq %rax, %r14
movq 0x1869c(%rip), %rdi     # 0x1c248
movq %rax, %rsi
callq 0x145d9
leaq (,%r15,8), %rdi
callq 0x32b0
movq %rax, %r13
leaq 0x134aa(%rip), %rdi     # 0x17075
movl $0x6, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x3410
testl %r15d, %r15d
movl %ebx, %eax
movq %r12, %rbx
jle 0x3c0a
movl %eax, %r15d
xorl %r12d, %r12d
movl (%r14,%r12,4), %edx
movq %rbx, %rdi
leaq 0x13481(%rip), %rsi     # 0x1707c
xorl %eax, %eax
callq 0x32f0
incq %r12
cmpq %r12, %r15
jne 0x3bed
movl $0xa, %edi
movq %rbx, %rsi
callq 0x3280
movq %r14, %rdi
callq 0x3250
movq %rbx, %r12
jmp 0x3c27
xorl %r13d, %r13d
movl $0x400, 0x18623(%rip)   # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x32b0
movq %rax, 0x18616(%rip)     # 0x1c258
movq %rax, %rdi
movl $0x400, %esi            # imm = 0x400
movq 0x30(%rsp), %rdx
callq 0x3340
xorpd %xmm0, %xmm0
testq %rax, %rax
je 0x401b
movapd %xmm0, 0x70(%rsp)
movq $0x0, 0x18(%rsp)
leaq 0x13412(%rip), %r14     # 0x17089
xorl %ebp, %ebp
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x40(%rsp)
movq %r13, 0x58(%rsp)
movq %r12, 0x50(%rsp)
movq 0x185c2(%rip), %rbx     # 0x1c258
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3200
testq %rax, %rax
jne 0x3cfa
movslq 0x185a5(%rip), %r15     # 0x1c254
addq %r15, %r15
movl %r15d, 0x1859b(%rip)    # 0x1c254
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3380
movq %rax, %rbx
movq %rax, 0x1858a(%rip)     # 0x1c258
movq %rax, %rdi
callq 0x30b0
cltq
addq %rax, %rbx
subl %eax, %r15d
movq %rbx, %rdi
movl %r15d, %esi
movq 0x30(%rsp), %rdx
callq 0x3340
testq %rax, %rax
jne 0x3c8f
movq 0x1855e(%rip), %rbx     # 0x1c258
testq %rbx, %rbx
je 0x4036
movq %rbx, %rdi
leaq 0x13373(%rip), %rsi     # 0x17080
callq 0x3330
testq %rax, %rax
je 0x415a
movq %rax, %rbx
movq %rbp, 0x8(%rsp)
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3130
movq 0x10(%rsp), %rax
cmpq %rbx, %rax
je 0x4150
cmpb $0x0, (%rax)
jne 0x4150
movapd %xmm0, 0x80(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq 0x184c4(%rip), %rsi     # 0x1c220
leal -0x2(%rsi), %eax
cmpl %eax, %r13d
jl 0x3d84
leal (%rsi,%rsi), %eax
movl %eax, 0x184b3(%rip)     # 0x1c220
movq 0x184cc(%rip), %rdi     # 0x1c240
shlq $0x5, %rsi
callq 0x3380
movq %rax, 0x184bc(%rip)     # 0x1c240
xorl %edi, %edi
leaq 0x132f7(%rip), %rsi     # 0x17084
callq 0x3330
movq %rax, %rbx
xorl %edi, %edi
leaq 0x132e8(%rip), %rsi     # 0x17086
callq 0x3330
testq %rax, %rax
je 0x3e8b
movq %rax, %r12
callq 0x3040
movl %r13d, %r14d
movq %rax, %r13
movl $0x0, (%rax)
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x32e0
movq %rax, %r15
movq 0x18464(%rip), %rax     # 0x1c240
movl %r14d, 0x20(%rsp)
movl %r14d, %r14d
shlq $0x4, %r14
movl %r15d, (%rax,%r14)
movq 0x10(%rsp), %rax
cmpq %rbx, %rax
je 0x413c
cmpl $0x0, (%r13)
jne 0x413c
cmpb $0x0, (%rax)
jne 0x413c
cmpl %r15d, %ebp
jge 0x413c
movl $0x0, (%r13)
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3130
movq 0x1840d(%rip), %rbx     # 0x1c240
movsd %xmm0, 0x8(%rbx,%r14)
movq 0x10(%rsp), %rax
cmpq %r12, %rax
je 0x4146
cmpl $0x0, (%r13)
jne 0x4146
movsbl (%rax), %edi
testl %edi, %edi
je 0x3e67
callq 0x3060
testl %eax, %eax
je 0x4146
xorl %eax, %eax
movl 0x3c(%rsp), %ecx
cmpl %ecx, (%rbx,%r14)
setle %al
movl 0x20(%rsp), %r13d
addl %eax, %r13d
movl %r15d, %ebp
leaq 0x13203(%rip), %r14     # 0x17089
jmp 0x3d55
movq 0x183b6(%rip), %rdi     # 0x1c248
movsd 0xc8(%rdi), %xmm0
ucomisd 0x1316e(%rip), %xmm0    # 0x17010
movq 0x18397(%rip), %rsi     # 0x1c240
jb 0x3ec2
movl %r13d, %eax
shlq $0x4, %rax
movl 0x38(%rsp), %ecx
movl %ecx, (%rsi,%rax)
movsd %xmm0, 0x8(%rsi,%rax)
incl %r13d
movq 0x50(%rsp), %r12
movslq %r13d, %rax
shlq $0x4, %rax
movl $0xffffffff, (%rsi,%rax) # imm = 0xFFFFFFFF
cmpl $0x0, 0x18374(%rip)     # 0x1c250
je 0x3f58
movq 0x58(%rsp), %r13
movq %r13, %rdx
callq 0x13c40
movq %r12, %rdi
leaq 0x13195(%rip), %rsi     # 0x1708a
movapd %xmm0, 0x20(%rsp)
movb $0x1, %al
callq 0x32f0
movq 0x1833f(%rip), %rax     # 0x1c248
cmpl $0x0, 0xb0(%rax)
movq 0x8(%rsp), %rbp
jle 0x3f43
xorl %ebx, %ebx
movsd (%r13,%rbx,8), %xmm0
movq %r12, %rdi
movq %r14, %rsi
movb $0x1, %al
callq 0x32f0
incq %rbx
movq 0x18311(%rip), %rax     # 0x1c248
movslq 0xb0(%rax), %rax
cmpq %rax, %rbx
jl 0x3f19
movl $0xa, %edi
movq %r12, %rsi
callq 0x3280
movapd 0x20(%rsp), %xmm4
jmp 0x3f84
callq 0x13a9d
movapd %xmm0, 0x20(%rsp)
movq %r12, %rdi
leaq 0x13120(%rip), %rsi     # 0x1708d
movb $0x1, %al
callq 0x32f0
movapd 0x20(%rsp), %xmm4
movq 0x58(%rsp), %r13
movq 0x8(%rsp), %rbp
movapd %xmm4, %xmm0
movapd 0x80(%rsp), %xmm3
cmpeqsd %xmm3, %xmm0
movq %xmm0, %rax
movq 0x18(%rsp), %rcx
subl %eax, %ecx
movq %rcx, 0x18(%rsp)
movapd %xmm4, %xmm0
subsd %xmm3, %xmm0
movapd %xmm4, %xmm1
unpcklpd %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0]
movapd 0x60(%rsp), %xmm2
addpd %xmm1, %xmm2
movapd %xmm2, 0x60(%rsp)
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
mulpd %xmm3, %xmm3
movapd 0x40(%rsp), %xmm0
addpd %xmm3, %xmm0
movapd %xmm0, 0x40(%rsp)
unpcklpd %xmm4, %xmm4            # xmm4 = xmm4[0,0]
mulpd %xmm1, %xmm4
movapd 0x70(%rsp), %xmm0
addpd %xmm4, %xmm0
movapd %xmm0, 0x70(%rsp)
incl %ebp
movq 0x18258(%rip), %rdi     # 0x1c258
movl 0x1824e(%rip), %esi     # 0x1c254
movq 0x30(%rsp), %rdx
callq 0x3340
testq %rax, %rax
jne 0x3c8f
jmp 0x4036
movapd %xmm0, 0x70(%rsp)
movq $0x0, 0x18(%rsp)
movapd %xmm0, 0x60(%rsp)
movapd %xmm0, 0x40(%rsp)
movq 0x1820b(%rip), %rax     # 0x1c248
movl (%rax), %eax
addl $-0xb, %eax
cmpl $0x2, %eax
ja 0x40d9
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movapd %xmm1, 0x20(%rsp)
movapd 0x40(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
divsd %xmm1, %xmm0
leaq 0x13024(%rip), %rdi     # 0x17091
movb $0x1, %al
callq 0x3050
movapd 0x60(%rsp), %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
mulsd %xmm0, %xmm0
movapd 0x40(%rsp), %xmm2
movapd 0x20(%rsp), %xmm3
mulsd %xmm3, %xmm2
subsd %xmm0, %xmm2
movapd %xmm1, %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
mulpd %xmm1, %xmm0
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
mulpd 0x70(%rsp), %xmm3
subpd %xmm0, %xmm3
shufpd $0x2, %xmm3, %xmm2      # xmm2 = xmm2[0],xmm3[1]
mulpd %xmm3, %xmm2
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
divsd %xmm2, %xmm0
leaq 0x12fe7(%rip), %rdi     # 0x170b7
movb $0x1, %al
callq 0x3050
jmp 0x4108
movq 0x18(%rsp), %rsi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
divsd %xmm1, %xmm0
mulsd 0x12f10(%rip), %xmm0    # 0x17008
leaq 0x12feb(%rip), %rdi     # 0x170ea
movl %ebp, %edx
movb $0x1, %al
callq 0x3050
cmpl $0x0, 0x18141(%rip)     # 0x1c250
je 0x412a
movq %r13, %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3250
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
callq 0x347a
movq 0x8(%rsp), %rdi
callq 0x3455
movq 0x8(%rsp), %rdi
callq 0x349f
movl %ebp, %edi
callq 0x34c4
callq 0x3430