; LLVM IR from 3ki5tj/minmd :: src/lib/minmd_math/rng (test)

; 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"

; 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 @rng_rand01(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local double @rng_gauss(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  br label %8

8:                                                ; preds = %50, %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call double @rng_rand01(ptr noundef %9)
  %11 = fsub double 1.000000e+00, %10
  store double %11, ptr %5, align 8, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call double @rng_rand01(ptr noundef %12)
  %14 = fsub double %13, 5.000000e-01
  %15 = fmul double 1.715600e+00, %14
  store double %15, ptr %6, align 8, !tbaa !9
  %16 = load double, ptr %5, align 8, !tbaa !9
  %17 = fsub double %16, 4.498710e-01
  store double %17, ptr %3, align 8, !tbaa !9
  %18 = load double, ptr %6, align 8, !tbaa !9
  %19 = call double @llvm.fabs.f64(double %18)
  %20 = fadd double %19, 3.865950e-01
  store double %20, ptr %4, align 8, !tbaa !9
  %21 = load double, ptr %3, align 8, !tbaa !9
  %22 = load double, ptr %3, align 8, !tbaa !9
  %23 = load double, ptr %4, align 8, !tbaa !9
  %24 = load double, ptr %4, align 8, !tbaa !9
  %25 = load double, ptr %3, align 8, !tbaa !9
  %26 = fmul double 2.547200e-01, %25
  %27 = fneg double %26
  %28 = call double @llvm.fmuladd.f64(double 1.960000e-01, double %24, double %27)
  %29 = fmul double %23, %28
  %30 = call double @llvm.fmuladd.f64(double %21, double %22, double %29)
  store double %30, ptr %7, align 8, !tbaa !9
  %31 = load double, ptr %7, align 8, !tbaa !9
  %32 = fcmp olt double %31, 2.759700e-01
  br i1 %32, label %33, label %34

33:                                               ; preds = %8
  br label %52

34:                                               ; preds = %8
  br label %35

35:                                               ; preds = %34
  %36 = load double, ptr %7, align 8, !tbaa !9
  %37 = fcmp ogt double %36, 2.784600e-01
  br i1 %37, label %50, label %38

38:                                               ; preds = %35
  %39 = load double, ptr %6, align 8, !tbaa !9
  %40 = load double, ptr %6, align 8, !tbaa !9
  %41 = fmul double %39, %40
  %42 = load double, ptr %5, align 8, !tbaa !9
  %43 = fmul double -4.000000e+00, %42
  %44 = load double, ptr %5, align 8, !tbaa !9
  %45 = fmul double %43, %44
  %46 = load double, ptr %5, align 8, !tbaa !9
  %47 = call double @log(double noundef %46) #4
  %48 = fmul double %45, %47
  %49 = fcmp ogt double %41, %48
  br label %50

50:                                               ; preds = %38, %35
  %51 = phi i1 [ true, %35 ], [ %49, %38 ]
  br i1 %51, label %8, label %52, !llvm.loop !11

52:                                               ; preds = %50, %33
  %53 = load double, ptr %6, align 8, !tbaa !9
  %54 = load double, ptr %5, align 8, !tbaa !9
  %55 = fdiv double %53, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret double %55
}

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

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

; 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 = !{!"any pointer", !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"

; Function Attrs: nounwind uwtable
declare dso_local double @rng_rand01(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @rng_gauss(ptr noundef %0) local_unnamed_addr #0 {
  br label %.critedge

.critedge:                                        ; preds = %.critedge.backedge, %1
  %2 = tail call double @rng_rand01(ptr noundef %0)
  %3 = fsub double 1.000000e+00, %2
  %4 = tail call double @rng_rand01(ptr noundef %0)
  %5 = fadd double %4, -5.000000e-01
  %6 = fmul double %5, 1.715600e+00
  %7 = fadd double %3, -4.498710e-01
  %8 = tail call double @llvm.fabs.f64(double %6)
  %9 = fadd double %8, 3.865950e-01
  %10 = fmul double %7, -2.547200e-01
  %11 = tail call double @llvm.fmuladd.f64(double %9, double 1.960000e-01, double %10)
  %12 = fmul double %9, %11
  %13 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %12)
  %14 = fcmp olt double %13, 2.759700e-01
  br i1 %14, label %24, label %15

15:                                               ; preds = %.critedge
  %16 = fcmp ogt double %13, 2.784600e-01
  br i1 %16, label %.critedge.backedge, label %17

17:                                               ; preds = %15
  %18 = fmul double %6, %6
  %19 = fmul double %3, -4.000000e+00
  %20 = fmul double %3, %19
  %21 = tail call double @log(double noundef %3) #3
  %22 = fmul double %20, %21
  %23 = fcmp ogt double %18, %22
  br i1 %23, label %.critedge.backedge, label %24

.critedge.backedge:                               ; preds = %17, %15
  br label %.critedge, !llvm.loop !5

24:                                               ; preds = %.critedge, %17
  %25 = fdiv double %6, %3
  ret double %25
}

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

; 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 @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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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