// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r15
movsd 0x68(%rsi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movl 0x54(%rsi), %ebx
movl %ebx, %ebp
sbbl $-0x1, %ebp
leaq 0x37e1(%rip), %rsi      # 0xdffd
callq 0x2190
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xaa4b
movq %rax, %r12
xorl %r14d, %r14d
movl $0x6, %edi
xorl %esi, %esi
callq 0x2120
testq %rax, %rax
je 0xa851
movq %rax, %rdi
callq 0x22b0
movq %rax, %r14
leaq 0x3dd6(%rip), %rsi      # 0xe62e
movl $0x6, %edi
callq 0x2120
movl 0x50(%r15), %eax
cmpl $0x2, %eax
jne 0xa879
movl $0x1, 0x4(%rsp)
cmpl $0x4, (%r15)
jne 0xa87d
movl %eax, 0x4(%rsp)
movq %r14, 0x10(%rsp)
movslq (%r15), %rax
leaq 0x7414(%rip), %rcx      # 0x11ca0
movq (%rcx,%rax,8), %rdx
leaq 0x3768(%rip), %rsi      # 0xdfff
movq %r12, %rdi
xorl %eax, %eax
callq 0x2220
movl 0x50(%r15), %edx
leaq 0x3763(%rip), %rsi      # 0xe00f
movq %r12, %rdi
xorl %eax, %eax
callq 0x2220
cmpq $0x0, 0x60(%r15)
je 0xa915
leaq 0x3758(%rip), %rdi      # 0xe01c
movl $0x5, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x22f0
cmpl $0x0, 0x50(%r15)
jle 0xa908
leaq 0x373e(%rip), %r13      # 0xe022
xorl %r14d, %r14d
movq 0x60(%r15), %rax
movl (%rax,%r14,4), %edx
movq %r12, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2220
incq %r14
movslq 0x50(%r15), %rax
cmpq %rax, %r14
jl 0xa8e7
movl $0xa, %edi
movq %r12, %rsi
callq 0x21d0
leaq 0x370a(%rip), %rsi      # 0xe026
movq %r12, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2220
movsd 0x68(%r15), %xmm0
leaq 0x3700(%rip), %rsi      # 0xe035
movq %r12, %rdi
movb $0x1, %al
callq 0x2220
cmpl $0x15, (%r15)
jne 0xa95c
movsd 0x70(%r15), %xmm0
leaq 0x36ef(%rip), %rsi      # 0xe041
movq %r12, %rdi
movb $0x1, %al
callq 0x2220
movq %r15, 0x30(%rsp)
leaq 0x36e4(%rip), %rdi      # 0xe04c
movl $0x2, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x22f0
testl %ebp, %ebp
jle 0xaa12
movl %ebp, %eax
movq %rax, 0x28(%rsp)
movl 0x4(%rsp), %eax
movq %rax, 0x18(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x36a0(%rip), %r13      # 0xe04f
xorl %ebx, %ebx
movq 0x30(%rsp), %r14
cmpl $0x0, 0x4(%rsp)
movq %r12, %r15
jle 0xa9e9
movq 0x18(%rsp), %r12
movq 0x8(%rsp), %rbp
movq 0x58(%r14), %rax
movsd (%rax,%rbp), %xmm0
movq %r15, %rdi
movq %r13, %rsi
movb $0x1, %al
callq 0x2220
addq $0x8, %rbp
decq %r12
jne 0xa9ca
movl $0xa, %edi
movq %r15, %rsi
callq 0x21d0
incq %rbx
movq 0x8(%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq 0x28(%rsp), %rbx
movq %r15, %r12
jne 0xa9b6
movl $0x6, %edi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21a0
movq %r12, %rdi
callq 0x22d0
testl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jne 0xaa4b
movq %r12, %rdi
callq 0x2140
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
movl %ecx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq