// File: /workspace/github_c_makefile_star2_O0/SimpleDoger[P]Darknet_CPU_Only/deconvolutional_layer.c
// Function: make_deconvolutional_layer
layer make_deconvolutional_layer(int batch, int h, int w, int c, int n, int size, int stride, int padding, ACTIVATION activation, int batch_normalize, int adam)
{
    int i;
    layer l = {0};
    l.type = DECONVOLUTIONAL;

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

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

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

    l.biases = calloc(n, sizeof(float));
    l.bias_updates = calloc(n, sizeof(float));
    //float scale = n/(size*size*c);
    //printf("scale: %f\n", scale);
    float scale = .02;
    for(i = 0; i < c*n*size*size; ++i) l.weights[i] = scale*rand_normal();
    //bilinear_init(l);
    for(i = 0; i < n; ++i){
        l.biases[i] = 0;
    }
    l.pad = padding;

    l.out_h = (l.h - 1) * l.stride + l.size - 2*l.pad;
    l.out_w = (l.w - 1) * l.stride + l.size - 2*l.pad;
    l.out_c = n;
    l.outputs = l.out_w * l.out_h * l.out_c;
    l.inputs = l.w * l.h * l.c;

    scal_cpu(l.nweights, (float)l.out_w*l.out_h/(l.w*l.h), l.weights, 1);

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

    l.forward = forward_deconvolutional_layer;
    l.backward = backward_deconvolutional_layer;
    l.update = update_deconvolutional_layer;

    l.batch_normalize = batch_normalize;

    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(c*n*size*size, sizeof(float));
        l.v = calloc(c*n*size*size, 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.activation = activation;
    l.workspace_size = get_workspace_size(l);

    fprintf(stderr, "deconv%5d %2d x%2d /%2d  %4d x%4d x%4d   ->  %4d x%4d x%4d\n", n, size, size, stride, w, h, c, l.out_w, l.out_h, l.out_c);

    return l;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x4d8, %rsp            # imm = 0x4D8
movq %rdi, -0x40(%rbp)
movq %rdi, %rax
movq %rax, -0x48(%rbp)
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 -0x40(%rbp), %rdi
movl $0x1, (%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 -0x1c(%rbp), %eax
movl %eax, 0x48(%rdi)
movl 0x18(%rbp), %eax
movl %eax, 0x98(%rdi)
movl 0x10(%rbp), %eax
movl %eax, 0x90(%rdi)
movl -0x28(%rbp), %eax
imull -0x2c(%rbp), %eax
imull 0x10(%rbp), %eax
imull 0x10(%rbp), %eax
movl %eax, 0x5c(%rdi)
movl -0x2c(%rbp), %eax
movl %eax, 0x60(%rdi)
movl -0x28(%rbp), %eax
imull -0x2c(%rbp), %eax
imull 0x10(%rbp), %eax
imull 0x10(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x40(%rbp), %rdi
movq %rax, 0x250(%rdi)
movl -0x28(%rbp), %eax
imull -0x2c(%rbp), %eax
imull 0x10(%rbp), %eax
imull 0x10(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x40(%rbp), %rdi
movq %rax, 0x258(%rdi)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x40(%rbp), %rdi
movq %rax, 0x230(%rdi)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x40(%rbp), %rdi
movq %rax, 0x238(%rdi)
movss 0x6ae09(%rip), %xmm0    # 0x71140
movss %xmm0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x28(%rbp), %ecx
imull -0x2c(%rbp), %ecx
imull 0x10(%rbp), %ecx
imull 0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x6395
movss -0x34(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movb $0x0, %al
callq 0x5d50
movq -0x40(%rbp), %rax
movaps %xmm0, %xmm1
movss -0x4c(%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 0x6343
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x63c6
movq -0x40(%rbp), %rax
movq 0x230(%rax), %rax
movslq -0x30(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x639c
movq -0x40(%rbp), %rax
movl 0x20(%rbp), %ecx
movl %ecx, 0xa8(%rax)
movl 0x6c(%rax), %ecx
subl $0x1, %ecx
imull 0x98(%rax), %ecx
addl 0x90(%rax), %ecx
movl 0xa8(%rax), %edx
shll %edx
subl %edx, %ecx
movl %ecx, 0x78(%rax)
movl 0x70(%rax), %ecx
subl $0x1, %ecx
imull 0x98(%rax), %ecx
addl 0x90(%rax), %ecx
movl 0xa8(%rax), %edx
shll %edx
subl %edx, %ecx
movl %ecx, 0x7c(%rax)
movl -0x2c(%rbp), %ecx
movl %ecx, 0x80(%rax)
movl 0x7c(%rax), %ecx
imull 0x78(%rax), %ecx
imull 0x80(%rax), %ecx
movl %ecx, 0x58(%rax)
movl 0x70(%rax), %ecx
imull 0x6c(%rax), %ecx
imull 0x74(%rax), %ecx
movl %ecx, 0x54(%rax)
movl 0x5c(%rax), %edi
cvtsi2ssl 0x7c(%rax), %xmm0
cvtsi2ssl 0x78(%rax), %xmm1
mulss %xmm1, %xmm0
movl 0x70(%rax), %ecx
imull 0x6c(%rax), %ecx
cvtsi2ss %ecx, %xmm1
divss %xmm1, %xmm0
movq 0x250(%rax), %rsi
movl $0x1, %edx
callq 0x2f6f0
movq -0x40(%rbp), %rcx
movl 0x48(%rcx), %eax
imull 0x58(%rcx), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x40(%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 -0x40(%rbp), %rax
movq %rcx, 0x260(%rax)
leaq 0x2e8(%rip), %rcx       # 0x67a0
movq %rcx, 0x10(%rax)
leaq 0x4ed(%rip), %rcx       # 0x69b0
movq %rcx, 0x18(%rax)
leaq 0x782(%rip), %rcx       # 0x6c50
movq %rcx, 0x20(%rax)
movl 0x30(%rbp), %ecx
movl %ecx, 0x40(%rax)
cmpl $0x0, 0x30(%rbp)
je 0x6636
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x240(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x248(%rax)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x6550
movq -0x40(%rbp), %rax
movq 0x240(%rax), %rax
movslq -0x30(%rbp), %rcx
movss 0x6aacc(%rip), %xmm0    # 0x7100c
movss %xmm0, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x6521
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x290(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x298(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2a0(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2a8(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2b0(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x40(%rbp), %rcx
movq %rax, 0x2b8(%rcx)
movl 0x48(%rcx), %eax
imull 0x58(%rcx), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq -0x40(%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 -0x40(%rbp), %rax
movq %rcx, 0x2c8(%rax)
cmpl $0x0, 0x38(%rbp)
je 0x6704
movl -0x28(%rbp), %eax
imull -0x2c(%rbp), %eax
imull 0x10(%rbp), %eax
imull 0x10(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2d0(%rax)
movl -0x28(%rbp), %eax
imull -0x2c(%rbp), %eax
imull 0x10(%rbp), %eax
imull 0x10(%rbp), %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2d8(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2e0(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2f0(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2e8(%rax)
movslq -0x2c(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2f8(%rax)
movq -0x40(%rbp), %rsi
movl 0x28(%rbp), %eax
movl %eax, 0x4(%rsi)
movq %rsp, %rdi
movl $0x94, %ecx
rep  movsq (%rsi), %es:(%rdi)
callq 0x6e00
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x498(%rax)
movq 0x7c8c5(%rip), %rcx     # 0x82ff8
movq (%rcx), %rdi
movl -0x2c(%rbp), %edx
movl 0x10(%rbp), %ecx
movl 0x10(%rbp), %r8d
movl 0x18(%rbp), %r9d
movl -0x24(%rbp), %r15d
movl -0x20(%rbp), %r14d
movl -0x28(%rbp), %ebx
movl 0x7c(%rax), %r11d
movl 0x78(%rax), %r10d
movl 0x80(%rax), %eax
leaq 0x6a9e0(%rip), %rsi     # 0x71144
movl %r15d, (%rsp)
movl %r14d, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movb $0x0, %al
callq 0x3240
movq -0x48(%rbp), %rax
addq $0x4d8, %rsp            # imm = 0x4D8
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)