// File: /workspace/github_cpp_makefile_star2_O3/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 0x2d77(%rip), %rsi      # 0xe31b
callq 0x2190
testq %rax, %rax
je 0xb8a0
movq %rax, %r14
movl $0x78, %edi
callq 0x21f0
movq %rax, %r15
movl $0x0, 0x18(%rax)
xorl %ebx, %ebx
movq %rbx, 0x40(%rax)
movq %rbx, 0x60(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rax)
movl $0x6, %edi
xorl %esi, %esi
callq 0x2120
testq %rax, %rax
je 0xb5f8
movq %rax, %rdi
callq 0x22b0
movq %rax, %rbx
movq %rbx, (%rsp)
leaq 0x40db(%rip), %rsi      # 0xf6de
movl $0x6, %edi
callq 0x2120
leaq 0x3af2(%rip), %rsi      # 0xf106
xorl %r12d, %r12d
leaq 0x50(%rsp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xb8b4
movabsq $0x745f7265766c6f73, %rbx # imm = 0x745F7265766C6F73
leaq 0x50(%rsp), %rbp
xorl %r12d, %r12d
movq %r15, 0x20(%rsp)
movq 0x50(%rsp), %rax
xorq %rbx, %rax
movl 0x58(%rsp), %ecx
xorq $0x657079, %rcx         # imm = 0x657079
orq %rax, %rcx
je 0xb706
movq 0x50(%rsp), %rax
movabsq $0x7373616c635f726e, %rcx # imm = 0x7373616C635F726E
xorq %rcx, %rax
movzbl 0x58(%rsp), %ecx
orq %rax, %rcx
je 0xb760
movq 0x50(%rsp), %rax
movabsq $0x75746165665f726e, %rcx # imm = 0x75746165665F726E
xorq %rcx, %rax
movq 0x53(%rsp), %rcx
movabsq $0x65727574616566, %rdx # imm = 0x65727574616566
xorq %rdx, %rcx
orq %rax, %rcx
je 0xb78d
movl 0x50(%rsp), %eax
movl $0x73616962, %ecx       # imm = 0x73616962
xorl %ecx, %eax
movzbl 0x54(%rsp), %ecx
orl %eax, %ecx
je 0xb7ba
movl 0x50(%rsp), %eax
cmpl $0x6f6872, %eax         # imm = 0x6F6872
jne 0xb80d
movq %r14, %rdi
leaq 0x3a8e(%rip), %rsi      # 0xf16e
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xba3e
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x70(%r15)
jmp 0xb7eb
movq %r14, %rdi
leaq 0x39f6(%rip), %rsi      # 0xf106
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xb9ee
leaq 0x7576(%rip), %rbx      # 0x12ca0
xorl %r13d, %r13d
movq (%rbx), %rdi
movq %rbp, %rsi
callq 0x2200
testl %eax, %eax
je 0xb74e
incq %r13
addq $0x8, %rbx
cmpq $0x16, %r13
jne 0xb72d
jmp 0xb891
movl %r13d, (%r15)
movabsq $0x745f7265766c6f73, %rbx # imm = 0x745F7265766C6F73
jmp 0xb7eb
movq %r14, %rdi
leaq 0x3969(%rip), %rsi      # 0xf0d3
leaq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xba02
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rsp)
movl %eax, 0x50(%r15)
jmp 0xb7eb
movq %r14, %rdi
leaq 0x393c(%rip), %rsi      # 0xf0d3
leaq 0x1c(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xba16
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rsp)
movl %eax, 0x54(%r15)
jmp 0xb7eb
movq %r14, %rdi
leaq 0x39aa(%rip), %rsi      # 0xf16e
leaq 0x48(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xba2a
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd %xmm0, 0x68(%r15)
movq %r14, %rdi
leaq 0x3911(%rip), %rsi      # 0xf106
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
je 0xb646
jmp 0xb8b4
cmpw $0x77, %ax
movl 0x10(%rsp), %edx
je 0xb8d8
movl 0x50(%rsp), %eax
movl $0x6562616c, %ecx       # imm = 0x6562616C
xorl %ecx, %eax
movzwl 0x54(%rsp), %ecx
xorl $0x6c, %ecx
orl %eax, %ecx
jne 0xba52
movslq %edx, %rbx
leaq (,%rbx,4), %rdi
movl %edx, 0x10(%rsp)
callq 0x21f0
movq %rax, %r12
movq %rax, 0x60(%r15)
testl %ebx, %ebx
jle 0xb751
movl 0x10(%rsp), %ebx
shlq $0x2, %rbx
xorl %r15d, %r15d
leaq (%r12,%r15), %rdx
movq %r14, %rdi
leaq 0x3861(%rip), %rsi      # 0xf0d3
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xb8c5
addq $0x4, %r15
cmpq %r15, %rbx
jne 0xb864
movq 0x20(%rsp), %r15
jmp 0xb751
movq (%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x27c1
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2814
jmp 0xb8a0
movq (%rsp), %rdi
movq %r12, %rsi
movq 0x20(%rsp), %rdx
callq 0x257c
jmp 0xb8a0
xorpd %xmm0, %xmm0
movsd 0x28(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl 0xc(%rsp), %ebx
movl %ebx, 0x1c(%rsp)
sbbl $-0x1, %ebx
movl 0x18(%rsp), %eax
cmpl $0x4, %r13d
movl $0x1, %ecx
cmovel %eax, %ecx
cmpl $0x2, %eax
cmovnel %eax, %ecx
movl %ecx, 0xc(%rsp)
movl %ecx, %eax
imull %ebx, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x21f0
movq %rax, 0x58(%r15)
testl %ebx, %ebx
jle 0xb996
movq %rax, %rbp
movl 0xc(%rsp), %edx
movl %ebx, %ecx
movq %rcx, 0x38(%rsp)
movq %rdx, 0x28(%rsp)
leaq (,%rdx,8), %rcx
movq %rcx, 0x30(%rsp)
leaq 0x3849(%rip), %r13      # 0xf194
xorl %ecx, %ecx
movq %rcx, 0x10(%rsp)
movq 0x28(%rsp), %r15
movq %rbp, %rbx
cmpl $0x0, 0xc(%rsp)
jle 0xb97f
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xb9d8
addq $0x8, %rbp
decq %r15
jne 0xb961
movq 0x10(%rsp), %rcx
incq %rcx
movq %rbx, %rbp
addq 0x30(%rsp), %rbp
cmpq 0x38(%rsp), %rcx
jne 0xb94d
movl $0x6, %edi
movq (%rsp), %rbx
movq %rbx, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21a0
movq %r14, %rdi
callq 0x22d0
testl %eax, %eax
jne 0xb8a0
movq %r14, %rdi
callq 0x2140
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmoveq 0x20(%rsp), %rax
jmp 0xb8a2
movq (%rsp), %rdi
movq %r12, %rsi
movq 0x20(%rsp), %rdx
callq 0x25cf
jmp 0xb8a0
movq (%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x276e
jmp 0xb8a0
movq (%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x271b
jmp 0xb8a0
movq (%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x26c8
jmp 0xb8a0
movq (%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2675
jmp 0xb8a0
movq (%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2622
jmp 0xb8a0
leaq 0x50(%rsp), %rdi
movq (%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x252a
jmp 0xb8a0