// File: /workspace/github_cpp_makefile_star2_O2/cjlin1[P]liblinear/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;
	double rho;
	model *model_ = Malloc(model,1);
	parameter& param = model_->param;
	// parameters for training only won't be assigned, but arrays are assigned as NULL for safety
	param.nr_weight = 0;
	param.weight_label = NULL;
	param.weight = NULL;
	param.init_sol = NULL;

	model_->label = NULL;

	char *old_locale = setlocale(LC_ALL, NULL);
	if (old_locale)
	{
		old_locale = strdup(old_locale);
	}
	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");
				EXIT_LOAD_MODEL()
			}
		}
		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,"rho")==0)
		{
			FSCANF(fp,"%lf",&rho);
			model_->rho=rho;
		}
		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);
			EXIT_LOAD_MODEL()
		}
	}

	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]);
	}

	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 $0xa8, %rsp
leaq 0x26ae(%rip), %rsi      # 0xc31b
callq 0x2190
testq %rax, %rax
je 0xa071
movq %rax, %r12
pushq $0x78
popq %rdi
callq 0x21f0
movq %rax, %rbx
andl $0x0, 0x18(%rax)
andq $0x0, 0x40(%rax)
andq $0x0, 0x60(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
pushq $0x6
popq %rdi
xorl %esi, %esi
callq 0x2110
movl $0x0, %ecx
testq %rax, %rax
je 0x9cbd
movq %rax, %rdi
callq 0x22b0
movq %rax, %rcx
movq %rcx, 0x8(%rsp)
leaq 0x39b5(%rip), %rsi      # 0xd67e
pushq $0x6
popq %rdi
callq 0x2110
leaq 0x33ce(%rip), %r13      # 0xd0a6
leaq 0x50(%rsp), %rbp
movq %rax, 0x20(%rsp)
movq $0x0, (%rsp)
movq %rbx, 0x18(%rsp)
movl 0x30(%rsp), %ecx
movslq %ecx, %rax
leaq (,%rax,4), %rdx
movq %rdx, 0x28(%rsp)
testl %eax, %eax
movl $0x0, %eax
cmovgl %ecx, %eax
leaq 0x4(,%rax,4), %r14
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0x9f12
movq %rbp, %rdi
leaq 0x339b(%rip), %rsi      # 0xd0d3
pushq $0xc
popq %rdx
callq 0x2150
testl %eax, %eax
je 0x9e3d
movq %rbp, %rdi
leaq 0x33a3(%rip), %rsi      # 0xd0f5
pushq $0x9
popq %rdx
callq 0x2150
testl %eax, %eax
je 0x9e82
movq %rbp, %rdi
leaq 0x3392(%rip), %rsi      # 0xd0fe
pushq $0xb
popq %rdx
callq 0x2150
testl %eax, %eax
je 0x9ead
movq %rbp, %rdi
leaq 0x3383(%rip), %rsi      # 0xd109
pushq $0x5
popq %rdx
callq 0x2150
testl %eax, %eax
je 0x9ee1
movl 0x50(%rsp), %eax
cmpl $0x6f6872, %eax         # imm = 0x6F6872
jne 0x9dd0
movq %r12, %rdi
leaq 0x3363(%rip), %rsi      # 0xd10e
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0x9f12
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x70(%rbx)
jmp 0x9d15
cmpw $0x77, %ax
je 0x9f6c
movq %rbp, %rdi
leaq 0x3288(%rip), %rsi      # 0xd06c
pushq $0x6
popq %rdx
callq 0x2150
testl %eax, %eax
jne 0xa0c0
movq 0x28(%rsp), %rdi
callq 0x21f0
movq %rax, (%rsp)
movq %rax, 0x60(%rbx)
xorl %edx, %edx
leaq 0x4(%rdx), %rbx
cmpq %rbx, %r14
je 0x9e33
addq (%rsp), %rdx
movq %r12, %rdi
leaq 0x3254(%rip), %rsi      # 0xd073
xorl %eax, %eax
callq 0x22c0
movq %rbx, %rdx
cmpl $0x1, %eax
je 0x9e08
jmp 0xa02a
movq 0x18(%rsp), %rbx
jmp 0x9d15
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0x9f12
leaq 0x6e43(%rip), %r14      # 0x10ca0
xorl %r15d, %r15d
cmpq $0x16, %r15
je 0x9f27
movq (%r14), %rdi
movq %rbp, %rsi
callq 0x2200
testl %eax, %eax
je 0x9ed9
incq %r15
addq $0x8, %r14
jmp 0x9e60
movq %r12, %rdi
leaq 0x31e7(%rip), %rsi      # 0xd073
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0x9f12
movl 0x10(%rsp), %eax
movl %eax, 0x30(%rsp)
movl %eax, 0x50(%rbx)
jmp 0x9cef
movq %r12, %rdi
leaq 0x31bc(%rip), %rsi      # 0xd073
leaq 0x14(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0x9f12
movl 0x14(%rsp), %eax
movq %rax, 0x20(%rsp)
movl %eax, 0x54(%rbx)
jmp 0x9cef
movl %r15d, (%rbx)
jmp 0x9cef
movq %r12, %rdi
leaq 0x3223(%rip), %rsi      # 0xd10e
leaq 0x48(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0x9f12
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd %xmm0, 0x68(%rbx)
jmp 0x9cef
movq 0x70c7(%rip), %rax      # 0x10fe0
movq (%rax), %rcx
leaq 0x3188(%rip), %rdi      # 0xd0ab
pushq $0x27
jmp 0x9f3a
movq 0x70b2(%rip), %rax      # 0x10fe0
movq (%rax), %rcx
leaq 0x31a7(%rip), %rdi      # 0xd0df
pushq $0x15
popq %rsi
pushq $0x1
popq %rdx
callq 0x22f0
pushq $0x6
popq %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2110
movq (%rsp), %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x21a0
movq %r14, %rdi
jmp 0xa06c
xorpd %xmm0, %xmm0
movsd 0x38(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq 0x20(%rsp), %r14
movl %r14d, 0x14(%rsp)
sbbl $-0x1, %r14d
movl 0x10(%rsp), %eax
cmpl $0x4, %r15d
pushq $0x1
popq %rbp
cmovel %eax, %ebp
cmpl $0x2, %eax
cmovnel %eax, %ebp
movl %ebp, %eax
imull %r14d, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x21f0
movq %rbx, %rcx
movq %rax, %rbx
movq %rax, 0x58(%rcx)
xorl %eax, %eax
testl %ebp, %ebp
movl $0x0, %ecx
cmovgl %ebp, %ecx
movslq %ebp, %rdx
testl %r14d, %r14d
cmovlel %eax, %r14d
movq %r14, 0x20(%rsp)
shlq $0x3, %rdx
movq %rdx, 0x28(%rsp)
incq %rcx
movq %rcx, 0x30(%rsp)
leaq 0x3149(%rip), %r14      # 0xd134
xorl %ebp, %ebp
cmpq 0x20(%rsp), %rbp
je 0xa088
movq 0x30(%rsp), %r15
movq %rbx, %rdx
decq %r15
je 0xa020
leaq 0x8(%rdx), %r13
movq %r12, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x22c0
movq %r13, %rdx
cmpl $0x1, %eax
je 0xa000
jmp 0xa02a
incq %rbp
addq 0x28(%rsp), %rbx
jmp 0x9fed
movq 0x6faf(%rip), %rax      # 0x10fe0
movq (%rax), %rcx
leaq 0x3070(%rip), %rdi      # 0xd0ab
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x22f0
pushq $0x6
popq %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2110
movq (%rsp), %rdi
callq 0x21a0
movq 0x18(%rsp), %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x21a0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x6
popq %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2110
movq %rbx, %rdi
callq 0x21a0
movq %r12, %rdi
callq 0x22d0
testl %eax, %eax
jne 0xa071
movq %r12, %rdi
callq 0x2130
xorl %ebx, %ebx
testl %eax, %eax
cmoveq 0x18(%rsp), %rbx
jmp 0xa073
movq 0x6f19(%rip), %rax      # 0x10fe0
movq (%rax), %rdi
leaq 0x3041(%rip), %rsi      # 0xd112
movq %rbx, %r14
xorl %ebx, %ebx
leaq 0x50(%rsp), %rdx
xorl %eax, %eax
callq 0x2220
pushq $0x6
popq %rdi
movq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x2110
movq (%rsp), %rdi
callq 0x21a0
movq %r14, %rdi
callq 0x21a0
movq %r15, %rdi
callq 0x21a0
jmp 0xa073