// File: /workspace/github_c_makefile_star2_O3/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 $0xa8, %rsp
movl 0xe4(%rsp), %edx
movl 0x158(%rsp), %ebp
imull 0x15c(%rsp), %ebp
movq 0x348(%rsp), %rdi
movslq 0x138(%rsp), %r14
movslq 0x128(%rsp), %rbx
movl %ebx, %esi
imull %r14d, %esi
movq 0x340(%rsp), %r15
movq %r15, %rcx
callq 0x28ee8
movq %rbx, 0x28(%rsp)
testq %rbx, %rbx
jle 0x3a631
leaq 0xe0(%rsp), %r12
movq 0x238(%r12), %rbx
leaq (,%r14,4), %rax
movq 0x28(%rsp), %r13
movq %r15, 0x20(%rsp)
movq %rax, 0x50(%rsp)
movl %r14d, %edi
movss 0x1acf2(%rip), %xmm0    # 0x55008
movq %r15, %rsi
movl $0x1, %edx
movq %rbx, %rcx
movl $0x1, %r8d
callq 0x29d31
movq 0x50(%rsp), %rax
addq %rax, %r15
decq %r13
jne 0x3a30b
cmpl $0x0, 0x28(%rsp)
movq 0x20(%rsp), %rbx
jle 0x3a631
movq %rbp, %r13
leaq 0x580(%rsp), %rdi
movq 0xd8(%rdi), %rax
movq %rax, 0x80(%rsp)
movq 0xe8(%rdi), %rax
movq %rax, 0x30(%rsp)
movl 0x6c(%r12), %r15d
movl 0x70(%r12), %ecx
movl %ecx, 0x18(%rsp)
imull %r15d, %ecx
movl 0x74(%r12), %edx
imull %edx, %ecx
movl %ecx, 0x44(%rsp)
movl 0x90(%r12), %ecx
movl 0x98(%r12), %esi
movl %esi, 0xc(%rsp)
movl 0xa8(%r12), %esi
movq %rsi, 0x48(%rsp)
movq 0xf0(%rdi), %rbp
movl %ecx, 0x10(%rsp)
movl %ecx, %r14d
imull %r14d, %r14d
movq 0x258(%r12), %rcx
movq %rcx, 0xa0(%rsp)
movl 0x84(%r12), %ecx
movl %edx, 0x14(%rsp)
imull %edx, %r14d
movq 0x250(%r12), %rdx
movq %rdx, 0x58(%rsp)
movl %r14d, %eax
movl %ecx, 0x40(%rsp)
imull %ecx, %eax
movl %eax, 0x3c(%rsp)
movl %r13d, %eax
movq %rax, 0x78(%rsp)
leaq (,%rax,4), %rax
movq %rax, 0x98(%rsp)
xorl %ecx, %ecx
movl %r15d, 0x1c(%rsp)
movq %rbp, 0x60(%rsp)
movq %r13, 0x70(%rsp)
movq %r14, 0x68(%rsp)
movl 0x44(%rsp), %eax
movq %rcx, 0x90(%rsp)
imull %ecx, %eax
movslq %eax, %rcx
movq 0x80(%rsp), %rax
movq %rcx, 0x88(%rsp)
leaq (%rax,%rcx,4), %rdi
movl 0x14(%rsp), %esi
movl %r15d, %edx
movl 0x18(%rsp), %ecx
movl 0x10(%rsp), %r8d
movl 0xc(%rsp), %r9d
pushq %rbp
pushq 0x50(%rsp)
callq 0x28f73
addq $0x10, %rsp
testl %r13d, %r13d
jle 0x3a5a7
xorl %r15d, %r15d
movq 0x78(%rsp), %r13
movq %rbx, 0x20(%rsp)
movq %rbp, %r12
movl 0x40(%rsp), %edx
movl 0x3c(%rsp), %eax
movss 0x1ab6d(%rip), %xmm0    # 0x55008
movslq %r15d, %r15
movl %eax, %ebp
movq 0xa0(%rsp), %rax
leaq (%rax,%r15,4), %rax
subq $0x8, %rsp
xorl %edi, %edi
movl $0x1, %esi
movq 0x70(%rsp), %rcx
movl %edx, %r14d
movl $0x1, %r8d
movq %rbx, %r9
movaps %xmm0, %xmm1
pushq %rcx
pushq %rax
movq 0x88(%rsp), %rax
pushq %rax
pushq %r12
pushq %rax
callq 0xe50d
movss 0x1ab22(%rip), %xmm0    # 0x55008
movl %ebp, %eax
movl %r14d, %edx
addq $0x30, %rsp
addl %ebp, %r15d
addq $0x4, %r12
addq $0x4, %rbx
decq %r13
jne 0x3a49b
cmpq $0x0, 0x30(%rsp)
movq 0x20(%rsp), %r12
movq 0x60(%rsp), %r10
movq 0x70(%rsp), %r11
movq 0x68(%rsp), %r8
movq 0x58(%rsp), %rax
je 0x3a605
testl %r11d, %r11d
jle 0x3a5bb
xorl %ebx, %ebx
xorl %r15d, %r15d
movslq %r15d, %r15
leaq (%rax,%r15,4), %r9
leaq (%r12,%rbx), %rax
addq %rbx, %r10
subq $0x8, %rsp
xorps %xmm1, %xmm1
movl $0x1, %edi
xorl %esi, %esi
movl %r8d, %edx
movl $0x1, %ecx
movq %r8, %r13
movl %r14d, %r8d
pushq %r11
pushq %r10
pushq %r11
pushq %rax
pushq %r13
movq %r11, %r12
callq 0xe50d
movq 0xc8(%rsp), %rcx
movq %r13, %r8
movq %r12, %r11
movq 0x90(%rsp), %r10
movq 0x50(%rsp), %r12
movss 0x1aa78(%rip), %xmm0    # 0x55008
addq $0x30, %rsp
addl %ebp, %r15d
movq 0x58(%rsp), %rax
addq $0x4, %rbx
cmpq %rbx, %rcx
jne 0x3a532
jmp 0x3a5bb
cmpq $0x0, 0x30(%rsp)
movq %r13, %r11
movq %rbx, %r12
movq %r14, %r8
movq %rbp, %r10
je 0x3a605
movq 0x30(%rsp), %rax
movq 0x88(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
movq %r10, %rbx
movq %r10, %rdi
movl 0x14(%rsp), %esi
movl 0x1c(%rsp), %edx
movl 0x18(%rsp), %ecx
movq %r8, %r15
movl 0x10(%rsp), %r8d
movl 0xc(%rsp), %r9d
pushq %rax
pushq 0x50(%rsp)
movq %r11, %r14
callq 0x29125
movq %r15, %r8
movq %r14, %r11
movq %rbx, %r10
addq $0x10, %rsp
movq 0x90(%rsp), %rcx
incq %rcx
addq 0x50(%rsp), %r12
cmpq 0x28(%rsp), %rcx
movq %r10, %rbp
movq %r12, %rbx
movq %r11, %r13
movl 0x1c(%rsp), %r15d
movq %r8, %r14
jne 0x3a429
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq