; LLVM IR from TheAlgorithms/C-Plus-Plus :: probability/binomial_dist.ll (Z3nCrdd)

; 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: mustprogress nounwind uwtable
define dso_local noundef double @_Z3nCrdd(double noundef %0, double noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store double %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %9 = load double, ptr %3, align 8, !tbaa !5
  store double %9, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %10 = load double, ptr %4, align 8, !tbaa !5
  store double %10, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %11 = load double, ptr %3, align 8, !tbaa !5
  %12 = fsub double %11, 1.000000e+00
  %13 = fptosi double %12 to i32
  store i32 %13, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %28, %2
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = sitofp i32 %15 to double
  %17 = load double, ptr %3, align 8, !tbaa !5
  %18 = load double, ptr %4, align 8, !tbaa !5
  %19 = fsub double %17, %18
  %20 = fadd double %19, 1.000000e+00
  %21 = fcmp oge double %16, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %31

23:                                               ; preds = %14
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sitofp i32 %24 to double
  %26 = load double, ptr %5, align 8, !tbaa !5
  %27 = fmul double %26, %25
  store double %27, ptr %5, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %23
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !11

31:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %43, %31
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = sitofp i32 %33 to double
  %35 = load double, ptr %4, align 8, !tbaa !5
  %36 = fcmp olt double %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %46

38:                                               ; preds = %32
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = sitofp i32 %39 to double
  %41 = load double, ptr %6, align 8, !tbaa !5
  %42 = fmul double %41, %40
  store double %42, ptr %6, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %38
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %8, align 4, !tbaa !9
  br label %32, !llvm.loop !13

46:                                               ; preds = %37
  %47 = load double, ptr %5, align 8, !tbaa !5
  %48 = load double, ptr %6, align 8, !tbaa !5
  %49 = fdiv double %47, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret double %49
}

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

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef double @_Z3nCrdd(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = fadd double %0, -1.000000e+00
  %4 = fptosi double %3 to i32
  %5 = fsub double %0, %1
  %6 = fadd double %5, 1.000000e+00
  %7 = sitofp i32 %4 to double
  %8 = fcmp ugt double %6, %7
  br i1 %8, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %2
  %.017.lcssa = phi double [ %0, %2 ], [ %11, %.lr.ph ]
  %9 = fcmp ogt double %1, 1.000000e+00
  br i1 %9, label %.lr.ph24, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %10 = phi double [ %13, %.lr.ph ], [ %7, %2 ]
  %.01521 = phi i32 [ %12, %.lr.ph ], [ %4, %2 ]
  %.01720 = phi double [ %11, %.lr.ph ], [ %0, %2 ]
  %11 = fmul double %.01720, %10
  %12 = add nsw i32 %.01521, -1
  %13 = sitofp i32 %12 to double
  %14 = fcmp ugt double %6, %13
  br i1 %14, label %.preheader, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph24, %.preheader
  %.016.lcssa = phi double [ %1, %.preheader ], [ %17, %.lr.ph24 ]
  %15 = fdiv double %.017.lcssa, %.016.lcssa
  ret double %15

.lr.ph24:                                         ; preds = %.preheader, %.lr.ph24
  %16 = phi double [ %19, %.lr.ph24 ], [ 1.000000e+00, %.preheader ]
  %.023 = phi i32 [ %18, %.lr.ph24 ], [ 1, %.preheader ]
  %.01622 = phi double [ %17, %.lr.ph24 ], [ %1, %.preheader ]
  %17 = fmul double %.01622, %16
  %18 = add nuw nsw i32 %.023, 1
  %19 = uitofp nneg i32 %18 to double
  %20 = fcmp olt double %19, %1
  br i1 %20, label %.lr.ph24, label %._crit_edge, !llvm.loop !7
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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" }

!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"}
!7 = distinct !{!7, !6}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass