// File: /workspace/github_c_makefile_star2_O2/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 0x31f96
movl %r12d, %eax
cltd
idivl %r13d
movl %eax, %r11d
movl %r8d, %eax
cltd
idivl %r13d
movl %eax, %r15d
imull %r9d, %r10d
jmp 0x31fae
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 0x32012
movq 0x3200d(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
subq $0x8, %rsp
leaq 0x1ed60(%rip), %rsi     # 0x50d59
movl %r13d, %edx
movl %r12d, %ecx
xorl %eax, %eax
pushq %r10
pushq %r15
pushq %r11
callq 0x3270
addq $0x20, %rsp
jmp 0x32040
andl $0x0, 0x80(%rbx)
andq $0x0, 0x78(%rbx)
addl %edx, %ebp
movl %ebp, 0x58(%rbx)
movq 0x31fce(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
leaq 0x1ed03(%rip), %rsi     # 0x50d37
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3270
movl %ebp, %r14d
imull 0x4(%rsp), %r14d
movslq %r14d, %r14
pushq $0x4
popq %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3250
movq %rax, 0x268(%rbx)
movq %r14, %rdi
movq %r15, %rsi
callq 0x3250
movq %rax, 0x260(%rbx)
leaq 0x21(%rip), %rax        # 0x32099
movq %rax, 0x10(%rbx)
leaq 0x15b(%rip), %rax       # 0x321de
movq %rax, 0x18(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq