// File: /workspace/github_cpp_makefile_star2_O3/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 0x51f0
movq 0x8(%r15), %rdx
leaq 0x82ec(%rip), %rsi      # 0x1a146
movq %r12, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x5090
leaq 0x824e(%rip), %rsi      # 0x1a0bc
movq %r12, %rdi
callq 0x5450
testq %rax, %rax
je 0x12064
movq %rax, %r14
movq 0x30(%rbx), %rcx
leaq 0x82c3(%rip), %r15      # 0x1a150
movq %rax, %rdi
movq %r15, %rsi
movl $0x25, %edx
xorl %eax, %eax
callq 0x5540
movq 0x8(%rbx), %rcx
subq (%rbx), %rcx
sarq $0x3, %rcx
movq %r14, %rdi
movq %r15, %rsi
movl $0x25, %edx
xorl %eax, %eax
callq 0x5540
leaq 0x8295(%rip), %rsi      # 0x1a158
movq %r14, %rdi
movl $0x25, %edx
xorl %eax, %eax
callq 0x5540
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cmpq $0x8, %rax
je 0x11f17
movl $0x1, %r12d
leaq 0x8271(%rip), %r15      # 0x1a15d
movl $0x2, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x5750
movq 0x8(%rbx), %rax
subq (%rbx), %rax
incq %r12
sarq $0x3, %rax
decq %rax
cmpq %rax, %r12
jbe 0x11eec
movl $0xa, %edi
movq %r14, %rsi
callq 0x54b0
leaq 0x8235(%rip), %rsi      # 0x1a160
movq %r14, %rdi
movl $0x25, %edx
xorl %eax, %eax
callq 0x5540
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cmpq $0x8, %rax
je 0x11fb6
movl $0x1, %r15d
leaq -0x38(%rbp), %r12
leaq 0x820f(%rip), %r13      # 0x1a167
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfe54
movq %r12, -0x48(%rbp)
movq 0x80(%rax), %rsi
movq 0x88(%rax), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0xb188
movq -0x48(%rbp), %rdx
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x5540
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x11fa0
callq 0x5340
movq 0x8(%rbx), %rax
subq (%rbx), %rax
incq %r15
sarq $0x3, %rax
decq %rax
cmpq %rax, %r15
jbe 0x11f58
movl $0xa, %edi
movq %r14, %rsi
callq 0x54b0
movq 0x28(%rbx), %r15
testq %r15, %r15
je 0x1204a
leaq 0x8198(%rip), %r12      # 0x1a16b
movq 0x8(%r15), %rdx
movq %r14, %rdi
leaq 0x7a02(%rip), %rsi      # 0x199e3
xorl %eax, %eax
callq 0x5540
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cmpq $0x8, %rax
je 0x12035
movl $0x1, %r13d
movq %rbx, %rdi
movq %r13, %rsi
callq 0xfe54
movq 0x8(%r15), %rsi
movq %rax, %rdi
callq 0xf964
movq %r14, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x5540
movq 0x8(%rbx), %rax
subq (%rbx), %rax
incq %r13
sarq $0x3, %rax
decq %rax
cmpq %rax, %r13
jbe 0x11ffb
movl $0xa, %edi
movq %r14, %rsi
callq 0x54b0
movq (%r15), %r15
testq %r15, %r15
jne 0x11fd3
movq %r14, %rdi
callq 0x5390
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xff7d(%rip), %rdi      # 0x21fe8
leaq 0x804c(%rip), %rsi      # 0x1a0be
callq 0x5380
leaq 0x804e(%rip), %rsi      # 0x1a0cc
movq %rax, %rdi
callq 0x5380
leaq 0x7ea0(%rip), %rsi      # 0x19f2d
movq %rax, %rdi
callq 0x5380
movq %rax, %rdi
movl $0x4d, %esi
callq 0x5670
leaq 0x8039(%rip), %rsi      # 0x1a0e2
movq %rax, %rdi
callq 0x5380
leaq -0x450(%rbp), %rsi
movq %rax, %rdi
callq 0x5380
movq %rax, %rdi
callq 0x51a0
movq %rax, %rdi
callq 0x51a0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x5480
nop