// File: /workspace/github_c_makefile_star2_O2/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 $0x20b8, %rsp           # imm = 0x20B8
movl %esi, 0xc(%rsp)
movq %rdi, 0x18(%rsp)
testq %rdx, %rdx
je 0x107cf
movq %rdx, %rbx
leaq 0x20(%rsp), %r14
movq %rdx, %rdi
movq %r14, %rsi
callq 0x35d0
movl $0xf000, %eax           # imm = 0xF000
andl 0x18(%r14), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x10809
movq %rbx, %rdi
callq 0x3430
testq %rax, %rax
je 0x10843
movq %rax, %r15
xorl %r12d, %r12d
movq %r15, %rdi
callq 0x3440
testq %rax, %rax
je 0x107b5
cmpl $0x9, %r12d
ja 0x107b5
movq %rax, %r14
movq %rax, %r13
movq %rbx, %rdi
callq 0x3130
movq %rax, %rbp
addq $0x13, %r14
movq %r14, %rdi
callq 0x3130
leaq (%rax,%rbp), %rdi
incq %rdi
callq 0x3030
movq %rax, %rbp
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3270
movb 0x13(%r13), %al
addb $-0x7b, %al
cmpb $-0x1a, %al
jb 0x1067f
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3560
movl $0xa0, %edi
callq 0x32c0
movq %rax, %r13
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x4120
movq %rbp, %rdi
leaq 0x42b1(%rip), %rsi      # 0x149ba
callq 0x3320
testq %rax, %rax
je 0x1087d
movq %rax, %r14
movq 0x18(%rsp), %rax
movq (%rax), %rdi
movq %r13, 0x10(%rsp)
movq %r13, %rsi
callq 0xd0f4
xorl %ebp, %ebp
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
movl $0x1fff, %esi           # imm = 0x1FFF
movq %r14, %rdx
callq 0x3490
testq %rax, %rax
je 0x107a5
movq %r13, %rdi
callq 0x3130
cmpq $0x2, %rax
jb 0x10739
movq 0x10(%rsp), %rdi
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
movl %ebp, 0x8(%rsp)
movl %ebp, %ecx
callq 0x42e0
movq %rax, %rbp
movq %r13, %rdi
leaq 0x5e4a(%rip), %rsi      # 0x165c9
callq 0x3470
testq %rax, %rax
je 0x1079d
movq %rax, %rdi
callq 0x3360
movq %rbp, %rdi
callq 0x38da
xorl %edi, %edi
jmp 0x10778
movl 0x8(%rsp), %ebp
incl %ebp
jmp 0x10731
movq %r14, %rdi
callq 0x32b0
incl %r12d
jmp 0x1067f
movq %r15, %rdi
callq 0x34c0
addq $0x20b8, %rsp           # imm = 0x20B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf7f2(%rip), %rdi      # 0x1ffc8
leaq 0x5ff0(%rip), %rsi      # 0x167cd
callq 0x32a0
movq %rax, %rdi
callq 0x3160
leaq 0x4bbf(%rip), %rdi      # 0x153b0
leaq 0x5da7(%rip), %rsi      # 0x1659f
leaq 0x5fe5(%rip), %rcx      # 0x167e4
movl $0x89, %edx
callq 0x31b0
movq 0xf7b8(%rip), %rdi      # 0x1ffc8
leaq 0x5ff3(%rip), %rsi      # 0x1680a
callq 0x32a0
movq %rax, %rdi
callq 0x3160
leaq 0x4b85(%rip), %rdi      # 0x153b0
leaq 0x5d6d(%rip), %rsi      # 0x1659f
leaq 0x5fab(%rip), %rcx      # 0x167e4
movl $0x90, %edx
callq 0x31b0
movq 0xf77e(%rip), %rdi      # 0x1ffc8
leaq 0x5fd7(%rip), %rsi      # 0x16828
callq 0x32a0
movq %rax, %rdi
callq 0x3160
leaq 0x4b4b(%rip), %rdi      # 0x153b0
leaq 0x5d33(%rip), %rsi      # 0x1659f
leaq 0x5f71(%rip), %rcx      # 0x167e4
movl $0x97, %edx
callq 0x31b0
leaq 0x4b2c(%rip), %rdi      # 0x153b0
leaq 0x5d14(%rip), %rsi      # 0x1659f
leaq 0x5f52(%rip), %rcx      # 0x167e4
movl $0xa8, %edx
callq 0x31b0
movq %rax, %rbx
movl $0xa0, %esi
movq %r13, %rdi
callq 0x32d0
movq %rbx, %rdi
callq 0x3540