// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/crnn_layer.c
// Function: backward_crnn_layer
void backward_crnn_layer(layer l, network net)
{
    network s = net;
    int i;
    layer input_layer = *(l.input_layer);
    layer self_layer = *(l.self_layer);
    layer output_layer = *(l.output_layer);

    increment_layer(&input_layer, l.steps-1);
    increment_layer(&self_layer, l.steps-1);
    increment_layer(&output_layer, l.steps-1);

    l.state += l.hidden*l.batch*l.steps;
    for (i = l.steps-1; i >= 0; --i) {
        copy_cpu(l.hidden * l.batch, input_layer.output, 1, l.state, 1);
        axpy_cpu(l.hidden * l.batch, 1, self_layer.output, 1, l.state, 1);

        s.input = l.state;
        s.delta = self_layer.delta;
        backward_convolutional_layer(output_layer, s);

        l.state -= l.hidden*l.batch;
        /*
           if(i > 0){
           copy_cpu(l.hidden * l.batch, input_layer.output - l.hidden*l.batch, 1, l.state, 1);
           axpy_cpu(l.hidden * l.batch, 1, self_layer.output - l.hidden*l.batch, 1, l.state, 1);
           }else{
           fill_cpu(l.hidden * l.batch, 0, l.state, 1);
           }
         */

        s.input = l.state;
        s.delta = self_layer.delta - l.hidden*l.batch;
        if (i == 0) s.delta = 0;
        backward_convolutional_layer(self_layer, s);

        copy_cpu(l.hidden*l.batch, self_layer.delta, 1, input_layer.delta, 1);
        if (i > 0 && l.shortcut) axpy_cpu(l.hidden*l.batch, 1, self_layer.delta, 1, self_layer.delta - l.hidden*l.batch, 1);
        s.input = net.input + i*l.inputs*l.batch;
        if(net.delta) s.delta = net.delta + i*l.inputs*l.batch;
        else s.delta = 0;
        backward_convolutional_layer(input_layer, s);

        increment_layer(&input_layer, -1);
        increment_layer(&self_layer, -1);
        increment_layer(&output_layer, -1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x14e8, %rsp           # imm = 0x14E8
leaq 0x19c0(%rsp), %r12
leaq 0x5f8(%rsp), %rdi
movl $0x110, %edx            # imm = 0x110
movq %r12, %rsi
callq 0x32b0
movq 0x18b0(%rsp), %rsi
leaq 0xba8(%rsp), %r15
movl $0x4a0, %edx            # imm = 0x4A0
movq %r15, %rdi
callq 0x32b0
movq 0x18b8(%rsp), %rsi
leaq 0x708(%rsp), %r14
movl $0x4a0, %edx            # imm = 0x4A0
movq %r14, %rdi
callq 0x32b0
movq 0x18c0(%rsp), %rsi
leaq 0x1048(%rsp), %rbx
movl $0x4a0, %edx            # imm = 0x4A0
movq %rbx, %rdi
callq 0x32b0
movslq 0x15e0(%rsp), %rax
leal -0x1(%rax), %ecx
movl 0x58(%r15), %edx
imull %ecx, %edx
imull 0x48(%r15), %edx
movslq %edx, %rdx
shlq $0x2, %rdx
movq 0x268(%r15), %rsi
addq %rdx, %rsi
movq %rsi, 0x268(%r15)
addq %rdx, 0x260(%r15)
addq %rdx, 0x2c0(%r15)
addq %rdx, 0x2c8(%r15)
movl 0x58(%r14), %edx
imull %ecx, %edx
imull 0x48(%r14), %edx
movslq %edx, %rdx
shlq $0x2, %rdx
movq 0x268(%r14), %r15
addq %rdx, %r15
movq %r15, 0x268(%r14)
movq 0x260(%r14), %r13
addq %rdx, %r13
movq %r13, 0x260(%r14)
addq %rdx, 0x2c0(%r14)
addq %rdx, 0x2c8(%r14)
imull 0x58(%rbx), %ecx
imull 0x48(%rbx), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, 0x268(%rbx)
addq %rcx, 0x260(%rbx)
addq %rcx, 0x2c0(%rbx)
addq %rcx, 0x2c8(%rbx)
testq %rax, %rax
jle 0x3c53b
leaq 0x1520(%rsp), %rcx
movl 0x48(%rcx), %edi
movl 0xc4(%rcx), %r8d
imull %edi, %r8d
movl %r8d, %edx
imull %eax, %edx
movslq %edx, %rdx
shlq $0x2, %rdx
addq 0x1e0(%rcx), %rdx
movq %rdx, 0x5c0(%rsp)
movl %r8d, 0x5b4(%rsp)
movslq %r8d, %rdx
movq %rdx, %r8
negq %r8
movl 0x44(%rcx), %r9d
movl %r9d, 0x5b8(%rsp)
movq 0xd8(%r12), %r9
movq %r9, 0x5e0(%rsp)
movq 0xe8(%r12), %r9
movq %r9, 0x5d8(%rsp)
imull 0x54(%rcx), %edi
movq %rax, %rbp
incq %rbp
leal -0x1(%rax), %r12d
movl %edi, 0x5bc(%rsp)
imull %edi, %r12d
shlq $0x2, %rdx
negq %rdx
movq %rdx, 0x5e8(%rsp)
leaq 0x5f8(%rsp), %rbx
movq %r8, 0x5c8(%rsp)
leaq (,%r8,4), %rax
movq %rax, 0x5d0(%rsp)
movl 0x5b4(%rsp), %r14d
movq %rbp, 0x5f0(%rsp)
movl %r14d, %edi
movl $0x1, %edx
movq 0x5c0(%rsp), %rbp
movq %rbp, %rcx
movl $0x1, %r8d
callq 0x29fe0
movl %r14d, %edi
movss 0x18d2a(%rip), %xmm0    # 0x55008
movq %r15, %rsi
movl $0x1, %edx
movq %rbp, %rcx
movl $0x1, %r8d
callq 0x29d31
movq %rbp, 0x6d0(%rsp)
movq %r13, 0x6e0(%rsp)
movl $0x94, %ecx
movq %rsp, %rdi
leaq 0x1048(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x4a0(%rsp), %rdi
movl $0x22, %ecx
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x10c2a
addq 0x5e8(%rsp), %rbp
movq %rbp, 0x5c0(%rsp)
movq %rbp, 0x6d0(%rsp)
movq 0x5f0(%rsp), %rbp
movq 0x968(%rsp), %rax
addq 0x5d0(%rsp), %rax
cmpq $0x2, %rbp
movl $0x0, %ecx
cmoveq %rcx, %rax
movq %rax, 0x6e0(%rsp)
movl $0x94, %ecx
movq %rsp, %rdi
leaq 0x708(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x4a0(%rsp), %rdi
movl $0x22, %ecx
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x10c2a
movq 0x968(%rsp), %r15
movq 0xe08(%rsp), %rcx
movl %r14d, %edi
movq %r15, %rsi
movl $0x1, %edx
movl $0x1, %r8d
callq 0x29fe0
cmpq $0x2, %rbp
je 0x3c403
cmpl $0x0, 0x5b8(%rsp)
je 0x3c403
movq 0x5c8(%rsp), %rax
leaq (%r15,%rax,4), %rcx
movl 0x5b4(%rsp), %edi
movss 0x18c18(%rip), %xmm0    # 0x55008
movq %r15, %rsi
movl $0x1, %edx
movl $0x1, %r8d
callq 0x29d31
movq 0x5d8(%rsp), %rcx
testq %rcx, %rcx
movslq %r12d, %r12
movq 0x5e0(%rsp), %rax
leaq (%rax,%r12,4), %rax
movq %rax, 0x6d0(%rsp)
leaq (%rcx,%r12,4), %rax
cmoveq %rcx, %rax
movq %rax, 0x6e0(%rsp)
movl $0x94, %ecx
movq %rsp, %rdi
leaq 0xba8(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x4a0(%rsp), %rdi
movl $0x22, %ecx
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x10c2a
movl 0xc00(%rsp), %eax
imull 0xbf0(%rsp), %eax
negl %eax
cltq
shlq $0x2, %rax
movq 0xe10(%rsp), %rsi
addq %rax, %rsi
movq %rsi, 0xe10(%rsp)
addq %rax, 0xe08(%rsp)
addq %rax, 0xe68(%rsp)
addq %rax, 0xe70(%rsp)
movl 0x760(%rsp), %eax
imull 0x750(%rsp), %eax
negl %eax
cltq
shlq $0x2, %rax
movq 0x970(%rsp), %r15
addq %rax, %r15
movq %r15, 0x970(%rsp)
movq 0x968(%rsp), %r13
addq %rax, %r13
movq %r13, 0x968(%rsp)
addq %rax, 0x9c8(%rsp)
addq %rax, 0x9d0(%rsp)
movl 0x10a0(%rsp), %eax
imull 0x1090(%rsp), %eax
negl %eax
cltq
shlq $0x2, %rax
addq %rax, 0x12b0(%rsp)
addq %rax, 0x12a8(%rsp)
addq %rax, 0x1308(%rsp)
addq %rax, 0x1310(%rsp)
decq %rbp
subl 0x5bc(%rsp), %r12d
cmpq $0x1, %rbp
ja 0x3c2ad
addq $0x14e8, %rsp           # imm = 0x14E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq