#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 kernel(double *, int, double, int);
double smoothPar(double *, int);
void kernestim(double *x, int *n, double *smoothing, double *value) {
  int i;
  int maxD = 0;
  double D[2];
  if (*smoothing == 0)
    *smoothing = smoothPar(x, *n);
  D[0] = kernel(x, *n, *smoothing, 0);
  for (i = 1; i < *n; i++) {
    D[1] = kernel(x, *n, *smoothing, i);
    if (D[1] > D[0]) {
      D[0] = D[1];
      maxD = i;
    }
  }
  *value = x[maxD];
}


x86 assembly (clang, -O0):
<kernestim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1171 <kernestim+0x51>
jp     1171 <kernestim+0x51>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <smoothPar@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
xor    %edx,%edx
call   1030 <kernel@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    11f7 <kernestim+0xd7>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x24(%rbp),%edx
call   1030 <kernel@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    11e4 <kernestim+0xc4>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11e9 <kernestim+0xc9>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <kernestim+0x76>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernestim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r15
movsd  (%rdx),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1159 <kernestim+0x39>
jp     1159 <kernestim+0x39>
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1040 <smoothPar@plt>
movsd  %xmm0,(%r12)
mov    0x0(%r13),%esi
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %edx,%edx
call   1030 <kernel@plt>
mov    0x0(%r13),%esi
cmp    $0x2,%esi
jl     11b3 <kernestim+0x93>
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%r12),%xmm0
mov    %r15,%rdi
mov    %ebp,%edx
call   1030 <kernel@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
cmova  %ebp,%ebx
maxsd  %xmm1,%xmm0
add    $0x1,%ebp
mov    0x0(%r13),%esi
cmp    %esi,%ebp
jl     1180 <kernestim+0x60>
movslq %ebx,%rbx
movsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @kernestim(double* %0, i32* %1, double* %2, double* %3) {
%5 = alloca double*
%6 = alloca i32*
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [2 x double]
store double* %0, double** %5
store i32* %1, i32** %6
store double* %2, double** %7
store double* %3, double** %8
store i32 0, i32* %10
%12 = load double*, double** %7
%13 = load double, double* %12
%14 = fcmp oeq double %13, 0.000000e+00
br i1 %14, label %15, label %21
15: ; preds = %4
%16 = load double*, double** %5
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = call double @smoothPar(double* %16, i32 %18)
%20 = load double*, double** %7
store double %19, double* %20
br label %21
21: ; preds = %15, %4
%22 = load double*, double** %5
%23 = load i32*, i32** %6
%24 = load i32, i32* %23
%25 = load double*, double** %7
%26 = load double, double* %25
%27 = call double @kernel(double* %22, i32 %24, double %26, i32 0)
%28 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 0
store double %27, double* %28
store i32 1, i32* %9
br label %29
29: ; preds = %54, %21
%30 = load i32, i32* %9
%31 = load i32*, i32** %6
%32 = load i32, i32* %31
%33 = icmp slt i32 %30, %32
br i1 %33, label %34, label %57
34: ; preds = %29
%35 = load double*, double** %5
%36 = load i32*, i32** %6
%37 = load i32, i32* %36
%38 = load double*, double** %7
%39 = load double, double* %38
%40 = load i32, i32* %9
%41 = call double @kernel(double* %35, i32 %37, double %39, i32 %40)
%42 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 1
store double %41, double* %42
%43 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 1
%44 = load double, double* %43
%45 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 0
%46 = load double, double* %45
%47 = fcmp ogt double %44, %46
br i1 %47, label %48, label %53
48: ; preds = %34
%49 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 1
%50 = load double, double* %49
%51 = getelementptr inbounds [2 x double], [2 x double]* %11, i64 0, i64 0
store double %50, double* %51
%52 = load i32, i32* %9
store i32 %52, i32* %10
br label %53
53: ; preds = %48, %34
br label %54
54: ; preds = %53
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %29
57: ; preds = %29
%58 = load double*, double** %5
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = load double*, double** %8
store double %62, double* %63
ret void
}

LLVM IR (-O2):
define void @kernestim(double* %0, i32* nocapture %1, double* nocapture %2, double* nocapture writeonly %3) {
%5 = load double, double* %2
%6 = fcmp oeq double %5, 0.000000e+00
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* %1
%9 = tail call double @smoothPar(double* %0, i32 %8)
store double %9, double* %2
br label %10
10: ; preds = %7, %4
%11 = phi double [ %9, %7 ], [ %5, %4 ]
%12 = load i32, i32* %1
%13 = tail call double @kernel(double* %0, i32 %12, double %11, i32 0)
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %31
16: ; preds = %10, %16
%17 = phi i32 [ %27, %16 ], [ %14, %10 ]
%18 = phi double [ %25, %16 ], [ %13, %10 ]
%19 = phi i32 [ %26, %16 ], [ 1, %10 ]
%20 = phi i32 [ %24, %16 ], [ 0, %10 ]
%21 = load double, double* %2
%22 = tail call double @kernel(double* %0, i32 %17, double %21, i32 %19)
%23 = fcmp ogt double %22, %18
%24 = select i1 %23, i32 %19, i32 %20
%25 = select i1 %23, double %22, double %18
%26 = add nuw nsw i32 %19, 1
%27 = load i32, i32* %1
%28 = icmp slt i32 %26, %27
br i1 %28, label %16, label %29
29: ; preds = %16
%30 = sext i32 %24 to i64
br label %31
31: ; preds = %29, %10
%32 = phi i64 [ 0, %10 ], [ %30, %29 ]
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
store double %34, double* %3
ret void
}