// File: 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
subq $0x4e0, %rsp            # imm = 0x4E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x490(%rbp)
leaq -0x420(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x5210
movq -0x490(%rbp), %rdi
leaq -0x420(%rbp), %rax
movq %rax, -0x488(%rbp)
addq $0x8, %rdi
callq 0x5190
movq -0x488(%rbp), %rdi
movq %rax, %rdx
movq -0x18(%rbp), %rcx
leaq 0x11f96(%rip), %rsi     # 0x3613e
movb $0x0, %al
callq 0x50b0
leaq -0x420(%rbp), %rdi
leaq 0x11ef7(%rip), %rsi     # 0x360b4
callq 0x54b0
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
jne 0x2425b
movq 0x28e0a(%rip), %rdi     # 0x4cfe8
leaq 0x11ed1(%rip), %rsi     # 0x360b6
callq 0x53f0
movq %rax, %rdi
leaq 0x11ed0(%rip), %rsi     # 0x360c4
callq 0x53f0
movq %rax, %rdi
leaq 0x11d22(%rip), %rsi     # 0x35f25
callq 0x53f0
movq %rax, %rdi
movl $0x4d, %esi
callq 0x5710
movq %rax, %rdi
leaq 0x11ebb(%rip), %rsi     # 0x360da
callq 0x53f0
movq %rax, %rdi
leaq -0x420(%rbp), %rsi
callq 0x53f0
movq %rax, %rdi
movq 0x28d53(%rip), %rsi     # 0x4cf90
callq 0x5440
movq %rax, %rdi
movq 0x28d44(%rip), %rsi     # 0x4cf90
callq 0x5440
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x54f0
movq -0x428(%rbp), %rax
movq %rax, -0x4a0(%rbp)
movq -0x10(%rbp), %rdi
callq 0xa520
movq -0x4a0(%rbp), %rdi
movq %rax, %rcx
leaq 0x11ec5(%rip), %rsi     # 0x36148
movl $0x25, %edx
movb $0x0, %al
callq 0x5610
movq -0x428(%rbp), %rax
movq %rax, -0x498(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20620
movq -0x498(%rbp), %rdi
movq %rax, %rcx
addq $0x1, %rcx
leaq 0x11e8d(%rip), %rsi     # 0x36148
movl $0x25, %edx
movb $0x0, %al
callq 0x5610
movq -0x428(%rbp), %rdi
leaq 0x11e7b(%rip), %rsi     # 0x36150
movl $0x25, %edx
movb $0x0, %al
callq 0x5610
movq $0x1, -0x430(%rbp)
movq -0x430(%rbp), %rax
movq %rax, -0x4a8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20620
movq %rax, %rcx
movq -0x4a8(%rbp), %rax
cmpq %rcx, %rax
ja 0x2433b
movq -0x428(%rbp), %rdi
leaq 0x11e35(%rip), %rsi     # 0x36155
movb $0x0, %al
callq 0x5610
movq -0x430(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x430(%rbp)
jmp 0x242ec
movq -0x428(%rbp), %rdi
leaq 0x122c9(%rip), %rsi     # 0x36612
movb $0x0, %al
callq 0x5610
movq -0x428(%rbp), %rdi
leaq 0x11dfa(%rip), %rsi     # 0x36158
movl $0x25, %edx
movb $0x0, %al
callq 0x5610
movq $0x1, -0x438(%rbp)
movq -0x438(%rbp), %rax
movq %rax, -0x4b0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20620
movq %rax, %rcx
movq -0x4b0(%rbp), %rax
cmpq %rcx, %rax
ja 0x2440f
movq -0x428(%rbp), %rax
movq %rax, -0x4b8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x438(%rbp), %rsi
callq 0x1e9d0
movq %rax, %rsi
leaq -0x458(%rbp), %rdi
callq 0x20bb0
leaq -0x458(%rbp), %rdi
callq 0x5190
movq -0x4b8(%rbp), %rdi
movq %rax, %rdx
leaq 0x11d7a(%rip), %rsi     # 0x3615f
movb $0x0, %al
callq 0x5610
leaq -0x458(%rbp), %rdi
callq 0x5250
movq -0x438(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x438(%rbp)
jmp 0x24375
movq -0x428(%rbp), %rdi
leaq 0x121f5(%rip), %rsi     # 0x36612
movb $0x0, %al
callq 0x5610
movq -0x10(%rbp), %rdi
callq 0x24690
movq %rax, -0x460(%rbp)
movq -0x460(%rbp), %rdi
callq 0xbfd0
movq %rax, -0x468(%rbp)
movq -0x460(%rbp), %rdi
callq 0xc0b0
movq %rax, -0x470(%rbp)
leaq -0x468(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0xa1d0
testb $0x1, %al
jne 0x24476
jmp 0x24574
movq -0x428(%rbp), %rax
movq %rax, -0x4c0(%rbp)
leaq -0x468(%rbp), %rdi
callq 0xa310
movq -0x4c0(%rbp), %rdi
movq (%rax), %rdx
leaq 0x11549(%rip), %rsi     # 0x359ea
movb $0x0, %al
callq 0x5610
movq $0x1, -0x478(%rbp)
movq -0x478(%rbp), %rax
movq %rax, -0x4c8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20620
movq %rax, %rcx
movq -0x4c8(%rbp), %rax
cmpq %rcx, %rax
ja 0x24545
movq -0x428(%rbp), %rax
movq %rax, -0x4d0(%rbp)
movq -0x10(%rbp), %rdi
movq -0x478(%rbp), %rsi
callq 0x1e9d0
movq %rax, -0x4d8(%rbp)
leaq -0x468(%rbp), %rdi
callq 0xa310
movq -0x4d8(%rbp), %rdi
movq (%rax), %rsi
callq 0x1cb40
movq -0x4d0(%rbp), %rdi
leaq 0x11c3c(%rip), %rsi     # 0x36163
movb $0x1, %al
callq 0x5610
movq -0x478(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x478(%rbp)
jmp 0x244b3
movq -0x428(%rbp), %rdi
leaq 0x120bf(%rip), %rsi     # 0x36612
movb $0x0, %al
callq 0x5610
leaq -0x468(%rbp), %rdi
xorl %esi, %esi
callq 0xa340
movq %rax, -0x480(%rbp)
jmp 0x24447
movq -0x428(%rbp), %rdi
callq 0x5400
addq $0x4e0, %rsp            # imm = 0x4E0
popq %rbp
retq
nopl (%rax)