// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/deconvolutional_layer.c
// Function: backward_deconvolutional_layer
void backward_deconvolutional_layer(layer l, network net)
{
    int i;

    gradient_array(l.output, l.outputs*l.batch, l.activation, l.delta);

    if(l.batch_normalize){
        backward_batchnorm_layer(l, net);
    } else {
        backward_bias(l.bias_updates, l.delta, l.batch, l.n, l.out_w*l.out_h);
    }

    //if(net.delta) memset(net.delta, 0, l.batch*l.h*l.w*l.c*sizeof(float));

    for(i = 0; i < l.batch; ++i){
        int m = l.c;
        int n = l.size*l.size*l.n;
        int k = l.h*l.w;

        float *a = net.input + i*m*k;
        float *b = net.workspace;
        float *c = l.weight_updates;

        im2col_cpu(l.delta + i*l.outputs, l.out_c, l.out_h, l.out_w, 
                l.size, l.stride, l.pad, b);
        gemm_cpu(0,1,m,n,k,1,a,k,b,k,1,c,n);

        if(net.delta){
            int m = l.c;
            int n = l.h*l.w;
            int k = l.size*l.size*l.n;

            float *a = l.weights;
            float *b = net.workspace;
            float *c = net.delta + i*n*m;

            gemm_cpu(0,0,m,n,k,1,a,k,b,n,1,c,n);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x4f0(%rsp), %rbx
leaq 0x50(%rsp), %r14
movq 0x268(%r14), %rdi
movl 0x4(%r14), %edx
movl 0x48(%r14), %ebp
movl 0x58(%r14), %esi
imull %ebp, %esi
movq 0x260(%r14), %r15
movq %r15, %rcx
callq 0x1a748
cmpl $0x0, 0x40(%r14)
je 0x5659
subq $0x5b0, %rsp            # imm = 0x5B0
movl $0x94, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x4a0(%rsp), %rdi
pushq $0x22
popq %rcx
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x2fe3b
addq $0x5b0, %rsp            # imm = 0x5B0
jmp 0x567a
movq 0x238(%r14), %rdi
movl 0x78(%r14), %r8d
movl 0x84(%r14), %ecx
imull 0x7c(%r14), %r8d
movq %r15, %rsi
movl %ebp, %edx
callq 0x6dbf
xorl %r13d, %r13d
cmpl 0x48(%r14), %r13d
jge 0x57ca
movl 0x70(%r14), %r15d
movl 0x74(%r14), %eax
movl %eax, 0xc(%rsp)
movl 0x90(%r14), %r8d
movl %r8d, %r12d
imull %r12d, %r12d
imull 0x84(%r14), %r12d
imull 0x6c(%r14), %r15d
imull %r13d, %eax
imull %r15d, %eax
movslq %eax, %rbp
shlq $0x2, %rbp
addq 0xd8(%rbx), %rbp
leaq 0x4f0(%rsp), %rax
movq 0xf0(%rax), %rbx
movq 0x258(%r14), %rax
movq %rax, 0x10(%rsp)
movslq 0x58(%r14), %rax
movslq %r13d, %rdi
imulq %rax, %rdi
shlq $0x2, %rdi
addq 0x260(%r14), %rdi
movl 0x80(%r14), %esi
movl 0x78(%r14), %edx
movl 0x7c(%r14), %ecx
movl 0x98(%r14), %r9d
movl 0xa8(%r14), %eax
pushq %rbx
pushq %rax
callq 0x1a7d7
popq %rax
popq %rcx
subq $0x8, %rsp
xorl %edi, %edi
pushq $0x1
popq %rsi
movl 0x14(%rsp), %edx
movl %r12d, %ecx
movl %r15d, %r8d
movss 0x468d2(%rip), %xmm0    # 0x4c008
movq %rbp, %r9
movaps %xmm0, %xmm1
pushq %r12
pushq 0x20(%rsp)
pushq %r15
pushq %rbx
leaq 0x518(%rsp), %rbx
pushq %r15
callq 0x3831
addq $0x30, %rsp
movq 0xe8(%rbx), %rax
testq %rax, %rax
je 0x57c2
movl 0x70(%r14), %ecx
movl 0x74(%r14), %edx
imull 0x6c(%r14), %ecx
movl 0x90(%r14), %r8d
imull %r8d, %r8d
imull 0x84(%r14), %r8d
movq 0x250(%r14), %r9
movl %edx, %esi
imull %r13d, %esi
imull %ecx, %esi
movslq %esi, %rsi
leaq (%rax,%rsi,4), %rax
subq $0x8, %rsp
xorl %edi, %edi
xorl %esi, %esi
movss 0x4685d(%rip), %xmm0    # 0x4c008
movaps %xmm0, %xmm1
pushq %rcx
pushq %rax
pushq %rcx
pushq 0xf0(%rbx)
pushq %r8
callq 0x3831
addq $0x30, %rsp
incl %r13d
jmp 0x567d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq