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

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

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

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

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



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

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

    l.batch_normalize = batch_normalize;


    l.outputs = outputs;
    l.output = calloc(outputs*batch*steps, sizeof(float));
    l.delta = calloc(outputs*batch*steps, sizeof(float));
    l.state = calloc(outputs*batch, sizeof(float));
    l.prev_state = calloc(outputs*batch, sizeof(float));
    l.forgot_state = calloc(outputs*batch, sizeof(float));
    l.forgot_delta = calloc(outputs*batch, sizeof(float));

    l.r_cpu = calloc(outputs*batch, sizeof(float));
    l.z_cpu = calloc(outputs*batch, sizeof(float));
    l.h_cpu = calloc(outputs*batch, sizeof(float));

    l.forward = forward_gru_layer;
    l.backward = backward_gru_layer;
    l.update = update_gru_layer;


    return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4c8, %rsp            # imm = 0x4C8
movl %r9d, 0x1c(%rsp)
movl %r8d, %r15d
movl %esi, %ebp
movq %rdi, %rbx
movq 0x35dc3(%rip), %rax     # 0x63ff8
movq (%rax), %rdi
leaq 0x229d0(%rip), %rsi     # 0x50c0f
movl %edx, %r13d
movl %ecx, %r12d
movl %ecx, 0x18(%rsp)
xorl %eax, %eax
callq 0x3270
movl %ebp, %eax
cltd
idivl %r15d
movl %eax, %r14d
movl $0x4a0, %edx            # imm = 0x4A0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x31c0
movl %r14d, 0x48(%rbx)
movl $0x10, (%rbx)
movl %r15d, 0xc0(%rbx)
movl %r15d, 0x24(%rsp)
movl %r13d, 0x54(%rbx)
movl %r13d, %ebp
movl %r13d, 0x20(%rsp)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r13
movq %rax, 0x428(%rbx)
movq 0x35d53(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x2295d(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
movl %r14d, %esi
imull %r15d, %esi
movl %esi, 0x14(%rsp)
movl 0x500(%rsp), %eax
movl %eax, (%rsp)
leaq 0x28(%rsp), %r15
pushq $0x3
popq %r8
movq %r15, %rdi
movl %ebp, %edx
movl %r12d, %ecx
movl 0x1c(%rsp), %r12d
movl %r12d, %r9d
callq 0x24180
movl $0x4a0, %edx            # imm = 0x4A0
movq %r13, %rdi
movq %r15, %rsi
callq 0x32b0
movl %r14d, 0x48(%r13)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r15
movq %rax, 0x420(%rbx)
movq 0x35cdc(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x228e6(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
movl 0x500(%rsp), %eax
movl %eax, (%rsp)
leaq 0x28(%rsp), %rdi
movl 0x14(%rsp), %ebp
movl %ebp, %esi
movl 0x18(%rsp), %ecx
movl %ecx, %edx
pushq $0x3
popq %r8
movl %r12d, %r13d
movl %r12d, %r9d
callq 0x24180
movl $0x4a0, %edx            # imm = 0x4A0
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x32b0
movl %r14d, 0x48(%r15)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r15
movq %rax, 0x438(%rbx)
movq 0x35c6c(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x22876(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
movl 0x500(%rsp), %eax
movl %eax, (%rsp)
leaq 0x28(%rsp), %rdi
movl %ebp, %esi
movl 0x20(%rsp), %edx
movl 0x18(%rsp), %r12d
movl %r12d, %ecx
pushq $0x3
popq %r8
movl %r13d, %r9d
movl %r13d, %ebp
callq 0x24180
movl $0x4a0, %edx            # imm = 0x4A0
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x32b0
movl %r14d, 0x48(%r15)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r15
movq %rax, 0x430(%rbx)
movq 0x35bfa(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x22804(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
movl 0x500(%rsp), %eax
movl %eax, (%rsp)
leaq 0x28(%rsp), %rdi
movl 0x14(%rsp), %r13d
movl %r13d, %esi
movl %r12d, %edx
movl %r12d, %ecx
pushq $0x3
popq %r8
movl %ebp, %r9d
callq 0x24180
movl $0x4a0, %edx            # imm = 0x4A0
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x32b0
movl %r14d, %ebp
movl %r14d, 0x48(%r15)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r15
movq %rax, 0x448(%rbx)
movq 0x35b88(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x22792(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
movl 0x500(%rsp), %eax
movl %eax, (%rsp)
leaq 0x28(%rsp), %rdi
movl %r13d, %esi
movl 0x20(%rsp), %edx
movl %r12d, %ecx
pushq $0x3
popq %r8
movl 0x1c(%rsp), %r14d
movl %r14d, %r9d
callq 0x24180
movl $0x4a0, %edx            # imm = 0x4A0
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x32b0
movl %ebp, 0x48(%r15)
movl $0x4a0, %edi            # imm = 0x4A0
callq 0x3300
movq %rax, %r15
movq %rax, 0x440(%rbx)
movq 0x35b18(%rip), %rax     # 0x63ff8
movq (%rax), %rcx
leaq 0x22722(%rip), %rdi     # 0x50c0c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3440
movl 0x500(%rsp), %eax
movl %eax, (%rsp)
leaq 0x28(%rsp), %r13
movq %r13, %rdi
movl 0x14(%rsp), %esi
movl %r12d, %edx
movl %r12d, %ecx
pushq $0x3
popq %r8
movl %r14d, %r9d
callq 0x24180
movl $0x4a0, %edx            # imm = 0x4A0
movq %r15, %rdi
movq %r13, %rsi
callq 0x32b0
movl %ebp, 0x48(%r15)
movl %r14d, 0x40(%rbx)
movl %r12d, 0x58(%rbx)
imull %r12d, %ebp
movl 0x24(%rsp), %eax
imull %ebp, %eax
movslq %eax, %r15
pushq $0x4
popq %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x268(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x260(%rbx)
movslq %ebp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x1e0(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x1e8(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x1f0(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x1f8(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x308(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x300(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3250
movq %rax, 0x310(%rbx)
leaq 0x2f(%rip), %rax        # 0x2e626
movq %rax, 0x10(%rbx)
leaq 0x6f7(%rip), %rax       # 0x2ecf9
movq %rax, 0x18(%rbx)
leaq 0x6ed(%rip), %rax       # 0x2ecfa
movq %rax, 0x20(%rbx)
movq %rbx, %rax
addq $0x4c8, %rsp            # imm = 0x4C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq