// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/crnn_layer.c
// Function: make_crnn_layer
layer make_crnn_layer(int batch, int h, int w, int c, int hidden_filters, int output_filters, int steps, ACTIVATION activation, int batch_normalize)
{
    fprintf(stderr, "CRNN Layer: %d x %d x %d image, %d filters\n", h,w,c,output_filters);
    batch = batch / steps;
    layer l = {0};
    l.batch = batch;
    l.type = CRNN;
    l.steps = steps;
    l.h = h;
    l.w = w;
    l.c = c;
    l.out_h = h;
    l.out_w = w;
    l.out_c = output_filters;
    l.inputs = h*w*c;
    l.hidden = h * w * hidden_filters;
    l.outputs = l.out_h * l.out_w * l.out_c;

    l.state = calloc(l.hidden*batch*(steps+1), sizeof(float));

    l.input_layer = malloc(sizeof(layer));
    fprintf(stderr, "\t\t");
    *(l.input_layer) = make_convolutional_layer(batch*steps, h, w, c, hidden_filters, 1, 3, 1, 1,  activation, batch_normalize, 0, 0, 0);
    l.input_layer->batch = batch;

    l.self_layer = malloc(sizeof(layer));
    fprintf(stderr, "\t\t");
    *(l.self_layer) = make_convolutional_layer(batch*steps, h, w, hidden_filters, hidden_filters, 1, 3, 1, 1,  activation, batch_normalize, 0, 0, 0);
    l.self_layer->batch = batch;

    l.output_layer = malloc(sizeof(layer));
    fprintf(stderr, "\t\t");
    *(l.output_layer) = make_convolutional_layer(batch*steps, h, w, hidden_filters, output_filters, 1, 3, 1, 1,  activation, batch_normalize, 0, 0, 0);
    l.output_layer->batch = batch;

    l.output = l.output_layer->output;
    l.delta = l.output_layer->delta;

    l.forward = forward_crnn_layer;
    l.backward = backward_crnn_layer;
    l.update = update_crnn_layer;


    return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
movl %r9d, 0x4(%rsp)
movl %r8d, %r14d
movl %ecx, %r15d
movl %edx, %r12d
movl %esi, %ebp
movq %rdi, %rbx
movl 0x4f8(%rsp), %r13d
movl 0x4f0(%rsp), %r9d
movq 0x3510d(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
leaq 0x21d3c(%rip), %rsi     # 0x50c31
xorl %eax, %eax
callq 0x3270
movl %ebp, %eax
cltd
idivl %r13d
movl %eax, %ebp
movl $0x4a0, %edx            # imm = 0x4A0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31c0
movl %ebp, 0x48(%rbx)
movl $0x12, (%rbx)
movl %r13d, 0xc0(%rbx)
movl %r12d, 0xc(%rsp)
movl %r12d, 0x6c(%rbx)
movl %r15d, 0x8(%rsp)
movl %r15d, 0x70(%rbx)
movl %r14d, 0x74(%rbx)
movl %r12d, 0x78(%rbx)
movl %r15d, 0x7c(%rbx)
movl 0x4f0(%rsp), %edx
movl %edx, 0x80(%rbx)
imull %r12d, %r15d
movl %r15d, %ecx
imull %r14d, %ecx
movl %ecx, 0x54(%rbx)
movl %r15d, %ecx
movl 0x4(%rsp), %r12d
imull %r12d, %ecx
movl %ecx, 0xc4(%rbx)
imull %edx, %r15d
movl %r15d, 0x58(%rbx)
leal 0x1(%r13), %eax
imull %ecx, %eax
imull %ebp, %eax
movslq %eax, %rdi
pushq $0x4
popq %rsi
callq 0x3250
movq %rax, 0x1e0(%rbx)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r15
movq %rax, 0x390(%rbx)
movq 0x3504b(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x21c55(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
movq %r13, %rsi
imull %ebp, %esi
movq %rsi, 0x10(%rsp)
movl %ebp, %r13d
subq $0x8, %rsp
pushq $0x1
popq %r11
pushq $0x3
popq %r10
leaq 0x20(%rsp), %rdi
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %ebp
movl %ebp, %ecx
movl %r14d, %r8d
movl %r12d, %r9d
pushq $0x0
pushq $0x0
pushq $0x0
movl 0x528(%rsp), %eax
pushq %rax
movl 0x528(%rsp), %eax
pushq %rax
pushq %r11
pushq %r11
pushq %r10
pushq %r11
callq 0x5dce
addq $0x50, %rsp
movl $0x4a0, %edx            # imm = 0x4A0
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
callq 0x32b0
movl %r13d, 0x48(%r15)
movl %r13d, %r15d
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r14
movq %rax, 0x398(%rbx)
movq 0x34fac(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x21bb6(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
subq $0x8, %rsp
leaq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r13
movl %r13d, %esi
movl 0x14(%rsp), %r12d
movl %r12d, %edx
movl %ebp, %ecx
movl 0xc(%rsp), %ebp
movl %ebp, %r8d
movl %ebp, %r9d
pushq $0x0
pushq $0x0
pushq $0x0
movl 0x528(%rsp), %eax
pushq %rax
movl 0x528(%rsp), %eax
pushq %rax
pushq $0x1
popq %rax
pushq %rax
pushq %rax
pushq $0x3
popq %r10
pushq %r10
pushq %rax
callq 0x5dce
addq $0x50, %rsp
movl $0x4a0, %edx            # imm = 0x4A0
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x32b0
movl %r15d, 0x48(%r14)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r14
movq %rax, 0x3a0(%rbx)
movq 0x34f16(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x21b20(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
subq $0x8, %rsp
leaq 0x20(%rsp), %rdi
movl %r13d, %esi
movl %r12d, %edx
movl 0x10(%rsp), %ecx
movl %ebp, %r8d
movl 0x4f8(%rsp), %r9d
pushq $0x0
pushq $0x0
pushq $0x0
movl 0x528(%rsp), %eax
pushq %rax
movl 0x528(%rsp), %eax
pushq %rax
pushq $0x1
popq %rax
pushq %rax
pushq %rax
movq %rax, %r10
pushq $0x3
popq %rax
pushq %rax
pushq %r10
callq 0x5dce
addq $0x50, %rsp
movl $0x4a0, %edx            # imm = 0x4A0
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x32b0
movl %r15d, 0x48(%r14)
movups 0x260(%r14), %xmm0
movups %xmm0, 0x260(%rbx)
leaq 0x2f(%rip), %rax        # 0x2f19d
movq %rax, 0x10(%rbx)
leaq 0x3c3(%rip), %rax       # 0x2f53c
movq %rax, 0x18(%rbx)
leaq 0x845(%rip), %rax       # 0x2f9c9
movq %rax, 0x20(%rbx)
movq %rbx, %rax
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq