// File: /workspace/github_cpp_makefile_star2_O2/CK7[P]abawaca/src/ClusterWriter.cpp
// Function: ClusterEsomWriter::write_clustering_info_file(ClusterData const&, char const*) const
void ClusterEsomWriter::write_clustering_info_file(const ClusterData& clustering_db, const char* cluster_name) const
{
	char	lrn_file[1024] = {};

	sprintf(lrn_file, "%s/%s.lrn", out_dir.c_str(), cluster_name);

        FILE* fp = fopen(lrn_file, "w");
	if(fp == NULL) {
		cerr << "Fatal error, " << __FILE__ << " (" << __LINE__ << "): could write to file " << lrn_file << endl << endl;
		exit(-1); 
	}

        fprintf(fp, "%c %lu\n", '%', clustering_db.ndps());
        fprintf(fp, "%c %lu\n", '%', clustering_db.ndimensions()+1);
        fprintf(fp, "%c 9", '%');
        for(size_t i=1; i<=clustering_db.ndimensions(); i++)
                fprintf(fp, "\t1");
        fprintf(fp, "\n");
        fprintf(fp, "%c Key", '%');
        for(size_t i=1; i<=clustering_db.ndimensions(); i++)
                fprintf(fp, "\t%s", clustering_db.get_dimension(i).get_dimension_name().c_str());
        fprintf(fp, "\n");

	const unordered_set<size_t>& dps = clustering_db.datapoints();
        for(auto vit=dps.begin(); vit!=dps.end(); vit++) {
                fprintf(fp, "%lu", *vit);
                for(size_t i=1; i<=clustering_db.ndimensions(); i++)
                        fprintf(fp, "\t%lf", clustering_db.get_dimension(i).get_value(*vit));
                fprintf(fp, "\n");
        }
        fclose(fp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
leaq -0x450(%rbp), %r12
movl $0x400, %edx            # imm = 0x400
movq %r12, %rdi
xorl %esi, %esi
callq 0x41f0
movq 0x8(%r15), %rdx
leaq 0x7ab8(%rip), %rsi      # 0x16116
movq %r12, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x4080
leaq 0x7a1a(%rip), %rsi      # 0x1608c
movq %r12, %rdi
callq 0x4400
testq %rax, %rax
je 0xe822
movq %rax, %r14
movq 0x30(%rbx), %rcx
leaq 0x7a8f(%rip), %r15      # 0x16120
pushq $0x25
popq %r12
movq %rax, %rdi
movq %r15, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x4520
movq 0x8(%rbx), %rcx
subq (%rbx), %rcx
sarq $0x3, %rcx
movq %r14, %rdi
movq %r15, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x4520
leaq 0x7a61(%rip), %rsi      # 0x16128
movq %r14, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x4520
pushq $0x1
popq %r12
pushq $0x2
popq %r13
movq %r12, %r15
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
decq %rax
cmpq %rax, %r15
ja 0xe70c
leaq 0x7a34(%rip), %rdi      # 0x1612d
movq %r13, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x4720
incq %r15
jmp 0xe6df
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x4460
leaq 0x7a12(%rip), %rsi      # 0x16130
pushq $0x25
popq %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x4520
pushq $0x1
popq %r15
leaq -0x48(%rbp), %r12
leaq 0x79fd(%rip), %r13      # 0x16137
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
decq %rax
cmpq %rax, %r15
ja 0xe785
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc9d2
leaq 0x80(%rax), %rsi
movq %r12, %rdi
callq 0x44d0
movq -0x48(%rbp), %rdx
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x4520
movq %r12, %rdi
callq 0x4180
incq %r15
jmp 0xe73a
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x4460
leaq 0x28(%rbx), %r12
leaq 0x79a0(%rip), %r13      # 0x1613b
movq (%r12), %r12
testq %r12, %r12
je 0xe808
movq 0x8(%r12), %rdx
movq %r14, %rdi
leaq 0x7200(%rip), %rsi      # 0x159b3
xorl %eax, %eax
callq 0x4520
pushq $0x1
popq %r15
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
decq %rax
cmpq %rax, %r15
ja 0xe7fb
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc9d2
movq 0x8(%r12), %rsi
movq %rax, %rdi
callq 0xc452
movq %r14, %rdi
movq %r13, %rsi
movb $0x1, %al
callq 0x4520
incq %r15
jmp 0xe7be
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x4460
jmp 0xe79b
movq %r14, %rdi
callq 0x4350
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x107bf(%rip), %rdi     # 0x1efe8
leaq 0x785e(%rip), %rsi      # 0x1608e
callq 0x4340
leaq 0x7860(%rip), %rsi      # 0x1609c
movq %rax, %rdi
callq 0x4340
leaq 0x76b2(%rip), %rsi      # 0x15efd
movq %rax, %rdi
callq 0x4340
pushq $0x4d
popq %rsi
movq %rax, %rdi
callq 0x4630
leaq 0x784d(%rip), %rsi      # 0x160b2
movq %rax, %rdi
callq 0x4340
leaq -0x450(%rbp), %rsi
movq %rax, %rdi
callq 0x4340
movq %rax, %rdi
callq 0x41a0
movq %rax, %rdi
callq 0x41a0
pushq $-0x1
popq %rdi
callq 0x4430