#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);
void gaussian1d(int *out, int n, double sd, double max) {
  int i;
  double di;
  for (i = 0; i <= (n / 2); i++) {
    di = (double)i;
    out[i] = max * exp(-(di * di) / (sd * sd));
    if (i > 0)
      out[n - i] = out[i];
  }
}


x86 assembly (clang, -O0):
<gaussian1d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jg     11e9 <gaussian1d+0xd9>
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
cmpl   $0x0,-0x24(%rbp)
jle    11d6 <gaussian1d+0xc6>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    -0x24(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11db <gaussian1d+0xcb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1130 <gaussian1d+0x20>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian1d>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0xffffffff,%esi
jl     11d4 <gaussian1d+0xc4>
movapd %xmm0,%xmm2
mov    %esi,%r14d
mov    %rdi,%r15
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0xec0(%rip),%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1030 <exp@plt>
movsd  0x8(%rsp),%xmm2
mulsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r15)
lea    0x1(%r14),%eax
cmp    $0x3,%eax
jb     11d4 <gaussian1d+0xc4>
mov    %r14d,%r12d
shr    $0x1f,%r12d
add    %r14d,%r12d
sar    %r12d
movslq %r14d,%rax
add    $0x1,%r12d
lea    (%r15,%rax,4),%r14
add    $0xfffffffffffffffc,%r14
mov    $0x1,%ebx
nopl   0x0(%rax)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movapd %xmm1,%xmm0
xorpd  0xe6d(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
call   1030 <exp@plt>
movsd  0x8(%rsp),%xmm2
mulsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r15,%rbx,4)
mov    %eax,(%r14)
add    $0x1,%rbx
add    $0xfffffffffffffffc,%r14
cmp    %rbx,%r12
jne    1190 <gaussian1d+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @gaussian1d(i32* %0, i32 %1, double %2, double %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca double
store i32* %0, i32** %5
store i32 %1, i32* %6
store double %2, double* %7
store double %3, double* %8
store i32 0, i32* %9
br label %11
11: ; preds = %50, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %6
%14 = sdiv i32 %13, 2
%15 = icmp sle i32 %12, %14
br i1 %15, label %16, label %53
16: ; preds = %11
%17 = load i32, i32* %9
%18 = sitofp i32 %17 to double
store double %18, double* %10
%19 = load double, double* %8
%20 = load double, double* %10
%21 = load double, double* %10
%22 = fmul double %20, %21
%23 = fneg double %22
%24 = load double, double* %7
%25 = load double, double* %7
%26 = fmul double %24, %25
%27 = fdiv double %23, %26
%28 = call double @exp(double %27)
%29 = fmul double %19, %28
%30 = fptosi double %29 to i32
%31 = load i32*, i32** %5
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
store i32 %30, i32* %34
%35 = load i32, i32* %9
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %49
37: ; preds = %16
%38 = load i32*, i32** %5
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = load i32*, i32** %5
%44 = load i32, i32* %6
%45 = load i32, i32* %9
%46 = sub nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %43, i64 %47
store i32 %42, i32* %48
br label %49
49: ; preds = %37, %16
br label %50
50: ; preds = %49
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %11
53: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @gaussian1d(i32* nocapture writeonly %0, i32 %1, double %2, double %3) {
%5 = icmp slt i32 %1, -1
br i1 %5, label %33, label %6
6: ; preds = %4
%7 = sdiv i32 %1, 2
%8 = fmul double %2, %2
%9 = sext i32 %1 to i64
%10 = add nuw nsw i32 %7, 1
%11 = zext i32 %10 to i64
%12 = fdiv double -0.000000e+00, %8
%13 = tail call double @exp(double %12)
%14 = fmul double %13, %3
%15 = fptosi double %14 to i32
store i32 %15, i32* %0
%16 = add i32 %1, 1
%17 = icmp ult i32 %16, 3
br i1 %17, label %33, label %18
18: ; preds = %6, %18
%19 = phi i64 [ %31, %18 ], [ 1, %6 ]
%20 = trunc i64 %19 to i32
%21 = sitofp i32 %20 to double
%22 = fneg double %21
%23 = fmul double %22, %21
%24 = fdiv double %23, %8
%25 = tail call double @exp(double %24)
%26 = fmul double %25, %3
%27 = fptosi double %26 to i32
%28 = getelementptr inbounds i32, i32* %0, i64 %19
store i32 %27, i32* %28
%29 = sub nsw i64 %9, %19
%30 = getelementptr inbounds i32, i32* %0, i64 %29
store i32 %27, i32* %30
%31 = add nuw nsw i64 %19, 1
%32 = icmp eq i64 %31, %11
br i1 %32, label %33, label %18
33: ; preds = %18, %6, %4
ret void
}