// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/normalization_layer.c
// Function: forward_normalization_layer
void forward_normalization_layer(const layer layer, network net)
{
    int k,b;
    int w = layer.w;
    int h = layer.h;
    int c = layer.c;
    scal_cpu(w*h*c*layer.batch, 0, layer.squared, 1);

    for(b = 0; b < layer.batch; ++b){
        float *squared = layer.squared + w*h*c*b;
        float *norms   = layer.norms + w*h*c*b;
        float *input   = net.input + w*h*c*b;
        pow_cpu(w*h*c, 2, input, 1, squared, 1);

        const_cpu(w*h, layer.kappa, norms, 1);
        for(k = 0; k < layer.size/2; ++k){
            axpy_cpu(w*h, layer.alpha, squared + w*h*k, 1, norms, 1);
        }

        for(k = 1; k < layer.c; ++k){
            copy_cpu(w*h, norms + w*h*(k-1), 1, norms + w*h*k, 1);
            int prev = k - ((layer.size-1)/2) - 1;
            int next = k + (layer.size/2);
            if(prev >= 0)      axpy_cpu(w*h, -layer.alpha, squared + w*h*prev, 1, norms + w*h*k, 1);
            if(next < layer.c) axpy_cpu(w*h,  layer.alpha, squared + w*h*next, 1, norms + w*h*k, 1);
        }
    }
    pow_cpu(w*h*c*layer.batch, -layer.beta, layer.norms, 1, layer.output, 1);
    mul_cpu(w*h*c*layer.batch, net.input, 1, layer.output, 1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
leaq 0xf0(%rsp), %r14
movl 0x48(%r14), %r15d
movl 0x6c(%r14), %ebx
movslq 0x74(%r14), %rax
imull 0x70(%r14), %ebx
movslq %ebx, %rbp
movq %rbp, %r12
movq %rax, 0x38(%rsp)
imulq %rax, %r12
movl %r12d, %edi
imull %r15d, %edi
movq 0x278(%r14), %r13
pushq $0x1
popq %rdx
xorps %xmm0, %xmm0
movl %edi, 0xc(%rsp)
movq %r13, %rsi
callq 0x1b423
movq 0x280(%r14), %r8
movq 0x668(%rsp), %rax
movq %rax, 0x20(%rsp)
movss 0x13c(%r14), %xmm0
movss %xmm0, 0x14(%rsp)
movl 0x90(%r14), %ecx
pushq $0x2
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
movl %eax, %esi
movss 0x134(%r14), %xmm0
decl %ecx
pushq $-0x2
popq %rdi
movl %ecx, %eax
cltd
idivl %edi
movaps 0x20158(%rip), %xmm1    # 0x4c150
movaps %xmm0, 0x90(%rsp)
xorps %xmm0, %xmm1
movaps %xmm1, 0xa0(%rsp)
xorl %ecx, %ecx
testl %esi, %esi
movl $0x0, %edx
cmovgl %esi, %edx
movq %rdx, 0x48(%rsp)
movslq %esi, %rdx
testl %r15d, %r15d
cmovlel %ecx, %r15d
movq %r15, 0x60(%rsp)
movq %r12, 0x58(%rsp)
leaq (,%r12,4), %rsi
movq %rsi, 0x40(%rsp)
movq %rax, 0x88(%rsp)
imull %ebx, %eax
movl %eax, 0x10(%rsp)
movq %rdx, 0x80(%rsp)
leaq 0x1(%rdx), %rax
imulq %rbp, %rax
shlq $0x2, %rbp
movq %rbp, (%rsp)
leaq (,%rax,4), %rax
addq %r13, %rax
movq %rax, 0x30(%rsp)
movq %r8, 0x18(%rsp)
movq %r8, 0x28(%rsp)
movq %r13, 0x50(%rsp)
movq %r13, %r12
pushq $0x1
popq %rbp
cmpq 0x60(%rsp), %rcx
je 0x2c1ed
movq %rcx, 0x70(%rsp)
movq %rcx, %rax
movq 0x58(%rsp), %rdi
imulq %rdi, %rax
movq 0x50(%rsp), %rcx
leaq (%rcx,%rax,4), %r8
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %r15
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
movss 0x20194(%rip), %xmm0    # 0x4c25c
pushq $0x1
popq %r13
movl %r13d, %edx
movq %r8, 0x78(%rsp)
movq %r8, %rcx
movl %r13d, %r8d
callq 0x1b385
movl %ebx, %edi
movss 0x14(%rsp), %xmm0
movq %r15, %rsi
movl %r13d, %edx
callq 0x1b335
movq %r12, 0x68(%rsp)
movq 0x48(%rsp), %r14
subq $0x1, %r14
jb 0x2c123
movl %ebx, %edi
movaps 0x90(%rsp), %xmm0
movq %r12, %rsi
movl %r13d, %edx
movq %r15, %rcx
movl %r13d, %r8d
callq 0x1b3ed
addq (%rsp), %r12
jmp 0x2c0fc
movq 0x30(%rsp), %r12
movq 0x28(%rsp), %rsi
movl 0x10(%rsp), %r13d
pushq $0x1
popq %r14
cmpq 0x38(%rsp), %r14
jge 0x2c1c9
movq (%rsp), %rax
leaq (%rsi,%rax), %r15
movl %ebx, %edi
movl %ebp, %edx
movq %r15, %rcx
movl %ebp, %r8d
callq 0x1b5a3
movq 0x88(%rsp), %rax
addl %r14d, %eax
testl %eax, %eax
jle 0x2c18a
movslq %r13d, %rax
movq 0x78(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
movl %ebx, %edi
movaps 0xa0(%rsp), %xmm0
movl %ebp, %edx
movq %r15, %rcx
movl %ebp, %r8d
callq 0x1b3ed
movq 0x80(%rsp), %rax
addq %r14, %rax
cmpq 0x38(%rsp), %rax
jge 0x2c1b7
movl %ebx, %edi
movaps 0x90(%rsp), %xmm0
movq %r12, %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
movl %edx, %r8d
callq 0x1b3ed
incq %r14
addl %ebx, %r13d
addq (%rsp), %r12
movq %r15, %rsi
jmp 0x2c136
movq 0x70(%rsp), %rcx
incq %rcx
movq 0x40(%rsp), %rax
movq 0x68(%rsp), %r12
addq %rax, %r12
addq %rax, 0x28(%rsp)
addq %rax, 0x30(%rsp)
jmp 0x2c089
leaq 0xf0(%rsp), %rax
movss 0x138(%rax), %xmm0
xorps 0x1ff4c(%rip), %xmm0    # 0x4c150
movq 0x268(%rax), %rbx
pushq $0x1
popq %rbp
movl 0xc(%rsp), %r14d
movl %r14d, %edi
movq 0x18(%rsp), %rsi
movl %ebp, %edx
movq %rbx, %rcx
movl %ebp, %r8d
callq 0x1b385
movl %r14d, %edi
movq 0x20(%rsp), %rsi
movl %ebp, %edx
movq %rbx, %rcx
movl %ebp, %r8d
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1b353