; LLVM IR from ShahjalalShohag/code-library :: Number Theory/Number of Solutions to x^2 = 1 mod m.ll (ZN10PollardRho11pollard_rhoEx)

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

%"class.std::mersenne_twister_engine" = type { [624 x i64], i64 }

@_ZN10PollardRho3rndE = external dso_local global %"class.std::mersenne_twister_engine", align 8
@_ZN10PollardRho3seqE = external dso_local global [1000009 x i64], align 16

; 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: mustprogress uwtable
define dso_local noundef i64 @_ZN10PollardRho11pollard_rhoEx(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %96, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %14 = call noundef i64 @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv(ptr noundef nonnull align 8 dereferenceable(5000) @_ZN10PollardRho3rndE)
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %16 = urem i64 %14, %15
  store i64 %16, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %17 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = call noundef i64 @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv(ptr noundef nonnull align 8 dereferenceable(5000) @_ZN10PollardRho3rndE)
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = urem i64 %18, %19
  store i64 %20, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 1, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store ptr @_ZN10PollardRho3seqE, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr @_ZN10PollardRho3seqE, ptr %11, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %78, %13
  br label %22

22:                                               ; preds = %21
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %5, align 8, !tbaa !5
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = call noundef i64 @_ZN10PollardRho7mul_modExxx(i64 noundef %23, i64 noundef %24, i64 noundef %25)
  %27 = load i64, ptr %6, align 8, !tbaa !5
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = call noundef i64 @_ZN10PollardRho7add_modExxx(i64 noundef %26, i64 noundef %27, i64 noundef %28)
  store i64 %29, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %11, align 8, !tbaa !9
  %31 = getelementptr inbounds i64, ptr %30, i32 1
  store ptr %31, ptr %11, align 8, !tbaa !9
  store i64 %29, ptr %30, align 8, !tbaa !5
  %32 = load i64, ptr %5, align 8, !tbaa !5
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = call noundef i64 @_ZN10PollardRho7mul_modExxx(i64 noundef %32, i64 noundef %33, i64 noundef %34)
  %36 = load i64, ptr %6, align 8, !tbaa !5
  %37 = load i64, ptr %3, align 8, !tbaa !5
  %38 = call noundef i64 @_ZN10PollardRho7add_modExxx(i64 noundef %35, i64 noundef %36, i64 noundef %37)
  store i64 %38, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !9
  %40 = getelementptr inbounds i64, ptr %39, i32 1
  store ptr %40, ptr %11, align 8, !tbaa !9
  store i64 %38, ptr %39, align 8, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = getelementptr inbounds i64, ptr %41, i32 1
  store ptr %42, ptr %10, align 8, !tbaa !9
  %43 = load i64, ptr %41, align 8, !tbaa !5
  store i64 %43, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = icmp eq i64 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %22
  br label %79

47:                                               ; preds = %22
  %48 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %48, ptr %8, align 8, !tbaa !5
  %49 = load i64, ptr %7, align 8, !tbaa !5
  %50 = load i64, ptr %5, align 8, !tbaa !5
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = sub nsw i64 %50, %51
  %53 = call noundef i64 @_ZSt3absx(i64 noundef %52)
  %54 = load i64, ptr %3, align 8, !tbaa !5
  %55 = call noundef i64 @_ZN10PollardRho7mul_modExxx(i64 noundef %49, i64 noundef %53, i64 noundef %54)
  store i64 %55, ptr %7, align 8, !tbaa !5
  %56 = load i64, ptr %7, align 8, !tbaa !5
  %57 = icmp ne i64 %56, 0
  br i1 %57, label %62, label %58

58:                                               ; preds = %47
  %59 = load i64, ptr %8, align 8, !tbaa !5
  %60 = load i64, ptr %3, align 8, !tbaa !5
  %61 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %59, i64 noundef %60)
  store i64 %61, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %94

62:                                               ; preds = %47
  %63 = load i64, ptr %9, align 8, !tbaa !5
  %64 = add nsw i64 %63, 1
  store i64 %64, ptr %9, align 8, !tbaa !5
  %65 = icmp eq i64 %64, 32
  br i1 %65, label %66, label %78

66:                                               ; preds = %62
  store i64 0, ptr %9, align 8, !tbaa !5
  %67 = load i64, ptr %7, align 8, !tbaa !5
  %68 = load i64, ptr %3, align 8, !tbaa !5
  %69 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %67, i64 noundef %68)
  store i64 %69, ptr %7, align 8, !tbaa !5
  %70 = icmp sgt i64 %69, 1
  br i1 %70, label %71, label %77

71:                                               ; preds = %66
  %72 = load i64, ptr %7, align 8, !tbaa !5
  %73 = load i64, ptr %3, align 8, !tbaa !5
  %74 = icmp slt i64 %72, %73
  br i1 %74, label %75, label %77

75:                                               ; preds = %71
  %76 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %76, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %94

77:                                               ; preds = %71, %66
  br label %78

78:                                               ; preds = %77, %62
  br label %21, !llvm.loop !11

79:                                               ; preds = %46
  %80 = load i64, ptr %9, align 8, !tbaa !5
  %81 = icmp ne i64 %80, 0
  br i1 %81, label %82, label %93

82:                                               ; preds = %79
  %83 = load i64, ptr %7, align 8, !tbaa !5
  %84 = load i64, ptr %3, align 8, !tbaa !5
  %85 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %83, i64 noundef %84)
  store i64 %85, ptr %7, align 8, !tbaa !5
  %86 = icmp sgt i64 %85, 1
  br i1 %86, label %87, label %93

87:                                               ; preds = %82
  %88 = load i64, ptr %7, align 8, !tbaa !5
  %89 = load i64, ptr %3, align 8, !tbaa !5
  %90 = icmp slt i64 %88, %89
  br i1 %90, label %91, label %93

91:                                               ; preds = %87
  %92 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %92, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %94

93:                                               ; preds = %87, %82, %79
  store i32 0, ptr %12, align 4
  br label %94

94:                                               ; preds = %93, %91, %75, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  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
  %95 = load i32, ptr %12, align 4
  switch i32 %95, label %99 [
    i32 0, label %96
    i32 1, label %97
  ]

96:                                               ; preds = %94
  br label %13, !llvm.loop !13

97:                                               ; preds = %94
  %98 = load i64, ptr %2, align 8
  ret i64 %98

99:                                               ; preds = %94
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv(ptr noundef nonnull align 8 dereferenceable(5000)) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN10PollardRho7add_modExxx(i64 noundef, i64 noundef, i64 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN10PollardRho7mul_modExxx(i64 noundef, i64 noundef, i64 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { inlinehint 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 #3 = { 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 #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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

%"class.std::mersenne_twister_engine" = type { [624 x i64], i64 }

@_ZN10PollardRho3rndE = external dso_local global %"class.std::mersenne_twister_engine", align 8
@_ZN10PollardRho3seqE = external dso_local local_unnamed_addr global [1000009 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN10PollardRho11pollard_rhoEx(i64 noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %.backedge84, %1
  %3 = tail call noundef i64 @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv(ptr noundef nonnull align 8 dereferenceable(5000) @_ZN10PollardRho3rndE)
  %4 = urem i64 %3, %0
  %5 = tail call noundef i64 @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv(ptr noundef nonnull align 8 dereferenceable(5000) @_ZN10PollardRho3rndE)
  %6 = urem i64 %5, %0
  br label %7

7:                                                ; preds = %.backedge, %2
  %.045 = phi i64 [ %4, %2 ], [ %12, %.backedge ]
  %.043 = phi i64 [ 1, %2 ], [ %.043.be, %.backedge ]
  %.040 = phi i64 [ 0, %2 ], [ %.040.be, %.backedge ]
  %.039 = phi ptr [ @_ZN10PollardRho3seqE, %2 ], [ %14, %.backedge ]
  %.038 = phi ptr [ @_ZN10PollardRho3seqE, %2 ], [ %13, %.backedge ]
  %8 = tail call noundef i64 @_ZN10PollardRho7mul_modExxx(i64 noundef %.045, i64 noundef %.045, i64 noundef %0)
  %9 = tail call noundef i64 @_ZN10PollardRho7add_modExxx(i64 noundef %8, i64 noundef %6, i64 noundef %0)
  %10 = getelementptr inbounds i8, ptr %.038, i64 8
  store i64 %9, ptr %.038, align 8, !tbaa !5
  %11 = tail call noundef i64 @_ZN10PollardRho7mul_modExxx(i64 noundef %9, i64 noundef %9, i64 noundef %0)
  %12 = tail call noundef i64 @_ZN10PollardRho7add_modExxx(i64 noundef %11, i64 noundef %6, i64 noundef %0)
  %13 = getelementptr inbounds i8, ptr %.038, i64 16
  store i64 %12, ptr %10, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.039, i64 8
  %15 = load i64, ptr %.039, align 8, !tbaa !5
  %16 = icmp eq i64 %15, %12
  br i1 %16, label %30, label %17

17:                                               ; preds = %7
  %18 = sub nsw i64 %12, %15
  %19 = tail call noundef i64 @_ZSt3absx(i64 noundef %18)
  %20 = tail call noundef i64 @_ZN10PollardRho7mul_modExxx(i64 noundef %.043, i64 noundef %19, i64 noundef %0)
  %.not = icmp eq i64 %20, 0
  br i1 %.not, label %21, label %23

21:                                               ; preds = %17
  %22 = tail call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %.043, i64 noundef %0)
  br label %.loopexit

23:                                               ; preds = %17
  %24 = add nsw i64 %.040, 1
  %25 = icmp eq i64 %24, 32
  br i1 %25, label %26, label %.backedge

26:                                               ; preds = %23
  %27 = tail call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %20, i64 noundef %0)
  %28 = icmp sgt i64 %27, 1
  %29 = icmp slt i64 %27, %0
  %or.cond = and i1 %28, %29
  br i1 %or.cond, label %.loopexit, label %.backedge

.backedge:                                        ; preds = %26, %23
  %.043.be = phi i64 [ %27, %26 ], [ %20, %23 ]
  %.040.be = phi i64 [ 0, %26 ], [ %24, %23 ]
  br label %7, !llvm.loop !9

30:                                               ; preds = %7
  %.not53 = icmp eq i64 %.040, 0
  br i1 %.not53, label %.backedge84, label %31

.backedge84:                                      ; preds = %30, %31
  br label %2

31:                                               ; preds = %30
  %32 = tail call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %.043, i64 noundef %0)
  %33 = icmp sgt i64 %32, 1
  %34 = icmp slt i64 %32, %0
  %or.cond54 = and i1 %33, %34
  br i1 %or.cond54, label %.loopexit, label %.backedge84

.loopexit:                                        ; preds = %31, %26, %21
  %.142.ph = phi i64 [ %22, %21 ], [ %27, %26 ], [ %32, %31 ]
  ret i64 %.142.ph
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv(ptr noundef nonnull align 8 dereferenceable(5000)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) local_unnamed_addr #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 = { inlinehint 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 #2 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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