// File: /workspace/github_cpp_makefile_star2_O1/cjlin1[P]liblinear/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,"%.17g\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(check_regression_model(model_))
	{
		info("Mean squared error = %g (regression)\n",error/total);
		info("Squared correlation coefficient = %g (regression)\n",
			((total*sumpt-sump*sumt)*(total*sumpt-sump*sumt))/
			((total*sumpp-sump*sump)*(total*sumtt-sumt*sumt))
			);
	}
	else
		info("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 $0x78, %rsp
movq %rsi, %r12
movq %rdi, 0x50(%rsp)
movq 0xe87f(%rip), %rdi      # 0x111a0
callq 0xaa99
movl %eax, %ebx
movq 0xe871(%rip), %rdi      # 0x111a0
callq 0xaa95
movq 0xe865(%rip), %rdi      # 0x111a0
movsd 0x68(%rdi), %xmm0
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
movsd %xmm1, 0x48(%rsp)
ucomisd %xmm2, %xmm0
movl %eax, 0x5c(%rsp)
sbbl $-0x1, %eax
movl %eax, 0x58(%rsp)
xorl %ebp, %ebp
cmpl $0x0, 0xe842(%rip)      # 0x111a8
je 0x2a0b
callq 0xa30a
testl %eax, %eax
je 0x2f7d
movslq %ebx, %r15
leaq (,%r15,4), %rdi
callq 0x21a0
movq %rax, %r14
movq 0xe80d(%rip), %rdi      # 0x111a0
movq %rax, %rsi
callq 0xaa9d
leaq (,%r15,8), %rdi
callq 0x21a0
movq %rax, %r13
leaq 0xa6c3(%rip), %rdi      # 0xd075
movl $0x6, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x22a0
testl %r15d, %r15d
movl %ebx, %eax
movq %r12, %rbx
jle 0x29f1
movl %eax, %r15d
xorl %r12d, %r12d
movl (%r14,%r12,4), %edx
movq %rbx, %rdi
leaq 0xa69a(%rip), %rsi      # 0xd07c
xorl %eax, %eax
callq 0x21d0
incq %r12
cmpq %r12, %r15
jne 0x29d4
movl $0xa, %edi
movq %rbx, %rsi
callq 0x2180
movq %r14, %rdi
callq 0x2160
movq %rbx, %r12
jmp 0x2a0e
xorl %r13d, %r13d
movl $0x400, 0xe794(%rip)    # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x21a0
movq %rax, 0xe787(%rip)      # 0x111b0
movq %rax, %rdi
movl $0x400, %esi            # imm = 0x400
movq 0x50(%rsp), %rdx
callq 0x2210
xorpd %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd %xmm0, 0x38(%rsp)
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x20(%rsp)
movl $0x0, %ecx
movq %rcx, 0x18(%rsp)
testq %rax, %rax
je 0x2e5a
movq $0x0, 0x18(%rsp)
leaq 0xa609(%rip), %r14      # 0xd089
xorl %ebp, %ebp
movsd %xmm0, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x30(%rsp)
movsd %xmm0, 0x38(%rsp)
movsd %xmm0, 0x40(%rsp)
movsd %xmm0, 0x48(%rsp)
movq %r13, 0x68(%rsp)
movq %r12, 0x60(%rsp)
movq 0xe6f9(%rip), %rbx      # 0x111b0
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
testq %rax, %rax
jne 0x2b14
movslq 0xe6dc(%rip), %r15      # 0x111ac
addq %r15, %r15
movl %r15d, 0xe6d2(%rip)     # 0x111ac
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2220
movq %rax, %rbx
movq %rax, 0xe6c1(%rip)      # 0x111b0
movq %rax, %rdi
callq 0x2070
cltq
addq %rax, %rbx
subl %eax, %r15d
movq %rbx, %rdi
movl %r15d, %esi
movq 0x50(%rsp), %rdx
callq 0x2210
testq %rax, %rax
jne 0x2ab0
cmpq $0x0, 0xe694(%rip)      # 0x111b0
je 0x2e5a
movq 0xe687(%rip), %rdi      # 0x111b0
leaq 0xa550(%rip), %rsi      # 0xd080
callq 0x2200
testq %rax, %rax
je 0x2f76
movq %rax, %rbx
movq %rbp, 0x8(%rsp)
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x20a0
movq 0x10(%rsp), %rax
cmpq %rbx, %rax
je 0x2f6c
cmpb $0x0, (%rax)
jne 0x2f6c
movsd %xmm0, 0x70(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq 0xe5ec(%rip), %rsi      # 0x11168
leal -0x2(%rsi), %eax
cmpl %eax, %r13d
jl 0x2ba4
leal (%rsi,%rsi), %eax
movl %eax, 0xe5db(%rip)      # 0x11168
movq 0xe604(%rip), %rdi      # 0x11198
shlq $0x5, %rsi
callq 0x2220
movq %rax, 0xe5f4(%rip)      # 0x11198
xorl %edi, %edi
leaq 0xa4d7(%rip), %rsi      # 0xd084
callq 0x2200
movq %rax, %rbx
xorl %edi, %edi
leaq 0xa4c8(%rip), %rsi      # 0xd086
callq 0x2200
testq %rax, %rax
je 0x2ca9
movq %rax, %r12
callq 0x2040
movl %r13d, %r14d
movq %rax, %r13
movl $0x0, (%rax)
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x21c0
movq %rax, %r15
movq 0xe59c(%rip), %rax      # 0x11198
movl %r14d, (%rsp)
movl %r14d, %r14d
shlq $0x4, %r14
movl %r15d, (%rax,%r14)
movq 0x10(%rsp), %rax
cmpq %rbx, %rax
je 0x2f58
cmpl $0x0, (%r13)
jne 0x2f58
cmpb $0x0, (%rax)
jne 0x2f58
cmpl %r15d, %ebp
jge 0x2f58
movl $0x0, (%r13)
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x20a0
movq 0xe546(%rip), %rbx      # 0x11198
movsd %xmm0, 0x8(%rbx,%r14)
movq 0x10(%rsp), %rax
cmpq %r12, %rax
je 0x2f62
cmpl $0x0, (%r13)
jne 0x2f62
movsbl (%rax), %edi
testl %edi, %edi
je 0x2c86
callq 0x2050
testl %eax, %eax
je 0x2f62
xorl %eax, %eax
movl 0x5c(%rsp), %ecx
cmpl %ecx, (%rbx,%r14)
setle %al
movl (%rsp), %r13d
addl %eax, %r13d
movl %r15d, %ebp
leaq 0xa3e5(%rip), %r14      # 0xd089
jmp 0x2b75
movq 0xe4f0(%rip), %rdi      # 0x111a0
movsd 0x68(%rdi), %xmm0
ucomisd 0xa353(%rip), %xmm0     # 0xd010
jb 0x2cdd
movq 0xe4d2(%rip), %rax      # 0x11198
movl %r13d, %ecx
shlq $0x4, %rcx
movl 0x58(%rsp), %edx
movl %edx, (%rax,%rcx)
movsd %xmm0, 0x8(%rax,%rcx)
incl %r13d
movq 0x60(%rsp), %r12
movq 0xe4af(%rip), %rsi      # 0x11198
movslq %r13d, %rax
shlq $0x4, %rax
movl $0xffffffff, (%rsi,%rax) # imm = 0xFFFFFFFF
cmpl $0x0, 0xe4aa(%rip)      # 0x111a8
je 0x2d72
movq 0x68(%rsp), %r13
movq %r13, %rdx
callq 0xa226
movq %r12, %rdi
leaq 0xa373(%rip), %rsi      # 0xd08a
movsd %xmm0, (%rsp)
movb $0x1, %al
callq 0x21d0
movq 0xe476(%rip), %rax      # 0x111a0
cmpl $0x0, 0x50(%rax)
movq 0x8(%rsp), %rbp
jle 0x2d5e
xorl %ebx, %ebx
movsd (%r13,%rbx,8), %xmm0
movq %r12, %rdi
movq %r14, %rsi
movb $0x1, %al
callq 0x21d0
incq %rbx
movq 0xe44b(%rip), %rax      # 0x111a0
movslq 0x50(%rax), %rax
cmpq %rax, %rbx
jl 0x2d37
movl $0xa, %edi
movq %r12, %rsi
callq 0x2180
movsd (%rsp), %xmm3
jmp 0x2d9c
callq 0x9580
movsd %xmm0, (%rsp)
movq %r12, %rdi
leaq 0xa919(%rip), %rsi      # 0xd69f
movb $0x1, %al
callq 0x21d0
movsd (%rsp), %xmm3
movq 0x68(%rsp), %r13
movq 0x8(%rsp), %rbp
movapd %xmm3, %xmm0
movsd 0x70(%rsp), %xmm2
cmpeqsd %xmm2, %xmm0
movq %xmm0, %rax
movq 0x18(%rsp), %rcx
subl %eax, %ecx
movq %rcx, 0x18(%rsp)
movapd %xmm3, %xmm0
subsd %xmm2, %xmm0
mulsd %xmm0, %xmm0
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0x28(%rsp), %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x30(%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x30(%rsp)
movapd %xmm3, %xmm0
mulsd %xmm3, %xmm0
movsd 0x38(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
mulsd %xmm2, %xmm3
mulsd %xmm2, %xmm2
movsd 0x40(%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x48(%rsp), %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, 0x48(%rsp)
incl %ebp
movq 0xe36f(%rip), %rdi      # 0x111b0
movl 0xe365(%rip), %esi      # 0x111ac
movq 0x50(%rsp), %rdx
callq 0x2210
testq %rax, %rax
jne 0x2ab0
movq 0xe33f(%rip), %rdi      # 0x111a0
callq 0x69d5
movq 0xe303(%rip), %rcx      # 0x11170
testl %eax, %eax
je 0x2efe
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd %xmm1, (%rsp)
movsd 0x20(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0xa1fb(%rip), %rdi      # 0xd08d
movb $0x1, %al
callq *%rcx
movsd 0x30(%rsp), %xmm3
movapd %xmm3, %xmm1
movsd 0x28(%rsp), %xmm4
mulsd %xmm4, %xmm1
movsd 0x48(%rsp), %xmm0
movsd (%rsp), %xmm5
mulsd %xmm5, %xmm0
subsd %xmm1, %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm4, %xmm4
movsd 0x38(%rsp), %xmm2
mulsd %xmm5, %xmm2
subsd %xmm4, %xmm2
mulsd %xmm3, %xmm3
movsd 0x40(%rsp), %xmm1
mulsd %xmm5, %xmm1
subsd %xmm3, %xmm1
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0xa1bf(%rip), %rdi      # 0xd0b3
movb $0x1, %al
callq *0xe274(%rip)           # 0x11170
jmp 0x2f2a
movq 0x18(%rsp), %rsi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
divsd %xmm1, %xmm0
mulsd 0xa0eb(%rip), %xmm0     # 0xd008
leaq 0xa1c2(%rip), %rdi      # 0xd0e6
movl %ebp, %edx
movb $0x1, %al
callq *%rcx
cmpl $0x0, 0xe277(%rip)      # 0x111a8
je 0x2f49
movq %r13, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2160
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
callq 0x230a
movq 0x8(%rsp), %rdi
callq 0x22e5
movq 0x8(%rsp), %rdi
callq 0x232f
movl %ebp, %edi
callq 0x2354
callq 0x22c0