// File: /workspace/github_c_makefile_star2_O0/SimpleDoger[P]Darknet_CPU_Only/connected_layer.c
// Function: make_connected_layer
layer make_connected_layer(int batch, int inputs, int outputs, ACTIVATION activation, int batch_normalize, int adam)
{
    int i;
    layer l = {0};
    l.learning_rate_scale = 1;
    l.type = CONNECTED;

    l.inputs = inputs;
    l.outputs = outputs;
    l.batch=batch;
    l.batch_normalize = batch_normalize;
    l.h = 1;
    l.w = 1;
    l.c = inputs;
    l.out_h = 1;
    l.out_w = 1;
    l.out_c = outputs;

    l.output = calloc(batch*outputs, sizeof(float));
    l.delta = calloc(batch*outputs, sizeof(float));

    l.weight_updates = calloc(inputs*outputs, sizeof(float));
    l.bias_updates = calloc(outputs, sizeof(float));

    l.weights = calloc(outputs*inputs, sizeof(float));
    l.biases = calloc(outputs, sizeof(float));

    l.forward = forward_connected_layer;
    l.backward = backward_connected_layer;
    l.update = update_connected_layer;

    //float scale = 1./sqrt(inputs);
    float scale = sqrt(2./inputs);
    for(i = 0; i < outputs*inputs; ++i){
        l.weights[i] = scale*rand_uniform(-1, 1);
    }

    for(i = 0; i < outputs; ++i){
        l.biases[i] = 0;
    }

    if(adam){
        l.m = calloc(l.inputs*l.outputs, sizeof(float));
        l.v = calloc(l.inputs*l.outputs, sizeof(float));
        l.bias_m = calloc(l.outputs, sizeof(float));
        l.scale_m = calloc(l.outputs, sizeof(float));
        l.bias_v = calloc(l.outputs, sizeof(float));
        l.scale_v = calloc(l.outputs, sizeof(float));
    }
    if(batch_normalize){
        l.scales = calloc(outputs, sizeof(float));
        l.scale_updates = calloc(outputs, sizeof(float));
        for(i = 0; i < outputs; ++i){
            l.scales[i] = 1;
        }

        l.mean = calloc(outputs, sizeof(float));
        l.mean_delta = calloc(outputs, sizeof(float));
        l.variance = calloc(outputs, sizeof(float));
        l.variance_delta = calloc(outputs, sizeof(float));

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

        l.x = calloc(batch*outputs, sizeof(float));
        l.x_norm = calloc(batch*outputs, sizeof(float));
    }

    l.activation = activation;
    fprintf(stderr, "connected                            %4d  ->  %4d\n", inputs, outputs);
    return l;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x28(%rbp)
movq %rdi, %rax
movq %rax, -0x30(%rbp)
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 -0x28(%rbp), %rdi
movss 0x34d6d(%rip), %xmm0    # 0x7100c
movss %xmm0, 0xec(%rdi)
movl $0x2, (%rdi)
movl -0x8(%rbp), %eax
movl %eax, 0x54(%rdi)
movl -0xc(%rbp), %eax
movl %eax, 0x58(%rdi)
movl -0x4(%rbp), %eax
movl %eax, 0x48(%rdi)
movl -0x14(%rbp), %eax
movl %eax, 0x40(%rdi)
movl $0x1, 0x6c(%rdi)
movl $0x1, 0x70(%rdi)
movl -0x8(%rbp), %eax
movl %eax, 0x74(%rdi)
movl $0x1, 0x78(%rdi)
movl $0x1, 0x7c(%rdi)
movl -0xc(%rbp), %eax
movl %eax, 0x80(%rdi)
movl -0x4(%rbp), %eax
imull -0xc(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x28(%rbp), %rdi
movq %rax, 0x268(%rdi)
movl -0x4(%rbp), %eax
imull -0xc(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x28(%rbp), %rdi
movq %rax, 0x260(%rdi)
movl -0x8(%rbp), %eax
imull -0xc(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x28(%rbp), %rdi
movq %rax, 0x258(%rdi)
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x28(%rbp), %rdi
movq %rax, 0x238(%rdi)
movl -0xc(%rbp), %eax
imull -0x8(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x28(%rbp), %rdi
movq %rax, 0x250(%rdi)
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x28(%rbp), %rdi
movq %rax, 0x230(%rdi)
leaq 0x32b(%rip), %rax       # 0x3c6d0
movq %rax, 0x10(%rdi)
leaq 0x470(%rip), %rax       # 0x3c820
movq %rax, 0x18(%rdi)
leaq 0x625(%rip), %rax       # 0x3c9e0
movq %rax, 0x20(%rdi)
cvtsi2sdl -0x8(%rbp), %xmm1
movsd 0x34c8c(%rip), %xmm0    # 0x71058
divsd %xmm1, %xmm0
callq 0x3430
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl -0xc(%rbp), %ecx
imull -0x8(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3c43d
movss -0x1c(%rbp), %xmm0
movss %xmm0, -0x34(%rbp)
movss 0x37cd7(%rip), %xmm0    # 0x740dc
movss 0x34bff(%rip), %xmm1    # 0x7100c
callq 0x5b30
movq -0x28(%rbp), %rax
movaps %xmm0, %xmm1
movss -0x34(%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 0x3c3e5
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x3c46e
movq -0x28(%rbp), %rax
movq 0x230(%rax), %rax
movslq -0x18(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3c444
cmpl $0x0, 0x10(%rbp)
je 0x3c52d
movq -0x28(%rbp), %rcx
movl 0x54(%rcx), %eax
imull 0x58(%rcx), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x28(%rbp), %rcx
movq %rax, 0x2d0(%rcx)
movl 0x54(%rcx), %eax
imull 0x58(%rcx), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2d8(%rax)
movslq 0x58(%rax), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2e0(%rax)
movslq 0x58(%rax), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2f0(%rax)
movslq 0x58(%rax), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2e8(%rax)
movslq 0x58(%rax), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2f8(%rax)
cmpl $0x0, -0x14(%rbp)
je 0x3c691
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x240(%rax)
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x248(%rax)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x3c5a5
movq -0x28(%rbp), %rax
movq 0x240(%rax), %rax
movslq -0x18(%rbp), %rcx
movss 0x34a77(%rip), %xmm0    # 0x7100c
movss %xmm0, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3c576
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x290(%rax)
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2a0(%rax)
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x298(%rax)
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2a8(%rax)
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2b0(%rax)
movslq -0xc(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2b8(%rax)
movl -0x4(%rbp), %eax
imull -0xc(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2c0(%rax)
movl -0x4(%rbp), %eax
imull -0xc(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x2c8(%rax)
movq -0x28(%rbp), %rax
movl -0x10(%rbp), %ecx
movl %ecx, 0x4(%rax)
movq 0x46956(%rip), %rax     # 0x82ff8
movq (%rax), %rdi
movl -0x8(%rbp), %edx
movl -0xc(%rbp), %ecx
leaq 0x38050(%rip), %rsi     # 0x74702
movb $0x0, %al
callq 0x3240
movq -0x30(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)