// File: huiwenliuge[P]EmoAnaer/src/RNNet.cpp
// Function: RNNet::FetchSent(char const*)
Sentence RNNet::FetchSent(const char* pathRoot){

    //Sentence ret;
    char** filelist=(char**)malloc(sizeof(char*)*EMOTIONNUM);
    int i,j,len,pathrootlen;
    FILE* sentfp;
    char* line=(char*)calloc(sizeof(char),421);
    totnum = 0;
    pathrootlen=strlen(pathRoot);
    for(i=0;i<EMOTIONNUM;++i){
        filelist[i]=(char*)calloc(sizeof(char),101);
        strcpy(filelist[i],pathRoot);
        strcpy(filelist[i]+pathrootlen,EMOLIST[i]);
        //std::cout<< filelist[i] <<std::endl;

        sentfp=fopen(filelist[i],"r");
        // const double* ans=(double*)calloc(sizeof(double),EMOTIONNUM);
        // ans[i]=1.0;

        while(fscanf(sentfp,"%s\n",line)!=-1){

            len=strLenUTF8(line);
            Sentence sentunit=(Sentence)malloc(sizeof(struct sentence));
            sentunit->num = totnum;
            totnum++;
            sentunit->schar=line;
            sentunit->tlen=len;
            sentunit->inVec=crtInvec(line,featureNUM,ccdict);
            sentunit->hidLay=(double**)malloc(sizeof(double*)*len);
            sentunit->kLayer=(double**)malloc(sizeof(double*)*len);
            sentunit->outLay=(double**)malloc(sizeof(double*)*len);
            sentunit->DLDo  =(double**)malloc(sizeof(double*)*len);
            sentunit->DLDh  =(double**)malloc(sizeof(double*)*len);
            sentunit->DLDx  =(double**)malloc(sizeof(double*)*len);
            sentunit->energy=(double**)malloc(sizeof(double*)*len);
            sentunit->stdAns=(double*)calloc(sizeof(double),EMOTIONNUM);
            sentunit->eng=(double*)calloc(sizeof(double),EMOTIONNUM);

            for(j=0;j<len;++j){
                // for(int k=0;k<featureNUM;++k){
                //     std::cout<<sentunit->inVec[j][k];
                // }
                //std::cout<<std::endl;
                sentunit->energy[j]=(double*)calloc(sizeof(double),EMOTIONNUM);
                sentunit->hidLay[j]=(double*)calloc(sizeof(double),hidlayerNUM);
                sentunit->kLayer[j]=(double*)calloc(sizeof(double),hidlayerNUM);
                sentunit->outLay[j]=(double*)calloc(sizeof(double),EMOTIONNUM);
                sentunit->DLDo[j]  =(double*)calloc(sizeof(double),EMOTIONNUM);
                sentunit->DLDh[j]  =(double*)calloc(sizeof(double),hidlayerNUM);
                sentunit->DLDx[j]  =(double*)calloc(sizeof(double),featureNUM);
            }

            sentunit->stdAns[i]=1.0;
            sentunit->next=sent;
            sent=sentunit;

            
            line=(char*)calloc(sizeof(char),421);
        }
        fclose(sentfp);

    }

    for(i=0;i<EMOTIONNUM;++i)
        free(filelist[i]);
    //fclose(sentfp);
    free(filelist);
    std::cout<< totnum <<std::endl;
    return sent;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x38, %edi
callq 0x21c0
movq %rax, -0x18(%rbp)
movl $0x1, %edi
movl $0x1a5, %esi            # imm = 0x1A5
callq 0x20b0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, -0x38(%rbp)
movq $0x0, 0x50(%rax)
movq -0x10(%rbp), %rdi
callq 0x2070
movl %eax, -0x28(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x7, -0x1c(%rbp)
jge 0x340d
movl $0x1, %edi
movl $0x65, %esi
callq 0x20b0
movq %rax, %rdx
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rsi
callq 0x2120
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movq (%rcx,%rdx,8), %rdi
movslq -0x28(%rbp), %rcx
addq %rcx, %rdi
movq 0x80(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x2120
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4f4a(%rip), %rsi      # 0x8070
callq 0x2190
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x4f34(%rip), %rsi      # 0x8072
movb $0x0, %al
callq 0x2260
cmpl $-0x1, %eax
je 0x33f6
movq -0x38(%rbp), %rdi
callq 0x73f0
movl %eax, -0x24(%rbp)
movl $0x78, %edi
callq 0x21c0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, -0x40(%rbp)
movq 0x50(%rax), %rdx
movq -0x40(%rbp), %rcx
movq %rdx, (%rcx)
movq 0x50(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x50(%rax)
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq %rdx, 0x8(%rcx)
movl -0x24(%rbp), %edx
movq -0x40(%rbp), %rcx
movl %edx, 0x10(%rcx)
movq -0x38(%rbp), %rdi
movl 0x30(%rax), %esi
movq (%rax), %rdx
callq 0x7450
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movslq -0x24(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movslq -0x24(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
movslq -0x24(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x30(%rax)
movslq -0x24(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x58(%rax)
movslq -0x24(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x60(%rax)
movslq -0x24(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x68(%rax)
movslq -0x24(%rbp), %rdi
shlq $0x3, %rdi
callq 0x21c0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x38(%rax)
movl $0x8, %edi
movl $0x7, %esi
callq 0x20b0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x48(%rax)
movl $0x8, %edi
movl $0x7, %esi
callq 0x20b0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x40(%rax)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x33ad
movl $0x8, %edi
movl $0x7, %esi
callq 0x20b0
movq %rax, %rsi
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x38(%rcx), %rcx
movslq -0x20(%rbp), %rdx
movq %rsi, (%rcx,%rdx,8)
movslq 0x34(%rax), %rsi
movl $0x8, %edi
callq 0x20b0
movq %rax, %rsi
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x20(%rbp), %rdx
movq %rsi, (%rcx,%rdx,8)
movslq 0x34(%rax), %rsi
movl $0x8, %edi
callq 0x20b0
movq %rax, %rdx
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x8, %edi
movl $0x7, %esi
callq 0x20b0
movq %rax, %rdx
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x8, %edi
movl $0x7, %esi
callq 0x20b0
movq %rax, %rsi
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x58(%rcx), %rcx
movslq -0x20(%rbp), %rdx
movq %rsi, (%rcx,%rdx,8)
movslq 0x34(%rax), %rsi
movl $0x8, %edi
callq 0x20b0
movq %rax, %rsi
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x60(%rcx), %rcx
movslq -0x20(%rbp), %rdx
movq %rsi, (%rcx,%rdx,8)
movslq 0x30(%rax), %rsi
movl $0x8, %edi
callq 0x20b0
movq %rax, %rdx
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3299
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x48(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movsd 0x4c43(%rip), %xmm0     # 0x8008
movsd %xmm0, (%rcx,%rdx,8)
movq 0x78(%rax), %rdx
movq -0x40(%rbp), %rcx
movq %rdx, 0x70(%rcx)
movq -0x40(%rbp), %rcx
movq %rcx, 0x78(%rax)
movl $0x1, %edi
movl $0x1a5, %esi            # imm = 0x1A5
callq 0x20b0
movq %rax, -0x38(%rbp)
jmp 0x312f
movq -0x30(%rbp), %rdi
callq 0x2150
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x30ab
movl $0x0, -0x1c(%rbp)
cmpl $0x7, -0x1c(%rbp)
jge 0x3436
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x21a0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3414
movq -0x18(%rbp), %rdi
callq 0x21a0
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rsi
movq 0x7b8a(%rip), %rdi      # 0xafd8
callq 0x2250
movq %rax, %rdi
movq 0x7b63(%rip), %rsi      # 0xafc0
callq 0x2170
movq -0x48(%rbp), %rax
movq 0x78(%rax), %rax
addq $0x50, %rsp
popq %rbp
retq