// File: /workspace/github_c_makefile_star2_O1/SimpleDoger[P]Darknet_CPU_Only/local_layer.c
// Function: backward_local_layer
void backward_local_layer(local_layer l, network net)
{
    int i, j;
    int locations = l.out_w*l.out_h;

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

    for(i = 0; i < l.batch; ++i){
        axpy_cpu(l.outputs, 1, l.delta + i*l.outputs, 1, l.bias_updates, 1);
    }

    for(i = 0; i < l.batch; ++i){
        float *input = net.input + i*l.w*l.h*l.c;
        im2col_cpu(input, l.c, l.h, l.w, 
                l.size, l.stride, l.pad, net.workspace);

        for(j = 0; j < locations; ++j){ 
            float *a = l.delta + i*l.outputs + j;
            float *b = net.workspace + j;
            float *c = l.weight_updates + j*l.size*l.size*l.c*l.n;
            int m = l.n;
            int n = l.size*l.size*l.c;
            int k = 1;

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

        if(net.delta){
            for(j = 0; j < locations; ++j){ 
                float *a = l.weights + j*l.size*l.size*l.c*l.n;
                float *b = l.delta + i*l.outputs + j;
                float *c = net.workspace + j;

                int m = l.size*l.size*l.c;
                int n = 1;
                int k = l.n;

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

            col2im_cpu(net.workspace, l.c,  l.h,  l.w,  l.size,  l.stride, l.pad, net.delta+i*l.c*l.h*l.w);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
leaq 0xc0(%rsp), %rbx
movl 0x4(%rbx), %edx
movl 0x78(%rbx), %eax
imull 0x7c(%rbx), %eax
movq %rax, 0x30(%rsp)
movq 0x268(%rbx), %rdi
movslq 0x58(%rbx), %r12
movslq 0x48(%rbx), %r14
movl %r14d, %esi
imull %r12d, %esi
movq 0x260(%rbx), %rcx
movq %rcx, 0x20(%rsp)
callq 0x27834
movq %r14, 0x28(%rsp)
testq %r14, %r14
jle 0x38137
movq 0x238(%rbx), %r14
leaq (,%r12,4), %r13
movq 0x28(%rsp), %rbp
movq 0x20(%rsp), %r15
movl %r12d, %edi
movss 0x1aeef(%rip), %xmm0    # 0x53008
movq %r15, %rsi
movl $0x1, %edx
movq %r14, %rcx
movl $0x1, %r8d
callq 0x285e9
addq %r13, %r15
decq %rbp
jne 0x3810e
cmpl $0x0, 0x28(%rsp)
jle 0x38389
leaq 0x560(%rsp), %rax
movq 0xd8(%rax), %rcx
movq %rcx, 0x60(%rsp)
movq 0xe8(%rax), %rcx
movq %rcx, 0x48(%rsp)
movl 0x6c(%rbx), %ecx
movl 0x70(%rbx), %edx
movl %edx, 0x10(%rsp)
movl %ecx, 0x14(%rsp)
imull %ecx, %edx
movl 0x74(%rbx), %ecx
imull %ecx, %edx
movl %edx, 0xc(%rsp)
movl 0x90(%rbx), %edx
movl 0x98(%rbx), %esi
movl %esi, (%rsp)
movl 0xa8(%rbx), %esi
movq %rsi, 0x40(%rsp)
movq 0xf0(%rax), %rax
movq %rax, 0x38(%rsp)
movl %edx, 0x4(%rsp)
movl %edx, %ebp
imull %ebp, %ebp
movq 0x258(%rbx), %rax
movl 0x84(%rbx), %r8d
movl %ecx, 0x8(%rsp)
imull %ecx, %ebp
movq 0x250(%rbx), %rcx
movl %ebp, %edx
imull %r8d, %edx
shlq $0x2, %r12
movl 0x30(%rsp), %esi
movq %rsi, 0x58(%rsp)
leaq (,%rsi,4), %rsi
xorl %edi, %edi
movq %r12, 0x68(%rsp)
movq %rax, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movl %r8d, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movl 0xc(%rsp), %eax
movq %rdi, 0x50(%rsp)
imull %edi, %eax
cltq
movq 0x60(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
movl 0x8(%rsp), %esi
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ecx
movl 0x4(%rsp), %r8d
movl (%rsp), %r9d
pushq 0x38(%rsp)
pushq 0x48(%rsp)
callq 0x278bf
addq $0x10, %rsp
movq 0x30(%rsp), %rbx
testl %ebx, %ebx
jle 0x382b2
xorl %r15d, %r15d
movq 0x58(%rsp), %r13
movq 0x20(%rsp), %r14
movq 0x38(%rsp), %r12
movslq %r15d, %r15
movq 0x80(%rsp), %rax
leaq (%rax,%r15,4), %rax
subq $0x8, %rsp
xorl %edi, %edi
movl $0x1, %esi
movl 0x24(%rsp), %edx
movl %ebp, %ecx
movl $0x1, %r8d
movss 0x1ad7d(%rip), %xmm0    # 0x53008
movq %r14, %r9
movaps %xmm0, %xmm1
pushq %rbp
pushq %rax
pushq %rbx
pushq %r12
pushq %rbx
callq 0xdd4d
addq $0x30, %rsp
addl 0x18(%rsp), %r15d
addq $0x4, %r12
addq $0x4, %r14
decq %r13
jne 0x3825d
cmpq $0x0, 0x48(%rsp)
movq 0x20(%rsp), %r13
je 0x38369
movq 0x30(%rsp), %rax
testl %eax, %eax
movq 0x38(%rsp), %r12
jle 0x3832f
movq %rax, %rbx
xorl %r14d, %r14d
xorl %r15d, %r15d
movslq %r15d, %r15
movq 0x78(%rsp), %rax
leaq (%rax,%r15,4), %r9
leaq (%r14,%r13), %rax
leaq (%r12,%r14), %r10
subq $0x8, %rsp
xorps %xmm1, %xmm1
movl $0x1, %edi
xorl %esi, %esi
movl %ebp, %edx
movl $0x1, %ecx
movl 0x24(%rsp), %r8d
movss 0x1acf8(%rip), %xmm0    # 0x53008
pushq %rbx
pushq %r10
pushq %rbx
pushq %rax
pushq %rbp
callq 0xdd4d
addq $0x30, %rsp
addl 0x18(%rsp), %r15d
addq $0x4, %r14
cmpq %r14, 0x70(%rsp)
jne 0x382da
movl 0xc(%rsp), %eax
imull 0x50(%rsp), %eax
cltq
movq 0x48(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %r12, %rdi
movl 0x8(%rsp), %esi
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ecx
movl 0x4(%rsp), %r8d
movl (%rsp), %r9d
pushq %rax
pushq 0x48(%rsp)
callq 0x27a81
addq $0x10, %rsp
movq 0x50(%rsp), %rdi
incq %rdi
movq 0x68(%rsp), %r12
addq %r12, %r13
movq %r13, 0x20(%rsp)
cmpq 0x28(%rsp), %rdi
jne 0x38205
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq