#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 */
scalar_t__ exp(double);
double pow(double, int);
int /*<<< orphan*/ printf(char *, int, double);
double sqrt(int);
void createGauss(int dim, double sigma, double g[]) {
  int i;
  double e;
  if (0)
    printf("Creating gaussian (size: %d, sig: %2.4f)\n", dim, sigma);
  e = sqrt(2 * 3.14159265358979323846) * sigma;
  for (i = 0; i < dim; i++) {
    g[i] = (double)exp(-0.5 * pow((double)i, 2) / pow(sigma, 2)) / e;
  }
}


x86 assembly (clang, -O0):
<createGauss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x6,%edi
call   1050 <sqrt@plt>
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d3 <createGauss+0xa3>
cvtsi2sdl -0x1c(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe7b(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1030 <exp@plt>
cvtsi2sd %rax,%xmm0
divsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <createGauss+0x2f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createGauss>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
movsd  %xmm0,0x10(%rsp)
mov    %edi,%ebp
mov    $0x6,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
test   %ebp,%ebp
jle    11cf <createGauss+0x9f>
movsd  0x8(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   (%rax)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
mulsd  0xe77(%rip),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
movsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <createGauss+0x40>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @createGauss(i32 %0, double %1, double* nocapture writeonly %2) {
%4 = tail call double @sqrt(i32 6)
%5 = fmul double %4, %1
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %23
7: ; preds = %3
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %21, %9 ]
%11 = trunc i64 %10 to i32
%12 = sitofp i32 %11 to double
%13 = tail call double @pow(double %12, i32 2)
%14 = fmul double %13, -5.000000e-01
%15 = tail call double @pow(double %1, i32 2)
%16 = fdiv double %14, %15
%17 = tail call i64 @exp(double %16)
%18 = sitofp i64 %17 to double
%19 = fdiv double %18, %5
%20 = getelementptr inbounds double, double* %2, i64 %10
store double %19, double* %20
%21 = add nuw nsw i64 %10, 1
%22 = icmp eq i64 %21, %8
br i1 %22, label %23, label %9
23: ; preds = %9, %3
ret void
}