// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/batchnorm_layer.c
// Function: make_batchnorm_layer
layer make_batchnorm_layer(int batch, int w, int h, int c)
{
    fprintf(stderr, "Batch Normalization Layer: %d x %d x %d image\n", w,h,c);
    layer l = {0};
    l.type = BATCHNORM;
    l.batch = batch;
    l.h = l.out_h = h;
    l.w = l.out_w = w;
    l.c = l.out_c = c;
    l.output = calloc(h * w * c * batch, sizeof(float));
    l.delta  = calloc(h * w * c * batch, sizeof(float));
    l.inputs = w*h*c;
    l.outputs = l.inputs;

    l.scales = calloc(c, sizeof(float));
    l.scale_updates = calloc(c, sizeof(float));
    l.biases = calloc(c, sizeof(float));
    l.bias_updates = calloc(c, sizeof(float));
    int i;
    for(i = 0; i < c; ++i){
        l.scales[i] = 1;
    }

    l.mean = calloc(c, sizeof(float));
    l.variance = calloc(c, sizeof(float));

    l.rolling_mean = calloc(c, sizeof(float));
    l.rolling_variance = calloc(c, sizeof(float));

    l.forward = forward_batchnorm_layer;
    l.backward = backward_batchnorm_layer;
    return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %r14d
movl %ecx, %ebp
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %rbx
movq 0x63e0c(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
leaq 0x51b72(%rip), %rsi     # 0x59d68
xorl %eax, %eax
callq 0x3270
movl $0x4a0, %edx            # imm = 0x4A0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31c0
movl $0x13, (%rbx)
movl %r15d, 0x48(%rbx)
movl %ebp, 0x78(%rbx)
movl %ebp, 0x6c(%rbx)
movl %r12d, 0x7c(%rbx)
movl %r12d, 0x70(%rbx)
movl %r14d, 0x80(%rbx)
movl %r14d, 0x74(%rbx)
imull %r12d, %ebp
imull %r14d, %ebp
imull %ebp, %r15d
movslq %r15d, %r15
pushq $0x4
popq %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x3250
movq %rax, 0x268(%rbx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x3250
movq %rax, 0x260(%rbx)
movl %ebp, 0x54(%rbx)
movl %ebp, 0x58(%rbx)
movslq %r14d, %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x3250
movq %rax, %r12
movq %rax, 0x240(%rbx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x3250
movq %rax, 0x248(%rbx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x3250
movq %rax, 0x230(%rbx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x3250
movq %rax, 0x238(%rbx)
testl %r15d, %r15d
jle 0x83c4
movl %r14d, %eax
addl $0x3, %r14d
decq %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %r14d
shlq $0x4, %r14
movdqa 0x4ce89(%rip), %xmm1    # 0x55170
movdqa 0x4cd91(%rip), %xmm2    # 0x55080
xorl %eax, %eax
movdqa 0x4cd97(%rip), %xmm3    # 0x55090
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x4ce77(%rip), %xmm5    # 0x55180
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %ecx
notl %ecx
testb $0x1, %cl
je 0x8345
movl $0x3f800000, (%r12,%rax) # imm = 0x3F800000
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x835c
movl $0x3f800000, 0x4(%r12,%rax) # imm = 0x3F800000
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %ecx
testb $0x1, %cl
je 0x839c
movl $0x3f800000, 0x8(%r12,%rax) # imm = 0x3F800000
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x83af
movl $0x3f800000, 0xc(%r12,%rax) # imm = 0x3F800000
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rax
cmpq %rax, %r14
jne 0x8309
pushq $0x4
popq %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x290(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x298(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x2b0(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x2b8(%rbx)
leaq 0x34219(%rip), %rax     # 0x3c630
movq %rax, 0x10(%rbx)
leaq 0x34420(%rip), %rax     # 0x3c842
movq %rax, 0x18(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq