// File: /workspace/github_cpp_makefile_star2_O2/huiwenliuge[P]EmoAnaer/src/RNNet.cpp
// Function: RNNet::_Backward_CROSSENTROPY(sentence*)
void RNNet::_Backward_CROSSENTROPY(Sentence sen){
    int t,i,j,k;
    t=sen->tlen-1;
    for(i=0;i<EMOTIONNUM;++i)
        sen->DLDo[t][i]=-(sen->stdAns[i]-sen->energy[t][i]);

    for(t=sen->tlen-2;t>-1;--t){
        for(i=0;i<EMOTIONNUM;++i){
            sen->DLDo[t][i]=-(sen->stdAns[i]-sen->energy[t][i]);
            for(k=0;k<EMOTIONNUM;++k){
                for(j=0;j<hidlayerNUM;++j){
                    sen->DLDo[t][i]+=sen->DLDo[t+1][k]\
                            *k2out[k][j]*dsigm(sen->hidLay[t+1][j])\
                            *ro2h[j][i];
                }
            }
        }
    }
    
    t=sen->tlen-1;
    for(i=0;i<hidlayerNUM;++i){
        sen->DLDh[t][i]=0.0;
        for(j=0;j<EMOTIONNUM;++j){
            sen->DLDh[t][i]+=sen->DLDo[t][j]*k2out[j][i]\
                    *dsigm(sen->hidLay[t][i]);
        }
    }
    for(t=sen->tlen-2;t>-1;--t){
        for(i=0;i<hidlayerNUM;++i){
            sen->DLDh[t][i]=0.0;
            for(j=0;j<EMOTIONNUM;++j){
                sen->DLDh[t][i]+=sen->DLDo[t][j]*k2out[j][i]\
                        *dsigm(sen->hidLay[t][i]);
            }
            for(j=0;j<hidlayerNUM;++j){
                sen->DLDh[t][i]+=sen->DLDh[t+1][j]*rh2h[j][i]\
                        *dsigm(sen->hidLay[t+1][i]);
            }
        }
    }
    
    t=sen->tlen-1;
    for(i=0;i<featureNUM;++i){
        sen->DLDx[t][i]=0.0;
        for(j=0;j<hidlayerNUM;++j){
            sen->DLDx[t][i]+=sen->DLDh[t][j]*in2hid[j][i];
        }
    }
    for(t=sen->tlen-2;t>-1;--t){
        for(i=0;i<featureNUM;++i){
            sen->DLDx[t][i]=0.0;
            for(j=0;j<hidlayerNUM;++j){
                sen->DLDx[t][i]+=sen->DLDh[t][j]*in2hid[j][i];
                for(k=0;k<hidlayerNUM;++k){
                    sen->DLDx[t][i]+=sen->DLDh[t+1][j]*rh2h[j][k]\
                        *dsigm(sen->hidLay[t][k])*in2hid[k][i];
                }
            }
            // for(j=0;j<hidlayerNUM;++j){
            //     for(k=0;k<hidlayerNUM;++k){
            //         sen->DLDx[t][i]+=sen->DLDh[t+1][j]*rh2h[j][k]\
            //             *dsigm(sen->hidLay[t][k])*in2hid[k][i];
            //     }
            // }
        }
    }
    
    double plnrt = lnrt/sen->tlen;
    static std::mutex g_mutex;
    g_mutex.lock();
    upgradeDict(ccdict,sen->schar,sen->DLDx,featureNUM,plnrt);    
    g_mutex.unlock();
    double pder;
    for(i=0;i<EMOTIONNUM;++i){
        for(j=0;j<hidlayerNUM;++j){
            pder=0.0;
            for(t=0;t<sen->tlen;++t){
                pder+=sen->DLDo[t][i]*sen->kLayer[t][j];
            }
            pder/=sen->tlen;
            g_mutex.lock();
            DLDk2out[i][j]=pder/sen->tlen;
            g_mutex.unlock();
        }
    }
    
    for(i=0;i<hidlayerNUM;++i){
        for(j=0;j<featureNUM;++j){
            pder=0.0;
            for(t=0;t<sen->tlen;++t){
                pder+=sen->DLDh[t][i]*sen->inVec[t][j];
            }
            pder/=sen->tlen;
            g_mutex.lock();
            DLDin2hid[i][j]+=pder;
            g_mutex.unlock();
        }
    }

    for(i=0;i<hidlayerNUM;++i){
        for(j=0;j<hidlayerNUM;++j){
            pder=0.0;
            for(t=1;t<sen->tlen;++t){
                pder+=sen->DLDh[t][i]*sen->kLayer[t-1][j];
            }
            pder/=sen->tlen;
            g_mutex.lock();
            DLDrh2h[i][j]+=pder;
            g_mutex.unlock();
        }
    }

    for(i=0;i<hidlayerNUM;++i){
        for(j=0;j<EMOTIONNUM;++j){
            pder=0.0;
            for(t=1;t<sen->tlen;++t){
                pder+=sen->DLDh[t][i]*sen->outLay[t-1][j];
            }
            pder/=sen->tlen;
            g_mutex.lock();
            DLDro2h[i][j]+=pder;
            g_mutex.unlock();
        }
    }
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movslq 0x10(%rsi), %rcx
movq 0x38(%rsi), %rax
movq 0x48(%rsi), %rdx
movq -0x8(%rax,%rcx,8), %r9
movq %rsi, -0x30(%rbp)
movq 0x58(%rsi), %rax
movq -0x8(%rax,%rcx,8), %rsi
xorl %r8d, %r8d
cmpq $0x7, %r8
je 0x3917
movsd (%rdx,%r8,8), %xmm0
subsd (%r9,%r8,8), %xmm0
xorpd 0x2704(%rip), %xmm0     # 0x6010
movlpd %xmm0, (%rsi,%r8,8)
incq %r8
jmp 0x38f2
addl $-0x2, %ecx
movq %rdi, -0x40(%rbp)
movq -0x30(%rbp), %r14
testl %ecx, %ecx
js 0x3a06
movl %ecx, %edx
movq %rdx, -0x48(%rbp)
movq %rcx, -0x50(%rbp)
leal 0x1(%rcx), %r13d
xorl %r15d, %r15d
cmpq $0x7, %r15
je 0x39fb
movq -0x30(%rbp), %rdx
movq 0x38(%rdx), %rcx
movq 0x48(%rdx), %rdx
movsd (%rdx,%r15,8), %xmm0
movq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
subsd (%rcx,%r15,8), %xmm0
xorpd 0x26a3(%rip), %xmm0     # 0x6010
movq (%rax,%rdx,8), %rcx
movlpd %xmm0, (%rcx,%r15,8)
xorl %ebx, %ebx
cmpq $0x7, %rbx
je 0x39f3
xorl %r12d, %r12d
movslq 0x34(%rdi), %rcx
cmpq %rcx, %r12
jge 0x39ee
movq (%rax,%r13,8), %rax
movsd (%rax,%rbx,8), %xmm0
movq 0x18(%rdi), %rax
movq (%rax,%rbx,8), %rax
mulsd (%rax,%r12,8), %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x20(%r14), %rax
movq (%rax,%r13,8), %rax
movsd (%rax,%r12,8), %xmm0
callq 0x4794
movq -0x40(%rbp), %rdi
mulsd -0x38(%rbp), %xmm0
movq 0x28(%rdi), %rax
movq (%rax,%r12,8), %rcx
movq 0x58(%r14), %rax
movq -0x48(%rbp), %rdx
movq (%rax,%rdx,8), %rdx
mulsd (%rcx,%r15,8), %xmm0
addsd (%rdx,%r15,8), %xmm0
movsd %xmm0, (%rdx,%r15,8)
incq %r12
jmp 0x3982
incq %rbx
jmp 0x3979
incq %r15
jmp 0x393b
movq -0x50(%rbp), %rcx
decl %ecx
jmp 0x3922
movq -0x30(%rbp), %rax
movslq 0x10(%rax), %rbx
xorl %r15d, %r15d
movq -0x30(%rbp), %r14
movslq 0x34(%rdi), %rax
cmpq %rax, %r15
jge 0x3a9a
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x8(%rax,%rbx,8), %rax
andq $0x0, (%rax,%r15,8)
xorl %r12d, %r12d
cmpq $0x7, %r12
je 0x3a92
movq 0x20(%r14), %rax
movq 0x58(%r14), %rcx
movq -0x8(%rcx,%rbx,8), %rcx
movsd (%rcx,%r12,8), %xmm0
movq 0x18(%rdi), %rcx
movq (%rcx,%r12,8), %rcx
mulsd (%rcx,%r15,8), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rax,%rbx,8), %rax
movsd (%rax,%r15,8), %xmm0
callq 0x4794
movq -0x40(%rbp), %rdi
movq 0x60(%r14), %rax
movq -0x8(%rax,%rbx,8), %rax
mulsd -0x38(%rbp), %xmm0
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %r12
jmp 0x3a33
incq %r15
jmp 0x3a15
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
addl $-0x2, %ecx
testl %ecx, %ecx
js 0x3bab
movl %ecx, %r12d
movq %rcx, -0x48(%rbp)
leal 0x1(%rcx), %r13d
xorl %r15d, %r15d
movslq %eax, %rcx
cmpq %rcx, %r15
jge 0x3ba0
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rcx
movq (%rcx,%r12,8), %rax
andq $0x0, (%rax,%r15,8)
xorl %ebx, %ebx
cmpq $0x7, %rbx
je 0x3b38
movq -0x30(%rbp), %r14
movq 0x20(%r14), %rax
movq 0x58(%r14), %rcx
movq (%rcx,%r12,8), %rcx
movsd (%rcx,%rbx,8), %xmm0
movq 0x18(%rdi), %rcx
movq (%rcx,%rbx,8), %rcx
mulsd (%rcx,%r15,8), %xmm0
movsd %xmm0, -0x38(%rbp)
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm0
callq 0x4794
movq -0x40(%rbp), %rdi
movq 0x60(%r14), %rcx
movq (%rcx,%r12,8), %rax
mulsd -0x38(%rbp), %xmm0
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %rbx
jmp 0x3ad9
xorl %ebx, %ebx
movslq 0x34(%rdi), %rax
cmpq %rax, %rbx
jge 0x3b98
movq (%rcx,%r13,8), %rax
movsd (%rax,%rbx,8), %xmm0
movq 0x20(%rdi), %rax
movq (%rax,%rbx,8), %rax
mulsd (%rax,%r15,8), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x30(%rbp), %r14
movq 0x20(%r14), %rax
movq (%rax,%r13,8), %rax
movsd (%rax,%r15,8), %xmm0
callq 0x4794
movq -0x40(%rbp), %rdi
movq 0x60(%r14), %rcx
movq (%rcx,%r12,8), %rax
mulsd -0x38(%rbp), %xmm0
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %rbx
jmp 0x3b3a
incq %r15
jmp 0x3aba
movq -0x48(%rbp), %rcx
decl %ecx
jmp 0x3aa4
movq -0x30(%rbp), %rcx
movslq 0x10(%rcx), %r14
movl 0x30(%rdi), %ecx
xorl %edx, %edx
testl %eax, %eax
movl $0x0, %esi
cmovgl %eax, %esi
testl %ecx, %ecx
movl $0x0, %ebx
cmovgl %ecx, %ebx
cmpq %rbx, %rdx
je 0x3c28
movq -0x30(%rbp), %r8
movq 0x68(%r8), %r8
movq -0x8(%r8,%r14,8), %r8
andq $0x0, (%r8,%rdx,8)
movq 0x10(%rdi), %r9
xorpd %xmm0, %xmm0
xorl %r10d, %r10d
cmpq %r10, %rsi
je 0x3c1f
movq -0x30(%rbp), %r11
movq 0x60(%r11), %r11
movq -0x8(%r11,%r14,8), %r11
movsd (%r11,%r10,8), %xmm1
movq (%r9,%r10,8), %r11
mulsd (%r11,%rdx,8), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%r8,%rdx,8)
incq %r10
jmp 0x3bee
incq %rdx
movq -0x40(%rbp), %rdi
jmp 0x3bcc
addl $-0x2, %r14d
testl %r14d, %r14d
js 0x3d2e
movq %r14, -0x48(%rbp)
movl %r14d, %r12d
xorl %r13d, %r13d
movslq %ecx, %rdx
cmpq %rdx, %r13
jge 0x3d22
movq -0x30(%rbp), %rcx
movq 0x68(%rcx), %rcx
movq (%rcx,%r12,8), %rdx
andq $0x0, (%rdx,%r13,8)
xorl %r15d, %r15d
movslq %eax, %rdx
cmpq %rdx, %r15
jge 0x3d17
movq -0x30(%rbp), %rdx
movq 0x60(%rdx), %rdx
movq (%rdx,%r12,8), %rdx
movsd (%rdx,%r15,8), %xmm0
movq 0x10(%rdi), %rdx
movq (%rdx,%r15,8), %rdx
movq (%rcx,%r12,8), %rsi
mulsd (%rdx,%r13,8), %xmm0
addsd (%rsi,%r13,8), %xmm0
movsd %xmm0, (%rsi,%r13,8)
xorl %ebx, %ebx
movslq %eax, %rdx
cmpq %rdx, %rbx
jge 0x3d0f
movq -0x30(%rbp), %r14
movq 0x20(%r14), %rax
movq 0x60(%r14), %rcx
movq 0x8(%rcx,%r12,8), %rcx
movsd (%rcx,%r15,8), %xmm0
movq 0x20(%rdi), %rcx
movq (%rcx,%r15,8), %rcx
mulsd (%rcx,%rbx,8), %xmm0
movsd %xmm0, -0x38(%rbp)
movq (%rax,%r12,8), %rax
movsd (%rax,%rbx,8), %xmm0
callq 0x4794
movq -0x40(%rbp), %rdi
mulsd -0x38(%rbp), %xmm0
movq 0x10(%rdi), %rax
movq (%rax,%rbx,8), %rax
movq 0x68(%r14), %rcx
movq (%rcx,%r12,8), %rdx
mulsd (%rax,%r13,8), %xmm0
addsd (%rdx,%r13,8), %xmm0
movsd %xmm0, (%rdx,%r13,8)
incq %rbx
movl 0x34(%rdi), %eax
jmp 0x3c9d
incq %r15
jmp 0x3c5f
incq %r13
movl 0x30(%rdi), %ecx
jmp 0x3c3f
movq -0x48(%rbp), %r14
decl %r14d
jmp 0x3c2c
movsd 0x40(%rdi), %xmm1
movq -0x30(%rbp), %rbx
cvtsi2sdl 0x10(%rbx), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
leaq 0x5414(%rip), %r15      # 0x9160
movq %r15, %rdi
callq 0x47d8
movq -0x40(%rbp), %rax
movq (%rax), %rdi
movq 0x8(%rbx), %rsi
movq 0x68(%rbx), %rdx
movq -0x40(%rbp), %rax
movl 0x30(%rax), %ecx
movsd -0x38(%rbp), %xmm0
callq 0x5148
movq %r15, %rdi
callq 0x20e0
movq -0x40(%rbp), %rcx
xorl %r12d, %r12d
cmpq $0x7, %r12
je 0x3e37
xorl %r13d, %r13d
movslq 0x34(%rcx), %rax
cmpq %rax, %r13
jge 0x3e2f
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
xorpd %xmm1, %xmm1
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x3de2
movq -0x30(%rbp), %rdi
movq 0x28(%rdi), %rsi
movq 0x58(%rdi), %rdi
movq (%rdi,%rdx,8), %rdi
movsd (%rdi,%r12,8), %xmm0
movq (%rsi,%rdx,8), %rsi
mulsd (%rsi,%r13,8), %xmm0
addsd %xmm0, %xmm1
incq %rdx
jmp 0x3db4
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
movq %r15, %rdi
callq 0x47d8
movq -0x30(%rbp), %rax
cvtsi2sdl 0x10(%rax), %xmm0
movsd -0x38(%rbp), %xmm1
divsd %xmm0, %xmm1
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rax
movq (%rax,%r12,8), %rax
movsd %xmm1, (%rax,%r13,8)
movq %r15, %rdi
callq 0x20e0
movq -0x40(%rbp), %rcx
incq %r13
jmp 0x3d90
incq %r12
jmp 0x3d83
xorl %r12d, %r12d
leaq 0x531f(%rip), %r15      # 0x9160
movslq 0x34(%rcx), %rax
cmpq %rax, %r12
jge 0x3ef1
xorl %r13d, %r13d
movslq 0x30(%rcx), %rax
cmpq %rax, %r13
jge 0x3ee9
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
xorpd %xmm1, %xmm1
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x3ea3
movq -0x30(%rbp), %rdi
movq 0x18(%rdi), %rsi
movq 0x60(%rdi), %rdi
movq (%rdi,%rdx,8), %rdi
movsd (%rdi,%r12,8), %xmm0
movq (%rsi,%rdx,8), %rsi
mulsd (%rsi,%r13,8), %xmm0
addsd %xmm0, %xmm1
incq %rdx
jmp 0x3e75
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
movq %r15, %rdi
callq 0x47d8
movq -0x40(%rbp), %rax
movq 0x58(%rax), %rax
movq (%rax,%r12,8), %rax
movsd -0x38(%rbp), %xmm0
addsd (%rax,%r13,8), %xmm0
movsd %xmm0, (%rax,%r13,8)
movq %r15, %rdi
callq 0x20e0
movq -0x40(%rbp), %rcx
incq %r13
jmp 0x3e51
incq %r12
jmp 0x3e41
xorl %r12d, %r12d
pushq $0x1
popq %rbx
leaq 0x5262(%rip), %r15      # 0x9160
movslq %eax, %rcx
cmpq %rcx, %r12
jge 0x3fa8
xorl %r13d, %r13d
movslq %eax, %rcx
cmpq %rcx, %r13
jge 0x3fa0
movq -0x30(%rbp), %rax
movslq 0x10(%rax), %rax
xorpd %xmm1, %xmm1
movq %rbx, %rcx
cmpq %rax, %rcx
jge 0x3f57
movq -0x30(%rbp), %rsi
movq 0x28(%rsi), %rdx
movq 0x60(%rsi), %rsi
movq (%rsi,%rcx,8), %rsi
movsd (%rsi,%r12,8), %xmm0
movq -0x8(%rdx,%rcx,8), %rdx
mulsd (%rdx,%r13,8), %xmm0
addsd %xmm0, %xmm1
incq %rcx
jmp 0x3f28
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
movq %r15, %rdi
callq 0x47d8
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movq (%rax,%r12,8), %rax
movsd -0x38(%rbp), %xmm0
addsd (%rax,%r13,8), %xmm0
movsd %xmm0, (%rax,%r13,8)
movq %r15, %rdi
callq 0x20e0
incq %r13
movq -0x40(%rbp), %rax
movl 0x34(%rax), %eax
jmp 0x3f0d
incq %r12
jmp 0x3efe
xorl %r12d, %r12d
pushq $0x1
popq %r13
leaq 0x51aa(%rip), %r15      # 0x9160
cltq
cmpq %rax, %r12
jge 0x4052
xorl %ebx, %ebx
cmpq $0x7, %rbx
je 0x4043
movq -0x30(%rbp), %rax
movslq 0x10(%rax), %rax
xorpd %xmm1, %xmm1
movq %r13, %rcx
cmpq %rax, %rcx
jge 0x4006
movq -0x30(%rbp), %rsi
movq 0x30(%rsi), %rdx
movq 0x60(%rsi), %rsi
movq (%rsi,%rcx,8), %rsi
movsd (%rsi,%r12,8), %xmm0
movq -0x8(%rdx,%rcx,8), %rdx
mulsd (%rdx,%rbx,8), %xmm0
addsd %xmm0, %xmm1
incq %rcx
jmp 0x3fd8
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
movq %r15, %rdi
callq 0x47d8
movq -0x40(%rbp), %rax
movq 0x70(%rax), %rax
movq (%rax,%r12,8), %rax
movsd -0x38(%rbp), %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
movq %r15, %rdi
callq 0x20e0
incq %rbx
jmp 0x3fc3
incq %r12
movq -0x40(%rbp), %rax
movl 0x34(%rax), %eax
jmp 0x3fb6
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop