// File: /workspace/github_cpp_makefile_star2_O1/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 0x9196(%rip), %rsi      # 0x1b156
movq %r12, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x5090
leaq 0x90f8(%rip), %rsi      # 0x1b0cc
movq %r12, %rdi
callq 0x5450
testq %rax, %rax
je 0x121ca
movq %rax, %r14
movq 0x30(%rbx), %rcx
leaq 0x916d(%rip), %r15      # 0x1b160
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 0x913f(%rip), %rsi      # 0x1b168
movq %r14, %rdi
movl $0x25, %edx
xorl %eax, %eax
callq 0x5540
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cmpq $0x8, %rax
je 0x1207d
movl $0x1, %r12d
leaq 0x911b(%rip), %r15      # 0x1b16d
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 0x12052
movl $0xa, %edi
movq %r14, %rsi
callq 0x54b0
leaq 0x90df(%rip), %rsi      # 0x1b170
movq %r14, %rdi
movl $0x25, %edx
xorl %eax, %eax
callq 0x5540
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cmpq $0x8, %rax
je 0x1211c
movl $0x1, %r15d
leaq -0x38(%rbp), %r12
leaq 0x90b9(%rip), %r13      # 0x1b177
movq %rbx, %rdi
movq %r15, %rsi
callq 0xff94
movq %r12, -0x48(%rbp)
movq 0x80(%rax), %rsi
movq 0x88(%rax), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0xb27a
movq -0x48(%rbp), %rdx
movq %r14, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x5540
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x12106
callq 0x5340
movq 0x8(%rbx), %rax
subq (%rbx), %rax
incq %r15
sarq $0x3, %rax
decq %rax
cmpq %rax, %r15
jbe 0x120be
movl $0xa, %edi
movq %r14, %rsi
callq 0x54b0
movq 0x28(%rbx), %r15
testq %r15, %r15
je 0x121b0
leaq 0x9042(%rip), %r12      # 0x1b17b
movq 0x8(%r15), %rdx
movq %r14, %rdi
leaq 0x88ac(%rip), %rsi      # 0x1a9f3
xorl %eax, %eax
callq 0x5540
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cmpq $0x8, %rax
je 0x1219b
movl $0x1, %r13d
movq %rbx, %rdi
movq %r13, %rsi
callq 0xff94
movq 0x8(%r15), %rsi
movq %rax, %rdi
callq 0xfa80
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 0x12161
movl $0xa, %edi
movq %r14, %rsi
callq 0x54b0
movq (%r15), %r15
testq %r15, %r15
jne 0x12139
movq %r14, %rdi
callq 0x5390
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10e17(%rip), %rdi     # 0x22fe8
leaq 0x8ef6(%rip), %rsi      # 0x1b0ce
callq 0x5380
leaq 0x8ef8(%rip), %rsi      # 0x1b0dc
movq %rax, %rdi
callq 0x5380
leaq 0x8d4a(%rip), %rsi      # 0x1af3d
movq %rax, %rdi
callq 0x5380
movq %rax, %rdi
movl $0x4d, %esi
callq 0x5670
leaq 0x8ee3(%rip), %rsi      # 0x1b0f2
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