#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 exp(double);
double *gaussianFilter(double *out, double *x, double sigma, double sz) {
  for (int it = 0; it < sz; it++) {
    double d2 = x[it];
    out[it] = exp(-d2 / 2.0 / (sigma * sigma));
  }
  return out;
}


x86 assembly (clang, -O0):
<gaussianFilter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ad <gaussianFilter+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe85(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1030 <exp@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1131 <gaussianFilter+0x21>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussianFilter>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,(%rsp)
mov    %rdi,%r15
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jbe    1185 <gaussianFilter+0x75>
mov    %rsi,%r14
movsd  (%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
movsd  %xmm1,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  (%r14,%rbx,8),%xmm0
mulsd  0xea2(%rip),%xmm0
divsd  (%rsp),%xmm0
call   1030 <exp@plt>
movsd  0x8(%rsp),%xmm1
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
ucomisd %xmm0,%xmm1
ja     1150 <gaussianFilter+0x40>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @gaussianFilter(double* %0, double* %1, double %2, double %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca double
store double* %0, double** %5
store double* %1, double** %6
store double %2, double* %7
store double %3, double* %8
store i32 0, i32* %9
br label %11
11: ; preds = %34, %4
%12 = load i32, i32* %9
%13 = sitofp i32 %12 to double
%14 = load double, double* %8
%15 = fcmp olt double %13, %14
br i1 %15, label %16, label %37
16: ; preds = %11
%17 = load double*, double** %6
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
store double %21, double* %10
%22 = load double, double* %10
%23 = fneg double %22
%24 = fdiv double %23, 2.000000e+00
%25 = load double, double* %7
%26 = load double, double* %7
%27 = fmul double %25, %26
%28 = fdiv double %24, %27
%29 = call double @exp(double %28)
%30 = load double*, double** %5
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double %29, double* %33
br label %34
34: ; preds = %16
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %11
37: ; preds = %11
%38 = load double*, double** %5
ret double* %38
}

LLVM IR (-O2):
define double* @gaussianFilter(double* returned writeonly %0, double* nocapture %1, double %2, double %3) {
%5 = fcmp ogt double %3, 0.000000e+00
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = fmul double %2, %2
br label %9
8: ; preds = %9, %4
ret double* %0
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %17, %9 ]
%11 = getelementptr inbounds double, double* %1, i64 %10
%12 = load double, double* %11
%13 = fmul double %12, -5.000000e-01
%14 = fdiv double %13, %7
%15 = tail call double @exp(double %14)
%16 = getelementptr inbounds double, double* %0, i64 %10
store double %15, double* %16
%17 = add nuw i64 %10, 1
%18 = trunc i64 %17 to i32
%19 = sitofp i32 %18 to double
%20 = fcmp olt double %19, %3
br i1 %20, label %9, label %8
}