#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double tanh(double);
void forward(const int rows, const int cols, double *W, double *x, double *a) {
  int row, col;
  double *W_it, *x_it, *a_it;
  W_it = W;
  a_it = a;
  for (row = 0; row < rows; row++) {
    *a_it = 0.0;
    x_it = x;
    for (col = 0; col < cols; col++) {
      *a_it += *W_it * *x_it;
      W_it++;
      x_it++;
    }
    *a_it = tanh(*a_it);
    a_it++;
  }
}


x86 assembly (clang, -O0):
<forward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ec <forward+0xdc>
mov    -0x40(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11bd <forward+0xad>
mov    -0x30(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x38(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1167 <forward+0x57>
mov    -0x40(%rbp),%rax
movsd  (%rax),%xmm0
call   1030 <tanh@plt>
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x40(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <forward+0x31>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forward>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %edi,0x14(%rsp)
test   %edi,%edi
jle    1264 <forward+0x154>
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    0x8(%rsp),%r13
lea    -0x1(%r13),%eax
mov    %eax,0x10(%rsp)
mov    %r13d,%r12d
and    $0xfffffffc,%r12d
and    $0x3,%r13d
shl    $0x3,%r13
xor    %ebp,%ebp
jmp    117e <forward+0x6e>
nopl   0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
call   1030 <tanh@plt>
movsd  %xmm0,(%rbx)
add    $0x8,%rbx
add    $0x1,%ebp
cmp    0x14(%rsp),%ebp
je     1264 <forward+0x154>
movq   $0x0,(%rbx)
cmpl   $0x0,0x8(%rsp)
jle    1160 <forward+0x50>
xorpd  %xmm0,%xmm0
cmpl   $0x3,0x10(%rsp)
jae    11b0 <forward+0xa0>
mov    %r14,%rcx
testb  $0x3,0x8(%rsp)
jne    1237 <forward+0x127>
jmp    1164 <forward+0x54>
nopw   0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movsd  (%r15,%rcx,8),%xmm1
mulsd  (%r14,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
movsd  0x8(%r15,%rcx,8),%xmm0
mulsd  0x8(%r14,%rcx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
movsd  0x10(%r15,%rcx,8),%xmm1
mulsd  0x10(%r14,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
movsd  0x18(%r15,%rcx,8),%xmm0
mulsd  0x18(%r14,%rcx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
add    $0xffffffffffffffe0,%rax
add    $0x4,%rcx
cmp    %ecx,%r12d
jne    11c0 <forward+0xb0>
mov    %r14,%rcx
sub    %rax,%rcx
sub    %rax,%r15
testb  $0x3,0x8(%rsp)
je     1164 <forward+0x54>
xor    %eax,%eax
nopl   0x0(%rax)
movsd  (%r15,%rax,1),%xmm1
mulsd  (%rcx,%rax,1),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
add    $0x8,%rax
cmp    %eax,%r13d
jne    1240 <forward+0x130>
add    %rax,%r15
jmp    1164 <forward+0x54>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @forward(i32 %0, i32 %1, double* %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca double*
%14 = alloca double*
%15 = alloca double*
store i32 %0, i32* %6
store i32 %1, i32* %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
%16 = load double*, double** %8
store double* %16, double** %13
%17 = load double*, double** %10
store double* %17, double** %15
store i32 0, i32* %11
br label %18
18: ; preds = %51, %5
%19 = load i32, i32* %11
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %54
22: ; preds = %18
%23 = load double*, double** %15
store double 0.000000e+00, double* %23
%24 = load double*, double** %9
store double* %24, double** %14
store i32 0, i32* %12
br label %25
25: ; preds = %41, %22
%26 = load i32, i32* %12
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %44
29: ; preds = %25
%30 = load double*, double** %13
%31 = load double, double* %30
%32 = load double*, double** %14
%33 = load double, double* %32
%34 = load double*, double** %15
%35 = load double, double* %34
%36 = call double @llvm.fmuladd.f64(double %31, double %33, double %35)
store double %36, double* %34
%37 = load double*, double** %13
%38 = getelementptr inbounds double, double* %37, i32 1
store double* %38, double** %13
%39 = load double*, double** %14
%40 = getelementptr inbounds double, double* %39, i32 1
store double* %40, double** %14
br label %41
41: ; preds = %29
%42 = load i32, i32* %12
%43 = add nsw i32 %42, 1
store i32 %43, i32* %12
br label %25
44: ; preds = %25
%45 = load double*, double** %15
%46 = load double, double* %45
%47 = call double @tanh(double %46)
%48 = load double*, double** %15
store double %47, double* %48
%49 = load double*, double** %15
%50 = getelementptr inbounds double, double* %49, i32 1
store double* %50, double** %15
br label %51
51: ; preds = %44
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
br label %18
54: ; preds = %18
ret void
}

LLVM IR (-O2):
define void @forward(i32 %0, i32 %1, double* nocapture %2, double* nocapture %3, double* nocapture %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %71
7: ; preds = %5
%8 = icmp sgt i32 %1, 0
%9 = add i32 %1, -1
%10 = and i32 %1, 3
%11 = icmp ult i32 %9, 3
%12 = and i32 %1, -4
%13 = icmp eq i32 %10, 0
br label %14
14: ; preds = %7, %64
%15 = phi double* [ %4, %7 ], [ %68, %64 ]
%16 = phi double* [ %2, %7 ], [ %66, %64 ]
%17 = phi i32 [ 0, %7 ], [ %69, %64 ]
store double 0.000000e+00, double* %15
br i1 %8, label %18, label %64
18: ; preds = %14
br i1 %11, label %46, label %19
19: ; preds = %18, %19
%20 = phi double [ %41, %19 ], [ 0.000000e+00, %18 ]
%21 = phi double* [ %43, %19 ], [ %3, %18 ]
%22 = phi double* [ %42, %19 ], [ %16, %18 ]
%23 = phi i32 [ %44, %19 ], [ 0, %18 ]
%24 = load double, double* %22
%25 = load double, double* %21
%26 = tail call double @llvm.fmuladd.f64(double %24, double %25, double %20)
store double %26, double* %15
%27 = getelementptr inbounds double, double* %22, i64 1
%28 = getelementptr inbounds double, double* %21, i64 1
%29 = load double, double* %27
%30 = load double, double* %28
%31 = tail call double @llvm.fmuladd.f64(double %29, double %30, double %26)
store double %31, double* %15
%32 = getelementptr inbounds double, double* %22, i64 2
%33 = getelementptr inbounds double, double* %21, i64 2
%34 = load double, double* %32
%35 = load double, double* %33
%36 = tail call double @llvm.fmuladd.f64(double %34, double %35, double %31)
store double %36, double* %15
%37 = getelementptr inbounds double, double* %22, i64 3
%38 = getelementptr inbounds double, double* %21, i64 3
%39 = load double, double* %37
%40 = load double, double* %38
%41 = tail call double @llvm.fmuladd.f64(double %39, double %40, double %36)
store double %41, double* %15
%42 = getelementptr inbounds double, double* %22, i64 4
%43 = getelementptr inbounds double, double* %21, i64 4
%44 = add i32 %23, 4
%45 = icmp eq i32 %44, %12
br i1 %45, label %46, label %19
46: ; preds = %19, %18
%47 = phi double [ undef, %18 ], [ %41, %19 ]
%48 = phi double* [ undef, %18 ], [ %42, %19 ]
%49 = phi double [ 0.000000e+00, %18 ], [ %41, %19 ]
%50 = phi double* [ %3, %18 ], [ %43, %19 ]
%51 = phi double* [ %16, %18 ], [ %42, %19 ]
br i1 %13, label %64, label %52
52: ; preds = %46, %52
%53 = phi double [ %59, %52 ], [ %49, %46 ]
%54 = phi double* [ %61, %52 ], [ %50, %46 ]
%55 = phi double* [ %60, %52 ], [ %51, %46 ]
%56 = phi i32 [ %62, %52 ], [ 0, %46 ]
%57 = load double, double* %55
%58 = load double, double* %54
%59 = tail call double @llvm.fmuladd.f64(double %57, double %58, double %53)
store double %59, double* %15
%60 = getelementptr inbounds double, double* %55, i64 1
%61 = getelementptr inbounds double, double* %54, i64 1
%62 = add i32 %56, 1
%63 = icmp eq i32 %62, %10
br i1 %63, label %64, label %52
64: ; preds = %46, %52, %14
%65 = phi double [ 0.000000e+00, %14 ], [ %47, %46 ], [ %59, %52 ]
%66 = phi double* [ %16, %14 ], [ %48, %46 ], [ %60, %52 ]
%67 = tail call double @tanh(double %65)
store double %67, double* %15
%68 = getelementptr inbounds double, double* %15, i64 1
%69 = add nuw nsw i32 %17, 1
%70 = icmp eq i32 %69, %0
br i1 %70, label %71, label %14
71: ; preds = %64, %5
ret void
}