; LLVM IR from vmartinv/eldiego :: math/phollards.rho.ll (Z13es_primo_probxi)

; 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
declare dso_local noundef i64 @_Z6mulmodxxx(i64 noundef, i64 noundef, i64 noundef) #0

; 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
declare dso_local noundef i64 @_Z6expmodxxx(i64 noundef, i64 noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z13es_primo_probxi(i64 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %11 = load i64, ptr %4, align 8, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = icmp eq i64 %11, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i1 true, ptr %3, align 1
  br label %72

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = sub nsw i64 %17, 1
  store i64 %18, ptr %7, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %23, %16
  %20 = load i64, ptr %7, align 8, !tbaa !5
  %21 = srem i64 %20, 2
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %19
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = add nsw i64 %24, 1
  store i64 %25, ptr %6, align 8, !tbaa !5
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = sdiv i64 %26, 2
  store i64 %27, ptr %7, align 8, !tbaa !5
  br label %19, !llvm.loop !11

28:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = load i64, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = call noundef i64 @_Z6expmodxxx(i64 noundef %30, i64 noundef %31, i64 noundef %32)
  store i64 %33, ptr %8, align 8, !tbaa !5
  %34 = load i64, ptr %8, align 8, !tbaa !5
  %35 = icmp eq i64 %34, 1
  br i1 %35, label %41, label %36

36:                                               ; preds = %28
  %37 = load i64, ptr %8, align 8, !tbaa !5
  %38 = add nsw i64 %37, 1
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = icmp eq i64 %38, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %36, %28
  store i1 true, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %71

42:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %65, %42
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = load i64, ptr %6, align 8, !tbaa !5
  %47 = sub nsw i64 %46, 1
  %48 = icmp slt i64 %45, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %43
  store i32 4, ptr %9, align 4
  br label %68

50:                                               ; preds = %43
  %51 = load i64, ptr %8, align 8, !tbaa !5
  %52 = load i64, ptr %8, align 8, !tbaa !5
  %53 = load i64, ptr %4, align 8, !tbaa !5
  %54 = call noundef i64 @_Z6mulmodxxx(i64 noundef %51, i64 noundef %52, i64 noundef %53)
  store i64 %54, ptr %8, align 8, !tbaa !5
  %55 = load i64, ptr %8, align 8, !tbaa !5
  %56 = icmp eq i64 %55, 1
  br i1 %56, label %57, label %58

57:                                               ; preds = %50
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %68

58:                                               ; preds = %50
  %59 = load i64, ptr %8, align 8, !tbaa !5
  %60 = add nsw i64 %59, 1
  %61 = load i64, ptr %4, align 8, !tbaa !5
  %62 = icmp eq i64 %60, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %58
  store i1 true, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %68

64:                                               ; preds = %58
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %10, align 4, !tbaa !9
  br label %43, !llvm.loop !13

68:                                               ; preds = %63, %57, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %69 = load i32, ptr %9, align 4
  switch i32 %69, label %71 [
    i32 4, label %70
  ]

70:                                               ; preds = %68
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %71

71:                                               ; preds = %70, %68, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %72

72:                                               ; preds = %71, %15
  %73 = load i1, ptr %3, align 1
  ret i1 %73
}

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 = { 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 #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 = !{!"long long", !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 nounwind uwtable
declare dso_local noundef i64 @_Z6mulmodxxx(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z6expmodxxx(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z13es_primo_probxi(i64 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = sext i32 %1 to i64
  %4 = icmp eq i64 %3, %0
  br i1 %4, label %._crit_edge40, label %5

5:                                                ; preds = %2
  %6 = add nsw i64 %0, -1
  %7 = and i64 %6, 1
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.02433 = phi i64 [ %10, %.lr.ph ], [ %6, %5 ]
  %.02532 = phi i64 [ %9, %.lr.ph ], [ 0, %5 ]
  %9 = add nuw nsw i64 %.02532, 1
  %10 = ashr exact i64 %.02433, 1
  %11 = and i64 %.02433, 2
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.025.lcssa = phi i64 [ -1, %5 ], [ %.02532, %.lr.ph ]
  %.024.lcssa = phi i64 [ %6, %5 ], [ %10, %.lr.ph ]
  %13 = tail call noundef i64 @_Z6expmodxxx(i64 noundef %3, i64 noundef %.024.lcssa, i64 noundef %0)
  %14 = icmp eq i64 %13, 1
  %15 = add nsw i64 %13, 1
  %16 = icmp eq i64 %15, %0
  %or.cond = select i1 %14, i1 true, i1 %16
  br i1 %or.cond, label %._crit_edge40, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %.not35 = icmp sgt i64 %.025.lcssa, 0
  br i1 %.not35, label %.lr.ph39.preheader, label %._crit_edge40

.lr.ph39.preheader:                               ; preds = %.preheader
  %17 = tail call noundef i64 @_Z6mulmodxxx(i64 noundef %13, i64 noundef %13, i64 noundef %0)
  %18 = icmp eq i64 %17, 1
  br i1 %18, label %._crit_edge40, label %.lr.ph51

19:                                               ; preds = %.lr.ph51
  %indvars.iv.next = add nuw nsw i64 %indvars.iv49, 1
  %.not = icmp sgt i64 %.025.lcssa, %indvars.iv.next
  %exitcond.not = icmp eq i64 %indvars.iv.next, %.025.lcssa
  br i1 %exitcond.not, label %._crit_edge40.loopexit.loopexit, label %.lr.ph39, !llvm.loop !7

.lr.ph39:                                         ; preds = %19
  %20 = tail call noundef i64 @_Z6mulmodxxx(i64 noundef %22, i64 noundef %22, i64 noundef %0)
  %21 = icmp eq i64 %20, 1
  br i1 %21, label %._crit_edge40.loopexit.loopexit, label %.lr.ph51, !llvm.loop !7

.lr.ph51:                                         ; preds = %.lr.ph39.preheader, %.lr.ph39
  %22 = phi i64 [ %20, %.lr.ph39 ], [ %17, %.lr.ph39.preheader ]
  %.not3850 = phi i1 [ %.not, %.lr.ph39 ], [ true, %.lr.ph39.preheader ]
  %indvars.iv49 = phi i64 [ %indvars.iv.next, %.lr.ph39 ], [ 0, %.lr.ph39.preheader ]
  %23 = add nsw i64 %22, 1
  %24 = icmp eq i64 %23, %0
  br i1 %24, label %._crit_edge40.loopexit.loopexit, label %19

._crit_edge40.loopexit.loopexit:                  ; preds = %.lr.ph51, %.lr.ph39, %19
  %.not.lcssa.ph.ph = phi i1 [ %.not, %19 ], [ %.not, %.lr.ph39 ], [ %.not3850, %.lr.ph51 ]
  %.026.ph.ph = phi i1 [ undef, %19 ], [ false, %.lr.ph39 ], [ true, %.lr.ph51 ]
  %25 = and i1 %.not.lcssa.ph.ph, %.026.ph.ph
  br label %._crit_edge40

._crit_edge40:                                    ; preds = %.lr.ph39.preheader, %._crit_edge40.loopexit.loopexit, %.preheader, %._crit_edge, %2
  %.2 = phi i1 [ true, %2 ], [ true, %._crit_edge ], [ false, %.preheader ], [ false, %.lr.ph39.preheader ], [ %25, %._crit_edge40.loopexit.loopexit ]
  ret i1 %.2
}

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 = { 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" }

!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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass