#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 sign(double);
void calcOutputPattern(const int patternSize, const double W[][1000],
                       const double inputPattern[], double outputPattern[]) {
  for (int outIndex = 0; outIndex < patternSize; outIndex++) {
    double delta = 0.0;
    for (int inIndex = 0; inIndex < patternSize; inIndex++) {
      delta += inputPattern[inIndex] * W[outIndex][inIndex];
    }
    outputPattern[outIndex] = sign(delta);
  }
}


x86 assembly (clang, -O0):
<calcOutputPattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c2 <calcOutputPattern+0xb2>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119d <calcOutputPattern+0x8d>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x1f40,%rcx,%rcx
add    %rcx,%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1149 <calcOutputPattern+0x39>
movsd  -0x30(%rbp),%xmm0
call   1030 <sign@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112e <calcOutputPattern+0x1e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcOutputPattern>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
test   %edi,%edi
jle    122c <calcOutputPattern+0x11c>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%r12d
lea    -0x1(%r12),%rax
mov    %rax,(%rsp)
mov    %r12d,%ebp
and    $0x3,%ebp
mov    %r12,0x8(%rsp)
and    $0xfffffffc,%r12d
lea    0x18(%rsi),%r13
xor    %r14d,%r14d
jmp    118d <calcOutputPattern+0x7d>
cs nopw 0x0(%rax,%rax,1)
nop
call   1030 <sign@plt>
mov    0x10(%rsp),%rax
movsd  %xmm0,(%rax,%r14,8)
add    $0x1,%r14
add    $0x1f40,%r13
add    $0x1f40,%r15
cmp    0x8(%rsp),%r14
je     122c <calcOutputPattern+0x11c>
cmpq   $0x3,(%rsp)
jae    11a0 <calcOutputPattern+0x90>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
jmp    11fc <calcOutputPattern+0xec>
nopl   0x0(%rax)
xorpd  %xmm0,%xmm0
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
movsd  (%rbx,%rax,8),%xmm1
movsd  0x8(%rbx,%rax,8),%xmm2
mulsd  -0x18(%r13,%rax,8),%xmm1
mulsd  -0x10(%r13,%rax,8),%xmm2
addsd  %xmm0,%xmm1
movsd  0x10(%rbx,%rax,8),%xmm3
mulsd  -0x8(%r13,%rax,8),%xmm3
addsd  %xmm1,%xmm2
movsd  0x18(%rbx,%rax,8),%xmm0
mulsd  0x0(%r13,%rax,8),%xmm0
addsd  %xmm2,%xmm3
addsd  %xmm3,%xmm0
add    $0x4,%rax
cmp    %rax,%r12
jne    11b0 <calcOutputPattern+0xa0>
test   %rbp,%rbp
je     1160 <calcOutputPattern+0x50>
lea    (%r15,%rax,8),%rcx
lea    (%rbx,%rax,8),%rax
xor    %edx,%edx
nop
movsd  (%rax,%rdx,8),%xmm1
mulsd  (%rcx,%rdx,8),%xmm1
addsd  %xmm1,%xmm0
add    $0x1,%rdx
cmp    %rdx,%rbp
jne    1210 <calcOutputPattern+0x100>
jmp    1160 <calcOutputPattern+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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