// File: /workspace/github_cpp_makefile_star2_O3/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 0x1130
movq %rax, 0x18(%rsp)
movq %rax, %rdi
callq 0x1140
movq %rax, %r15
movabsq $0x200000000, %rax      # imm = 0x200000000
movq %rax, 0x8(%rsp)
movl $0x10, %edi
callq 0x1030
movq %rax, %r12
movq %rax, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x2572
xorpd %xmm0, %xmm0
testq %r15, %r15
je 0x2200
movsd %xmm0, (%rsp)
leaq 0xf44(%rip), %r12       # 0x30e7
leaq 0x50(%rsp), %r13
leaq 0x30(%rsp), %rbp
leaq 0x8(%rsp), %rbx
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 0x1f35
movq 0x18(%rsp), %rdi
callq 0x1140
movq %rax, %r15
movsd (%rsp), %xmm0
addsd 0xecc(%rip), %xmm0      # 0x30c0
movsd %xmm0, (%rsp)
testq %rax, %rax
jne 0x21b2
jmp 0x2205
movsd %xmm0, (%rsp)
movl 0x2edd(%rip), %esi      # 0x50e8
cvttsd2si (%rsp), %edx
leaq 0xed6(%rip), %rdi       # 0x30ed
xorl %eax, %eax
callq 0x1040
movslq 0x2ec3(%rip), %r15      # 0x50e8
leaq (,%r15,8), %rbx
testq %r15, %r15
movq $-0x1, %rdi
cmovnsq %rbx, %rdi
callq 0x1030
movq %rax, %r14
testl %r15d, %r15d
jle 0x2255
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1080
movslq 0x8(%rsp), %rax
testq %rax, %rax
jle 0x231d
movq 0x10(%rsp), %rcx
xorl %edx, %edx
movsd 0xe4e(%rip), %xmm0      # 0x30c0
movq (%rcx,%rdx,8), %rdi
movslq 0x8(%rdi), %rsi
testq %rsi, %rsi
jle 0x22a2
movq 0x10(%rdi), %rdi
xorl %r8d, %r8d
movslq (%rdi,%r8,4), %r9
movsd (%r14,%r9,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r14,%r9,8)
incq %r8
cmpq %r8, %rsi
jne 0x2286
incq %rdx
cmpq %rax, %rdx
jne 0x2272
testl %eax, %eax
jle 0x231d
xorl %ebx, %ebx
movq 0x10(%rsp), %rcx
movq (%rcx,%rbx,8), %r15
cmpl $0x0, 0x8(%r15)
jle 0x2312
movq 0x18(%r15), %rax
xorl %r12d, %r12d
movq 0x10(%r15), %rcx
movslq (%rcx,%r12,4), %rcx
movsd (%rsp), %xmm0
divsd (%r14,%rcx,8), %xmm0
movsd (%rax,%r12,8), %xmm1
movaps %xmm1, 0x20(%rsp)
callq 0x10b0
cvttpd2dq 0x20(%rsp), %xmm1
cvtdq2pd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movq 0x18(%r15), %rax
movsd %xmm1, (%rax,%r12,8)
incq %r12
movslq 0x8(%r15), %rcx
cmpq %rcx, %r12
jl 0x22c7
movl 0x8(%rsp), %eax
incq %rbx
movslq %eax, %rcx
cmpq %rcx, %rbx
jl 0x22b0
movq %r14, %rdi
callq 0x10d0
leaq 0x8(%rsp), %rdi
callq 0x1bfb
movq 0x18(%rsp), %rdi
callq 0x1160
leaq 0x30(%rsp), %rdi
callq 0x2606
movq 0x10(%rsp), %rdi
callq 0x10d0
addq $0x1058, %rsp           # imm = 0x1058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x2378
jmp 0x2366
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2606
movq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x10d0
movq %rbx, %rdi
callq 0x1170