#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 log(double);
double mydnorm(double x, double mu, double sd, int l) {
  double X = (x - mu) / sd;
  if (l == 1) {
    return -(0.918938533204672741780329736406 + 0.5 * X * X + log(sd));
  }
  return (0.39894228040143267793994605993 * exp(-0.5 * X * X) / sd);
}


x86 assembly (clang, -O0):
<mydnorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %edi,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    11b6 <mydnorm+0x96>
movsd  0xeb8(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe9a(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e6 <mydnorm+0xc6>
movsd  0xe4a(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xe28(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mydnorm>:
push   %rax
subsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
cmp    $0x1,%edi
jne    1163 <mydnorm+0x43>
movsd  0xeda(%rip),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
addsd  0xed2(%rip),%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm2,%xmm0
call   1040 <log@plt>
addsd  (%rsp),%xmm0
xorpd  0xebf(%rip),%xmm0
pop    %rax
ret
movsd  0xe95(%rip),%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
movsd  %xmm2,(%rsp)
call   1030 <exp@plt>
mulsd  0xe7f(%rip),%xmm0
divsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @mydnorm(double %0, double %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store i32 %3, i32* %9
%11 = load double, double* %6
%12 = load double, double* %7
%13 = fsub double %11, %12
%14 = load double, double* %8
%15 = fdiv double %13, %14
store double %15, double* %10
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %27
18: ; preds = %4
%19 = load double, double* %10
%20 = fmul double 5.000000e-01, %19
%21 = load double, double* %10
%22 = call double @llvm.fmuladd.f64(double %20, double %21, double 0x3FED67F1C864BEB5)
%23 = load double, double* %8
%24 = call double @log(double %23)
%25 = fadd double %22, %24
%26 = fneg double %25
store double %26, double* %5
br label %36
27: ; preds = %4
%28 = load double, double* %10
%29 = fmul double -5.000000e-01, %28
%30 = load double, double* %10
%31 = fmul double %29, %30
%32 = call double @exp(double %31)
%33 = fmul double 0x3FD9884533D43651, %32
%34 = load double, double* %8
%35 = fdiv double %33, %34
store double %35, double* %5
br label %36
36: ; preds = %27, %18
%37 = load double, double* %5
ret double %37
}

LLVM IR (-O2):
define double @mydnorm(double %0, double %1, double %2, i32 %3) {
%5 = fsub double %0, %1
%6 = fdiv double %5, %2
%7 = icmp eq i32 %3, 1
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = fmul double %6, 5.000000e-01
%10 = tail call double @llvm.fmuladd.f64(double %9, double %6, double 0x3FED67F1C864BEB5)
%11 = tail call double @log(double %2)
%12 = fadd double %10, %11
%13 = fneg double %12
br label %20
14: ; preds = %4
%15 = fmul double %6, -5.000000e-01
%16 = fmul double %6, %15
%17 = tail call double @exp(double %16)
%18 = fmul double %17, 0x3FD9884533D43651
%19 = fdiv double %18, %2
br label %20
20: ; preds = %14, %8
%21 = phi double [ %13, %8 ], [ %19, %14 ]
ret double %21
}