// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x16210(%rip), %rsi     # 0x2500a
callq 0x3360
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xee17
movq $0x0, -0x8(%rbp)
jmp 0xf2d0
movl $0xd0, %edi
callq 0x33d0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq $0x0, 0xc0(%rax)
movl $0x6, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x3260
movq %rax, %rdi
callq 0x34f0
movq %rax, -0x48(%rbp)
movl $0x6, %edi
leaq 0x16a22(%rip), %rsi     # 0x25884
callq 0x3260
movq -0x18(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
leaq 0x166d1(%rip), %rsi     # 0x2554a
movb $0x0, %al
callq 0x3500
leaq -0xa0(%rbp), %rdi
leaq 0x166c1(%rip), %rsi     # 0x2554f
callq 0x33e0
cmpl $0x0, %eax
jne 0xef87
movq -0x18(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
leaq 0x1669c(%rip), %rsi     # 0x2554a
movb $0x0, %al
callq 0x3500
movl $0x0, -0xa4(%rbp)
movslq -0xa4(%rbp), %rcx
leaq 0x1c403(%rip), %rax     # 0x2b2d0
cmpq $0x0, (%rax,%rcx,8)
je 0xef18
movslq -0xa4(%rbp), %rcx
leaq 0x1c3ee(%rip), %rax     # 0x2b2d0
movq (%rax,%rcx,8), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x33e0
cmpl $0x0, %eax
jne 0xef05
movl -0xa4(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
jmp 0xef18
jmp 0xef07
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0xeebf
movslq -0xa4(%rbp), %rcx
leaq 0x1c3aa(%rip), %rax     # 0x2b2d0
cmpq $0x0, (%rax,%rcx,8)
jne 0xef82
movq 0x1c0a4(%rip), %rax     # 0x2afd8
movq (%rax), %rdi
leaq 0x1661d(%rip), %rsi     # 0x2555b
movb $0x0, %al
callq 0x3400
movq -0x48(%rbp), %rsi
movl $0x6, %edi
callq 0x3260
movq -0x38(%rbp), %rax
movq 0xc0(%rax), %rdi
callq 0x3370
movq -0x38(%rbp), %rdi
callq 0x3370
movq -0x48(%rbp), %rdi
callq 0x3370
movq $0x0, -0x8(%rbp)
jmp 0xf2d0
jmp 0xf16e
leaq -0xa0(%rbp), %rdi
leaq 0x165dc(%rip), %rsi     # 0x25571
callq 0x33e0
cmpl $0x0, %eax
jne 0xefc7
movq -0x18(%rbp), %rdi
leaq 0x16578(%rip), %rsi     # 0x25522
leaq -0x28(%rbp), %rdx
movb $0x0, %al
callq 0x3500
movl -0x28(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xb0(%rax)
jmp 0xf16c
leaq -0xa0(%rbp), %rdi
leaq 0x165a5(%rip), %rsi     # 0x2557a
callq 0x33e0
cmpl $0x0, %eax
jne 0xf007
movq -0x18(%rbp), %rdi
leaq 0x16538(%rip), %rsi     # 0x25522
leaq -0x20(%rbp), %rdx
movb $0x0, %al
callq 0x3500
movl -0x20(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xb4(%rax)
jmp 0xf16a
leaq -0xa0(%rbp), %rdi
leaq 0x16570(%rip), %rsi     # 0x25585
callq 0x33e0
cmpl $0x0, %eax
jne 0xf04b
movq -0x18(%rbp), %rdi
leaq 0x16560(%rip), %rsi     # 0x2558a
leaq -0x30(%rbp), %rdx
movb $0x0, %al
callq 0x3500
movsd -0x30(%rbp), %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, 0xc8(%rax)
jmp 0xf168
leaq -0xa0(%rbp), %rdi
leaq 0x164a3(%rip), %rsi     # 0x254fc
callq 0x33e0
cmpl $0x0, %eax
jne 0xf068
jmp 0xf173
leaq -0xa0(%rbp), %rdi
leaq 0x164a5(%rip), %rsi     # 0x2551b
callq 0x33e0
cmpl $0x0, %eax
jne 0xf108
movq -0x38(%rbp), %rax
movl 0xb0(%rax), %eax
movl %eax, -0xa8(%rbp)
movslq -0xa8(%rbp), %rdi
shlq $0x2, %rdi
callq 0x33d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0xc0(%rax)
movl $0x0, -0xac(%rbp)
movl -0xac(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jge 0xf106
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0xc0(%rax), %rdx
movslq -0xac(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdx
leaq 0x16434(%rip), %rsi     # 0x25522
movb $0x0, %al
callq 0x3500
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0xf0bc
jmp 0xf164
movq 0x1bec9(%rip), %rax     # 0x2afd8
movq (%rax), %rdi
leaq -0xa0(%rbp), %rdx
leaq 0x1646e(%rip), %rsi     # 0x2558e
movb $0x0, %al
callq 0x3400
movq -0x48(%rbp), %rsi
movl $0x6, %edi
callq 0x3260
movq -0x38(%rbp), %rax
movq 0xc0(%rax), %rdi
callq 0x3370
movq -0x38(%rbp), %rdi
callq 0x3370
movq -0x48(%rbp), %rdi
callq 0x3370
movq $0x0, -0x8(%rbp)
jmp 0xf2d0
jmp 0xf166
jmp 0xf168
jmp 0xf16a
jmp 0xf16c
jmp 0xf16e
jmp 0xee67
movq -0x38(%rbp), %rax
movl 0xb4(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movsd 0xc8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xf1a0
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xf1a6
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0xb0(%rbp)
cmpl $0x2, -0x28(%rbp)
jne 0xf1ca
movq -0x40(%rbp), %rax
cmpl $0x4, (%rax)
je 0xf1ca
movl $0x1, -0xb4(%rbp)
jmp 0xf1d3
movl -0x28(%rbp), %eax
movl %eax, -0xb4(%rbp)
movl -0xb0(%rbp), %eax
imull -0xb4(%rbp), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x33d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0xb8(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xb0(%rbp), %eax
jge 0xf28b
movl $0x0, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
cmpl -0xb4(%rbp), %eax
jge 0xf26b
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0xb8(%rax), %rdx
movl -0x1c(%rbp), %eax
imull -0xb4(%rbp), %eax
addl -0xb8(%rbp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x1635d(%rip), %rsi     # 0x255b0
movb $0x0, %al
callq 0x3500
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0xf216
movq -0x18(%rbp), %rdi
leaq 0x15db7(%rip), %rsi     # 0x2502d
movb $0x0, %al
callq 0x3500
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf201
movq -0x48(%rbp), %rsi
movl $0x6, %edi
callq 0x3260
movq -0x48(%rbp), %rdi
callq 0x3370
movq -0x18(%rbp), %rdi
callq 0x3510
cmpl $0x0, %eax
jne 0xf2be
movq -0x18(%rbp), %rdi
callq 0x32b0
cmpl $0x0, %eax
je 0xf2c8
movq $0x0, -0x8(%rbp)
jmp 0xf2d0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)