// File: /workspace/github_cpp_makefile_star2_O3/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 0x3687(%rip), %rsi      # 0x182b4
callq 0x3280
testq %rax, %rax
je 0x14eb9
movq %rax, %r14
movl $0xd0, %edi
callq 0x32f0
movq %rax, %rbp
movq $0x0, 0xc0(%rax)
movl $0x6, %edi
xorl %esi, %esi
callq 0x31d0
movq %rax, %rdi
callq 0x3420
movq %rax, 0x18(%rsp)
leaq 0x4c6b(%rip), %rsi      # 0x198e1
movl $0x6, %edi
callq 0x31d0
leaq 0x49b3(%rip), %r12      # 0x1963a
leaq 0x40(%rsp), %r13
leaq 0x4(%rsp), %r15
movq $0x0, 0x8(%rsp)
movq %rbp, 0x30(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3430
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 0x14de6
movq 0x40(%rsp), %rax
movabsq $0x7373616c635f726e, %rcx # imm = 0x7373616C635F726E
xorq %rcx, %rax
movzbl 0x48(%rsp), %ecx
orq %rax, %rcx
je 0x14e30
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
leaq 0x48ef(%rip), %rsi      # 0x19612
je 0x14e56
movl 0x40(%rsp), %eax
movl $0x73616962, %ecx       # imm = 0x73616962
xorl %ecx, %eax
movzbl 0x44(%rsp), %ecx
orl %eax, %ecx
je 0x14e78
cmpw $0x77, 0x40(%rsp)
je 0x14ecd
movl 0x40(%rsp), %eax
movl $0x6562616c, %ecx       # imm = 0x6562616C
xorl %ecx, %eax
movzwl 0x44(%rsp), %ecx
xorl $0x6c, %ecx
orl %eax, %ecx
jne 0x14fd3
movslq (%rsp), %r12
leaq (,%r12,4), %rdi
callq 0x32f0
movq %rax, 0x8(%rsp)
movq %rax, 0xc0(%rbp)
testl %r12d, %r12d
leaq 0x48ab(%rip), %r12      # 0x1963a
jle 0x14c9f
movl (%rsp), %r12d
shlq $0x2, %r12
xorl %ebp, %ebp
leaq 0x486c(%rip), %r15      # 0x19612
movq %r14, %r13
movq 0x8(%rsp), %r14
leaq (%r14,%rbp), %rdx
movq %r13, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x3430
addq $0x4, %rbp
cmpq %rbp, %r12
jne 0x14dae
movq 0x30(%rsp), %rbp
leaq 0x4866(%rip), %r12      # 0x1963a
leaq 0x4(%rsp), %r15
movq %r13, %r14
leaq 0x40(%rsp), %r13
jmp 0x14c9f
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0x8d83(%rip), %r12      # 0x1db80
xorl %ebx, %ebx
movq (%r12), %rdi
movq %r13, %rsi
callq 0x3310
testl %eax, %eax
je 0x14e21
incq %rbx
addq $0x8, %r12
cmpq $0x38, %rbx
jne 0x14dff
jmp 0x14ea7
movl %ebx, (%rbp)
leaq 0x480f(%rip), %r12      # 0x1963a
jmp 0x14c9f
movq %r14, %rdi
leaq 0x47d8(%rip), %rsi      # 0x19612
movq %r15, %rdx
xorl %eax, %eax
callq 0x3430
movl 0x4(%rsp), %eax
movl %eax, (%rsp)
movl %eax, 0xb0(%rbp)
jmp 0x14c9f
movq %r14, %rdi
leaq 0x14(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
movl 0x14(%rsp), %eax
movl %eax, 0x28(%rsp)
movl %eax, 0xb4(%rbp)
jmp 0x14c9f
movq %r14, %rdi
leaq 0x47f8(%rip), %rsi      # 0x1967a
leaq 0x38(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd %xmm0, 0xc8(%rbp)
jmp 0x14c9f
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x392e
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm0, %xmm0
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl 0x28(%rsp), %r12d
movl %r12d, 0x14(%rsp)
sbbl $-0x1, %r12d
movl 0x4(%rsp), %eax
cmpl $0x4, %ebx
movl $0x1, %ecx
cmovel %eax, %ecx
cmpl $0x2, %eax
cmovnel %eax, %ecx
movl %ecx, (%rsp)
movl %ecx, %eax
imull %r12d, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x32f0
movq %rax, %r15
movq %rax, 0xb8(%rbp)
testl %r12d, %r12d
jle 0x14f90
movl (%rsp), %ecx
movl %r12d, %eax
movq %rax, 0x8(%rsp)
movq %rcx, 0x20(%rsp)
leaq (,%rcx,8), %rax
movq %rax, 0x28(%rsp)
leaq 0x475a(%rip), %r12      # 0x196a0
xorl %r13d, %r13d
cmpl $0x0, (%rsp)
jle 0x14f70
movq 0x20(%rsp), %rbx
movq %r15, %rbp
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x3430
addq $0x8, %rbp
decq %rbx
jne 0x14f57
movq %r14, %rdi
leaq 0x335d(%rip), %rsi      # 0x182d7
xorl %eax, %eax
callq 0x3430
incq %r13
addq 0x28(%rsp), %r15
cmpq 0x8(%rsp), %r13
jne 0x14f49
movl $0x6, %edi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x31d0
movq %rbx, %rdi
callq 0x3290
movq %r14, %rdi
callq 0x3440
testl %eax, %eax
jne 0x14eb9
movq %r14, %rdi
callq 0x3200
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmoveq 0x30(%rsp), %rax
jmp 0x14ebb
leaq 0x40(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rbp, %rcx
callq 0x38dc
jmp 0x14eb9