// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2140, %rsp           # imm = 0x2140
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2110(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x2bb59
movq 0x214a9(%rip), %rdi     # 0x4cfc8
leaq 0xac17(%rip), %rsi      # 0x3673d
callq 0x4360
movq %rax, %rdi
movq 0x21483(%rip), %rsi     # 0x4cfb8
callq 0x43b0
leaq 0x97d7(%rip), %rdi      # 0x35318
leaq 0xa9bf(%rip), %rsi      # 0x36507
movl $0x89, %edx
leaq 0xac00(%rip), %rcx      # 0x36754
callq 0x4210
movq -0x18(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x4790
movl -0x90(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
je 0x2bbbc
movq 0x21446(%rip), %rdi     # 0x4cfc8
leaq 0xabf1(%rip), %rsi      # 0x3677a
callq 0x4360
movq %rax, %rdi
movq 0x21420(%rip), %rsi     # 0x4cfb8
callq 0x43b0
leaq 0x9774(%rip), %rdi      # 0x35318
leaq 0xa95c(%rip), %rsi      # 0x36507
movl $0x90, %edx
leaq 0xab9d(%rip), %rcx      # 0x36754
callq 0x4210
movq -0x18(%rbp), %rdi
callq 0x4590
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jne 0x2bc17
movq 0x213eb(%rip), %rdi     # 0x4cfc8
leaq 0xabb4(%rip), %rsi      # 0x36798
callq 0x4360
movq %rax, %rdi
movq 0x213c5(%rip), %rsi     # 0x4cfb8
callq 0x43b0
leaq 0x9719(%rip), %rdi      # 0x35318
leaq 0xa901(%rip), %rsi      # 0x36507
movl $0x97, %edx
leaq 0xab42(%rip), %rcx      # 0x36754
callq 0x4210
movl $0x0, -0xbc(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x45a0
movq %rax, %rcx
movq %rcx, -0xb0(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x2111(%rbp)
je 0x2bc55
cmpl $0xa, -0xbc(%rbp)
setl %al
movb %al, -0x2111(%rbp)
movb -0x2111(%rbp), %al
testb $0x1, %al
jne 0x2bc64
jmp 0x2bec6
movq -0x18(%rbp), %rdi
callq 0x4180
movq %rax, -0x2120(%rbp)
movq -0xb0(%rbp), %rdi
addq $0x13, %rdi
callq 0x4180
movq %rax, %rcx
movq -0x2120(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
addq $0x1, %rdi
callq 0x4030
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4330
movq -0xb0(%rbp), %rax
movsbl 0x13(%rax), %eax
cmpl $0x61, %eax
jl 0x2bcdf
movq -0xb0(%rbp), %rax
movsbl 0x13(%rax), %eax
cmpl $0x7a, %eax
jle 0x2bce4
jmp 0x2bc21
movq -0xd0(%rbp), %rdi
movq -0xb0(%rbp), %rsi
addq $0x13, %rsi
callq 0x4700
movl $0xa0, %edi
callq 0x4380
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x2128(%rbp)
movl -0xc(%rbp), %esi
callq 0x6e70
jmp 0x2bd1c
movq -0x2128(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rdi
leaq 0x8bba(%rip), %rsi      # 0x348f2
callq 0x4430
movq %rax, -0x2100(%rbp)
cmpq $0x0, -0x2100(%rbp)
jne 0x2bd95
leaq 0x95c3(%rip), %rdi      # 0x35318
leaq 0xa7ab(%rip), %rsi      # 0x36507
movl $0xa8, %edx
leaq 0xa9ec(%rip), %rcx      # 0x36754
callq 0x4210
movq -0x2128(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe0(%rbp)
movl %eax, -0xe4(%rbp)
movl $0xa0, %esi
callq 0x4390
jmp 0x2bedb
movq -0x2110(%rbp), %rax
movq (%rax), %rdi
movq -0xd8(%rbp), %rsi
callq 0x20d90
movl $0x0, -0x2104(%rbp)
leaq -0x20f0(%rbp), %rdi
movq -0x2100(%rbp), %rdx
movl $0x1fff, %esi           # imm = 0x1FFF
callq 0x45f0
cmpq $0x0, %rax
je 0x2be81
leaq -0x20f0(%rbp), %rdi
callq 0x4180
cmpq $0x1, %rax
ja 0x2bdeb
jmp 0x2bdb5
movq -0xd8(%rbp), %rdi
movl -0x2104(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x2104(%rbp)
movl $0xa, %esi
movl $0x1, %edx
callq 0x7170
movq %rax, -0xf0(%rbp)
leaq -0x20f0(%rbp), %rdi
leaq 0xa712(%rip), %rsi      # 0x36539
callq 0x45d0
movq %rax, -0x20f8(%rbp)
cmpq $0x0, -0x20f8(%rbp)
je 0x2be7c
movq -0xf0(%rbp), %rax
movq %rax, -0x2130(%rbp)
movq -0x20f8(%rbp), %rdi
callq 0x4490
movq -0x2130(%rbp), %rdi
callq 0x4c30
xorl %eax, %eax
movl %eax, %edi
leaq 0xa6cb(%rip), %rsi      # 0x36539
callq 0x45d0
movq %rax, -0x20f8(%rbp)
jmp 0x2be33
jmp 0x2bdb5
movq -0x2100(%rbp), %rdi
callq 0x4370
movq -0x20f8(%rbp), %rax
movq %rax, -0x2138(%rbp)
cmpq $0x0, %rax
je 0x2beb2
movq -0x2138(%rbp), %rdi
movl $0x1, %esi
callq 0x4390
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x2bc21
movq -0xb8(%rbp), %rdi
callq 0x4630
addq $0x2140, %rsp           # imm = 0x2140
popq %rbp
retq
movq -0xe0(%rbp), %rdi
callq 0x46d0
nopw (%rax,%rax)