// File: cjlin1[P]liblinear/linear.cpp
// Function: save_model
int save_model(const char *model_file_name, const struct model *model_)
{
	int i;
	int nr_feature=model_->nr_feature;
	int n;
	const parameter& param = model_->param;

	if(model_->bias>=0)
		n=nr_feature+1;
	else
		n=nr_feature;
	int w_size = n;
	FILE *fp = fopen(model_file_name,"w");
	if(fp==NULL) return -1;

	char *old_locale = setlocale(LC_ALL, NULL);
	if (old_locale)
	{
		old_locale = strdup(old_locale);
	}
	setlocale(LC_ALL, "C");

	int nr_w;
	if(model_->nr_class==2 && model_->param.solver_type != MCSVM_CS)
		nr_w=1;
	else
		nr_w=model_->nr_class;

	fprintf(fp, "solver_type %s\n", solver_type_table[param.solver_type]);
	fprintf(fp, "nr_class %d\n", model_->nr_class);

	if(model_->label)
	{
		fprintf(fp, "label");
		for(i=0; i<model_->nr_class; i++)
			fprintf(fp, " %d", model_->label[i]);
		fprintf(fp, "\n");
	}

	fprintf(fp, "nr_feature %d\n", nr_feature);

	fprintf(fp, "bias %.17g\n", model_->bias);

	if(check_oneclass_model(model_))
		fprintf(fp, "rho %.17g\n", model_->rho);

	fprintf(fp, "w\n");
	for(i=0; i<w_size; i++)
	{
		int j;
		for(j=0; j<nr_w; j++)
			fprintf(fp, "%.17g ", model_->w[i*nr_w+j]);
		fprintf(fp, "\n");
	}

	setlocale(LC_ALL, old_locale);
	free(old_locale);

	if (ferror(fp) != 0 || fclose(fp) != 0) return -1;
	else return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movsd 0x68(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xb0bf
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xb0c5
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x7f27(%rip), %rsi      # 0x12ffd
callq 0x2170
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0xb0f2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb31a
movl $0x6, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x2100
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xb118
movq -0x48(%rbp), %rdi
callq 0x2280
movq %rax, -0x48(%rbp)
movl $0x6, %edi
leaq 0x850e(%rip), %rsi      # 0x13632
callq 0x2100
movq -0x18(%rbp), %rax
cmpl $0x2, 0x50(%rax)
jne 0xb145
movq -0x18(%rbp), %rax
cmpl $0x4, (%rax)
je 0xb145
movl $0x1, -0x4c(%rbp)
jmp 0xb14f
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movslq (%rax), %rcx
leaq 0xb01f(%rip), %rax      # 0x16180
movq (%rax,%rcx,8), %rdx
leaq 0x7e93(%rip), %rsi      # 0x12fff
movb $0x0, %al
callq 0x21f0
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x50(%rax), %edx
leaq 0x7e8a(%rip), %rsi      # 0x1300f
movb $0x0, %al
callq 0x21f0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0xb1fa
movq -0x40(%rbp), %rdi
leaq 0x7e7a(%rip), %rsi      # 0x1301c
movb $0x0, %al
callq 0x21f0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jge 0xb1e8
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x7e4c(%rip), %rsi      # 0x13022
movb $0x0, %al
callq 0x21f0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xb1b0
movq -0x40(%rbp), %rdi
leaq 0x7a7e(%rip), %rsi      # 0x12c71
movb $0x0, %al
callq 0x21f0
movq -0x40(%rbp), %rdi
movl -0x20(%rbp), %edx
leaq 0x7e1e(%rip), %rsi      # 0x13026
movb $0x0, %al
callq 0x21f0
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x68(%rax), %xmm0
leaq 0x7e12(%rip), %rsi      # 0x13035
movb $0x1, %al
callq 0x21f0
movq -0x18(%rbp), %rdi
callq 0x84b0
cmpl $0x0, %eax
je 0xb253
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movsd 0x70(%rax), %xmm0
leaq 0x7df5(%rip), %rsi      # 0x13041
movb $0x1, %al
callq 0x21f0
movq -0x40(%rbp), %rdi
leaq 0x7dee(%rip), %rsi      # 0x1304c
movb $0x0, %al
callq 0x21f0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xb2d7
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0xb2ba
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x1c(%rbp), %ecx
imull -0x4c(%rbp), %ecx
addl -0x50(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
leaq 0x7da7(%rip), %rsi      # 0x1304f
movb $0x1, %al
callq 0x21f0
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xb27b
movq -0x40(%rbp), %rdi
leaq 0x79ac(%rip), %rsi      # 0x12c71
movb $0x0, %al
callq 0x21f0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xb26c
movq -0x48(%rbp), %rsi
movl $0x6, %edi
callq 0x2100
movq -0x48(%rbp), %rdi
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x22a0
cmpl $0x0, %eax
jne 0xb30a
movq -0x40(%rbp), %rdi
callq 0x2120
cmpl $0x0, %eax
je 0xb313
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb31a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)