// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x20(%rbp)
movq %rdi, %rax
movq %rax, -0x28(%rbp)
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movl %esi, -0x4(%rbp)
movl %edx, -0x8(%rbp)
movl %ecx, -0xc(%rbp)
movl %r8d, -0x10(%rbp)
movl %r9d, -0x14(%rbp)
xorl %esi, %esi
movl $0x4a0, %edx            # imm = 0x4A0
callq 0x3190
movq -0x20(%rbp), %rdi
movl $0x19, (%rdi)
movl -0x4(%rbp), %eax
movl %eax, 0x48(%rdi)
movl -0x14(%rbp), %eax
movl %eax, 0x98(%rdi)
movl 0x20(%rbp), %eax
movl %eax, 0x64(%rdi)
movl -0xc(%rbp), %eax
movl %eax, 0x6c(%rdi)
movl -0x8(%rbp), %eax
movl %eax, 0x70(%rdi)
movl -0x10(%rbp), %eax
movl %eax, 0x74(%rdi)
movl 0x18(%rbp), %eax
movl %eax, 0xa0(%rdi)
cmpl $0x0, 0x10(%rbp)
je 0x4e82c
movq -0x20(%rbp), %rax
movl -0x8(%rbp), %ecx
imull -0x14(%rbp), %ecx
movl %ecx, 0x7c(%rax)
movl -0xc(%rbp), %ecx
imull -0x14(%rbp), %ecx
movl %ecx, 0x78(%rax)
movl -0x10(%rbp), %eax
movl -0x14(%rbp), %ecx
imull -0x14(%rbp), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x80(%rax)
jmp 0x4e85f
movl -0x8(%rbp), %eax
cltd
idivl -0x14(%rbp)
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x7c(%rax)
movl -0xc(%rbp), %eax
cltd
idivl -0x14(%rbp)
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x78(%rax)
movl -0x10(%rbp), %ecx
movl -0x14(%rbp), %edx
imull -0x14(%rbp), %edx
imull %edx, %ecx
movl %ecx, 0x80(%rax)
movq -0x20(%rbp), %rax
movl 0x10(%rbp), %ecx
movl %ecx, 0x9c(%rax)
movl 0x78(%rax), %ecx
imull 0x7c(%rax), %ecx
imull 0x80(%rax), %ecx
movl %ecx, 0x58(%rax)
movl -0xc(%rbp), %ecx
imull -0x8(%rbp), %ecx
imull -0x10(%rbp), %ecx
movl %ecx, 0x54(%rax)
cmpl $0x0, 0x64(%rax)
je 0x4e8b6
movq -0x20(%rbp), %rax
movl $0x0, 0x80(%rax)
movl $0x0, 0x78(%rax)
movl $0x0, 0x7c(%rax)
movl 0x54(%rax), %ecx
addl 0x64(%rax), %ecx
movl %ecx, 0x58(%rax)
cmpl $0x0, 0x20(%rbp)
je 0x4e8e0
movq -0x20(%rbp), %rax
movq 0x34731(%rip), %rcx     # 0x82ff8
movq (%rcx), %rdi
movl 0x54(%rax), %edx
movl 0x58(%rax), %ecx
leaq 0x26d24(%rip), %rsi     # 0x755fb
movb $0x0, %al
callq 0x3240
jmp 0x4e925
movq -0x20(%rbp), %rax
movq 0x3470d(%rip), %rcx     # 0x82ff8
movq (%rcx), %rdi
movl -0x14(%rbp), %edx
movl -0x8(%rbp), %ecx
movl -0xc(%rbp), %r8d
movl -0x10(%rbp), %r9d
movl 0x7c(%rax), %r11d
movl 0x78(%rax), %r10d
movl 0x80(%rax), %eax
leaq 0x26d0c(%rip), %rsi     # 0x7561d
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
movb $0x0, %al
callq 0x3240
movq -0x20(%rbp), %rax
movl 0x58(%rax), %eax
imull -0x4(%rbp), %eax
movl %eax, -0x18(%rbp)
movslq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x268(%rax)
movslq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x3220
movq -0x20(%rbp), %rcx
movq %rax, %rdx
movq -0x28(%rbp), %rax
movq %rdx, 0x260(%rcx)
leaq 0x1a(%rip), %rdx        # 0x4e990
movq %rdx, 0x10(%rcx)
leaq 0x1bf(%rip), %rdx       # 0x4eb40
movq %rdx, 0x18(%rcx)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)