// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x25fa
xorpd %xmm0, %xmm0
testq %r15, %r15
je 0x224e
movsd %xmm0, (%rsp)
leaq 0xef6(%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 0x1f89
movq 0x18(%rsp), %rdi
callq 0x1140
movq %rax, %r15
movsd (%rsp), %xmm0
addsd 0xe7e(%rip), %xmm0      # 0x30c0
movsd %xmm0, (%rsp)
testq %rax, %rax
jne 0x2200
jmp 0x2253
movsd %xmm0, (%rsp)
movl 0x2e8f(%rip), %esi      # 0x50e8
cvttsd2si (%rsp), %edx
leaq 0xe88(%rip), %rdi       # 0x30ed
xorl %eax, %eax
callq 0x1040
movslq 0x2e75(%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 0x22a3
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1080
movslq 0x8(%rsp), %rax
testq %rax, %rax
jle 0x22f4
movq 0x10(%rsp), %rcx
xorl %edx, %edx
movsd 0xe04(%rip), %xmm0      # 0x30c0
movq (%rcx,%rdx,8), %rdi
movslq 0x8(%rdi), %rsi
testq %rsi, %rsi
jle 0x22ec
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 0x22d0
incq %rdx
cmpq %rax, %rdx
jne 0x22bc
cmpl $0x0, 0x8(%rsp)
jle 0x2372
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %r15
cmpl $0x0, 0x8(%r15)
movsd (%rsp), %xmm0
jle 0x2365
xorl %r12d, %r12d
movsd %xmm0, (%rsp)
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 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), %rax
cmpq %rax, %r12
jl 0x231a
incq %rbx
movslq 0x8(%rsp), %rax
cmpq %rax, %rbx
jl 0x22fd
movq %r14, %rdi
callq 0x10d0
leaq 0x8(%rsp), %rdi
callq 0x1c36
movq 0x18(%rsp), %rdi
callq 0x1160
leaq 0x30(%rsp), %rdi
callq 0x269c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x23a7
callq 0x10d0
addq $0x1058, %rsp           # imm = 0x1058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x23cd
jmp 0x23c0
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x269c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x23dc
callq 0x10d0
movq %rbx, %rdi
callq 0x1170