void bpnn_layerforward(l1, l2, conn, n1, n2) double *l1, *l2, **conn;
int n1, n2;
{
  double sum;
  int j, k;
  l1[0] = 1.0;
  for (j = 1; j <= n2; j++) {
    sum = 0.0;
    for (k = 0; k <= n1; k++) {
      sum += conn[k][j] * l1[k];
    }
    l2[j] = squash(sum);
  }
}


x86 assembly (clang, -O0):
<bpnn_layerforward>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     11d6 <bpnn_layerforward+0xc6>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     11ab <bpnn_layerforward+0x9b>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    115d <bpnn_layerforward+0x4d>
movsd  -0x28(%rbp),%xmm0
mov    $0x1,%al
call   1030 <squash@plt>
cvtsi2sd %eax,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1142 <bpnn_layerforward+0x32>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpnn_layerforward>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,(%rsp)
mov    %rsi,0x10(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rdi)
test   %r8d,%r8d
jle    1261 <bpnn_layerforward+0x151>
mov    %r8d,%r15d
mov    %rdx,%r13
mov    %rdi,%rbx
mov    (%rsp),%rax
lea    0x1(%rax),%r12d
add    $0x1,%r15d
lea    -0x1(%r12),%rax
mov    %rax,0x8(%rsp)
mov    %r12d,%ebp
and    $0x3,%ebp
and    $0xfffffffc,%r12d
mov    $0x1,%r14d
jmp    119a <bpnn_layerforward+0x8a>
xchg   %ax,%ax
xorpd  %xmm0,%xmm0
mov    $0x1,%al
call   1030 <squash@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    0x10(%rsp),%rax
movsd  %xmm0,(%rax,%r14,8)
add    $0x1,%r14
cmp    %r15,%r14
je     1261 <bpnn_layerforward+0x151>
cmpl   $0x0,(%rsp)
js     1170 <bpnn_layerforward+0x60>
cmpq   $0x3,0x8(%rsp)
jae    11b0 <bpnn_layerforward+0xa0>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
jmp    121c <bpnn_layerforward+0x10c>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13,%rax,8),%rcx
mov    0x8(%r13,%rax,8),%rdx
movsd  (%rcx,%r14,8),%xmm1
mulsd  (%rbx,%rax,8),%xmm1
addsd  %xmm0,%xmm1
movsd  (%rdx,%r14,8),%xmm2
mulsd  0x8(%rbx,%rax,8),%xmm2
addsd  %xmm1,%xmm2
mov    0x10(%r13,%rax,8),%rcx
movsd  (%rcx,%r14,8),%xmm1
mulsd  0x10(%rbx,%rax,8),%xmm1
mov    0x18(%r13,%rax,8),%rcx
movsd  (%rcx,%r14,8),%xmm0
mulsd  0x18(%rbx,%rax,8),%xmm0
addsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
add    $0x4,%rax
cmp    %rax,%r12
jne    11c0 <bpnn_layerforward+0xb0>
test   %rbp,%rbp
je     1174 <bpnn_layerforward+0x64>
lea    (%rbx,%rax,8),%rcx
lea    0x0(,%rax,8),%rax
add    %r13,%rax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
mov    (%rax,%rdx,8),%rsi
movsd  (%rsi,%r14,8),%xmm1
mulsd  (%rcx,%rdx,8),%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%rdx
cmp    %rdx,%rbp
jne    1240 <bpnn_layerforward+0x130>
jmp    1174 <bpnn_layerforward+0x64>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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