// File: /workspace/github_c_makefile_star2_O2/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 0x5f8(%rsp), %rdi
leaq 0x19c0(%rsp), %r12
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), %r13
movl $0x4a0, %edx            # imm = 0x4A0
movq %r13, %rdi
callq 0x32b0
movq 0x18c0(%rsp), %rsi
leaq 0x1048(%rsp), %r14
movl $0x4a0, %edx            # imm = 0x4A0
movq %r14, %rdi
callq 0x32b0
movslq 0x15e0(%rsp), %rbx
leal -0x1(%rbx), %r8d
movl 0x58(%r15), %eax
imull %r8d, %eax
imull 0x48(%r15), %eax
cltq
shlq $0x2, %rax
movq 0x268(%r15), %rsi
addq %rax, %rsi
movq %rsi, 0x268(%r15)
addq %rax, 0x260(%r15)
addq %rax, 0x2c0(%r15)
addq %rax, 0x2c8(%r15)
movl 0x58(%r13), %eax
imull %r8d, %eax
imull 0x48(%r13), %eax
cltq
shlq $0x2, %rax
movq 0x268(%r13), %r15
addq %rax, %r15
movq %r15, 0x268(%r13)
movq 0x260(%r13), %rbp
addq %rax, %rbp
movq %rbp, 0x260(%r13)
addq %rax, 0x2c0(%r13)
addq %rax, 0x2c8(%r13)
movl 0x58(%r14), %eax
imull %r8d, %eax
imull 0x48(%r14), %eax
cltq
shlq $0x2, %rax
addq %rax, 0x268(%r14)
addq %rax, 0x260(%r14)
addq %rax, 0x2c0(%r14)
addq %rax, 0x2c8(%r14)
movl 0x1568(%rsp), %ecx
movl 0x15e4(%rsp), %edx
imull %ecx, %edx
movl %edx, %eax
imull %ebx, %eax
cltq
shlq $0x2, %rax
addq 0x1700(%rsp), %rax
movq %rax, 0x5c0(%rsp)
movl 0x1564(%rsp), %eax
movl %eax, 0x5b8(%rsp)
movl %edx, 0x5b4(%rsp)
movslq %edx, %rax
movq %rax, %rdx
negq %rdx
movq 0xd8(%r12), %rdi
movq %rdi, 0x5e8(%rsp)
movq 0xe8(%r12), %rdi
movq %rdi, 0x5e0(%rsp)
imull 0x1574(%rsp), %ecx
movl %ecx, 0x5bc(%rsp)
imull %ecx, %r8d
shlq $0x2, %rax
negq %rax
movq %rax, 0x5f0(%rsp)
movq %rdx, 0x5d0(%rsp)
leaq (,%rdx,4), %rax
movq %rax, 0x5d8(%rsp)
movl 0x5b4(%rsp), %r14d
testq %rbx, %rbx
jle 0x2f9b7
movl %r14d, %edi
movq %r8, %r13
movq %rbx, 0x5c8(%rsp)
pushq $0x1
popq %rbx
movl %ebx, %edx
movq 0x5c0(%rsp), %r12
movq %r12, %rcx
movl %ebx, %r8d
callq 0x1b5a3
movl %r14d, %edi
movss 0x1c8aa(%rip), %xmm0    # 0x4c008
movq %r15, %rsi
movl %ebx, %edx
movq %r12, %rcx
movl %ebx, %r8d
callq 0x1b3ed
movq %r12, 0x6d0(%rsp)
movq %rbp, 0x6e0(%rsp)
movl $0x94, %ecx
movq %rsp, %rdi
leaq 0x1048(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x4a0(%rsp), %rdi
pushq $0x22
popq %rbp
movq %rbp, %rcx
leaq 0x5f8(%rsp), %r15
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x6600
addq 0x5f0(%rsp), %r12
movq %r12, 0x5c0(%rsp)
movq %r12, 0x6d0(%rsp)
movq 0x968(%rsp), %rax
addq 0x5d8(%rsp), %rax
cmpq $0x1, 0x5c8(%rsp)
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
movq %rbp, %rcx
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x6600
movq 0x968(%rsp), %r15
movq 0xe08(%rsp), %rcx
movl %r14d, %edi
movq %r15, %rsi
movl %ebx, %edx
movl %ebx, %r8d
movq 0x5c8(%rsp), %rbx
callq 0x1b5a3
cmpq $0x1, %rbx
je 0x2f87e
cmpl $0x0, 0x5b8(%rsp)
je 0x2f87e
movq 0x5d0(%rsp), %rax
leaq (%r15,%rax,4), %rcx
movl 0x5b4(%rsp), %edi
movss 0x1c798(%rip), %xmm0    # 0x4c008
movq %r15, %rsi
pushq $0x1
popq %rdx
movl %edx, %r8d
callq 0x1b3ed
movq 0x5e0(%rsp), %rcx
testq %rcx, %rcx
movslq %r13d, %r13
movq 0x5e8(%rsp), %rax
leaq (%rax,%r13,4), %rax
movq %rax, 0x6d0(%rsp)
leaq (%rcx,%r13,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
pushq $0x22
popq %rcx
leaq 0x5f8(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x6600
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), %rbp
addq %rax, %rbp
movq %rbp, 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)
subl 0x5bc(%rsp), %r13d
decq %rbx
movq %r13, %r8
jmp 0x2f724
addq $0x14e8, %rsp           # imm = 0x14E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq