// File: /workspace/github_c_makefile_star2_O3/SimpleDoger[P]Darknet_CPU_Only/reorg_layer.c
// Function: make_reorg_layer
layer make_reorg_layer(int batch, int w, int h, int c, int stride, int reverse, int flatten, int extra)
{
    layer l = {0};
    l.type = REORG;
    l.batch = batch;
    l.stride = stride;
    l.extra = extra;
    l.h = h;
    l.w = w;
    l.c = c;
    l.flatten = flatten;
    if(reverse){
        l.out_w = w*stride;
        l.out_h = h*stride;
        l.out_c = c/(stride*stride);
    }else{
        l.out_w = w/stride;
        l.out_h = h/stride;
        l.out_c = c*(stride*stride);
    }
    l.reverse = reverse;

    l.outputs = l.out_h * l.out_w * l.out_c;
    l.inputs = h*w*c;
    if(l.extra){
        l.out_w = l.out_h = l.out_c = 0;
        l.outputs = l.inputs + l.extra;
    }

    if(extra){
        fprintf(stderr, "reorg              %4d   ->  %4d\n",  l.inputs, l.outputs);
    } else {
        fprintf(stderr, "reorg              /%2d  %4d x%4d x%4d   ->  %4d x%4d x%4d\n",  stride, w, h, c, l.out_w, l.out_h, l.out_c);
    }
    int output_size = l.outputs * batch;
    l.output =  calloc(output_size, sizeof(float));
    l.delta =   calloc(output_size, sizeof(float));

    l.forward = forward_reorg_layer;
    l.backward = backward_reorg_layer;
    return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %r13d
movl %r8d, %r14d
movl %ecx, %ebp
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %rbx
movl $0x4a0, %edx            # imm = 0x4A0
xorl %esi, %esi
callq 0x31c0
movl 0x40(%rsp), %esi
movl %ebp, %r8d
movl 0x50(%rsp), %ebp
movl %r14d, %r9d
movl $0x19, (%rbx)
movl %r15d, 0x4(%rsp)
movl %r15d, 0x48(%rbx)
movl %r13d, 0x98(%rbx)
movl %ebp, 0x64(%rbx)
movl %r8d, 0x6c(%rbx)
movl %r12d, 0x70(%rbx)
movl %r14d, 0x74(%rbx)
movl 0x48(%rsp), %eax
movl %eax, 0xa0(%rbx)
movl %r13d, %r10d
imull %r10d, %r10d
testl %esi, %esi
jne 0x3ea66
movl %r12d, %eax
cltd
idivl %r13d
movl %eax, %r11d
movl %r8d, %eax
cltd
idivl %r13d
movl %eax, %r15d
imull %r9d, %r10d
jmp 0x3ea7e
movl %r13d, %r11d
imull %r12d, %r11d
movl %r13d, %r15d
imull %r8d, %r15d
movl %r9d, %eax
cltd
idivl %r10d
movl %eax, %r10d
movl %r11d, 0x7c(%rbx)
movl %r15d, 0x78(%rbx)
movl %r10d, 0x80(%rbx)
movl %esi, 0x9c(%rbx)
movl %r11d, %r14d
imull %r15d, %r14d
imull %r10d, %r14d
movl %r14d, 0x58(%rbx)
movl %r8d, %edx
imull %r12d, %edx
imull %r9d, %edx
movl %edx, 0x54(%rbx)
testl %ebp, %ebp
jne 0x3eae2
movq 0x2d53d(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
subq $0x8, %rsp
leaq 0x1b388(%rip), %rsi     # 0x59e51
movl %r13d, %edx
movl %r12d, %ecx
xorl %eax, %eax
pushq %r10
pushq %r15
pushq %r11
callq 0x3270
addq $0x20, %rsp
jmp 0x3eb16
movl $0x0, 0x80(%rbx)
movq $0x0, 0x78(%rbx)
addl %edx, %ebp
movl %ebp, 0x58(%rbx)
movq 0x2d4f8(%rip), %rax     # 0x6bff8
movq (%rax), %rdi
leaq 0x1b325(%rip), %rsi     # 0x59e2f
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3270
movl %ebp, %r14d
imull 0x4(%rsp), %r14d
movslq %r14d, %r14
movl $0x4, %esi
movq %r14, %rdi
callq 0x3250
movq %rax, 0x268(%rbx)
movl $0x4, %esi
movq %r14, %rdi
callq 0x3250
movq %rax, 0x260(%rbx)
leaq 0x21(%rip), %rax        # 0x3eb6f
movq %rax, 0x10(%rbx)
leaq 0x156(%rip), %rax       # 0x3ecaf
movq %rax, 0x18(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq