// File: /workspace/github_c_makefile_star2_O1/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, %r12d
movl %r8d, %r15d
movl %ecx, %r13d
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
movl $0x4a0, %edx            # imm = 0x4A0
xorl %esi, %esi
callq 0x31d0
movl 0x40(%rsp), %edi
movl 0x50(%rsp), %ecx
movl $0x19, (%rbx)
movl %r14d, 0x4(%rsp)
movl %r14d, 0x48(%rbx)
movl %ebp, %r14d
movl %r12d, 0x98(%rbx)
movl %ecx, 0x64(%rbx)
movl %r13d, 0x6c(%rbx)
movl %ebp, 0x70(%rbx)
movl %r15d, 0x74(%rbx)
movl 0x48(%rsp), %eax
movl %eax, 0xa0(%rbx)
movl %r12d, %esi
imull %r12d, %esi
testl %edi, %edi
jne 0x3c7d2
movl %r14d, %eax
cltd
idivl %r12d
movl %eax, 0x7c(%rbx)
movl %r13d, %eax
cltd
idivl %r12d
movl %eax, 0x78(%rbx)
imull %r15d, %esi
jmp 0x3c7ee
movl %r12d, %eax
imull %r14d, %eax
movl %eax, 0x7c(%rbx)
movl %r12d, %eax
imull %r13d, %eax
movl %eax, 0x78(%rbx)
movl %r15d, %eax
cltd
idivl %esi
movl %eax, %esi
movl %esi, 0x80(%rbx)
movl %edi, 0x9c(%rbx)
movl 0x7c(%rbx), %eax
imull 0x78(%rbx), %eax
imull %esi, %eax
movl %eax, 0x58(%rbx)
movl %r13d, %edx
imull %r14d, %edx
imull %r15d, %edx
movl %edx, 0x54(%rbx)
testl %ecx, %ecx
jne 0x3c85a
movq 0x2d7d8(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
movl 0x78(%rbx), %r10d
movl 0x7c(%rbx), %r11d
movl 0x80(%rbx), %ebp
subq $0x8, %rsp
leaq 0x1b505(%rip), %rsi     # 0x57d41
movl %r12d, %edx
movl %r14d, %ecx
movl %r13d, %r8d
movl %r15d, %r9d
xorl %eax, %eax
pushq %rbp
pushq %r10
pushq %r11
callq 0x3280
addq $0x20, %rsp
jmp 0x3c889
movl $0x0, 0x80(%rbx)
movq $0x0, 0x78(%rbx)
addl %edx, %ecx
movl %ecx, 0x58(%rbx)
movq 0x2d780(%rip), %rax     # 0x69ff8
movq (%rax), %rdi
leaq 0x1b49d(%rip), %rsi     # 0x57d1f
xorl %eax, %eax
callq 0x3280
movslq 0x58(%rbx), %rax
movslq 0x4(%rsp), %r14
imulq %rax, %r14
movl $0x4, %esi
movq %r14, %rdi
callq 0x3260
movq %rax, 0x268(%rbx)
movl $0x4, %esi
movq %r14, %rdi
callq 0x3260
movq %rax, 0x260(%rbx)
leaq 0x21(%rip), %rax        # 0x3c8e6
movq %rax, 0x10(%rbx)
leaq 0x156(%rip), %rax       # 0x3ca26
movq %rax, 0x18(%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq