// File: /workspace/github_c_makefile_star2_O0/SimpleDoger[P]Darknet_CPU_Only/local_layer.c
// Function: make_local_layer
local_layer make_local_layer(int batch, int h, int w, int c, int n, int size, int stride, int pad, ACTIVATION activation)
{
    int i;
    local_layer l = {0};
    l.type = LOCAL;

    l.h = h;
    l.w = w;
    l.c = c;
    l.n = n;
    l.batch = batch;
    l.stride = stride;
    l.size = size;
    l.pad = pad;

    int out_h = local_out_height(l);
    int out_w = local_out_width(l);
    int locations = out_h*out_w;
    l.out_h = out_h;
    l.out_w = out_w;
    l.out_c = n;
    l.outputs = l.out_h * l.out_w * l.out_c;
    l.inputs = l.w * l.h * l.c;

    l.weights = calloc(c*n*size*size*locations, sizeof(float));
    l.weight_updates = calloc(c*n*size*size*locations, sizeof(float));

    l.biases = calloc(l.outputs, sizeof(float));
    l.bias_updates = calloc(l.outputs, sizeof(float));

    // float scale = 1./sqrt(size*size*c);
    float scale = sqrt(2./(size*size*c));
    for(i = 0; i < c*n*size*size; ++i) l.weights[i] = scale*rand_uniform(-1,1);

    l.output = calloc(l.batch*out_h * out_w * n, sizeof(float));
    l.delta  = calloc(l.batch*out_h * out_w * n, sizeof(float));

    l.workspace_size = out_h*out_w*size*size*c;
    
    l.forward = forward_local_layer;
    l.backward = backward_local_layer;
    l.update = update_local_layer;

    l.activation = activation;

    fprintf(stderr, "Local Layer: %d x %d x %d image, %d filters -> %d x %d x %d image\n", h,w,c,n, out_h, out_w, n);

    return l;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4e0, %rsp            # imm = 0x4E0
movq %rdi, -0x30(%rbp)
movq %rdi, %rax
movq %rax, -0x38(%rbp)
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movl %esi, -0x4(%rbp)
movl %edx, -0x8(%rbp)
movl %ecx, -0xc(%rbp)
movl %r8d, -0x10(%rbp)
movl %r9d, -0x14(%rbp)
xorl %esi, %esi
movl $0x4a0, %edx            # imm = 0x4A0
callq 0x3190
movq -0x30(%rbp), %rsi
movl $0xc, (%rsi)
movl -0x8(%rbp), %eax
movl %eax, 0x6c(%rsi)
movl -0xc(%rbp), %eax
movl %eax, 0x70(%rsi)
movl -0x10(%rbp), %eax
movl %eax, 0x74(%rsi)
movl -0x14(%rbp), %eax
movl %eax, 0x84(%rsi)
movl -0x4(%rbp), %eax
movl %eax, 0x48(%rsi)
movl 0x18(%rbp), %eax
movl %eax, 0x98(%rsi)
movl 0x10(%rbp), %eax
movl %eax, 0x90(%rsi)
movl 0x20(%rbp), %eax
movl %eax, 0xa8(%rsi)
movq %rsp, %rdi
movl $0x94, %ecx
rep  movsq (%rsi), %es:(%rdi)
callq 0x473f0
movq -0x30(%rbp), %rsi
movl %eax, -0x1c(%rbp)
movq %rsp, %rdi
movl $0x94, %ecx
rep  movsq (%rsi), %es:(%rdi)
callq 0x47440
movq -0x30(%rbp), %rdi
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, 0x78(%rdi)
movl -0x20(%rbp), %eax
movl %eax, 0x7c(%rdi)
movl -0x14(%rbp), %eax
movl %eax, 0x80(%rdi)
movl 0x78(%rdi), %eax
imull 0x7c(%rdi), %eax
imull 0x80(%rdi), %eax
movl %eax, 0x58(%rdi)
movl 0x70(%rdi), %eax
imull 0x6c(%rdi), %eax
imull 0x74(%rdi), %eax
movl %eax, 0x54(%rdi)
movl -0x10(%rbp), %eax
imull -0x14(%rbp), %eax
imull 0x10(%rbp), %eax
imull 0x10(%rbp), %eax
imull -0x24(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x30(%rbp), %rdi
movq %rax, 0x250(%rdi)
movl -0x10(%rbp), %eax
imull -0x14(%rbp), %eax
imull 0x10(%rbp), %eax
imull 0x10(%rbp), %eax
imull -0x24(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x30(%rbp), %rdi
movq %rax, 0x258(%rdi)
movslq 0x58(%rdi), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x30(%rbp), %rdi
movq %rax, 0x230(%rdi)
movslq 0x58(%rdi), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x30(%rbp), %rdi
movq %rax, 0x238(%rdi)
movl 0x10(%rbp), %eax
imull 0x10(%rbp), %eax
imull -0x10(%rbp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x29a38(%rip), %xmm0    # 0x71058
divsd %xmm1, %xmm0
callq 0x3430
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x28(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl -0x10(%rbp), %ecx
imull -0x14(%rbp), %ecx
imull 0x10(%rbp), %ecx
imull 0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x47699
movss -0x28(%rbp), %xmm0
movss %xmm0, -0x3c(%rbp)
movss 0x2ca7b(%rip), %xmm0    # 0x740dc
movss 0x299a3(%rip), %xmm1    # 0x7100c
callq 0x5b30
movq -0x30(%rbp), %rax
movaps %xmm0, %xmm1
movss -0x3c(%rbp), %xmm0
mulss %xmm1, %xmm0
movq 0x250(%rax), %rax
movslq -0x18(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x47639
movq -0x30(%rbp), %rax
movl 0x48(%rax), %eax
imull -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
imull -0x14(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x268(%rax)
movl 0x48(%rax), %eax
imull -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
imull -0x14(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x260(%rax)
movl -0x1c(%rbp), %ecx
imull -0x20(%rbp), %ecx
imull 0x10(%rbp), %ecx
imull 0x10(%rbp), %ecx
imull -0x10(%rbp), %ecx
movslq %ecx, %rcx
movq %rcx, 0x498(%rax)
leaq 0x6b(%rip), %rcx        # 0x47780
movq %rcx, 0x10(%rax)
leaq 0x2d0(%rip), %rcx       # 0x479f0
movq %rcx, 0x18(%rax)
leaq 0x6a5(%rip), %rcx       # 0x47dd0
movq %rcx, 0x20(%rax)
movl 0x28(%rbp), %ecx
movl %ecx, 0x4(%rax)
movq 0x3b8bc(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
movl -0x8(%rbp), %edx
movl -0xc(%rbp), %ecx
movl -0x10(%rbp), %r8d
movl -0x14(%rbp), %r9d
movl -0x1c(%rbp), %r11d
movl -0x20(%rbp), %r10d
movl -0x14(%rbp), %eax
leaq 0x2dc03(%rip), %rsi     # 0x75362
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x3240
movq -0x38(%rbp), %rax
addq $0x4e0, %rsp            # imm = 0x4E0
popq %rbp
retq