// File: /workspace/github_c_makefile_star2_O1/stonezwr[P]SpiKL-IP/parser.C
// Function: Parser::ParseSpeech(int, char*)
void Parser::ParseSpeech(int cls, char* path){
	if(path==NULL){
		cout<<"directory path is NULL"<<endl;
		assert(0);
	}
	//check if path is a valid dir
	struct stat s;
	lstat(path,&s);
	if(!S_ISDIR(s.st_mode)){
		cout<<"path is not a valid directory"<<endl;
		assert(0);
	}
	struct dirent* filename;
	DIR *dir;
	dir=opendir(path);
	if(dir==NULL){
		cout<<"Cannot open dir"<<endl;
		assert(0);
	}
	int file_read=0;
	while((filename=readdir(dir))!=NULL&&file_read<SAMPLES_PER_CLASS){
		const size_t len = strlen(path)+strlen(filename->d_name);
		char *file_path=new char[len+1];
		strcpy(file_path,path);
		if(filename->d_name[0]<'a'||filename->d_name[0]>'z'){
			continue;
		}
		strcat(file_path,filename->d_name);
		Speech * speech = new Speech(cls);
		Channel * channel;
		char linestring[8192];
		char * token;
		FILE * fp = fopen(file_path,"r");
		if(fp==NULL){
			assert(0);	
		}
		_network->AddSpeech(speech);
		int index = 0;
		while(fgets(linestring,8191,fp)!=NULL){
			if(strlen(linestring) <= 1) continue;
			channel = speech->AddChannel(10, 1, index++);
			token = strtok(linestring," \t\n");
			while(token != NULL){
				channel->AddAnalog(atof(token));
				token = strtok(NULL," \t\n");
			}
		}
		fclose(fp);
		delete token;
		file_read++;
	}
	closedir(dir);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20c8, %rsp           # imm = 0x20C8
movl %esi, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
testq %rdx, %rdx
je 0x1324c
movq %rdx, %rbp
leaq 0x30(%rsp), %rbx
movq %rdx, %rdi
movq %rbx, %rsi
callq 0x3600
movl $0xf000, %eax           # imm = 0xF000
andl 0x18(%rbx), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x13286
movq %rbp, %rdi
callq 0x3460
testq %rax, %rax
je 0x132c0
movq %rax, %rbx
movq %rax, %rdi
callq 0x3470
testq %rax, %rax
je 0x13213
movq %rax, %r14
movq $0x0, 0x8(%rsp)
leaq 0xc0(%rsp), %r13
leaq 0x6486(%rip), %r12      # 0x19549
movq %rbp, 0x18(%rsp)
movq %rbx, 0x28(%rsp)
movq %rbp, %rdi
callq 0x3150
movq %rax, %rbx
leaq 0x13(%r14), %r15
movq %r15, %rdi
callq 0x3150
leaq (%rbx,%rax), %rdi
incq %rdi
callq 0x3030
movq %rax, %rbx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3290
movb 0x13(%r14), %al
addb $-0x7b, %al
cmpb $-0x1a, %al
jb 0x131f3
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3590
movl $0xa0, %edi
callq 0x32e0
movq %rax, (%rsp)
movq %rax, %rdi
movl 0x10(%rsp), %esi
callq 0x4690
movq %rbx, %rdi
leaq 0x47ff(%rip), %rsi      # 0x1793a
callq 0x3360
testq %rax, %rax
je 0x1322d
movq %rax, %r14
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq (%rsp), %rsi
callq 0xf92e
xorl %ebx, %ebx
movq %r13, %rdi
movl $0x1fff, %esi           # imm = 0x1FFF
movq %r14, %rdx
callq 0x34c0
testq %rax, %rax
je 0x131da
movq %r13, %rdi
callq 0x3150
cmpq $0x2, %rax
jb 0x1315f
leal 0x1(%rbx), %ebp
movq (%rsp), %rdi
movl $0xa, %esi
movl $0x1, %edx
movl %ebx, %ecx
callq 0x48f4
movq %rax, %r15
movq %r13, %rdi
movq %r12, %rsi
callq 0x34a0
movl %ebp, 0x14(%rsp)
movl %ebp, %ebx
testq %rax, %rax
je 0x1315f
movq %rax, %rdi
callq 0x33a0
movq %r15, %rdi
callq 0x3db4
xorl %edi, %edi
movq %r12, %rsi
callq 0x34a0
testq %rax, %rax
jne 0x131b3
movl 0x14(%rsp), %eax
movl %eax, %ebx
jmp 0x1315f
movq %r14, %rdi
callq 0x32d0
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rbp
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x3470
testq %rax, %rax
je 0x13213
movq %rax, %r14
cmpl $0xa, 0x8(%rsp)
jl 0x130cd
movq %rbx, %rdi
callq 0x34e0
addq $0x20c8, %rsp           # imm = 0x20C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x50fc(%rip), %rdi      # 0x18330
leaq 0x62e4(%rip), %rsi      # 0x1951f
leaq 0x6522(%rip), %rcx      # 0x19764
movl $0xa8, %edx
callq 0x31b0
movq 0xdd7d(%rip), %rdi      # 0x20fd0
leaq 0x64f3(%rip), %rsi      # 0x1974d
callq 0x32c0
movq %rax, %rdi
callq 0x3160
leaq 0x50c2(%rip), %rdi      # 0x18330
leaq 0x62aa(%rip), %rsi      # 0x1951f
leaq 0x64e8(%rip), %rcx      # 0x19764
movl $0x89, %edx
callq 0x31b0
movq 0xdd43(%rip), %rdi      # 0x20fd0
leaq 0x64f6(%rip), %rsi      # 0x1978a
callq 0x32c0
movq %rax, %rdi
callq 0x3160
leaq 0x5088(%rip), %rdi      # 0x18330
leaq 0x6270(%rip), %rsi      # 0x1951f
leaq 0x64ae(%rip), %rcx      # 0x19764
movl $0x90, %edx
callq 0x31b0
movq 0xdd09(%rip), %rdi      # 0x20fd0
leaq 0x64da(%rip), %rsi      # 0x197a8
callq 0x32c0
movq %rax, %rdi
callq 0x3160
leaq 0x504e(%rip), %rdi      # 0x18330
leaq 0x6236(%rip), %rsi      # 0x1951f
leaq 0x6474(%rip), %rcx      # 0x19764
movl $0x97, %edx
callq 0x31b0
movq %rax, %rbx
movl $0xa0, %esi
movq (%rsp), %rdi
callq 0x32f0
movq %rbx, %rdi
callq 0x3570
nop