// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/darknet.c
// Function: average
void average(int argc, char *argv[])
{
    char *cfgfile = argv[2];
    char *outfile = argv[3];
    gpu_index = -1;
    network *net = parse_network_cfg(cfgfile);
    network *sum = parse_network_cfg(cfgfile);

    char *weightfile = argv[4];   
    load_weights(sum, weightfile);

    int i, j;
    int n = argc - 5;
    for(i = 0; i < n; ++i){
        weightfile = argv[i+5];   
        load_weights(net, weightfile);
        for(j = 0; j < net->n; ++j){
            layer l = net->layers[j];
            layer out = sum->layers[j];
            if(l.type == CONVOLUTIONAL){
                int num = l.n*l.c*l.size*l.size;
                axpy_cpu(l.n, 1, l.biases, 1, out.biases, 1);
                axpy_cpu(num, 1, l.weights, 1, out.weights, 1);
                if(l.batch_normalize){
                    axpy_cpu(l.n, 1, l.scales, 1, out.scales, 1);
                    axpy_cpu(l.n, 1, l.rolling_mean, 1, out.rolling_mean, 1);
                    axpy_cpu(l.n, 1, l.rolling_variance, 1, out.rolling_variance, 1);
                }
            }
            if(l.type == CONNECTED){
                axpy_cpu(l.outputs, 1, l.biases, 1, out.biases, 1);
                axpy_cpu(l.outputs*l.inputs, 1, l.weights, 1, out.weights, 1);
            }
        }
    }
    n = n+1;
    for(j = 0; j < net->n; ++j){
        layer l = sum->layers[j];
        if(l.type == CONVOLUTIONAL){
            int num = l.n*l.c*l.size*l.size;
            scal_cpu(l.n, 1./n, l.biases, 1);
            scal_cpu(num, 1./n, l.weights, 1);
                if(l.batch_normalize){
                    scal_cpu(l.n, 1./n, l.scales, 1);
                    scal_cpu(l.n, 1./n, l.rolling_mean, 1);
                    scal_cpu(l.n, 1./n, l.rolling_variance, 1);
                }
        }
        if(l.type == CONNECTED){
            scal_cpu(l.outputs, 1./n, l.biases, 1);
            scal_cpu(l.outputs*l.inputs, 1./n, l.weights, 1);
        }
    }
    save_weights(sum, outfile);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r14
movl %edi, %ebp
movq 0x10(%rsi), %rbx
movq 0x18(%rsi), %rax
movq %rax, 0x38(%rsp)
leaq 0x1abe5(%rip), %rax     # 0x647c0
orl $-0x1, (%rax)
movq %rbx, %rdi
callq 0x27071
movq %rax, %r15
movq %rbx, %rdi
callq 0x27071
movq %r14, 0x40(%rsp)
movq 0x20(%r14), %rsi
movq %rax, 0x28(%rsp)
movq %rax, %rdi
callq 0x2958f
cmpl $0x6, %ebp
pushq $0x5
popq %rax
movl %ebp, 0x34(%rsp)
cmovgel %ebp, %eax
addl $-0x5, %eax
movq %rax, 0x48(%rsp)
xorl %ecx, %ecx
movq %r15, 0x20(%rsp)
cmpq 0x48(%rsp), %rcx
je 0x49e17
movq 0x40(%rsp), %rax
movq %rcx, 0x50(%rsp)
movq 0x28(%rax,%rcx,8), %rsi
movq %r15, %rdi
callq 0x2958f
movl $0x230, %r13d           # imm = 0x230
xorl %r12d, %r12d
movslq (%r15), %rax
cmpq %rax, %r12
jge 0x49e0a
movq 0x20(%r15), %rax
movl -0x230(%rax,%r13), %edi
movq (%rax,%r13), %rsi
movq 0x20(%rax,%r13), %rbp
movq 0x28(%rsp), %rcx
movq 0x20(%rcx), %rdx
movq (%rdx,%r13), %rcx
movq 0x20(%rdx,%r13), %rbx
cmpl $0x2, %edi
je 0x49daf
testl %edi, %edi
jne 0x49dfb
movl -0x1ac(%rax,%r13), %edi
movq 0x10(%rax,%r13), %r8
movq %r8, 0x60(%rsp)
movq 0x80(%rax,%r13), %r8
movq %r8, 0x70(%rsp)
movq 0x88(%rax,%r13), %r8
movq %r8, 0x10(%rsp)
movq 0x10(%rdx,%r13), %r8
movq %r8, 0x58(%rsp)
movq 0x80(%rdx,%r13), %r8
movq %r8, 0x68(%rsp)
movq 0x88(%rdx,%r13), %rdx
movq %rdx, 0x8(%rsp)
movl -0x1a0(%rax,%r13), %edx
movl %edx, %r15d
imull %edi, %r15d
imull %edx, %r15d
imull -0x1bc(%rax,%r13), %r15d
movl -0x1f0(%rax,%r13), %eax
movl %eax, 0x4(%rsp)
movl %edi, 0x18(%rsp)
movss 0x22f2(%rip), %xmm0     # 0x4c008
pushq $0x1
popq %r14
movl %r14d, %edx
movl %r14d, %r8d
callq 0x1b3ed
movl %r15d, %edi
movq 0x20(%rsp), %r15
movss 0x22d3(%rip), %xmm0     # 0x4c008
movq %rbp, %rsi
movl %r14d, %edx
movq %rbx, %rcx
movl %r14d, %r8d
callq 0x1b3ed
cmpl $0x0, 0x4(%rsp)
je 0x49dfb
movl 0x18(%rsp), %ebp
movl %ebp, %edi
movss 0x22a9(%rip), %xmm0     # 0x4c008
movq 0x60(%rsp), %rsi
pushq $0x1
popq %rbx
movl %ebx, %edx
movq 0x58(%rsp), %rcx
movl %ebx, %r8d
callq 0x1b3ed
movl %ebp, %edi
movss 0x2288(%rip), %xmm0     # 0x4c008
movq 0x70(%rsp), %rsi
movl %ebx, %edx
movq 0x68(%rsp), %rcx
movl %ebx, %r8d
callq 0x1b3ed
movl %ebp, %edi
movss 0x226a(%rip), %xmm0     # 0x4c008
movq 0x10(%rsp), %rsi
movl %ebx, %edx
movq 0x8(%rsp), %rcx
movl %ebx, %r8d
jmp 0x49df6
movl -0x1d8(%rax,%r13), %edi
movl -0x1dc(%rax,%r13), %r14d
imull %edi, %r14d
movss 0x223d(%rip), %xmm0     # 0x4c008
pushq $0x1
popq %r15
movl %r15d, %edx
movl %r15d, %r8d
callq 0x1b3ed
movl %r14d, %edi
movss 0x2223(%rip), %xmm0     # 0x4c008
movq %rbp, %rsi
movl %r15d, %edx
movq %rbx, %rcx
movl %r15d, %r8d
movq 0x20(%rsp), %r15
callq 0x1b3ed
incq %r12
addq $0x4a0, %r13            # imm = 0x4A0
jmp 0x49c4e
movq 0x50(%rsp), %rcx
incq %rcx
jmp 0x49c23
movl 0x34(%rsp), %eax
addl $-0x4, %eax
cvtsi2sd %eax, %xmm0
movsd 0x22fe(%rip), %xmm1     # 0x4c128
divsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x4(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x20(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r12
jge 0x49f71
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movl (%rax,%r15), %ecx
movq 0x230(%rax,%r15), %rsi
movq 0x250(%rax,%r15), %rbx
cmpl $0x2, %ecx
je 0x49f30
testl %ecx, %ecx
jne 0x49f62
movl 0x84(%rax,%r15), %r14d
movq 0x240(%rax,%r15), %rcx
movq %rcx, 0x8(%rsp)
movq 0x2b0(%rax,%r15), %rcx
movq %rcx, 0x10(%rsp)
movq 0x2b8(%rax,%r15), %rcx
movq %rcx, 0x18(%rsp)
movl 0x90(%rax,%r15), %ecx
movl %ecx, %ebp
imull %r14d, %ebp
imull %ecx, %ebp
imull 0x74(%rax,%r15), %ebp
movl 0x40(%rax,%r15), %r13d
movl %r14d, %edi
movss 0x4(%rsp), %xmm0
pushq $0x1
popq %rdx
callq 0x1b423
movl %ebp, %edi
movss 0x4(%rsp), %xmm0
movq %rbx, %rsi
pushq $0x1
popq %rdx
callq 0x1b423
testl %r13d, %r13d
je 0x49f62
movl %r14d, %edi
movss 0x4(%rsp), %xmm0
movq 0x8(%rsp), %rsi
pushq $0x1
popq %rbx
movl %ebx, %edx
callq 0x1b423
movl %r14d, %edi
movss 0x4(%rsp), %xmm0
movq 0x10(%rsp), %rsi
movl %ebx, %edx
callq 0x1b423
movl %r14d, %edi
movss 0x4(%rsp), %xmm0
movq 0x18(%rsp), %rsi
movl %ebx, %edx
jmp 0x49f5d
movl 0x58(%rax,%r15), %edi
movl 0x54(%rax,%r15), %ebp
imull %edi, %ebp
movss 0x4(%rsp), %xmm0
pushq $0x1
popq %r14
movl %r14d, %edx
callq 0x1b423
movl %ebp, %edi
movss 0x4(%rsp), %xmm0
movq %rbx, %rsi
movl %r14d, %edx
callq 0x1b423
incq %r12
addq $0x4a0, %r15            # imm = 0x4A0
jmp 0x49e3e
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x28aed