// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x14d0, %rsp           # imm = 0x14D0
leaq 0x4b0(%rbp), %rsi
movq %rsi, -0xf08(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0xf00(%rbp)
leaq -0x110(%rbp), %rdi
movl $0x110, %edx            # imm = 0x110
callq 0x3280
movq -0xf00(%rbp), %rax
movq 0x390(%rax), %rsi
leaq -0x5b8(%rbp), %rdi
movl $0x4a0, %edx            # imm = 0x4A0
callq 0x3280
movq -0xf00(%rbp), %rax
movq 0x398(%rax), %rsi
leaq -0xa58(%rbp), %rdi
movl $0x4a0, %edx            # imm = 0x4A0
callq 0x3280
movq -0xf00(%rbp), %rax
movq 0x3a0(%rax), %rsi
leaq -0xef8(%rbp), %rdi
movl $0x4a0, %edx            # imm = 0x4A0
callq 0x3280
movq -0xf00(%rbp), %rax
movl 0xc0(%rax), %esi
subl $0x1, %esi
leaq -0x5b8(%rbp), %rdi
callq 0x4afc0
movq -0xf00(%rbp), %rax
movl 0xc0(%rax), %esi
subl $0x1, %esi
leaq -0xa58(%rbp), %rdi
callq 0x4afc0
movq -0xf00(%rbp), %rax
movl 0xc0(%rax), %esi
subl $0x1, %esi
leaq -0xef8(%rbp), %rdi
callq 0x4afc0
movq -0xf00(%rbp), %rax
movl 0xc4(%rax), %edx
imull 0x48(%rax), %edx
imull 0xc0(%rax), %edx
movq 0x1e0(%rax), %rcx
movslq %edx, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movq %rcx, 0x1e0(%rax)
movl 0xc0(%rax), %eax
subl $0x1, %eax
movl %eax, -0x114(%rbp)
cmpl $0x0, -0x114(%rbp)
jl 0x4aebe
movq -0xf00(%rbp), %rax
movl 0xc4(%rax), %edi
imull 0x48(%rax), %edi
movq -0x350(%rbp), %rsi
movq 0x1e0(%rax), %rcx
movl $0x1, %r8d
movl %r8d, %edx
callq 0x2f960
movq -0xf00(%rbp), %rax
movl 0xc4(%rax), %edi
imull 0x48(%rax), %edi
movq -0x7f0(%rbp), %rsi
movq 0x1e0(%rax), %rcx
movss 0x263e6(%rip), %xmm0    # 0x7100c
movl $0x1, %r8d
movl %r8d, %edx
callq 0x2f680
movq -0xf00(%rbp), %rax
movq 0x1e0(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x7f8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq %rsp, %rdi
movq %rdi, -0xf10(%rbp)
movl $0x94, %ecx
leaq -0xef8(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0xf10(%rbp), %rdi
addq $0x4a0, %rdi            # imm = 0x4A0
movl $0x22, %ecx
leaq -0x110(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x7f00
movq -0xf00(%rbp), %rdx
movl 0xc4(%rdx), %ecx
imull 0x48(%rdx), %ecx
movq 0x1e0(%rdx), %rax
movslq %ecx, %rsi
xorl %ecx, %ecx
subq %rsi, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x1e0(%rdx)
movq 0x1e0(%rdx), %rax
movq %rax, -0x38(%rbp)
movq -0x7f8(%rbp), %rax
movl 0xc4(%rdx), %ecx
imull 0x48(%rdx), %ecx
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x114(%rbp)
jne 0x4acfa
movq $0x0, -0x28(%rbp)
movq %rsp, %rdi
movq %rdi, -0xf18(%rbp)
movl $0x94, %ecx
leaq -0xa58(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0xf18(%rbp), %rdi
addq $0x4a0, %rdi            # imm = 0x4A0
movl $0x22, %ecx
leaq -0x110(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x7f00
movq -0xf00(%rbp), %rax
movl 0xc4(%rax), %edi
imull 0x48(%rax), %edi
movq -0x7f8(%rbp), %rsi
movq -0x358(%rbp), %rcx
movl $0x1, %r8d
movl %r8d, %edx
callq 0x2f960
cmpl $0x0, -0x114(%rbp)
jle 0x4adc6
movq -0xf00(%rbp), %rax
cmpl $0x0, 0x44(%rax)
je 0x4adc6
movq -0xf00(%rbp), %rdx
movl 0xc4(%rdx), %edi
imull 0x48(%rdx), %edi
movq -0x7f8(%rbp), %rsi
movq -0x7f8(%rbp), %rcx
movl 0xc4(%rdx), %eax
imull 0x48(%rdx), %eax
movslq %eax, %rdx
xorl %eax, %eax
subq %rdx, %rax
shlq $0x2, %rax
addq %rax, %rcx
movss 0x26254(%rip), %xmm0    # 0x7100c
movl $0x1, %r8d
movl %r8d, %edx
callq 0x2f680
movq -0xf08(%rbp), %rax
movq -0xf00(%rbp), %rsi
movq 0xd8(%rax), %rcx
movl -0x114(%rbp), %edx
imull 0x54(%rsi), %edx
imull 0x48(%rsi), %edx
movslq %edx, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movq %rcx, -0x38(%rbp)
cmpq $0x0, 0xe8(%rax)
je 0x4ae34
movq -0xf00(%rbp), %rdx
movq -0xf08(%rbp), %rax
movq 0xe8(%rax), %rax
movl -0x114(%rbp), %ecx
imull 0x54(%rdx), %ecx
imull 0x48(%rdx), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x4ae3c
movq $0x0, -0x28(%rbp)
movq %rsp, %rdi
movq %rdi, -0xf20(%rbp)
movl $0x94, %ecx
leaq -0x5b8(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0xf20(%rbp), %rdi
addq $0x4a0, %rdi            # imm = 0x4A0
movl $0x22, %ecx
leaq -0x110(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x7f00
leaq -0x5b8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4afc0
leaq -0xa58(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4afc0
leaq -0xef8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x4afc0
movl -0x114(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x4abc5
addq $0x14d0, %rsp           # imm = 0x14D0
popq %rbp
retq
nopw (%rax,%rax)