; LLVM IR from cieslarmichal/rpg :: src/Random.ll (ZN6Random12isSuccessfulEd)

; 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 uwtable
declare dso_local noundef i32 @_ZN6Random15getRandomNumberEii(i32 noundef, i32 noundef) #0 align 2

; 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

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

7:                                                ; preds = %10, %1
  %8 = load double, ptr %3, align 8, !tbaa !5
  %9 = fcmp ole double %8, 1.000000e+02
  br i1 %9, label %10, label %15

10:                                               ; preds = %7
  %11 = load double, ptr %3, align 8, !tbaa !5
  %12 = fmul double %11, 1.000000e+01
  store double %12, ptr %3, align 8, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %4, align 4, !tbaa !9
  br label %7, !llvm.loop !11

15:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = sitofp i32 %16 to double
  %18 = call double @pow(double noundef 1.000000e+01, double noundef %17) #3
  %19 = fptosi double %18 to i32
  %20 = call noundef i32 @_ZN6Random15getRandomNumberEii(i32 noundef 1, i32 noundef %19)
  store i32 %20, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %15
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sitofp i32 %24 to double
  %26 = load double, ptr %3, align 8, !tbaa !5
  %27 = fcmp ole double %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %30

29:                                               ; preds = %23, %15
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %30

30:                                               ; preds = %29, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %31 = load i1, ptr %2, align 1
  ret i1 %31
}

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

attributes #0 = { mustprogress 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 "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 = !{!"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"}


; 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 uwtable
declare dso_local noundef i32 @_ZN6Random15getRandomNumberEii(i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN6Random12isSuccessfulEd(double noundef %0) local_unnamed_addr #0 align 2 {
  %2 = fcmp ugt double %0, 1.000000e+02
  br i1 %2, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.0713 = phi i32 [ %4, %.lr.ph ], [ 0, %1 ]
  %.0812 = phi double [ %3, %.lr.ph ], [ %0, %1 ]
  %3 = fmul double %.0812, 1.000000e+01
  %4 = add nuw nsw i32 %.0713, 1
  %5 = fcmp ugt double %3, 1.000000e+02
  br i1 %5, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !5

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %6 = uitofp nneg i32 %4 to double
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.08.lcssa = phi double [ %0, %1 ], [ %3, %._crit_edge.loopexit ]
  %.07.lcssa = phi double [ 0.000000e+00, %1 ], [ %6, %._crit_edge.loopexit ]
  %7 = tail call double @pow(double noundef 1.000000e+01, double noundef %.07.lcssa) #2
  %8 = fptosi double %7 to i32
  %9 = tail call noundef i32 @_ZN6Random15getRandomNumberEii(i32 noundef 1, i32 noundef %8)
  %10 = icmp sgt i32 %9, 0
  %11 = uitofp nneg i32 %9 to double
  %12 = fcmp oge double %.08.lcssa, %11
  %or.cond.not = select i1 %10, i1 %12, i1 false
  ret i1 %or.cond.not
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #1

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


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