; LLVM IR from FSmallenburg/EDMD :: Cell (mdCell)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@random_gaussian.have_deviate = external hidden global i32, align 4
@random_gaussian.u1 = external hidden global double, align 8
@random_gaussian.u2 = external hidden global double, align 8

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local double @genrand_real2() #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

; Function Attrs: nounwind uwtable
define dso_local double @random_gaussian() #1 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load i32, ptr @random_gaussian.have_deviate, align 4, !tbaa !5
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %10

8:                                                ; preds = %0
  store i32 0, ptr @random_gaussian.have_deviate, align 4, !tbaa !5
  %9 = load double, ptr @random_gaussian.u2, align 8, !tbaa !9
  store double %9, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %39

10:                                               ; preds = %0
  br label %11

11:                                               ; preds = %22, %10
  %12 = call double @genrand_real2()
  %13 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %12, double -1.000000e+00)
  store double %13, ptr %2, align 8, !tbaa !9
  %14 = call double @genrand_real2()
  %15 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %14, double -1.000000e+00)
  store double %15, ptr %3, align 8, !tbaa !9
  %16 = load double, ptr %2, align 8, !tbaa !9
  %17 = load double, ptr %2, align 8, !tbaa !9
  %18 = load double, ptr %3, align 8, !tbaa !9
  %19 = load double, ptr %3, align 8, !tbaa !9
  %20 = fmul double %18, %19
  %21 = call double @llvm.fmuladd.f64(double %16, double %17, double %20)
  store double %21, ptr %4, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %11
  %23 = load double, ptr %4, align 8, !tbaa !9
  %24 = fcmp oge double %23, 1.000000e+00
  br i1 %24, label %11, label %25, !llvm.loop !11

25:                                               ; preds = %22
  %26 = load double, ptr %4, align 8, !tbaa !9
  %27 = call double @log(double noundef %26) #4
  %28 = fmul double -2.000000e+00, %27
  %29 = load double, ptr %4, align 8, !tbaa !9
  %30 = fdiv double %28, %29
  %31 = call double @sqrt(double noundef %30) #4
  store double %31, ptr %4, align 8, !tbaa !9
  %32 = load double, ptr %2, align 8, !tbaa !9
  %33 = load double, ptr %4, align 8, !tbaa !9
  %34 = fmul double %32, %33
  store double %34, ptr @random_gaussian.u1, align 8, !tbaa !9
  %35 = load double, ptr %3, align 8, !tbaa !9
  %36 = load double, ptr %4, align 8, !tbaa !9
  %37 = fmul double %35, %36
  store double %37, ptr @random_gaussian.u2, align 8, !tbaa !9
  store i32 1, ptr @random_gaussian.have_deviate, align 4, !tbaa !5
  %38 = load double, ptr @random_gaussian.u1, align 8, !tbaa !9
  store double %38, ptr %1, align 8
  store i32 1, ptr %5, align 4
  br label %39

39:                                               ; preds = %25, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %40 = load double, ptr %1, align 8
  ret double %40
}

; Function Attrs: nounwind
declare double @log(double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@random_gaussian.have_deviate = external hidden local_unnamed_addr global i32, align 4
@random_gaussian.u1 = external hidden local_unnamed_addr global double, align 8
@random_gaussian.u2 = external hidden local_unnamed_addr global double, align 8

; Function Attrs: nounwind uwtable
declare dso_local double @genrand_real2() local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local double @random_gaussian() local_unnamed_addr #0 {
  %1 = load i32, ptr @random_gaussian.have_deviate, align 4, !tbaa !5
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.preheader, label %2

2:                                                ; preds = %0
  store i32 0, ptr @random_gaussian.have_deviate, align 4, !tbaa !5
  %3 = load double, ptr @random_gaussian.u2, align 8, !tbaa !9
  br label %18

.preheader:                                       ; preds = %0, %.preheader
  %4 = tail call double @genrand_real2()
  %5 = tail call double @llvm.fmuladd.f64(double %4, double 2.000000e+00, double -1.000000e+00)
  %6 = tail call double @genrand_real2()
  %7 = tail call double @llvm.fmuladd.f64(double %6, double 2.000000e+00, double -1.000000e+00)
  %8 = fmul double %7, %7
  %9 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %8)
  %10 = fcmp ult double %9, 1.000000e+00
  br i1 %10, label %11, label %.preheader, !llvm.loop !11

11:                                               ; preds = %.preheader
  %12 = tail call double @log(double noundef %9) #3
  %13 = fmul double %12, -2.000000e+00
  %14 = fdiv double %13, %9
  %15 = tail call double @sqrt(double noundef %14) #3
  %16 = fmul double %5, %15
  store double %16, ptr @random_gaussian.u1, align 8, !tbaa !9
  %17 = fmul double %7, %15
  store double %17, ptr @random_gaussian.u2, align 8, !tbaa !9
  store i32 1, ptr @random_gaussian.have_deviate, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %11, %2
  %.0 = phi double [ %3, %2 ], [ %16, %11 ]
  ret double %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #2

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass