void heaviside(double *input_data, double *output_data, int n) {
  int i;
  for (i = 0; i < n; i++) {
    if (input_data[i] < 0) {
      output_data[i] = 0;
    } else {
      output_data[i] = 1;
    }
  }
}


x86 assembly (clang, -O0):
<heaviside>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1175 <heaviside+0x75>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    114d <heaviside+0x4d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1162 <heaviside+0x62>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  0xea3(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1167 <heaviside+0x67>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1116 <heaviside+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<heaviside>:
test   %edx,%edx
jle    12cf <heaviside+0x1cf>
mov    %edx,%r9d
cmp    $0x4,%edx
jb     112a <heaviside+0x2a>
lea    (%rdi,%r9,8),%rax
cmp    %rsi,%rax
jbe    11f0 <heaviside+0xf0>
lea    (%rsi,%r9,8),%rax
cmp    %rdi,%rax
jbe    11f0 <heaviside+0xf0>
xor    %ecx,%ecx
mov    %rcx,%rax
not    %rax
add    %r9,%rax
mov    %r9,%rdx
and    $0x3,%rdx
je     116d <heaviside+0x6d>
xorpd  %xmm0,%xmm0
movsd  0xec6(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
movsd  (%rdi,%rcx,8),%xmm2
cmpltsd %xmm0,%xmm2
andnpd %xmm1,%xmm2
movlpd %xmm2,(%rsi,%rcx,8)
add    $0x1,%rcx
add    $0xffffffffffffffff,%rdx
jne    1150 <heaviside+0x50>
cmp    $0x3,%rax
jb     12cf <heaviside+0x1cf>
xorpd  %xmm0,%xmm0
movsd  0xe8d(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%rdi,%rcx,8),%xmm2
cmpltsd %xmm0,%xmm2
andnpd %xmm1,%xmm2
movlpd %xmm2,(%rsi,%rcx,8)
movsd  0x8(%rdi,%rcx,8),%xmm2
cmpltsd %xmm0,%xmm2
andnpd %xmm1,%xmm2
movlpd %xmm2,0x8(%rsi,%rcx,8)
movsd  0x10(%rdi,%rcx,8),%xmm2
cmpltsd %xmm0,%xmm2
andnpd %xmm1,%xmm2
movlpd %xmm2,0x10(%rsi,%rcx,8)
movsd  0x18(%rdi,%rcx,8),%xmm2
cmpltsd %xmm0,%xmm2
andnpd %xmm1,%xmm2
movlpd %xmm2,0x18(%rsi,%rcx,8)
add    $0x4,%rcx
cmp    %rcx,%r9
jne    1190 <heaviside+0x90>
jmp    12cf <heaviside+0x1cf>
mov    %r9d,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rax
mov    %rax,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rax,%rax
je     12d0 <heaviside+0x1d0>
mov    %r8,%rax
and    $0xfffffffffffffffe,%rax
xor    %edx,%edx
xorpd  %xmm0,%xmm0
movapd 0xddd(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movupd (%rdi,%rdx,8),%xmm2
movupd 0x10(%rdi,%rdx,8),%xmm3
cmpnltpd %xmm0,%xmm2
andpd  %xmm1,%xmm2
cmpnltpd %xmm0,%xmm3
andpd  %xmm1,%xmm3
movupd %xmm2,(%rsi,%rdx,8)
movupd %xmm3,0x10(%rsi,%rdx,8)
movupd 0x20(%rdi,%rdx,8),%xmm2
movupd 0x30(%rdi,%rdx,8),%xmm3
cmpnltpd %xmm0,%xmm2
andpd  %xmm1,%xmm2
cmpnltpd %xmm0,%xmm3
andpd  %xmm1,%xmm3
movupd %xmm2,0x20(%rsi,%rdx,8)
movupd %xmm3,0x30(%rsi,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rax
jne    1230 <heaviside+0x130>
test   $0x1,%r8b
je     12c6 <heaviside+0x1c6>
movupd (%rdi,%rdx,8),%xmm0
movupd 0x10(%rdi,%rdx,8),%xmm1
xorpd  %xmm2,%xmm2
cmpnltpd %xmm2,%xmm0
movapd 0xd52(%rip),%xmm3
andpd  %xmm3,%xmm0
cmpnltpd %xmm2,%xmm1
andpd  %xmm3,%xmm1
movupd %xmm0,(%rsi,%rdx,8)
movupd %xmm1,0x10(%rsi,%rdx,8)
cmp    %r9,%rcx
jne    112c <heaviside+0x2c>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    1292 <heaviside+0x192>
jmp    12c6 <heaviside+0x1c6>

LLVM IR (-O0):
define void @heaviside(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %30, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %33
12: ; preds = %8
%13 = load double*, double** %4
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %24
19: ; preds = %12
%20 = load double*, double** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
store double 0.000000e+00, double* %23
br label %29
24: ; preds = %12
%25 = load double*, double** %5
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
store double 1.000000e+00, double* %28
br label %29
29: ; preds = %24, %19
br label %30
30: ; preds = %29
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %8
33: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @heaviside(double* nocapture %0, double* nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %125
5: ; preds = %3
%6 = zext i32 %2 to i64
%7 = icmp ult i32 %2, 4
br i1 %7, label %78, label %8
8: ; preds = %5
%9 = getelementptr double, double* %1, i64 %6
%10 = getelementptr double, double* %0, i64 %6
%11 = icmp ugt double* %10, %1
%12 = icmp ugt double* %9, %0
%13 = and i1 %11, %12
br i1 %13, label %78, label %14
14: ; preds = %8
%15 = and i64 %6, 4294967292
%16 = add nsw i64 %15, -4
%17 = lshr exact i64 %16, 2
%18 = add nuw nsw i64 %17, 1
%19 = and i64 %18, 1
%20 = icmp eq i64 %16, 0
br i1 %20, label %58, label %21
21: ; preds = %14
%22 = and i64 %18, 9223372036854775806
br label %23
23: ; preds = %23, %21
%24 = phi i64 [ 0, %21 ], [ %55, %23 ]
%25 = phi i64 [ 0, %21 ], [ %56, %23 ]
%26 = getelementptr inbounds double, double* %0, i64 %24
%27 = bitcast double* %26 to <2 x double>*
%28 = load <2 x double>, <2 x double>* %27
%29 = getelementptr inbounds double, double* %26, i64 2
%30 = bitcast double* %29 to <2 x double>*
%31 = load <2 x double>, <2 x double>* %30
%32 = fcmp olt <2 x double> %28, zeroinitializer
%33 = fcmp olt <2 x double> %31, zeroinitializer
%34 = select <2 x i1> %32, <2 x double> zeroinitializer, <2 x double> <double 1.000000e+00, double 1.000000e+00>
%35 = select <2 x i1> %33, <2 x double> zeroinitializer, <2 x double> <double 1.000000e+00, double 1.000000e+00>
%36 = getelementptr inbounds double, double* %1, i64 %24
%37 = bitcast double* %36 to <2 x double>*
store <2 x double> %34, <2 x double>* %37
%38 = getelementptr inbounds double, double* %36, i64 2
%39 = bitcast double* %38 to <2 x double>*
store <2 x double> %35, <2 x double>* %39
%40 = or i64 %24, 4
%41 = getelementptr inbounds double, double* %0, i64 %40
%42 = bitcast double* %41 to <2 x double>*
%43 = load <2 x double>, <2 x double>* %42
%44 = getelementptr inbounds double, double* %41, i64 2
%45 = bitcast double* %44 to <2 x double>*
%46 = load <2 x double>, <2 x double>* %45
%47 = fcmp olt <2 x double> %43, zeroinitializer
%48 = fcmp olt <2 x double> %46, zeroinitializer
%49 = select <2 x i1> %47, <2 x double> zeroinitializer, <2 x double> <double 1.000000e+00, double 1.000000e+00>
%50 = select <2 x i1> %48, <2 x double> zeroinitializer, <2 x double> <double 1.000000e+00, double 1.000000e+00>
%51 = getelementptr inbounds double, double* %1, i64 %40
%52 = bitcast double* %51 to <2 x double>*
store <2 x double> %49, <2 x double>* %52
%53 = getelementptr inbounds double, double* %51, i64 2
%54 = bitcast double* %53 to <2 x double>*
store <2 x double> %50, <2 x double>* %54
%55 = add nuw i64 %24, 8
%56 = add i64 %25, 2
%57 = icmp eq i64 %56, %22
br i1 %57, label %58, label %23
58: ; preds = %23, %14
%59 = phi i64 [ 0, %14 ], [ %55, %23 ]
%60 = icmp eq i64 %19, 0
br i1 %60, label %76, label %61
61: ; preds = %58
%62 = getelementptr inbounds double, double* %0, i64 %59
%63 = bitcast double* %62 to <2 x double>*
%64 = load <2 x double>, <2 x double>* %63
%65 = getelementptr inbounds double, double* %62, i64 2
%66 = bitcast double* %65 to <2 x double>*
%67 = load <2 x double>, <2 x double>* %66
%68 = fcmp olt <2 x double> %64, zeroinitializer
%69 = fcmp olt <2 x double> %67, zeroinitializer
%70 = select <2 x i1> %68, <2 x double> zeroinitializer, <2 x double> <double 1.000000e+00, double 1.000000e+00>
%71 = select <2 x i1> %69, <2 x double> zeroinitializer, <2 x double> <double 1.000000e+00, double 1.000000e+00>
%72 = getelementptr inbounds double, double* %1, i64 %59
%73 = bitcast double* %72 to <2 x double>*
store <2 x double> %70, <2 x double>* %73
%74 = getelementptr inbounds double, double* %72, i64 2
%75 = bitcast double* %74 to <2 x double>*
store <2 x double> %71, <2 x double>* %75
br label %76
76: ; preds = %58, %61
%77 = icmp eq i64 %15, %6
br i1 %77, label %125, label %78
78: ; preds = %8, %5, %76
%79 = phi i64 [ 0, %8 ], [ 0, %5 ], [ %15, %76 ]
%80 = xor i64 %79, -1
%81 = add nsw i64 %80, %6
%82 = and i64 %6, 3
%83 = icmp eq i64 %82, 0
br i1 %83, label %95, label %84
84: ; preds = %78, %84
%85 = phi i64 [ %92, %84 ], [ %79, %78 ]
%86 = phi i64 [ %93, %84 ], [ 0, %78 ]
%87 = getelementptr inbounds double, double* %0, i64 %85
%88 = load double, double* %87
%89 = fcmp olt double %88, 0.000000e+00
%90 = select i1 %89, double 0.000000e+00, double 1.000000e+00
%91 = getelementptr inbounds double, double* %1, i64 %85
store double %90, double* %91
%92 = add nuw nsw i64 %85, 1
%93 = add i64 %86, 1
%94 = icmp eq i64 %93, %82
br i1 %94, label %95, label %84
95: ; preds = %84, %78
%96 = phi i64 [ %79, %78 ], [ %92, %84 ]
%97 = icmp ult i64 %81, 3
br i1 %97, label %125, label %98
98: ; preds = %95, %98
%99 = phi i64 [ %123, %98 ], [ %96, %95 ]
%100 = getelementptr inbounds double, double* %0, i64 %99
%101 = load double, double* %100
%102 = fcmp olt double %101, 0.000000e+00
%103 = select i1 %102, double 0.000000e+00, double 1.000000e+00
%104 = getelementptr inbounds double, double* %1, i64 %99
store double %103, double* %104
%105 = add nuw nsw i64 %99, 1
%106 = getelementptr inbounds double, double* %0, i64 %105
%107 = load double, double* %106
%108 = fcmp olt double %107, 0.000000e+00
%109 = select i1 %108, double 0.000000e+00, double 1.000000e+00
%110 = getelementptr inbounds double, double* %1, i64 %105
store double %109, double* %110
%111 = add nuw nsw i64 %99, 2
%112 = getelementptr inbounds double, double* %0, i64 %111
%113 = load double, double* %112
%114 = fcmp olt double %113, 0.000000e+00
%115 = select i1 %114, double 0.000000e+00, double 1.000000e+00
%116 = getelementptr inbounds double, double* %1, i64 %111
store double %115, double* %116
%117 = add nuw nsw i64 %99, 3
%118 = getelementptr inbounds double, double* %0, i64 %117
%119 = load double, double* %118
%120 = fcmp olt double %119, 0.000000e+00
%121 = select i1 %120, double 0.000000e+00, double 1.000000e+00
%122 = getelementptr inbounds double, double* %1, i64 %117
store double %121, double* %122
%123 = add nuw nsw i64 %99, 4
%124 = icmp eq i64 %123, %6
br i1 %124, label %125, label %98
125: ; preds = %95, %98, %76, %3
ret void
}