// File: /workspace/github_c_makefile_star2_O3/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 0x12ee0
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 0x12f1a
movq %rbp, %rdi
callq 0x3460
testq %rax, %rax
je 0x12f54
movq %rax, %rbx
movq %rax, %rdi
callq 0x3470
testq %rax, %rax
je 0x12ea7
movq %rax, %r14
movq $0x0, 0x8(%rsp)
leaq 0xc0(%rsp), %r13
leaq 0x6892(%rip), %r12      # 0x195e9
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 0x12e87
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3590
movl $0xa0, %edi
callq 0x32e0
movq %rax, (%rsp)
movq %rax, %rdi
movl 0x10(%rsp), %esi
callq 0x4718
movq %rbx, %rdi
leaq 0x4c0b(%rip), %rsi      # 0x179da
callq 0x3360
testq %rax, %rax
je 0x12ec1
movq %rax, %r14
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq (%rsp), %rsi
callq 0xf696
xorl %ebx, %ebx
movq %r13, %rdi
movl $0x1fff, %esi           # imm = 0x1FFF
movq %r14, %rdx
callq 0x34c0
testq %rax, %rax
je 0x12e6e
movq %r13, %rdi
callq 0x3150
cmpq $0x2, %rax
jb 0x12df3
leal 0x1(%rbx), %ebp
movq (%rsp), %rdi
movl $0xa, %esi
movl $0x1, %edx
movl %ebx, %ecx
callq 0x497c
movq %rax, %r15
movq %r13, %rdi
movq %r12, %rsi
callq 0x34a0
movl %ebp, 0x14(%rsp)
movl %ebp, %ebx
testq %rax, %rax
je 0x12df3
movq %rax, %rdi
callq 0x33a0
movq %r15, %rdi
callq 0x3d14
xorl %edi, %edi
movq %r12, %rsi
callq 0x34a0
testq %rax, %rax
jne 0x12e47
movl 0x14(%rsp), %eax
movl %eax, %ebx
jmp 0x12df3
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 0x12ea7
movq %rax, %r14
cmpl $0xa, 0x8(%rsp)
jl 0x12d61
movq %rbx, %rdi
callq 0x34e0
addq $0x20c8, %rsp           # imm = 0x20C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5508(%rip), %rdi      # 0x183d0
leaq 0x66f0(%rip), %rsi      # 0x195bf
leaq 0x692e(%rip), %rcx      # 0x19804
movl $0xa8, %edx
callq 0x31b0
movq 0xe0e9(%rip), %rdi      # 0x20fd0
leaq 0x68ff(%rip), %rsi      # 0x197ed
callq 0x32c0
movq %rax, %rdi
callq 0x3160
leaq 0x54ce(%rip), %rdi      # 0x183d0
leaq 0x66b6(%rip), %rsi      # 0x195bf
leaq 0x68f4(%rip), %rcx      # 0x19804
movl $0x89, %edx
callq 0x31b0
movq 0xe0af(%rip), %rdi      # 0x20fd0
leaq 0x6902(%rip), %rsi      # 0x1982a
callq 0x32c0
movq %rax, %rdi
callq 0x3160
leaq 0x5494(%rip), %rdi      # 0x183d0
leaq 0x667c(%rip), %rsi      # 0x195bf
leaq 0x68ba(%rip), %rcx      # 0x19804
movl $0x90, %edx
callq 0x31b0
movq 0xe075(%rip), %rdi      # 0x20fd0
leaq 0x68e6(%rip), %rsi      # 0x19848
callq 0x32c0
movq %rax, %rdi
callq 0x3160
leaq 0x545a(%rip), %rdi      # 0x183d0
leaq 0x6642(%rip), %rsi      # 0x195bf
leaq 0x6880(%rip), %rcx      # 0x19804
movl $0x97, %edx
callq 0x31b0
movq %rax, %rbx
movl $0xa0, %esi
movq (%rsp), %rdi
callq 0x32f0
movq %rbx, %rdi
callq 0x3570
nop