// File: /workspace/github_cpp_makefile_star2_O1/qmmlib[P]QmmLibrary/linear.cpp
// Function: load_model
struct model *load_model(const char *model_file_name)
{
	FILE *fp = fopen(model_file_name,"r");
	if(fp==NULL) return NULL;

	int i;
	int nr_feature;
	int n;
	int nr_class;
	double bias;
	model *model_ = Malloc(model,1);
	parameter& param = model_->param;

	model_->label = NULL;
	
	char *old_locale = strdup(setlocale(LC_ALL, NULL));
	setlocale(LC_ALL, "C");

	char cmd[81];
	while(1)
	{
		fscanf(fp,"%80s",cmd);
		if(strcmp(cmd,"solver_type")==0)
		{
			fscanf(fp,"%80s",cmd);
			int i;
			for(i=0;solver_type_table[i];i++)
			{
				if(strcmp(solver_type_table[i],cmd)==0)
				{
					param.solver_type=i;
					break;
				}
			}
			if(solver_type_table[i] == NULL)
			{
				fprintf(stderr,"unknown solver type.\n");
				
				setlocale(LC_ALL, old_locale);
				free(model_->label);
				free(model_);
				free(old_locale);
				return NULL;
			}
		}
		else if(strcmp(cmd,"nr_class")==0)
		{
			fscanf(fp,"%d",&nr_class);
			model_->nr_class=nr_class;
		}
		else if(strcmp(cmd,"nr_feature")==0)
		{
			fscanf(fp,"%d",&nr_feature);
			model_->nr_feature=nr_feature;
		}
		else if(strcmp(cmd,"bias")==0)
		{
			fscanf(fp,"%lf",&bias);
			model_->bias=bias;
		}
		else if(strcmp(cmd,"w")==0)
		{
			break;
		}
		else if(strcmp(cmd,"label")==0)
		{
			int nr_class = model_->nr_class;
			model_->label = Malloc(int,nr_class);
			for(int i=0;i<nr_class;i++)
				fscanf(fp,"%d",&model_->label[i]);
		}
		else
		{
			fprintf(stderr,"unknown text in model file: [%s]\n",cmd);
			setlocale(LC_ALL, old_locale);
			free(model_->label);
			free(model_);
			free(old_locale);
			return NULL;
		}
	}

	nr_feature=model_->nr_feature;
	if(model_->bias>=0)
		n=nr_feature+1;
	else
		n=nr_feature;
	int w_size = n;
	int nr_w;
	if(nr_class==2 && param.solver_type != MCSVM_CS)
		nr_w = 1;
	else
		nr_w = nr_class;

	model_->w=Malloc(double, w_size*nr_w);
	for(i=0; i<w_size; i++)
	{
		int j;
		for(j=0; j<nr_w; j++)
			fscanf(fp, "%lf ", &model_->w[i*nr_w+j]);
		fscanf(fp, "\n");
	}
	
	setlocale(LC_ALL, old_locale);
	free(old_locale);
	
	if (ferror(fp) != 0 || fclose(fp) != 0) return NULL;

	return model_;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
leaq 0x324f(%rip), %rsi      # 0x16286
callq 0x3270
testq %rax, %rax
je 0x1326b
movq %rax, %r14
movl $0xd0, %edi
callq 0x32e0
movq %rax, %rbx
addq $0xc0, %rax
movq %rax, (%rsp)
movq $0x0, 0xc0(%rbx)
movl $0x6, %edi
xorl %esi, %esi
callq 0x31c0
movq %rax, %rdi
callq 0x3410
movq %rax, 0x10(%rsp)
leaq 0x47e7(%rip), %rsi      # 0x17871
movl $0x6, %edi
callq 0x31c0
leaq 0x40(%rsp), %rbp
leaq 0x4502(%rip), %r15      # 0x175a2
movq %r14, %rdi
leaq 0x4520(%rip), %r12      # 0x175ca
movq %r12, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3420
movq 0x40(%rsp), %rax
movabsq $0x745f7265766c6f73, %rcx # imm = 0x745F7265766C6F73
xorq %rcx, %rax
movl 0x48(%rsp), %ecx
xorq $0x657079, %rcx         # imm = 0x657079
orq %rax, %rcx
je 0x131ae
movq 0x40(%rsp), %rax
movabsq $0x7373616c635f726e, %rcx # imm = 0x7373616C635F726E
xorq %rcx, %rax
movzbl 0x48(%rsp), %ecx
orq %rax, %rcx
je 0x131ef
movq 0x40(%rsp), %rax
movabsq $0x75746165665f726e, %rcx # imm = 0x75746165665F726E
xorq %rcx, %rax
movq 0x43(%rsp), %rcx
movabsq $0x65727574616566, %rdx # imm = 0x65727574616566
xorq %rdx, %rcx
orq %rax, %rcx
je 0x13210
movl 0x40(%rsp), %eax
movl $0x73616962, %ecx       # imm = 0x73616962
xorl %ecx, %eax
movzbl 0x44(%rsp), %ecx
orl %eax, %ecx
je 0x13231
cmpw $0x77, 0x40(%rsp)
je 0x1327f
movl 0x40(%rsp), %eax
movl $0x6562616c, %ecx       # imm = 0x6562616C
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x6c, %ecx
orl %eax, %ecx
jne 0x1338b
movslq 0xb0(%rbx), %r13
leaq (,%r13,4), %rdi
callq 0x32e0
movq %rax, 0xc0(%rbx)
testq %r13, %r13
jle 0x130a0
movq %rax, %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3420
addq $0x4, %r12
decq %r13
jne 0x13190
jmp 0x130a0
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3420
leaq 0x79bb(%rip), %r13      # 0x1ab80
xorl %r12d, %r12d
movq (%r13), %rdi
movq %rbp, %rsi
callq 0x3300
testl %eax, %eax
je 0x131e7
incq %r12
addq $0x8, %r13
cmpq $0x38, %r12
jne 0x131c8
jmp 0x1325a
movl %r12d, (%rbx)
jmp 0x130a0
movq %r14, %rdi
movq %r15, %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x3420
movl 0x8(%rsp), %eax
movl %eax, 0xb0(%rbx)
jmp 0x130a0
movq %r14, %rdi
movq %r15, %rsi
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x3420
movl 0xc(%rsp), %eax
movl %eax, 0xb4(%rbx)
jmp 0x130a0
movq %r14, %rdi
leaq 0x43cf(%rip), %rsi      # 0x1760a
leaq 0x38(%rsp), %rdx
xorl %eax, %eax
callq 0x3420
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0xc8(%rbx)
jmp 0x130a0
movq 0x10(%rsp), %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
callq 0x391e
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xb4(%rbx), %ebp
movl %ebp, 0xc(%rsp)
movsd 0xc8(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
sbbl $-0x1, %ebp
movl 0x8(%rsp), %eax
cmpl $0x2, %eax
jne 0x132af
movl $0x1, %ecx
cmpl $0x4, (%rbx)
jne 0x132b1
movl %eax, %ecx
movl %ecx, (%rsp)
movl %ecx, %eax
imull %ebp, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x32e0
movl (%rsp), %ecx
movq %rbx, 0x18(%rsp)
movq %rax, 0xb8(%rbx)
testl %ebp, %ebp
jle 0x13348
movq %rax, %r15
movl %ecx, %eax
movl %ebp, %edx
movq %rdx, 0x30(%rsp)
movq %rax, 0x20(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x28(%rsp)
leaq 0x4333(%rip), %r12      # 0x17630
xorl %r13d, %r13d
testl %ecx, %ecx
jle 0x13325
movq 0x20(%rsp), %rbx
movq %r15, %rbp
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3420
addq $0x8, %rbp
decq %rbx
jne 0x1330c
movq %r14, %rdi
leaq 0x2f7a(%rip), %rsi      # 0x162a9
xorl %eax, %eax
callq 0x3420
incq %r13
addq 0x28(%rsp), %r15
cmpq 0x30(%rsp), %r13
movl (%rsp), %ecx
jne 0x13300
movl $0x6, %edi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x31c0
movq %rbx, %rdi
callq 0x3280
movq %r14, %rdi
callq 0x3430
testl %eax, %eax
jne 0x1326b
movq %r14, %rdi
callq 0x31f0
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmoveq 0x18(%rsp), %rax
jmp 0x1326d
leaq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
movq %rbx, %rcx
callq 0x38cc
jmp 0x1326b