// File: /workspace/github_cpp_makefile_star2_O1/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 0x287f(%rip), %rsi      # 0xd2f3
callq 0x2190
testq %rax, %rax
je 0xad80
movq %rax, %r14
movl $0x78, %edi
callq 0x21f0
movl $0x0, 0x18(%rax)
xorl %ebx, %ebx
movq %rbx, 0x40(%rax)
movq %rbx, 0x60(%rax)
xorpd %xmm0, %xmm0
movq %rax, (%rsp)
movupd %xmm0, 0x20(%rax)
movl $0x6, %edi
xorl %esi, %esi
callq 0x2120
testq %rax, %rax
je 0xaac9
movq %rax, %rdi
callq 0x22b0
movq %rax, %rbx
movq %rbx, 0x8(%rsp)
movq (%rsp), %rax
addq $0x60, %rax
movq %rax, 0x10(%rsp)
leaq 0x3b4c(%rip), %rsi      # 0xe62e
movl $0x6, %edi
callq 0x2120
leaq 0x3563(%rip), %rsi      # 0xe056
leaq 0x50(%rsp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xad58
movabsq $0x745f7265766c6f73, %r12 # imm = 0x745F7265766C6F73
leaq 0x50(%rsp), %rbp
movq 0x50(%rsp), %rax
xorq %r12, %rax
movl 0x58(%rsp), %ecx
xorq $0x657079, %rcx         # imm = 0x657079
orq %rax, %rcx
je 0xabdc
movq 0x50(%rsp), %rax
movabsq $0x7373616c635f726e, %rcx # imm = 0x7373616C635F726E
xorq %rcx, %rax
movzbl 0x58(%rsp), %ecx
orq %rax, %rcx
je 0xac31
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 0xac60
movl 0x50(%rsp), %eax
movl $0x73616962, %ecx       # imm = 0x73616962
xorl %ecx, %eax
movzbl 0x54(%rsp), %ecx
orl %eax, %ecx
je 0xac8f
cmpl $0x6f6872, 0x50(%rsp)   # imm = 0x6F6872
jne 0xacbf
movq %r14, %rdi
leaq 0x350b(%rip), %rsi      # 0xe0be
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xaf2c
movsd 0x40(%rsp), %xmm0
movq (%rsp), %rax
movsd %xmm0, 0x70(%rax)
jmp 0xad3b
movq %r14, %rdi
leaq 0x3470(%rip), %rsi      # 0xe056
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xaecc
leaq 0x70a0(%rip), %r13      # 0x11ca0
xorl %r15d, %r15d
movq (%r13), %rdi
movq %rbp, %rsi
callq 0x2200
testl %eax, %eax
je 0xac25
incq %r15
addq $0x8, %r13
cmpq $0x16, %r15
jne 0xac03
jmp 0xad6d
movq (%rsp), %rax
movl %r15d, (%rax)
jmp 0xad3b
movq %r14, %rdi
leaq 0x33e8(%rip), %rsi      # 0xe023
leaq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xaee4
movl 0x18(%rsp), %eax
movq (%rsp), %rcx
movl %eax, 0x50(%rcx)
jmp 0xad3b
movq %r14, %rdi
leaq 0x33b9(%rip), %rsi      # 0xe023
leaq 0x1c(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xaefc
movl 0x1c(%rsp), %eax
movq (%rsp), %rcx
movl %eax, 0x54(%rcx)
jmp 0xad3b
movq %r14, %rdi
leaq 0x3425(%rip), %rsi      # 0xe0be
leaq 0x48(%rsp), %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xaf14
movsd 0x48(%rsp), %xmm0
movq (%rsp), %rax
movsd %xmm0, 0x68(%rax)
jmp 0xad3b
cmpw $0x77, 0x50(%rsp)
je 0xada7
movl 0x50(%rsp), %eax
movl $0x6562616c, %ecx       # imm = 0x6562616C
xorl %ecx, %eax
movzwl 0x54(%rsp), %ecx
xorl $0x6c, %ecx
orl %eax, %ecx
jne 0xaf44
movq (%rsp), %r12
movslq 0x50(%r12), %rbx
leaq (,%rbx,4), %r15
movq %r15, %rdi
callq 0x21f0
movq %rax, 0x60(%r12)
movabsq $0x745f7265766c6f73, %r12 # imm = 0x745F7265766C6F73
testq %rbx, %rbx
jle 0xad3b
movq %rax, %r13
xorl %ebx, %ebx
leaq (%rbx,%r13), %rdx
movq %r14, %rdi
leaq 0x32fd(%rip), %rsi      # 0xe023
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xad94
addq $0x4, %rbx
cmpq %rbx, %r15
jne 0xad18
movq %r14, %rdi
leaq 0x3311(%rip), %rsi      # 0xe056
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
je 0xab1a
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
callq 0x2814
jmp 0xad80
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
callq 0x27c1
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq (%rsp), %rdx
callq 0x257c
jmp 0xad80
movq (%rsp), %rax
movl 0x54(%rax), %ebp
movl %ebp, 0x1c(%rsp)
movsd 0x68(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
sbbl $-0x1, %ebp
movl 0x18(%rsp), %eax
cmpl $0x2, %eax
jne 0xadd9
movl $0x1, %ebx
movq (%rsp), %rcx
cmpl $0x4, (%rcx)
jne 0xaddb
movl %eax, %ebx
movl %ebx, %eax
imull %ebp, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x21f0
movq (%rsp), %rcx
movq %rax, 0x58(%rcx)
testl %ebp, %ebp
jle 0xae72
movl %ebx, %eax
movl %ebp, %ecx
movq %rcx, 0x38(%rsp)
movq %rax, 0x28(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x30(%rsp)
leaq 0x32ca(%rip), %r15      # 0xe0e4
movq $0x0, 0x20(%rsp)
xorl %ebp, %ebp
testl %ebx, %ebx
jle 0xae59
movq (%rsp), %rax
movq 0x58(%rax), %r12
addq 0x20(%rsp), %r12
movq 0x28(%rsp), %r13
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x22c0
cmpl $0x1, %eax
jne 0xaeb4
addq $0x8, %r12
decq %r13
jne 0xae3b
incq %rbp
movq 0x20(%rsp), %rax
addq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpq 0x38(%rsp), %rbp
jne 0xae25
movl $0x6, %edi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21a0
movq %r14, %rdi
callq 0x22d0
testl %eax, %eax
jne 0xad80
movq %r14, %rdi
callq 0x2140
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmoveq (%rsp), %rax
jmp 0xad82
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
callq 0x25cf
jmp 0xad80
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
callq 0x276e
jmp 0xad80
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
callq 0x271b
jmp 0xad80
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
callq 0x26c8
jmp 0xad80
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
callq 0x2675
jmp 0xad80
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
callq 0x2622
jmp 0xad80
leaq 0x50(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq (%rsp), %rcx
callq 0x252a
jmp 0xad80