// File: /workspace/github_c_makefile_star2_O0/SimpleDoger[P]Darknet_CPU_Only/convolutional_layer.c
// Function: make_convolutional_layer
convolutional_layer make_convolutional_layer(int batch, int h, int w, int c, int n, int groups, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int binary, int xnor, int adam)
{
    int i;
    convolutional_layer l = {0};
    l.type = CONVOLUTIONAL;

    l.groups = groups;
    l.h = h;
    l.w = w;
    l.c = c;
    l.n = n;
    l.binary = binary;
    l.xnor = xnor;
    l.batch = batch;
    l.stride = stride;
    l.size = size;
    l.pad = padding;
    l.batch_normalize = batch_normalize;

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

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

    l.nweights = c/groups*n*size*size;
    l.nbiases = n;

    // float scale = 1./sqrt(size*size*c);
    float scale = sqrt(2./(size*size*c/l.groups));
    //printf("convscale %f\n", scale);
    //scale = .02;
    //for(i = 0; i < c*n*size*size; ++i) l.weights[i] = scale*rand_uniform(-1, 1);
    for(i = 0; i < l.nweights; ++i) l.weights[i] = scale*rand_normal();
    int out_w = convolutional_out_width(l);
    int out_h = convolutional_out_height(l);
    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.output = calloc(l.batch*l.outputs, sizeof(float));
    l.delta  = calloc(l.batch*l.outputs, sizeof(float));

    l.forward = forward_convolutional_layer;
    l.backward = backward_convolutional_layer;
    l.update = update_convolutional_layer;
    if(binary){
        l.binary_weights = calloc(l.nweights, sizeof(float));
        l.cweights = calloc(l.nweights, sizeof(char));
        l.scales = calloc(n, sizeof(float));
    }
    if(xnor){
        l.binary_weights = calloc(l.nweights, sizeof(float));
        l.binary_input = calloc(l.inputs*l.batch, sizeof(float));
    }

    if(batch_normalize){
        l.scales = calloc(n, sizeof(float));
        l.scale_updates = calloc(n, sizeof(float));
        for(i = 0; i < n; ++i){
            l.scales[i] = 1;
        }

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

        l.mean_delta = calloc(n, sizeof(float));
        l.variance_delta = calloc(n, sizeof(float));

        l.rolling_mean = calloc(n, sizeof(float));
        l.rolling_variance = calloc(n, sizeof(float));
        l.x = calloc(l.batch*l.outputs, sizeof(float));
        l.x_norm = calloc(l.batch*l.outputs, sizeof(float));
    }
    if(adam){
        l.m = calloc(l.nweights, sizeof(float));
        l.v = calloc(l.nweights, sizeof(float));
        l.bias_m = calloc(n, sizeof(float));
        l.scale_m = calloc(n, sizeof(float));
        l.bias_v = calloc(n, sizeof(float));
        l.scale_v = calloc(n, sizeof(float));
    }

    l.workspace_size = get_workspace_size(l);
    l.activation = activation;

    fprintf(stderr, "conv  %5d %2d x%2d /%2d  %4d x%4d x%4d   ->  %4d x%4d x%4d  %5.3f BFLOPs\n", n, size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c, (2.0 * l.n * l.size*l.size*l.c/l.groups * l.out_h*l.out_w)/1000000000.);

    return l;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x4e8, %rsp            # imm = 0x4E8
movq %rdi, -0x48(%rbp)
movq %rdi, %rax
movq %rax, -0x50(%rbp)
movl 0x50(%rbp), %eax
movl 0x48(%rbp), %eax
movl 0x40(%rbp), %eax
movl 0x38(%rbp), %eax
movl 0x30(%rbp), %eax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movl %esi, -0x1c(%rbp)
movl %edx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
xorl %esi, %esi
movl $0x4a0, %edx            # imm = 0x4A0
callq 0x3190
movq -0x48(%rbp), %rdi
movl $0x0, (%rdi)
movl 0x10(%rbp), %eax
movl %eax, 0x8c(%rdi)
movl -0x20(%rbp), %eax
movl %eax, 0x6c(%rdi)
movl -0x24(%rbp), %eax
movl %eax, 0x70(%rdi)
movl -0x28(%rbp), %eax
movl %eax, 0x74(%rdi)
movl -0x2c(%rbp), %eax
movl %eax, 0x84(%rdi)
movl 0x40(%rbp), %eax
movl %eax, 0xb8(%rdi)
movl 0x48(%rbp), %eax
movl %eax, 0xbc(%rdi)
movl -0x1c(%rbp), %eax
movl %eax, 0x48(%rdi)
movl 0x20(%rbp), %eax
movl %eax, 0x98(%rdi)
movl 0x18(%rbp), %eax
movl %eax, 0x90(%rdi)
movl 0x28(%rbp), %eax
movl %eax, 0xa8(%rdi)
movl 0x38(%rbp), %eax
movl %eax, 0x40(%rdi)
movl -0x28(%rbp), %eax
cltd
idivl 0x10(%rbp)
imull -0x2c(%rbp), %eax
imull 0x18(%rbp), %eax
imull 0x18(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x48(%rbp), %rdi
movq %rax, 0x250(%rdi)
movl -0x28(%rbp), %eax
cltd
idivl 0x10(%rbp)
imull -0x2c(%rbp), %eax
imull 0x18(%rbp), %eax
imull 0x18(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x48(%rbp), %rdi
movq %rax, 0x258(%rdi)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x48(%rbp), %rdi
movq %rax, 0x230(%rdi)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x48(%rbp), %rdi
movq %rax, 0x238(%rdi)
movl -0x28(%rbp), %eax
cltd
idivl 0x10(%rbp)
imull -0x2c(%rbp), %eax
imull 0x18(%rbp), %eax
imull 0x18(%rbp), %eax
movl %eax, 0x5c(%rdi)
movl -0x2c(%rbp), %eax
movl %eax, 0x60(%rdi)
movl 0x18(%rbp), %eax
imull 0x18(%rbp), %eax
imull -0x28(%rbp), %eax
cltd
idivl 0x8c(%rdi)
cvtsi2sd %eax, %xmm1
movsd 0x6997c(%rip), %xmm0    # 0x71058
divsd %xmm1, %xmm0
callq 0x3430
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x48(%rbp), %rcx
movl -0x30(%rbp), %eax
cmpl 0x5c(%rcx), %eax
jge 0x773d
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movb $0x0, %al
callq 0x5d50
movq -0x48(%rbp), %rax
movaps %xmm0, %xmm1
movss -0x54(%rbp), %xmm0
mulss %xmm1, %xmm0
movq 0x250(%rax), %rax
movslq -0x30(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x76f5
movq -0x48(%rbp), %rsi
movq %rsp, %rdi
movl $0x94, %ecx
rep  movsq (%rsi), %es:(%rdi)
callq 0x74b0
movq -0x48(%rbp), %rsi
movl %eax, -0x38(%rbp)
movq %rsp, %rdi
movl $0x94, %ecx
rep  movsq (%rsi), %es:(%rdi)
callq 0x7480
movq -0x48(%rbp), %rcx
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, 0x78(%rcx)
movl -0x38(%rbp), %eax
movl %eax, 0x7c(%rcx)
movl -0x2c(%rbp), %eax
movl %eax, 0x80(%rcx)
movl 0x78(%rcx), %eax
imull 0x7c(%rcx), %eax
imull 0x80(%rcx), %eax
movl %eax, 0x58(%rcx)
movl 0x70(%rcx), %eax
imull 0x6c(%rcx), %eax
imull 0x74(%rcx), %eax
movl %eax, 0x54(%rcx)
movl 0x48(%rcx), %eax
imull 0x58(%rcx), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x48(%rbp), %rcx
movq %rax, 0x268(%rcx)
movl 0x48(%rcx), %eax
imull 0x58(%rcx), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x260(%rax)
leaq 0x3c5(%rip), %rcx       # 0x7bb0
movq %rcx, 0x10(%rax)
leaq 0x70a(%rip), %rcx       # 0x7f00
movq %rcx, 0x18(%rax)
leaq 0xaff(%rip), %rcx       # 0x8300
movq %rcx, 0x20(%rax)
cmpl $0x0, 0x40(%rbp)
je 0x7863
movq -0x48(%rbp), %rax
movslq 0x5c(%rax), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x228(%rax)
movslq 0x5c(%rax), %rdi
movl $0x1, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x198(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x240(%rax)
cmpl $0x0, 0x48(%rbp)
je 0x78a8
movq -0x48(%rbp), %rax
movslq 0x5c(%rax), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x48(%rbp), %rcx
movq %rax, 0x228(%rcx)
movl 0x54(%rcx), %eax
imull 0x48(%rcx), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x388(%rax)
cmpl $0x0, 0x38(%rbp)
je 0x7a06
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x240(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x248(%rax)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x7920
movq -0x48(%rbp), %rax
movq 0x240(%rax), %rax
movslq -0x30(%rbp), %rcx
movss 0x696fc(%rip), %xmm0    # 0x7100c
movss %xmm0, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x78f1
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x290(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x298(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2a0(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2a8(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2b0(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x48(%rbp), %rcx
movq %rax, 0x2b8(%rcx)
movl 0x48(%rcx), %eax
imull 0x58(%rcx), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x48(%rbp), %rcx
movq %rax, 0x2c0(%rcx)
movl 0x48(%rcx), %eax
imull 0x58(%rcx), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2c8(%rax)
cmpl $0x0, 0x50(%rbp)
je 0x7abc
movq -0x48(%rbp), %rax
movslq 0x5c(%rax), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2d0(%rax)
movslq 0x5c(%rax), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2d8(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2e0(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2f0(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2e8(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x2f8(%rax)
movq -0x48(%rbp), %rsi
movq %rsp, %rdi
movl $0x94, %ecx
rep  movsq (%rsi), %es:(%rdi)
callq 0x8490
movq -0x48(%rbp), %rsi
movq %rax, 0x498(%rsi)
movl 0x30(%rbp), %eax
movl %eax, 0x4(%rsi)
movq 0x7b510(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
movl -0x2c(%rbp), %edx
movl 0x18(%rbp), %ecx
movl 0x18(%rbp), %r8d
movl 0x20(%rbp), %r9d
movl -0x24(%rbp), %r15d
movl -0x20(%rbp), %r14d
movl -0x28(%rbp), %ebx
movl 0x7c(%rsi), %r11d
movl 0x78(%rsi), %r10d
movl 0x80(%rsi), %eax
cvtsi2sdl 0x84(%rsi), %xmm1
movsd 0x69536(%rip), %xmm0    # 0x71058
mulsd %xmm1, %xmm0
cvtsi2sdl 0x90(%rsi), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl 0x90(%rsi), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl 0x74(%rsi), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl 0x8c(%rsi), %xmm1
divsd %xmm1, %xmm0
cvtsi2sdl 0x78(%rsi), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl 0x7c(%rsi), %xmm1
mulsd %xmm1, %xmm0
movsd 0x69613(%rip), %xmm1    # 0x71180
divsd %xmm1, %xmm0
leaq 0x69610(%rip), %rsi     # 0x71188
movl %r15d, (%rsp)
movl %r14d, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movb $0x1, %al
callq 0x3240
movq -0x50(%rbp), %rax
addq $0x4e8, %rsp            # imm = 0x4E8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)