// File: /workspace/github_cpp_makefile_star2_O2/ivanzamanov[P]kmeans/src/kmeans/kmeans_main.cpp
// Function: processDirectory(char const*)
void processDirectory(const char* inputDirPath) {
	DIR* dirHandle = opendir(inputDirPath);
	struct dirent* entry = readdir(dirHandle);

	list<article_entry*> entries;
	char path[4096];
	ptree<int> p;
	double docCount = 0;
	while(entry != NULL) {
		sprintf(path, "%s/%s", inputDirPath, entry->d_name);
		processFile(path, entry->d_name, p, entries);
		entry = readdir(dirHandle);
		docCount++;
	}
	printf("Unique tokens: %d in %d documents\n", tokenCount, (int)docCount);
	// Document frequencies
	double* dfs = new double[tokenCount];
	for (int i=0; i<tokenCount; i++)
		dfs[i] = 0;
	for(int i=0; i<entries.size(); i++) {
		vector& v = entries.get(i)->v;
		for(int j=0; j<v.size; j++)
			dfs[ v.keys[j] ]++;
	}
	for(int i=0; i<entries.size(); i++) {
		vector& v = entries.get(i)->v;
		for(int j=0; j<v.size; j++) {
			int tf = v.values[j];
			double idf = log( docCount / dfs[ v.keys[j] ]);
			v.values[j] = ((double) tf) * idf;
		}
	}
	delete dfs;
	
	kmeans(entries);
	
	closedir(dirHandle);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1058, %rsp           # imm = 0x1058
movq %rdi, %r14
callq 0x1110
movq %rax, 0x18(%rsp)
movq %rax, %rdi
callq 0x1120
movq %rax, %r15
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, 0x8(%rsp)
pushq $0x10
popq %rdi
callq 0x1030
movq %rax, %r12
movq %rax, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x245e
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
leaq 0x1063(%rip), %r12      # 0x30d7
leaq 0x50(%rsp), %r13
leaq 0x30(%rsp), %rbp
leaq 0x8(%rsp), %rbx
testq %r15, %r15
je 0x20d1
addq $0x13, %r15
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x1050
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x1ea4
movq 0x18(%rsp), %rdi
callq 0x1120
movq %rax, %r15
movsd (%rsp), %xmm0
addsd 0xfe6(%rip), %xmm0      # 0x30b0
movsd %xmm0, (%rsp)
jmp 0x2083
movl 0x3001(%rip), %esi      # 0x50d8
cvttsd2si (%rsp), %edx
leaq 0xffa(%rip), %rdi       # 0x30dd
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1040
movslq 0x2fe5(%rip), %r15      # 0x50d8
leaq (,%r15,8), %rax
testq %r15, %r15
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0x1030
movq %rax, %r14
testl %r15d, %r15d
cmovlel %ebx, %r15d
cmpq %rbx, %r15
je 0x2123
andq $0x0, (%r14,%rbx,8)
incq %rbx
jmp 0x2114
movl 0x8(%rsp), %eax
movq 0x10(%rsp), %rcx
xorl %edx, %edx
testl %eax, %eax
movl $0x0, %esi
cmovgl %eax, %esi
xorl %edi, %edi
cmpq %rsi, %rdi
je 0x217c
movq (%rcx,%rdi,8), %r8
movl 0x8(%r8), %r9d
testl %r9d, %r9d
cmovlel %edx, %r9d
xorl %r10d, %r10d
cmpq %r10, %r9
je 0x2177
movq 0x10(%r8), %r11
movslq (%r11,%r10,4), %r11
movsd (%r14,%r11,8), %xmm0
addsd 0xf44(%rip), %xmm0      # 0x30b0
movsd %xmm0, (%r14,%r11,8)
incq %r10
jmp 0x2151
incq %rdi
jmp 0x213a
xorl %ebx, %ebx
cltq
cmpq %rax, %rbx
jge 0x21e7
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %r15
xorl %r12d, %r12d
movslq 0x8(%r15), %rax
cmpq %rax, %r12
jge 0x21de
movq 0x10(%r15), %rax
movq 0x18(%r15), %rcx
movslq (%rax,%r12,4), %rax
movsd (%rsp), %xmm0
divsd (%r14,%rax,8), %xmm0
movsd (%rcx,%r12,8), %xmm1
movaps %xmm1, 0x20(%rsp)
callq 0x10a0
cvttpd2dq 0x20(%rsp), %xmm1
cvtdq2pd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movq 0x18(%r15), %rax
movsd %xmm1, (%rax,%r12,8)
incq %r12
jmp 0x2191
incq %rbx
movl 0x8(%rsp), %eax
jmp 0x217e
movq %r14, %rdi
callq 0x10b0
leaq 0x8(%rsp), %rdi
callq 0x1b39
movq 0x18(%rsp), %rdi
callq 0x1140
leaq 0x30(%rsp), %rdi
callq 0x24d8
movq 0x10(%rsp), %rdi
callq 0x10b0
addq $0x1058, %rsp           # imm = 0x1058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2242
jmp 0x2230
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x24d8
movq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x10b0
movq %rbx, %rdi
callq 0x1150