// File: /workspace/github_c_makefile_star2_O2/SimpleDoger[P]Darknet_CPU_Only/rnn_layer.c
// Function: make_rnn_layer
layer make_rnn_layer(int batch, int inputs, int outputs, int steps, ACTIVATION activation, int batch_normalize, int adam)
{
    fprintf(stderr, "RNN Layer: %d inputs, %d outputs\n", inputs, outputs);
    batch = batch / steps;
    layer l = {0};
    l.batch = batch;
    l.type = RNN;
    l.steps = steps;
    l.inputs = inputs;

    l.state = calloc(batch*outputs, sizeof(float));
    l.prev_state = calloc(batch*outputs, sizeof(float));

    l.input_layer = malloc(sizeof(layer));
    fprintf(stderr, "\t\t");
    *(l.input_layer) = make_connected_layer(batch*steps, inputs, outputs, activation, batch_normalize, adam);
    l.input_layer->batch = batch;

    l.self_layer = malloc(sizeof(layer));
    fprintf(stderr, "\t\t");
    *(l.self_layer) = make_connected_layer(batch*steps, outputs, outputs, activation, batch_normalize, adam);
    l.self_layer->batch = batch;

    l.output_layer = malloc(sizeof(layer));
    fprintf(stderr, "\t\t");
    *(l.output_layer) = make_connected_layer(batch*steps, outputs, outputs, activation, batch_normalize, adam);
    l.output_layer->batch = batch;

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

    l.forward = forward_rnn_layer;
    l.backward = backward_rnn_layer;
    l.update = update_rnn_layer;

    return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
movl %r9d, 0x10(%rsp)
movl %r8d, %r15d
movl %ecx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
movq 0x368fc(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
leaq 0x234e4(%rip), %rsi     # 0x50bea
movl %edx, %r12d
movl %edx, 0x14(%rsp)
xorl %eax, %eax
callq 0x3270
movl %r14d, %eax
cltd
idivl %r15d
movl %eax, %r13d
movl $0x4a0, %edx            # imm = 0x4A0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31c0
movl %r13d, 0x48(%rbx)
movl $0xf, (%rbx)
movl %r15d, 0xc0(%rbx)
movl %r12d, 0x54(%rbx)
movl %r13d, %eax
imull %ebp, %eax
movslq %eax, %r14
pushq $0x4
popq %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x3250
movq %rax, 0x1e0(%rbx)
movq %r14, %rdi
movq %r12, %rsi
callq 0x3250
movq %rax, 0x1e8(%rbx)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r14
movq %rax, 0x390(%rbx)
movq 0x3686a(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x23474(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
imull %r13d, %r15d
movl 0x4f8(%rsp), %eax
movl %eax, (%rsp)
leaq 0x18(%rsp), %rdi
movl %r15d, %esi
movl 0x14(%rsp), %edx
movl %ebp, %ecx
movl 0x10(%rsp), %r12d
movl %r12d, %r8d
movl 0x4f0(%rsp), %r9d
callq 0x24180
movl $0x4a0, %edx            # imm = 0x4A0
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x32b0
movl %r13d, 0x48(%r14)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r14
movq %rax, 0x398(%rbx)
movq 0x367f3(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x233fd(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
movl 0x4f8(%rsp), %eax
movl %eax, (%rsp)
leaq 0x18(%rsp), %rdi
movl %r15d, %esi
movl %ebp, %edx
movl %ebp, %ecx
movl %r12d, %r8d
movl 0x4f0(%rsp), %r9d
callq 0x24180
movl $0x4a0, %edx            # imm = 0x4A0
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
callq 0x32b0
movl %r13d, 0x48(%r14)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r14
movq %rax, 0x3a0(%rbx)
movq 0x36787(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x23391(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
movl 0x4f8(%rsp), %eax
movl %eax, (%rsp)
leaq 0x18(%rsp), %r12
movq %r12, %rdi
movl %r15d, %esi
movl %ebp, %edx
movl %ebp, %ecx
movl 0x10(%rsp), %r8d
movl 0x4f0(%rsp), %r9d
callq 0x24180
movl $0x4a0, %edx            # imm = 0x4A0
movq %r14, %rdi
movq %r12, %rsi
callq 0x32b0
movl %r13d, 0x48(%r14)
movl %ebp, 0x58(%rbx)
movups 0x260(%r14), %xmm0
movups %xmm0, 0x260(%rbx)
leaq 0x2f(%rip), %rax        # 0x2d90d
movq %rax, 0x10(%rbx)
leaq 0x3a8(%rip), %rax       # 0x2dc91
movq %rax, 0x18(%rbx)
leaq 0x83b(%rip), %rax       # 0x2e12f
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