// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x7906(%rip), %rsi      # 0x12c50
callq 0x2170
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xb367
movq $0x0, -0x8(%rbp)
jmp 0xbb62
movl $0x78, %edi
callq 0x21c0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x48(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x48(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x48(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x60(%rax)
movl $0x6, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x2100
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0xb3de
movq -0x50(%rbp), %rdi
callq 0x2280
movq %rax, -0x50(%rbp)
movl $0x6, %edi
leaq 0x8248(%rip), %rsi      # 0x13632
callq 0x2100
jmp 0xb3f1
movq -0x18(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
leaq 0x7c53(%rip), %rsi      # 0x13056
movb $0x0, %al
callq 0x2290
cmpl $0x1, %eax
je 0xb461
movq 0xabca(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x7c3b(%rip), %rsi      # 0x1305b
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xb463
leaq -0xb0(%rbp), %rdi
leaq 0x7c12(%rip), %rsi      # 0x13083
callq 0x21d0
cmpl $0x0, %eax
jne 0xb5c2
jmp 0xb481
movq -0x18(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
leaq 0x7bc3(%rip), %rsi      # 0x13056
movb $0x0, %al
callq 0x2290
cmpl $0x1, %eax
je 0xb4f1
movq 0xab3a(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x7bab(%rip), %rsi      # 0x1305b
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xb4f3
movl $0x0, -0xb4(%rbp)
movslq -0xb4(%rbp), %rcx
leaq 0xac75(%rip), %rax      # 0x16180
cmpq $0x0, (%rax,%rcx,8)
je 0xb556
movslq -0xb4(%rbp), %rcx
leaq 0xac60(%rip), %rax      # 0x16180
movq (%rax,%rcx,8), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x21d0
cmpl $0x0, %eax
jne 0xb543
movl -0xb4(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
jmp 0xb556
jmp 0xb545
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0xb4fd
movslq -0xb4(%rbp), %rcx
leaq 0xac1c(%rip), %rax      # 0x16180
cmpq $0x0, (%rax,%rcx,8)
jne 0xb5bd
movq 0xaa6e(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x7b13(%rip), %rsi      # 0x1308f
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xb9b7
leaq -0xb0(%rbp), %rdi
leaq 0x7ad5(%rip), %rsi      # 0x130a5
callq 0x21d0
cmpl $0x0, %eax
jne 0xb65e
jmp 0xb5e0
movq -0x18(%rbp), %rdi
leaq 0x7a38(%rip), %rsi      # 0x13023
leaq -0x28(%rbp), %rdx
movb $0x0, %al
callq 0x2290
cmpl $0x1, %eax
je 0xb64d
movq 0xa9de(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x7a4f(%rip), %rsi      # 0x1305b
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xb64f
movl -0x28(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x50(%rax)
jmp 0xb9b5
leaq -0xb0(%rbp), %rdi
leaq 0x7a42(%rip), %rsi      # 0x130ae
callq 0x21d0
cmpl $0x0, %eax
jne 0xb6fa
jmp 0xb67c
movq -0x18(%rbp), %rdi
leaq 0x799c(%rip), %rsi      # 0x13023
leaq -0x20(%rbp), %rdx
movb $0x0, %al
callq 0x2290
cmpl $0x1, %eax
je 0xb6e9
movq 0xa942(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x79b3(%rip), %rsi      # 0x1305b
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xb6eb
movl -0x20(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x54(%rax)
jmp 0xb9b3
leaq -0xb0(%rbp), %rdi
leaq 0x79b1(%rip), %rsi      # 0x130b9
callq 0x21d0
cmpl $0x0, %eax
jne 0xb79a
jmp 0xb718
movq -0x18(%rbp), %rdi
leaq 0x799b(%rip), %rsi      # 0x130be
leaq -0x30(%rbp), %rdx
movb $0x0, %al
callq 0x2290
cmpl $0x1, %eax
je 0xb785
movq 0xa8a6(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x7917(%rip), %rsi      # 0x1305b
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xb787
movsd -0x30(%rbp), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x68(%rax)
jmp 0xb9b1
leaq -0xb0(%rbp), %rdi
leaq 0x791a(%rip), %rsi      # 0x130c2
callq 0x21d0
cmpl $0x0, %eax
jne 0xb83a
jmp 0xb7b8
movq -0x18(%rbp), %rdi
leaq 0x78fb(%rip), %rsi      # 0x130be
leaq -0x38(%rbp), %rdx
movb $0x0, %al
callq 0x2290
cmpl $0x1, %eax
je 0xb825
movq 0xa806(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x7877(%rip), %rsi      # 0x1305b
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xb827
movsd -0x38(%rbp), %xmm0
movq -0x40(%rbp), %rax
movsd %xmm0, 0x70(%rax)
jmp 0xb9af
leaq -0xb0(%rbp), %rdi
leaq 0x77b5(%rip), %rsi      # 0x12ffd
callq 0x21d0
cmpl $0x0, %eax
jne 0xb857
jmp 0xb9bc
leaq -0xb0(%rbp), %rdi
leaq 0x77b7(%rip), %rsi      # 0x1301c
callq 0x21d0
cmpl $0x0, %eax
jne 0xb952
movq -0x40(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0xb8(%rbp)
movslq -0xb8(%rbp), %rdi
shlq $0x2, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x60(%rax)
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
cmpl -0xb8(%rbp), %eax
jge 0xb950
jmp 0xb8b9
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdx
movslq -0xbc(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdx
leaq 0x7749(%rip), %rsi      # 0x13023
movb $0x0, %al
callq 0x2290
cmpl $0x1, %eax
je 0xb938
movq 0xa6f3(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x7764(%rip), %rsi      # 0x1305b
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xb93a
jmp 0xb93c
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0xb8a5
jmp 0xb9ab
movq 0xa687(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq -0xb0(%rbp), %rdx
leaq 0x775c(%rip), %rsi      # 0x130c6
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xb9ad
jmp 0xb9af
jmp 0xb9b1
jmp 0xb9b3
jmp 0xb9b5
jmp 0xb9b7
jmp 0xb3ef
movq -0x40(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x40(%rbp), %rax
movsd 0x68(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xb9e3
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xb9e9
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0xc0(%rbp)
cmpl $0x2, -0x28(%rbp)
jne 0xba0d
movq -0x48(%rbp), %rax
cmpl $0x4, (%rax)
je 0xba0d
movl $0x1, -0xc4(%rbp)
jmp 0xba16
movl -0x28(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0xc0(%rbp), %eax
imull -0xc4(%rbp), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x58(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc0(%rbp), %eax
jge 0xbb1d
movl $0x0, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
cmpl -0xc4(%rbp), %eax
jge 0xbb0d
jmp 0xba6e
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rdx
movl -0x1c(%rbp), %eax
imull -0xc4(%rbp), %eax
addl -0xc8(%rbp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x764e(%rip), %rsi      # 0x130e8
movb $0x0, %al
callq 0x2290
cmpl $0x1, %eax
je 0xbaf5
movq 0xa533(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x75a4(%rip), %rsi      # 0x1305b
movb $0x0, %al
callq 0x21f0
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq -0x50(%rbp), %rdi
callq 0x2180
movq $0x0, -0x8(%rbp)
jmp 0xbb62
jmp 0xbaf7
jmp 0xbaf9
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0xba5a
jmp 0xbb0f
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xba41
movq -0x50(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x50(%rbp), %rdi
callq 0x2180
movq -0x18(%rbp), %rdi
callq 0x22a0
cmpl $0x0, %eax
jne 0xbb50
movq -0x18(%rbp), %rdi
callq 0x2120
cmpl $0x0, %eax
je 0xbb5a
movq $0x0, -0x8(%rbp)
jmp 0xbb62
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nop