// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, %r15
movsd 0x68(%rsi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movl 0x54(%rsi), %r12d
movl %r12d, %eax
sbbl $-0x1, %eax
movq %rax, (%rsp)
leaq 0x35fb(%rip), %rsi      # 0xd04d
callq 0x2190
pushq $-0x1
popq %rcx
testq %rax, %rax
je 0x9c44
movq %rax, %r14
xorl %ebx, %ebx
pushq $0x6
popq %rdi
xorl %esi, %esi
callq 0x2110
testq %rax, %rax
je 0x9a82
movq %rax, %rdi
callq 0x22b0
movq %rax, %rbx
movq %rbx, 0x8(%rsp)
leaq 0x3bf0(%rip), %rsi      # 0xd67e
pushq $0x6
popq %rdi
callq 0x2110
movl 0x50(%r15), %eax
movslq (%r15), %rcx
cmpq $0x4, %rcx
pushq $0x1
popq %rbp
cmovel %eax, %ebp
cmpl $0x2, %eax
cmovnel %eax, %ebp
leaq 0x71ec(%rip), %rax      # 0x10ca0
movq (%rax,%rcx,8), %rdx
leaq 0x3590(%rip), %rsi      # 0xd04f
movq %r14, %rdi
xorl %eax, %eax
callq 0x2220
movl 0x50(%r15), %edx
leaq 0x358b(%rip), %rsi      # 0xd05f
movq %r14, %rdi
xorl %eax, %eax
callq 0x2220
cmpq $0x0, 0x60(%r15)
je 0x9b30
leaq 0x3580(%rip), %rdi      # 0xd06c
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x22f0
leaq 0x3571(%rip), %r13      # 0xd072
xorl %ebx, %ebx
movslq 0x50(%r15), %rax
cmpq %rax, %rbx
jge 0x9b25
movq 0x60(%r15), %rax
movl (%rax,%rbx,4), %edx
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2220
incq %rbx
jmp 0x9b03
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x21d0
leaq 0x353f(%rip), %rsi      # 0xd076
xorl %ebx, %ebx
movq %r14, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x2220
movsd 0x68(%r15), %xmm0
leaq 0x3532(%rip), %rsi      # 0xd085
movq %r14, %rdi
movb $0x1, %al
callq 0x2220
cmpl $0x15, (%r15)
jne 0x9b7a
movsd 0x70(%r15), %xmm0
leaq 0x3521(%rip), %rsi      # 0xd091
movq %r14, %rdi
movb $0x1, %al
callq 0x2220
leaq 0x351b(%rip), %rdi      # 0xd09c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x22f0
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
movq %rax, 0x18(%rsp)
movslq %ebp, %rax
movq (%rsp), %r12
testl %r12d, %r12d
cmovlel %ebx, %r12d
movq %r12, (%rsp)
shlq $0x3, %rax
movq %rax, 0x10(%rsp)
leaq 0x34df(%rip), %r13      # 0xd09f
xorl %r12d, %r12d
cmpq (%rsp), %r12
je 0x9c0f
movq 0x18(%rsp), %rbp
movq %rbx, 0x20(%rsp)
subq $0x1, %rbp
jb 0x9bf5
movq 0x58(%r15), %rax
movsd (%rax,%rbx), %xmm0
movq %r14, %rdi
movq %r13, %rsi
movb $0x1, %al
callq 0x2220
addq $0x8, %rbx
jmp 0x9bd3
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x21d0
incq %r12
movq 0x20(%rsp), %rbx
addq 0x10(%rsp), %rbx
jmp 0x9bc3
pushq $0x6
popq %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2110
movq %rbx, %rdi
callq 0x21a0
movq %r14, %rdi
callq 0x22d0
testl %eax, %eax
pushq $-0x1
popq %rcx
jne 0x9c44
movq %r14, %rdi
callq 0x2130
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
movl %ecx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq