#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 */
int exp(int);
int pow(double, int);
double kernel(double *x, int n, double h, int j) {
  int i;
  double k = 0;
  double z[n];
  for (i = 0; i < n; i++) {
    z[i] = (x[i] - x[j]) / h;
    k += (1 / pow(2 * 3.141592654, 0.5)) * exp(-pow(z[i], 2) / 2);
  }
  k = (1 / (n * h)) * k;
  return (k);
}


x86 assembly (clang, -O0):
<kernel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1213 <kernel+0xf3>
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
mov    -0x8(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
subsd  (%rcx,%rdx,8),%xmm0
divsd  -0x18(%rbp),%xmm0
movslq -0x20(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  0xe5b(%rip),%xmm0
xor    %edi,%edi
call   1040 <pow@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,-0x44(%rbp)
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <exp@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116d <kernel+0x4d>
cvtsi2sdl -0xc(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  0xddb(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %esi,%esi
mov    %esi,0xc(%rsp)
jle    11dc <kernel+0xbc>
mov    %rdi,%rbx
movslq %edx,%r15
mov    %esi,%r12d
xorpd  %xmm2,%xmm2
xor    %r13d,%r13d
xor    %r14d,%r14d
movsd  %xmm0,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm2,0x20(%rsp)
movsd  (%rbx,%r14,8),%xmm1
subsd  (%rbx,%r15,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  0xe7c(%rip),%xmm0
xor    %edi,%edi
call   1040 <pow@plt>
mov    %eax,%ebp
lea    0x1(%rbp),%eax
cmp    $0x3,%eax
cmovae %r13d,%ebp
movsd  0x18(%rsp),%xmm0
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
neg    %edi
call   1030 <exp@plt>
movsd  0x20(%rsp),%xmm2
imul   %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm0
add    $0x1,%r14
cmp    %r14,%r12
jne    1160 <kernel+0x40>
jmp    11e0 <kernel+0xc0>
xorpd  %xmm2,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sdl 0xc(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xe13(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @kernel(double* %0, i32 %1, double %2, i32 %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca i8*
%12 = alloca i64
store double* %0, double** %5
store i32 %1, i32* %6
store double %2, double* %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %10
%13 = load i32, i32* %6
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %11
%16 = alloca double, i64 %14
store i64 %14, i64* %12
store i32 0, i32* %9
br label %17
17: ; preds = %52, %4
%18 = load i32, i32* %9
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %55
21: ; preds = %17
%22 = load double*, double** %5
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = load double*, double** %5
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = fsub double %26, %31
%33 = load double, double* %7
%34 = fdiv double %32, %33
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %16, i64 %36
store double %34, double* %37
%38 = call i32 @pow(double 0x401921FB54524550, i32 0)
%39 = sdiv i32 1, %38
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %16, i64 %41
%43 = load double, double* %42
%44 = call i32 @pow(double %43, i32 2)
%45 = sub nsw i32 0, %44
%46 = sdiv i32 %45, 2
%47 = call i32 @exp(i32 %46)
%48 = mul nsw i32 %39, %47
%49 = sitofp i32 %48 to double
%50 = load double, double* %10
%51 = fadd double %50, %49
store double %51, double* %10
br label %52
52: ; preds = %21
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %17
55: ; preds = %17
%56 = load i32, i32* %6
%57 = sitofp i32 %56 to double
%58 = load double, double* %7
%59 = fmul double %57, %58
%60 = fdiv double 1.000000e+00, %59
%61 = load double, double* %10
%62 = fmul double %60, %61
store double %62, double* %10
%63 = load double, double* %10
%64 = load i8*, i8** %11
ret double %63
}

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